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 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056
|
/**
* @file
* @brief Functions related to ranged attacks.
**/
#include "AppHdr.h"
#include "beam.h"
#include <algorithm>
#include <cmath>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <set>
#include "act-iter.h"
#include "areas.h"
#include "attack.h"
#include "attitude-change.h"
#include "bloodspatter.h"
#include "chardump.h"
#include "cloud.h"
#include "colour.h"
#include "coordit.h"
#include "delay.h"
#include "directn.h"
#include "dungeon.h"
#include "english.h"
#include "exercise.h"
#include "fight.h"
#include "fineff.h"
#include "god-abil.h"
#include "god-conduct.h"
#include "god-item.h"
#include "god-passive.h" // passive_t::convert_orcs
#include "item-use.h"
#include "item-prop.h"
#include "items.h"
#include "killer-type.h"
#include "libutil.h"
#include "losglobal.h"
#include "los.h"
#include "message.h"
#include "misc.h"
#include "mon-behv.h"
#include "mon-clone.h"
#include "mon-death.h"
#include "mon-explode.h"
#include "mon-place.h"
#include "mon-poly.h"
#include "mon-util.h"
#include "mutation.h"
#include "nearby-danger.h"
#include "options.h"
#include "player-stats.h"
#include "potion.h"
#include "prompt.h"
#include "ranged-attack.h"
#include "religion.h"
#include "shout.h"
#include "spl-book.h"
#include "spl-clouds.h"
#include "spl-damage.h"
#include "spl-goditem.h"
#include "spl-monench.h"
#include "spl-summoning.h"
#include "spl-transloc.h"
#include "spl-util.h"
#include "spl-zap.h"
#include "state.h"
#include "stepdown.h"
#include "stringutil.h"
#include "target.h"
#include "teleport.h"
#include "terrain.h"
#include "throw.h"
#ifdef USE_TILE
#include "tilepick.h"
#endif
#include "tiles-build-specific.h"
#include "transform.h"
#include "traps.h"
#include "viewchar.h"
#include "view.h"
#include "xom.h"
// Helper functions (some of these should probably be public).
static void _ench_animation(int flavour, const monster* mon = nullptr,
bool force = false);
static beam_type _chaos_beam_flavour(bolt* beam);
static string _beam_type_name(beam_type type);
int _ench_pow_to_dur(int pow);
tracer_info::tracer_info()
{
reset();
}
void tracer_info::reset()
{
count = power = 0;
}
bolt::bolt() : animate(bool(Options.use_animations & UA_BEAM)) {}
bool bolt::is_blockable() const
{
// BEAM_ELECTRICITY is added here because chain lightning is not
// a true beam (stops at the first target it gets to and redirects
// from there)... but we don't want it shield blockable.
return !pierce && !is_explosion && flavour != BEAM_ELECTRICITY
&& hit != AUTOMATIC_HIT && flavour != BEAM_VISUAL;
}
/// Can 'omnireflection' (from the Warlock's Mirror) potentially reflect this?
bool bolt::is_omnireflectable() const
{
return !is_explosion && flavour != BEAM_VISUAL
&& origin_spell != SPELL_GLACIATE
&& flavour != BEAM_VAMPIRIC_DRAINING; // buggy :(
}
void bolt::emit_message(const char* m)
{
const string message = m;
if (!message_cache.count(message))
mpr(m);
message_cache.insert(message);
}
kill_category bolt::whose_kill() const
{
if (YOU_KILL(thrower) || source_id == MID_YOU_FAULTLESS)
return KC_YOU;
else if (MON_KILL(thrower))
{
if (source_id == MID_ANON_FRIEND)
return KC_FRIENDLY;
const monster* mon = monster_by_mid(source_id);
if (mon && mon->friendly())
return KC_FRIENDLY;
}
return KC_OTHER;
}
// A simple animated flash from Rupert Smith (expanded to be more
// generic).
static void _zap_animation(int colour, const monster* mon = nullptr,
bool force = false)
{
coord_def p = you.pos();
if (mon)
{
if (!force && !mon->visible_to(&you))
return;
p = mon->pos();
}
if (!you.see_cell(p))
return;
const coord_def drawp = grid2view(p);
if (in_los_bounds_v(drawp))
{
#ifdef USE_TILE
view_add_tile_overlay(p, tileidx_zap(colour));
#endif
view_add_glyph_overlay(p, {dchar_glyph(DCHAR_FIRED_ZAP),
static_cast<unsigned short>(colour)});
animation_delay(50, true);
}
}
// Special front function for zap_animation to interpret enchantment flavours.
static void _ench_animation(int flavour, const monster* mon, bool force)
{
element_type elem;
switch (flavour)
{
case BEAM_HEALING:
elem = ETC_HEAL;
break;
case BEAM_INFESTATION:
case BEAM_PAIN:
case BEAM_AGONY:
case BEAM_CURSE_OF_AGONY:
case BEAM_VILE_CLUTCH:
case BEAM_VAMPIRIC_DRAINING:
case BEAM_SOUL_SPLINTER:
elem = ETC_UNHOLY;
break;
case BEAM_DISPEL_UNDEAD:
elem = ETC_HOLY;
break;
case BEAM_POLYMORPH:
case BEAM_MALMUTATE:
elem = ETC_MUTAGENIC;
break;
case BEAM_CHAOS:
elem = ETC_RANDOM;
break;
case BEAM_TELEPORT:
case BEAM_BANISH:
case BEAM_BLINK:
case BEAM_BLINK_CLOSE:
case BEAM_BECKONING:
elem = ETC_WARP;
break;
case BEAM_MAGIC:
elem = ETC_MAGIC;
break;
case BEAM_ROOTS:
elem = ETC_EARTH;
break;
default:
elem = ETC_ENCHANT;
break;
}
_zap_animation(element_colour(elem), mon, force);
}
// If needs_tracer is true, we need to check the beam path for friendly
// monsters.
spret zapping(zap_type ztype, int power, bolt &pbolt,
bool needs_tracer, const char* msg, bool fail)
{
dprf(DIAG_BEAM, "zapping: power=%d", power);
pbolt.thrower = KILL_YOU_MISSILE;
// Check whether tracer goes through friendlies.
// NOTE: Whenever zapping() is called with a randomised value for power
// (or effect), player_tracer should be called directly with the highest
// power possible respecting current skill, experience level, etc.
if (needs_tracer && !player_tracer(ztype, power, pbolt))
return spret::abort;
fail_check();
// Fill in the bolt structure.
zappy(ztype, power, false, pbolt);
if (msg)
mpr(msg);
if (ztype == ZAP_DIG)
pbolt.aimed_at_spot = false;
// XXX: Not an explosion internally, which would do this automatically,
// but is aimed like one and should behavior like one UI-wise.
else if (ztype == ZAP_RUST_BREATH)
pbolt.aimed_at_spot = true;
pbolt.fire();
return spret::success;
}
void fire_partial_player_tracer(zap_type ztype, int power,
player_beam_tracer& tracer,
bolt &pbolt, int range)
{
// Non-controlleable during confusion.
// (We'll shoot in a different direction anyway.)
if (you.confused())
return;
zappy(ztype, power, false, pbolt);
pbolt.source = you.pos();
pbolt.source_id = MID_PLAYER;
pbolt.attitude = ATT_FRIENDLY;
pbolt.thrower = KILL_YOU_MISSILE;
pbolt.overshoot_prompt = false;
pbolt.passed_target = false;
// Clear misc
pbolt.seen = false;
pbolt.heard = false;
pbolt.reflections = 0;
pbolt.bounces = 0;
pbolt.loudness = 0;
// Save range before overriding it
const int old_range = pbolt.range;
if (range)
pbolt.range = range;
pbolt.fire(tracer);
if (range)
pbolt.range = old_range;
}
// Returns true if the path is considered "safe", and false if there are
// monsters in the way the player doesn't want to hit.
bool player_tracer(zap_type ztype, int power, bolt &pbolt, int range)
{
// Non-controlleable during confusion.
// (We'll shoot in a different direction anyway.)
if (you.confused())
return true;
player_beam_tracer tracer;
fire_partial_player_tracer(ztype, power, tracer, pbolt, range);
if (cancel_beam_prompt(pbolt, tracer))
{
dprf(DIAG_BEAM, "Beam cancelled.");
you.turn_is_over = false;
return false;
}
if (pbolt.friendly_past_target)
pbolt.aimed_at_spot = true;
return true;
}
// Returns true if the player wants / needs to abort based on god displeasure
// with targeting this target with this spell. Returns false otherwise.
static bool _stop_because_god_hates_target_prompt(const monster* mon,
spell_type spell,
bool check_only = false)
{
if (spell == SPELL_TUKIMAS_DANCE)
{
const item_def * const first = mon->weapon(0);
const item_def * const second = mon->weapon(1);
bool prompt = first && god_hates_item(*first)
|| second && god_hates_item(*second);
if (prompt)
{
if (check_only)
return true;
if (!yesno("Animating this weapon would place you under penance. "
"Really cast this spell?", false, 'n'))
{
canned_msg(MSG_OK);
return true;
}
}
}
return false;
}
struct zap_info
{
zap_type ztype;
const char* name; // nullptr means handled specially
int player_power_cap;
dam_deducer* player_damage;
tohit_deducer* player_tohit; // Enchantments have power modifier here
dam_deducer* monster_damage;
tohit_deducer* monster_tohit;
colour_t colour;
bool is_enchantment;
beam_type flavour;
dungeon_char_type glyph;
bool can_beam;
bool is_explosion;
tileidx_t tile_beam;
tileidx_t tile_explode;
};
#include "zap-data.h"
static int zap_index[NUM_ZAPS];
void init_zap_index()
{
for (int i = 0; i < NUM_ZAPS; ++i)
zap_index[i] = -1;
for (unsigned int i = 0; i < ARRAYSZ(zap_data); ++i)
zap_index[zap_data[i].ztype] = i;
}
static const zap_info* _seek_zap(zap_type z_type)
{
ASSERT_RANGE(z_type, 0, NUM_ZAPS);
if (zap_index[z_type] == -1)
return nullptr;
else
return &zap_data[zap_index[z_type]];
}
bool zap_explodes(zap_type z_type)
{
const zap_info* zinfo = _seek_zap(z_type);
return zinfo && zinfo->is_explosion;
}
bool zap_is_enchantment(zap_type z_type)
{
const zap_info* zinfo = _seek_zap(z_type);
return zinfo && zinfo->is_enchantment;
}
int zap_to_hit(zap_type z_type, int power, bool is_monster)
{
const zap_info* zinfo = _seek_zap(z_type);
if (!zinfo)
return 0;
const tohit_deducer* hit_calc = is_monster ? zinfo->monster_tohit
: zinfo->player_tohit;
if (zinfo->is_enchantment)
return 0;
ASSERT(hit_calc);
const int hit = (*hit_calc)(power);
if (hit != AUTOMATIC_HIT && !is_monster && crawl_state.need_save)
return max(0, hit - you.inaccuracy_penalty());
return hit;
}
dice_def zap_damage(zap_type z_type, int power, bool is_monster, bool random)
{
const zap_info* zinfo = _seek_zap(z_type);
if (!zinfo)
return dice_def(0,0);
const dam_deducer* dam_calc = is_monster ? zinfo->monster_damage
: zinfo->player_damage;
return dam_calc ? (*dam_calc)(power, random) : dice_def(0,0);
}
colour_t zap_colour(zap_type z_type)
{
const zap_info* zinfo = _seek_zap(z_type);
if (!zinfo)
return BLACK;
return zinfo->colour;
}
int zap_power_cap(zap_type z_type)
{
const zap_info* zinfo = _seek_zap(z_type);
return zinfo ? zinfo->player_power_cap : 0;
}
int zap_ench_power(zap_type z_type, int pow, bool is_monster)
{
const zap_info* zinfo = _seek_zap(z_type);
if (!zinfo)
return pow;
if (zinfo->player_power_cap > 0 && !is_monster)
pow = min(zinfo->player_power_cap, pow);
tohit_deducer* ench_calc = is_monster ? zinfo->monster_tohit
: zinfo->player_tohit;
if (zinfo->is_enchantment && ench_calc)
return (*ench_calc)(pow);
else
return pow;
}
static int _zap_loudness(zap_type zap, spell_type spell)
{
const zap_info* zinfo = _seek_zap(zap);
const int noise = spell_effect_noise(spell);
const spell_flags flags = get_spell_flags(spell);
// Explosions have noise handled separately.
if (zinfo->is_explosion || testbits(flags, spflag::silent))
return 0;
else if (noise > 0)
return noise;
// Enchantments are (usually) silent.
else if (zinfo->is_enchantment)
return 0;
else if (spell != SPELL_NO_SPELL)
return spell_difficulty(spell);
return 0;
}
#ifdef WIZARD
static bool _needs_monster_zap(const zap_info &zinfo)
{
// for enchantments we can't know from this data
if (zinfo.is_enchantment)
return false;
// if player tohit is missing from a non-enchantment, then it has to use
// a fake monster cast
if (!zinfo.player_tohit)
return true;
// otherwise, it should be possible to use a player zap (damage may or may
// not be defined)
return false;
}
#endif
void zappy(zap_type z_type, int power, bool is_monster, bolt &pbolt)
{
const zap_info* zinfo = _seek_zap(z_type);
// None found?
if (zinfo == nullptr)
{
dprf("Couldn't find zap type %d", z_type);
return;
}
#ifdef WIZARD
// we are in a wizmode cast scenario: use monster zap data to avoid crashes.
// N.b. this suppresses some player effects, such as inaccuracy.
if (!is_monster && you.wizard && _needs_monster_zap(*zinfo))
is_monster = true;
#endif
// Fill
pbolt.name = zinfo->name;
pbolt.flavour = zinfo->flavour;
pbolt.real_flavour = zinfo->flavour;
pbolt.colour = zinfo->colour;
pbolt.glyph = dchar_glyph(zinfo->glyph);
pbolt.pierce = zinfo->can_beam;
pbolt.is_explosion = zinfo->is_explosion;
if (zinfo->player_power_cap > 0 && !is_monster)
power = min(zinfo->player_power_cap, power);
ASSERT(zinfo->is_enchantment == pbolt.is_enchantment());
pbolt.ench_power = zap_ench_power(z_type, power, is_monster);
if (zinfo->is_enchantment)
pbolt.hit = AUTOMATIC_HIT;
else
pbolt.hit = zap_to_hit(z_type, power, is_monster);
pbolt.damage = zap_damage(z_type, power, is_monster);
if (pbolt.origin_spell == SPELL_NO_SPELL)
pbolt.origin_spell = zap_to_spell(z_type);
if (pbolt.loudness == 0)
pbolt.loudness = _zap_loudness(z_type, pbolt.origin_spell);
pbolt.tile_beam = zinfo->tile_beam;
pbolt.tile_explode = zinfo->tile_explode;
}
bool bolt::can_affect_actor(const actor *act) const
{
// Blinkbolt doesn't hit its caster, since they are the bolt.
if (origin_spell == SPELL_BLINKBOLT && act->mid == source_id)
return false;
// Damnation doesn't blast the one firing.
else if (item
&& item->props.exists(DAMNATION_BOLT_KEY)
&& act->mid == source_id)
{
return false;
}
// Xak'krixis' prisms are smart enough not to affect friendlies
else if (origin_spell == SPELL_FULMINANT_PRISM && thrower == KILL_MON
&& act->temp_attitude() == attitude)
{
return false;
}
auto cnt = hit_count.find(act->mid);
if (cnt != hit_count.end() && cnt->second >= 2)
{
// Note: this is done for balance, even if it hurts realism a bit.
// It is arcane knowledge which wall patterns will cause lightning
// to bounce thrice, double damage for ordinary bounces is enough.
#ifdef DEBUG_DIAGNOSTICS
if (!quiet_debug)
dprf(DIAG_BEAM, "skipping beam hit, affected them twice already");
#endif
return false;
}
return true;
}
// Choose the beam effect for BEAM_CHAOS that's analogous to the effect used by
// SPWPN_CHAOS, with weightings similar to those use by that brand. XXX: Rework
// this and SPWPN_CHAOS to use the same tables.
static beam_type _chaos_beam_flavour(bolt* beam)
{
UNUSED(beam);
beam_type flavour;
flavour = random_choose_weighted(
// SPWPN_CHAOS randomizes to brands analogous to these beam effects
// with similar weights.
80, BEAM_FIRE,
80, BEAM_COLD,
80, BEAM_ELECTRICITY,
80, BEAM_POISON,
// Combined weight from drain + vamp.
80, BEAM_NEG,
40, BEAM_HOLY,
40, BEAM_DRAIN_MAGIC,
16, BEAM_FOUL_FLAME,
// From here are beam effects analogous to effects that happen when
// SPWPN_CHAOS chooses itself again as the ego (roughly 1/7 chance).
// Weights similar to those from chaos_effects in attack.cc
5, BEAM_BERSERK,
12, BEAM_HASTE,
12, BEAM_MIGHT,
10, BEAM_RESISTANCE,
10, BEAM_SLOW,
12, BEAM_CONFUSION,
10, BEAM_WEAKNESS,
10, BEAM_VULNERABILITY,
10, BEAM_ACID,
5, BEAM_VITRIFY,
5, BEAM_ENSNARE,
3, BEAM_BLINK,
3, BEAM_PARALYSIS,
3, BEAM_PETRIFY,
3, BEAM_SLEEP,
// Combined weight for poly and clone effects.
4, BEAM_POLYMORPH,
5, BEAM_LIGHT);
return flavour;
}
dice_def combustion_breath_damage(int pow, bool allow_random)
{
if (allow_random)
return dice_def(3, 4 + div_rand_round(pow * 10, 9));
else
return dice_def(3, 4 + pow * 10 / 9);
}
static void _copy_affected_counts(bolt& dest, const bolt& source) noexcept
{
dest.foes_hurt = source.foes_hurt;
dest.foes_helped = source.foes_helped;
dest.friends_hurt = source.friends_hurt;
dest.friends_helped = source.friends_helped;
}
static void _combustion_breath_explode(bolt *parent, coord_def pos)
{
bolt beam;
bolt_parent_init(*parent, beam);
beam.name = "fiery explosion";
beam.aux_source = "combustion breath";
beam.damage = combustion_breath_damage(parent->ench_power);
beam.colour = RED;
beam.flavour = BEAM_FIRE;
beam.is_explosion = true;
beam.source = pos;
beam.target = pos;
beam.origin_spell = SPELL_COMBUSTION_BREATH;
beam.refine_for_explosion();
beam.explode();
_copy_affected_counts(*parent, beam);
}
bool bolt::visible() const
{
return !is_tracer() && glyph != 0 && !is_enchantment();
}
void bolt::initialise_fire()
{
// Fix some things which the tracer might have set.
extra_range_used = 0;
in_explosion_phase = false;
use_target_as_pos = false;
hit_count.clear();
if (special_explosion != nullptr)
{
ASSERT(!is_explosion);
ASSERT(special_explosion->is_explosion);
ASSERT(special_explosion->special_explosion == nullptr);
special_explosion->in_explosion_phase = false;
special_explosion->use_target_as_pos = false;
}
if (chose_ray)
{
ASSERT_IN_BOUNDS(ray.pos());
if (source == coord_def())
source = ray.pos();
}
if (target == source)
{
range = 0;
aimed_at_feet = true;
aimed_at_spot = true;
use_target_as_pos = true;
}
ASSERT_IN_BOUNDS(source);
ASSERT_RANGE(flavour, BEAM_NONE + 1, BEAM_FIRST_PSEUDO);
ASSERT(!drop_item || item && item->defined());
ASSERTM(range >= 0, "beam '%s', source '%s', item '%s'; has range -1",
name.c_str(),
(source_id == MID_PLAYER ? "player" :
monster_by_mid(source_id) ?
monster_by_mid(source_id)->name(DESC_PLAIN, true) :
"unknown").c_str(),
(item ? item->name(DESC_PLAIN, false, true) : "none").c_str());
ASSERT(!aimed_at_feet || source == target);
real_flavour = flavour;
message_cache.clear();
// seen might be set by caller to suppress this.
if (!seen && you.see_cell(source) && range > 0 && visible())
{
seen = true;
const monster* mon = monster_at(source);
if (flavour != BEAM_VISUAL
&& !YOU_KILL(thrower)
&& !crawl_state.is_god_acting()
&& (!mon || !mon->observable()))
{
mprf("%s appears from out of thin air!",
article_a(name, false).c_str());
}
}
// Visible self-targeted beams are always seen, even though they don't
// leave a path.
if (you.see_cell(source) && target == source && visible())
seen = true;
// The agent may die during the beam's firing, need to save these now.
// If the beam was reflected, assume it can "see" anything, since neither
// the reflector nor the original source was particularly aiming for this
// target. WARNING: if you change this logic, keep in mind that
// env.mons[YOU_FAULTLESS] cannot be safely queried for properties like
// can_see_invisible.
if (reflections > 0)
nightvision = can_see_invis = true;
else
precalc_agent_properties();
#ifdef DEBUG_DIAGNOSTICS
// Not a "real" tracer, merely a range/reachability check.
if (quiet_debug)
return;
dprf(DIAG_BEAM, "%s%s%s [%s] (%d,%d) to (%d,%d): "
"gl=%d col=%d flav=%d hit=%d dam=%dd%d range=%d",
(pierce) ? "beam" : "missile",
(is_explosion) ? "*" :
(is_big_cloud()) ? "+" : "",
(is_tracer()) ? " tracer" : "",
name.c_str(),
source.x, source.y,
target.x, target.y,
glyph, colour, flavour,
hit, damage.num, damage.size,
range);
#endif
}
void bolt::precalc_agent_properties()
{
const actor* a = agent();
// XXX: Should non-agents count as seeing invisible?
if (!a) return;
nightvision = a->nightvision();
can_see_invis = a->can_see_invisible();
}
void bolt::apply_beam_conducts()
{
if (is_tracer() && YOU_KILL(thrower))
{
switch (flavour)
{
case BEAM_DAMNATION:
{
const int level = 2 + random2(3);
did_god_conduct(DID_EVIL, level, god_cares());
break;
}
default:
break;
}
}
}
void bolt::choose_ray()
{
if ((!chose_ray || reflections > 0)
&& !find_ray(source, target, ray, opc_solid_see)
// If fire is blocked, at least try a visible path so the
// error message is better.
&& !find_ray(source, target, ray, opc_default))
{
fallback_ray(source, target, ray);
}
}
// Draw the bolt at p if needed.
void bolt::draw(const coord_def& p, bool force_refresh)
{
if (is_tracer() || is_enchantment() || !you.see_cell(p))
return;
// We don't clean up the old position.
// First, most people like to see the full path,
// and second, it is hard to do it right with
// respect to killed monsters, cloud trails, etc.
const coord_def drawpos = grid2view(p);
if (!in_los_bounds_v(drawpos))
return;
#ifdef USE_TILE
// Set default value if none specified.
if (tile_beam == 0)
tile_beam = tileidx_zap(colour);
view_add_tile_overlay(p, vary_bolt_tile(tile_beam, source, target, p));
#endif
const unsigned short c = colour == BLACK ? random_colour(true)
: element_colour(colour);
view_add_glyph_overlay(p, {glyph, c});
// If reduce_animations is set, the redraw is unnecessary and
// should be done only once outside the loop calling the bolt::draw
if (Options.reduce_animations)
return;
// to avoid redraws, set force_refresh = false, and draw_delay = 0. This
// will still force a refresh if there is a draw_delay regardless of the
// param, because a delay on drawing is pretty meaningless without a
// redraw.
if (force_refresh || draw_delay > 0)
animation_delay(draw_delay, true);
}
// Bounce a bolt off a solid feature.
// The ray is assumed to have just been advanced into
// the feature.
void bolt::bounce()
{
ASSERT(cell_is_solid(ray.pos()));
// Don't bounce player tracers off unknown cells, or cells that we
// incorrectly thought were non-bouncy.
if (is_tracer() && agent() == &you)
{
const dungeon_feature_type feat = env.map_knowledge(ray.pos()).feat();
if (feat == DNGN_UNSEEN || !feat_is_solid(feat) || !is_bouncy(feat))
{
ray.regress();
finish_beam();
return;
}
}
do
{
ray.regress();
}
while (cell_is_solid(ray.pos()));
extra_range_used += range_used(true);
bounce_pos = ray.pos();
bounces++;
reflect_grid rg;
for (adjacent_iterator ai(ray.pos(), false); ai; ++ai)
rg(*ai - ray.pos()) = cell_is_solid(*ai);
ray.bounce(rg);
extra_range_used += 2;
// Keep length of bounced spells constant despite reduced los (scarf of
// shadows, Robe of Night)
if (bounces == 1)
{
extra_range_used -= spell_range(origin_spell, ench_power, true, true)
- range;
}
ASSERT(!cell_is_solid(ray.pos()));
}
void bolt::fake_flavour()
{
if (real_flavour == BEAM_RANDOM)
flavour = static_cast<beam_type>(random_range(BEAM_FIRST_RANDOM, BEAM_LAST_RANDOM));
else if (real_flavour == BEAM_CHAOS)
flavour = _chaos_beam_flavour(this);
}
void bolt::digging_wall_effect()
{
if (env.markers.property_at(pos(), MAT_ANY, "veto_destroy") == "veto")
{
finish_beam();
return;
}
const dungeon_feature_type feat = env.grid(pos());
if (feat_is_diggable(feat))
{
// If this is temporary terrain and the underlying terrain is *not*
// diggable, just revert it to whatever it was before. But if the
// original terrain was also diggable, simply destroy it.
if (is_temp_terrain(pos()))
{
revert_terrain_change(pos());
if (feat_is_diggable(env.grid(pos())))
destroy_wall(pos());
}
else
destroy_wall(pos());
if (!msg_generated)
{
if (!you.see_cell(pos()))
{
if (!silenced(you.pos()))
{
mprf(MSGCH_SOUND, "You hear a grinding noise.");
obvious_effect = true; // You may still see the caster.
msg_generated = true;
}
return;
}
obvious_effect = true;
msg_generated = true;
string wall;
if (feat == DNGN_GRATE)
{
// XXX: should this change for monsters?
mpr("The damaged grate falls apart.");
return;
}
else if (feat == DNGN_SLIMY_WALL)
wall = "slime";
else if (player_in_branch(BRANCH_PANDEMONIUM))
wall = "weird stuff";
else
wall = "rock";
mprf("%s %s shatters into small pieces.",
agent() && agent()->is_player() ? "The" : "Some",
wall.c_str());
}
}
else if (feat_is_wall(feat))
finish_beam();
}
void bolt::burn_wall_effect()
{
dungeon_feature_type feat = env.grid(pos());
// Fire only affects things that can burn.
if (!feat_is_flammable(feat)
|| env.markers.property_at(pos(), MAT_ANY, "veto_destroy") == "veto"
|| !can_burn_trees()) // sanity
{
finish_beam();
return;
}
if (have_passive(passive_t::shoot_through_plants))
{
emit_message("Fedhas protects the tree from harm.");
finish_beam();
return;
}
if (you.see_cell(pos()))
{
if (feat == DNGN_TREE)
emit_message("The tree burns like a torch!");
else if (feat == DNGN_MANGROVE)
emit_message("The mangrove smoulders and burns.");
else if (feat == DNGN_DEMONIC_TREE)
emit_message("The demonic tree burns, releasing chaotic energy.");
}
else if (you.can_smell())
emit_message("You smell burning wood.");
// If the tree we're destroying is temporary, immediately revert
// terrain changes on this tile rather than permanently changing it.
if (is_temp_terrain(pos()))
revert_terrain_change(pos());
else
destroy_wall(pos());
// But burning a temporary tree that was created on open ground can still
// start a fire.
if (!cell_is_solid(pos()))
{
if (feat == DNGN_TREE)
place_cloud(CLOUD_FOREST_FIRE, pos(), random2(30)+25, agent());
// Mangroves do not burn so readily.
else if (feat == DNGN_MANGROVE)
place_cloud(CLOUD_FIRE, pos(), random2(12)+5, agent());
// Demonic trees produce a chaos cloud instead of fire.
else if (feat == DNGN_DEMONIC_TREE)
place_cloud(CLOUD_CHAOS, pos(), random2(30)+25, agent());
}
// If a tree turned back into a wall, place some fire around it to simulate
// the normal burning effect without removing the wall.
else if (feat == DNGN_TREE)
{
for (adjacent_iterator ai(pos()); ai; ++ai)
{
if (!in_bounds(*ai) || cloud_at(*ai) || is_sanctuary(*ai)
|| cell_is_solid(*ai) || !cell_see_cell(*ai, source, LOS_NO_TRANS))
{
continue;
}
if (one_chance_in(3))
place_cloud(CLOUD_FIRE, *ai, random_range(11, 25), agent());
}
}
obvious_effect = true;
finish_beam();
}
int bolt::range_used(bool leg_only) const
{
const int leg_length = pos().distance_from(leg_source());
return leg_only ? leg_length : leg_length + extra_range_used;
}
void bolt::finish_beam()
{
extra_range_used = BEAM_STOP;
}
void bolt::affect_wall()
{
if (is_tracer())
{
if (!in_bounds(pos()) || !can_affect_wall(pos(), true))
finish_beam();
// Digging is the only thing that doesn't stop at walls,
// (and even it needs to stop if an underlying feature isn't diggable).
if (flavour != BEAM_DIGGING
|| is_temp_terrain(pos()) && !feat_is_diggable(orig_terrain(pos())))
{
finish_beam();
}
return;
}
if (in_bounds(pos()))
{
if (flavour == BEAM_DIGGING)
digging_wall_effect();
else if (can_burn_trees())
burn_wall_effect();
}
if (cell_is_solid(pos()))
finish_beam();
}
coord_def bolt::pos() const
{
if (in_explosion_phase || use_target_as_pos)
return target;
else
return ray.pos();
}
bool bolt::need_regress() const
{
// XXX: The affects_wall check probably makes some of the
// others obsolete.
return (is_explosion && !in_explosion_phase)
|| drop_item
|| cell_is_solid(pos()) && !can_affect_wall(pos())
|| origin_spell == SPELL_PRIMAL_WAVE;
}
void bolt::affect_cell()
{
fake_flavour();
// Note that this can change the solidity of the wall.
if (cell_is_solid(pos()))
affect_wall();
if (origin_spell == SPELL_CHAIN_LIGHTNING && pos() != target)
return;
// If the player can ever walk through walls, this will need
// special-casing too.
bool hit_player = found_player() && !ignores_player();
if (hit_player && can_affect_actor(&you))
{
const int prev_reflections = reflections;
const coord_def old_pos = pos();
affect_player();
if (reflections != prev_reflections)
return;
if (hit == AUTOMATIC_HIT && !pierce)
finish_beam();
// XXX: If an ally stopped a piercing beam short to avoid hitting the
// player on this cell, don't attempt to hit a monster on the
// cell immediately before them again.
if (pos() != old_pos)
return;
}
// Stop single target beams from affecting a monster if they already
// affected the player on this square. -cao
if (!hit_player || pierce || is_explosion)
{
monster *m = monster_at(pos());
if (m && can_affect_actor(m))
{
const bool ignored = ignores_monster(m);
affect_monster(m);
if (hit == AUTOMATIC_HIT && !pierce && !ignored
&& (!is_tracer() || (agent() && m->visible_to(agent()))))
{
finish_beam();
}
}
}
if (!cell_is_solid(pos()))
affect_ground();
}
static void _undo_tracer(bolt &orig, bolt ©)
{
// FIXME: we should have a better idea of what gets changed!
orig.target = copy.target;
orig.source = copy.source;
orig.aimed_at_spot = copy.aimed_at_spot;
orig.aimed_at_feet = copy.aimed_at_feet;
orig.extra_range_used = copy.extra_range_used;
orig.ray = copy.ray;
orig.colour = copy.colour;
orig.flavour = copy.flavour;
orig.real_flavour = copy.real_flavour;
orig.bounces = copy.bounces;
orig.bounce_pos = copy.bounce_pos;
}
// This saves some important things before calling do_fire().
void bolt::fire()
{
path_taken.clear();
if (is_tracer())
{
bolt boltcopy = *this;
if (special_explosion != nullptr)
{
bolt special_explosion_copy = *special_explosion;
do_fire();
_undo_tracer(*special_explosion, special_explosion_copy);
}
else
do_fire();
_undo_tracer(*this, boltcopy);
}
else
do_fire();
//XXX: suspect, but code relies on path_taken being non-empty
if (path_taken.empty())
path_taken.push_back(source);
if (special_explosion != nullptr)
{
seen = seen || special_explosion->seen;
heard = heard || special_explosion->heard;
}
}
void bolt::fire(beam_tracer& new_tracer)
{
unwind_var<beam_tracer*> old_tracer(tracer, &new_tracer);
fire();
}
void bolt::do_fire()
{
initialise_fire();
if (range < extra_range_used && range > 0)
{
#ifdef DEBUG
dprf(DIAG_BEAM, "fire_beam() called on already done beam "
"'%s' (item = '%s')", name.c_str(),
item ? item->name(DESC_PLAIN).c_str() : "none");
#endif
return;
}
apply_beam_conducts();
cursor_control coff(false);
#ifdef USE_TILE
// Set up uninitialized / item-based beam tile, if we're actually firing.
if (!is_tracer())
{
if (item && (flavour == BEAM_MISSILE || flavour == BEAM_VISUAL))
{
const coord_def diff = target - source;
tile_beam = tileidx_item_throw(*item, diff.x, diff.y);
}
}
#endif
msg_generated = false;
if (!aimed_at_feet)
{
choose_ray();
// Take *one* step, so as not to hurt the source.
ray.advance();
}
// Note: nothing but this loop should be changing the ray.
while (map_bounds(pos()))
{
if (range_used() > range)
{
ray.regress();
extra_range_used++;
ASSERT(range_used() >= range);
break;
}
const dungeon_feature_type feat = env.grid(pos());
if (in_bounds(target)
// Starburst beams are essentially untargeted; some might even hit
// a victim if others have LOF blocked.
&& origin_spell != SPELL_STARBURST
// We ran into a solid wall with a real beam...
&& (feat_is_solid(feat)
&& flavour != BEAM_DIGGING && flavour <= BEAM_LAST_REAL
&& !cell_is_solid(target)
// Or hit a monster that'll stop our beam...
|| at_blocking_monster())
// and it's a player tracer that cares about blocked paths...
&& is_tracer() && tracer->is_collecting_warnings() && YOU_KILL(thrower)
// and we're actually between you and the target...
&& !passed_target && pos() != target && pos() != source
// ?
&& !tracer->has_hit_foe() && bounces == 0 && reflections == 0
// and you aren't shooting out of LOS.
&& you.see_cell(target))
{
// Okay, with all those tests passed, this is probably an instance
// of the player manually targeting something whose line of fire
// is blocked, even though its line of sight isn't blocked. Give
// a warning about this fact.
const monster* mon = monster_at(target);
string blockee;
if (mon && mon->observable())
blockee = mon->name(DESC_THE);
else
{
blockee = "the targeted "
+ feature_description_at(target, false, DESC_PLAIN);
}
const string blocker = feat_is_solid(feat) ?
feature_description_at(pos(), false, DESC_A) :
monster_at(pos())->name(DESC_A);
mprf("Your line of fire to %s is blocked by %s.",
blockee.c_str(), blocker.c_str());
tracer->cancel();
finish_beam();
return;
}
// digging is taken care of in affect_cell
if (feat_is_solid(feat) && !can_affect_wall(pos())
&& flavour != BEAM_DIGGING)
{
if (is_bouncy(feat))
{
bounce();
// see comment in bounce(); the beam will be cancelled if this
// is a tracer and showing the bounce would be an info leak.
// In that case, we have to break early to avoid adding this
// square to path_taken twice, which would make it look like a
// a bounce ANYWAY.
if (range_used() > range)
break;
}
else
{
// Regress for explosions: blow up in an open grid (if regressing
// makes any sense). Also regress when dropping items.
if (pos() != source && need_regress())
{
do
{
ray.regress();
}
while (ray.pos() != source && cell_is_solid(ray.pos()));
// target is where the explosion is centered, so update it.
if (is_explosion && !is_tracer())
target = ray.pos();
}
break;
}
}
path_taken.push_back(pos());
// Roots only have an effect during explosions.
if (flavour == BEAM_ROOTS)
{
if (cell_is_solid(pos()))
affect_wall();
const actor *victim = actor_at(pos());
if (victim
&& !ignores_monster(victim->as_monster())
&& (!is_tracer() || agent()->can_see(*victim)))
{
finish_beam();
}
}
else if (!affects_nothing)
affect_cell();
if (range_used() > range)
break;
// Weapons of returning should find an inverse ray
// through find_ray and setup_retrace, but they didn't
// always in the past, and we don't want to crash
// if they accidentally pass through a corner.
// Dig tracers continue through unseen cells.
ASSERT(!cell_is_solid(pos())
|| is_tracer() && can_affect_wall(pos(), true)
|| affects_nothing); // returning weapons
const bool was_seen = seen;
if (!was_seen && range > 0 && visible() && you.see_cell(pos()))
seen = true;
if (flavour != BEAM_VISUAL && !was_seen && seen && !is_tracer())
{
mprf("%s appears from out of your range of vision.",
article_a(name, false).c_str());
}
// Reset chaos beams so that it won't be considered an invisible
// enchantment beam for the purposes of animation.
if (real_flavour == BEAM_CHAOS)
flavour = real_flavour;
// Actually draw the beam/missile/whatever, if the player can see
// the cell.
if (animate)
draw(pos(), redraw_per_cell);
if (pos() == target)
{
passed_target = true;
if (stop_at_target())
break;
}
noise_generated = false;
ray.advance();
}
if (!map_bounds(pos()))
{
ASSERT(!aimed_at_spot);
int tries = max(GXM, GYM);
while (!map_bounds(ray.pos()) && tries-- > 0)
ray.regress();
// Something bizarre happening if we can't get back onto the map.
ASSERT(map_bounds(pos()));
}
// The beam has terminated.
if (!affects_nothing)
affect_endpoint();
// Tracers need nothing further.
if (is_tracer() || affects_nothing)
return;
// final delay for any draws that happened in the above loop
if (animate && Options.reduce_animations && draw_delay > 0)
animation_delay(15 + draw_delay, true);
// Canned msg for enchantments that affected no-one, but only if the
// enchantment is yours (and it wasn't a chaos beam, since with chaos
// enchantments are entirely random, and if it randomly attempts
// something which ends up having no obvious effect then the player
// isn't going to realise it).
if (!msg_generated && !obvious_effect && is_enchantment()
&& real_flavour != BEAM_CHAOS
&& YOU_KILL(thrower))
{
canned_msg(MSG_NOTHING_HAPPENS);
}
// Reactions if a monster zapped the beam.
if (monster_by_mid(source_id))
{
if (foes_hurt == 0 && friends_hurt > 0)
xom_is_stimulated(100);
else if (foes_helped > 0 && friends_helped == 0)
xom_is_stimulated(100);
// Allow friendlies to react to projectiles, except when in
// sanctuary when pet_target can only be explicitly changed by
// the player.
const monster* mon = monster_by_mid(source_id);
if (foes_hurt > 0 && !mon->wont_attack() && !crawl_state.game_is_arena()
&& you.pet_target == MHITNOT && env.sanctuary_time <= 0)
{
you.pet_target = mon->mindex();
}
}
}
// Returns damage taken by a monster from a "flavoured" (fire, ice, etc.)
// attack -- damage from clouds and branded weapons handled elsewhere.
int mons_adjust_flavoured(monster* mons, bolt &pbolt, int hurted,
bool doFlavouredEffects)
{
// If we're not doing flavoured effects, must be preliminary
// damage check only.
// Do not print messages or apply any side effects!
int original = hurted;
switch (pbolt.flavour)
{
case BEAM_FIRE:
case BEAM_STEAM:
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
if (!hurted)
{
if (original > 0 && doFlavouredEffects)
simple_monster_message(*mons, " completely resists.");
}
else if (original > hurted)
{
if (doFlavouredEffects)
simple_monster_message(*mons, " resists.");
}
else if (original < hurted && doFlavouredEffects)
{
if (mons->is_icy())
simple_monster_message(*mons, " melts!");
else if (mons_species(mons->type) == MONS_BUSH
&& mons->res_fire() < 0)
{
simple_monster_message(*mons, " is on fire!");
}
else if (pbolt.flavour == BEAM_FIRE)
simple_monster_message(*mons, " is burned terribly!");
else
simple_monster_message(*mons, " is scalded terribly!");
}
break;
case BEAM_WATER:
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
if (hurted > original && doFlavouredEffects)
simple_monster_message(*mons, " is doused terribly!");
break;
case BEAM_COLD:
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
if (!hurted)
{
if (original > 0 && doFlavouredEffects)
simple_monster_message(*mons, " completely resists.");
}
else if (original > hurted)
{
if (doFlavouredEffects)
simple_monster_message(*mons, " resists.");
}
else if (original < hurted)
{
if (doFlavouredEffects)
simple_monster_message(*mons, " is chilled terribly!");
}
break;
case BEAM_STUN_BOLT:
case BEAM_ELECTRICITY:
case BEAM_THUNDER:
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
if (!hurted)
{
if (original > 0 && doFlavouredEffects)
simple_monster_message(*mons, " completely resists.");
}
else if (original > hurted)
{
if (doFlavouredEffects)
simple_monster_message(*mons, " resists.");
}
else if (original < hurted)
{
if (doFlavouredEffects)
simple_monster_message(*mons, " is electrocuted!");
}
break;
case BEAM_ACID:
{
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
if (!hurted)
{
if (original > 0 && doFlavouredEffects)
simple_monster_message(*mons, " completely resists.");
}
else if (doFlavouredEffects && !one_chance_in(3))
mons->corrode(pbolt.agent());
break;
}
case BEAM_POISON:
{
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
if (!hurted && doFlavouredEffects && original > 0)
simple_monster_message(*mons, " completely resists.");
else if (doFlavouredEffects && !one_chance_in(3))
{
if (pbolt.origin_spell == SPELL_SPIT_POISON &&
pbolt.agent(true)->is_monster() &&
pbolt.agent(true)->as_monster()->has_ench(ENCH_CONCENTRATE_VENOM)
&& mons->res_poison() <= 0)
{
// set the cause to the reflected agent for piety &c.
//
// (7 bonus poison will apply exactly 1 additional level of
// poison to monsters, mirroring the normal effect of BEAM_POISON)
curare_actor(pbolt.agent(), mons, "concentrated venom",
pbolt.agent(true)->name(DESC_PLAIN), 7);
}
else
poison_monster(mons, pbolt.agent());
}
break;
}
case BEAM_POISON_ARROW:
{
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
const int stacks = pbolt.origin_spell == SPELL_STING ? 1 : 4;
if (hurted < original)
{
if (doFlavouredEffects)
{
simple_monster_message(*mons, " partially resists.");
poison_monster(mons, pbolt.agent(), div_rand_round(stacks, 2),
true);
}
}
else if (doFlavouredEffects)
poison_monster(mons, pbolt.agent(), stacks, true);
break;
}
case BEAM_MERCURY:
{
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
if (doFlavouredEffects)
{
int chance = get_mercury_weaken_chance(mons->get_hit_dice());
if (x_chance_in_y(chance, 100))
mons->weaken(pbolt.agent(), 5);
// Splash to adjacent actors.
bool did_splash_msg = false;
for (adjacent_iterator ai(mons->pos()); ai; ++ai)
{
if (actor* act = actor_at(*ai))
{
if (act == pbolt.agent()
|| never_harm_monster(pbolt.agent(), act->as_monster()))
{
continue;
}
if (!did_splash_msg)
{
if (you.see_cell(mons->pos()))
mprf("The mercury splashes!");
did_splash_msg = true;
}
chance = get_mercury_weaken_chance(act->get_hit_dice());
if (x_chance_in_y(chance, 100))
act->weaken(pbolt.agent(), 5);
}
}
}
break;
}
case BEAM_NEG:
if (mons->res_negative_energy() == 3)
{
if (doFlavouredEffects)
simple_monster_message(*mons, " completely resists.");
hurted = 0;
}
else
{
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
// Early out if no side effects.
if (!doFlavouredEffects)
return hurted;
if (original > hurted)
simple_monster_message(*mons, " resists.");
else if (original < hurted)
simple_monster_message(*mons, " is drained terribly!");
if (mons->observable())
pbolt.obvious_effect = true;
mons->drain(pbolt.agent());
if (YOU_KILL(pbolt.thrower))
did_god_conduct(DID_EVIL, 2, pbolt.god_cares());
}
break;
case BEAM_MIASMA:
if (mons->res_miasma())
{
if (doFlavouredEffects)
simple_monster_message(*mons, " completely resists.");
hurted = 0;
}
else
{
// Early out for tracer/no side effects.
if (!doFlavouredEffects)
return hurted;
miasma_monster(mons, pbolt.agent());
if (YOU_KILL(pbolt.thrower))
did_god_conduct(DID_UNCLEAN, 2, pbolt.god_cares());
}
break;
case BEAM_HOLY:
case BEAM_FOUL_FLAME:
{
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
if (doFlavouredEffects && original > 0
&& (!hurted || hurted != original))
{
simple_monster_message(*mons, hurted == 0 ? " completely resists." :
hurted < original ? " resists." :
" writhes in agony!");
}
break;
}
case BEAM_ICE:
// ice - 40% of damage is cold, other 60% is impact and
// can't be resisted (except by AC, of course)
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
if (hurted < original)
{
if (doFlavouredEffects)
simple_monster_message(*mons, " partially resists.");
}
else if (hurted > original)
{
if (doFlavouredEffects)
simple_monster_message(*mons, " is frozen!");
}
break;
case BEAM_LAVA:
hurted = resist_adjust_damage(mons, pbolt.flavour, hurted);
if (hurted < original)
{
if (doFlavouredEffects)
simple_monster_message(*mons, " partially resists.");
}
else if (hurted > original)
{
if (mons->is_icy())
{
if (doFlavouredEffects)
simple_monster_message(*mons, " melts!");
}
else
{
if (doFlavouredEffects)
simple_monster_message(*mons, " is burned terribly!");
}
}
break;
case BEAM_DAMNATION:
if (mons->res_damnation())
{
if (doFlavouredEffects)
simple_monster_message(*mons, " completely resists.");
hurted = 0;
}
break;
case BEAM_MEPHITIC:
if (mons->res_poison() > 0)
{
if (original > 0 && doFlavouredEffects)
simple_monster_message(*mons, " completely resists.");
hurted = 0;
}
break;
case BEAM_SPORE:
if (mons->type == MONS_BALLISTOMYCETE)
hurted = 0;
break;
case BEAM_ENSNARE:
if (doFlavouredEffects)
ensnare(mons);
break;
case BEAM_DEVASTATION:
if (doFlavouredEffects)
mons->strip_willpower(pbolt.agent(), random_range(20, 30));
break;
case BEAM_UMBRAL_TORCHLIGHT:
if (mons->holiness() & ~(MH_NATURAL | MH_DEMONIC | MH_HOLY))
{
if (doFlavouredEffects && !mons_aligned(mons, pbolt.agent(true)))
simple_monster_message(*mons, " completely resists.");
hurted = 0;
}
break;
case BEAM_WARPING:
if (doFlavouredEffects
&& x_chance_in_y(get_warp_space_chance(pbolt.ench_power), 100))
{
monster_blink(mons);
}
break;
case BEAM_SEISMIC:
if (mons->airborne())
hurted = hurted / 3;
break;
case BEAM_BOLAS:
if (doFlavouredEffects)
{
if (mons->is_insubstantial() || mons->is_amorphous())
{
mprf("The bolas passes through %s!",
mons->name(DESC_THE).c_str());
}
else
{
mons->add_ench(mon_enchant(ENCH_BOUND, 0, pbolt.agent(),
random_range(4, 8)));
mprf("The bolas warps around %s and binds %s in place!",
mons->name(DESC_THE).c_str(),
mons->pronoun(PRONOUN_OBJECTIVE).c_str());
}
}
break;
default:
break;
}
if (doFlavouredEffects)
{
const int burn_power = (pbolt.is_explosion) ? 5 :
(pbolt.pierce) ? 3
: 2;
mons->expose_to_element(pbolt.flavour, burn_power, pbolt.agent(), false);
}
return hurted;
}
// XXX: change mons to a reference
static bool _monster_resists_mass_enchantment(monster* mons,
enchant_type wh_enchant,
int pow,
bool* did_msg)
{
// Mass enchantments around lots of plants/fungi shouldn't cause a flood
// of "is unaffected" messages. --Eino
if (mons->is_firewood())
return true;
if (never_harm_monster(&you, mons))
return true;
switch (wh_enchant)
{
case ENCH_FEAR:
if (mons->friendly())
return true;
if (!mons->can_feel_fear(true))
{
if (simple_monster_message(*mons, " is unaffected."))
*did_msg = true;
return true;
}
break;
case ENCH_FRENZIED:
if (!mons->can_go_frenzy())
{
if (simple_monster_message(*mons, " is unaffected."))
*did_msg = true;
return true;
}
break;
case ENCH_ANGUISH:
if (mons->friendly())
return true;
if (mons_intel(*mons) <= I_BRAINLESS)
{
if (simple_monster_message(*mons, " is unaffected."))
*did_msg = true;
return true;
}
break;
default:
break;
}
int res_margin = mons->check_willpower(&you, pow);
if (res_margin > 0)
{
behaviour_event(mons, ME_ALERT, &you);
if (simple_monster_message(*mons,
mons->resist_margin_phrase(res_margin).c_str()))
{
*did_msg = true;
}
return true;
}
// If monster was affected, then there was a message.
*did_msg = true;
return false;
}
// Enchants all monsters in player's sight.
// If m_succumbed is non-nullptr, will be set to the number of monsters that
// were enchanted. If m_attempted is not nullptr, will be set to the number of
// monsters that we tried to enchant.
spret mass_enchantment(enchant_type wh_enchant, int pow, bool fail)
{
fail_check();
bool did_msg = false;
// Give mass enchantments a power multiplier.
pow *= 3;
pow /= 2;
pow = min(pow, 200);
for (monster_iterator mi; mi; ++mi)
{
if (!you.see_cell_no_trans(mi->pos()))
continue;
if (mi->has_ench(wh_enchant))
continue;
bool resisted = _monster_resists_mass_enchantment(*mi, wh_enchant,
pow, &did_msg);
if (resisted)
continue;
if ((wh_enchant == ENCH_FRENZIED && mi->go_frenzy(&you))
|| (wh_enchant != ENCH_FRENZIED
&& mi->add_ench(mon_enchant(wh_enchant, 0, &you))))
{
// Do messaging.
const char* msg = nullptr;
if (wh_enchant == ENCH_FEAR)
msg = " looks frightened!";
else if (wh_enchant == ENCH_ANGUISH)
msg = " is haunted by guilt!";
if (msg && simple_monster_message(**mi, msg))
did_msg = true;
// Extra check for fear (monster needs to reevaluate behaviour).
if (wh_enchant == ENCH_FEAR)
behaviour_event(*mi, ME_SCARE, &you);
else if (wh_enchant == ENCH_ANGUISH)
behaviour_event(*mi, ME_ALERT, &you);
}
}
if (!did_msg)
canned_msg(MSG_NOTHING_HAPPENS);
if (wh_enchant == ENCH_FRENZIED)
did_god_conduct(DID_HASTY, 8, true);
return spret::success;
}
void bolt::apply_bolt_paralysis(monster* mons)
{
if (mons->paralysed() || mons->stasis())
return;
// asleep monsters can still be paralysed (and will be always woken by
// trying to resist); the message might seem wrong but paralysis is
// always visible.
if (!mons_is_immotile(*mons)
&& simple_monster_message(*mons, " suddenly stops moving!"))
{
obvious_effect = true;
}
mons->add_ench(mon_enchant(ENCH_PARALYSIS, 0, agent(),
_ench_pow_to_dur(ench_power)));
}
// Petrification works in two stages. First the monster is slowed down in
// all of its actions, and when that times out it remains properly petrified
// (no movement or actions). The second part is similar to paralysis,
// except that insubstantial monsters can't be affected and damage is
// drastically reduced.
void bolt::apply_bolt_petrify(monster* mons)
{
if (mons->petrified())
return;
if (mons->petrifying())
{
// If the petrifying is not yet finished, we can force it to happen
// right away by casting again. Otherwise, the spell has no further
// effect.
mons->del_ench(ENCH_PETRIFYING, true, false);
// del_ench() would do it, but let's call it ourselves for proper agent
// blaming and messaging.
if (mons->fully_petrify(agent()))
obvious_effect = true;
}
else if (mons->add_ench(mon_enchant(ENCH_PETRIFYING, 0, agent())))
{
if (!mons_is_immotile(*mons)
&& simple_monster_message(*mons, " is moving more slowly."))
{
obvious_effect = true;
}
}
}
static bool _curare_hits_monster(actor *agent, monster* mons, int bonus_poison)
{
if (!mons->alive())
return false;
if (mons->res_poison() > 0)
return false;
poison_monster(mons, agent, 2 + (bonus_poison / 7), true);
simple_monster_message(*mons, " struggles to breathe.");
mons->hurt(agent, roll_dice(2, 6), BEAM_POISON);
if (mons->alive() && !mons->stasis())
{
if (!mons->cannot_act())
{
simple_monster_message(*mons, mons->has_ench(ENCH_SLOW)
? " seems to be slow for longer."
: " seems to slow down.");
}
mons->add_ench(mon_enchant (ENCH_SLOW, 0, agent));
}
return true;
}
// Actually poisons a monster (with message).
bool poison_monster(monster* mons, const actor *who, int levels,
bool force, bool verbose)
{
if (!mons->alive() || levels <= 0)
return false;
if (monster_resists_this_poison(*mons, force))
return false;
const mon_enchant old_pois = mons->get_ench(ENCH_POISON);
mons->add_ench(mon_enchant(ENCH_POISON, levels, who));
const mon_enchant new_pois = mons->get_ench(ENCH_POISON);
// Actually do the poisoning. The order is important here.
if (new_pois.degree > old_pois.degree
|| new_pois.degree >= MAX_ENCH_DEGREE_DEFAULT)
{
if (verbose)
{
const char* msg;
if (new_pois.degree >= MAX_ENCH_DEGREE_DEFAULT)
msg = " looks as sick as possible!";
else if (old_pois.degree > 0)
msg = " looks even sicker.";
else
msg = " is poisoned.";
simple_monster_message(*mons, msg);
}
}
return new_pois.duration > old_pois.duration;
}
// Actually poisons and/or slows a monster with miasma (with message).
bool miasma_monster(monster* mons, const actor* who)
{
if (!mons->alive())
return false;
if (mons->res_miasma())
return false;
bool success = false;
if (poison_monster(mons, who))
{
// Do additional impact damage to monsters who fail an rPois check
mons->hurt(who, roll_dice(2, 4), BEAM_MMISSILE, KILLED_BY_CLOUD);
success = true;
}
if (who && who->is_player() && is_good_god(you.religion))
did_god_conduct(DID_EVIL, 5 + random2(3));
if (mons->alive() && one_chance_in(3))
{
do_slow_monster(*mons, who, random_range(8, 12) * BASELINE_DELAY);
success = true;
}
return success;
}
// Actually vitrifies a monster with crystallizing beam (with message).
static bool crystallize_monster(monster* mons, const actor* who)
{
if (!mons->alive())
return false;
if (x_chance_in_y(1, 4))
return false;
const bool had_status = mons->has_ench(ENCH_VITRIFIED);
mons->add_ench(mon_enchant(ENCH_VITRIFIED, 0, who,
random_range(8, 18) * BASELINE_DELAY));
if (you.can_see(*mons))
{
if (had_status)
{
mprf("%s looks even more glass-like.",
mons->name(DESC_THE).c_str());
}
else
{
mprf("%s becomes as fragile as glass!",
mons->name(DESC_THE).c_str());
}
}
return true;
}
// Actually applies sticky flame to a monster (with message).
bool sticky_flame_monster(monster* mons, const actor *who, int dur, bool verbose)
{
if (!mons->alive())
return false;
if (mons->res_sticky_flame() || dur <= 0 || mons->has_ench(ENCH_WATER_HOLD))
return false;
const mon_enchant old_flame = mons->get_ench(ENCH_STICKY_FLAME);
mons->add_ench(mon_enchant(ENCH_STICKY_FLAME, 0, who, dur * BASELINE_DELAY));
const mon_enchant new_flame = mons->get_ench(ENCH_STICKY_FLAME);
// Actually do the napalming. The order is important here.
if (new_flame.degree > old_flame.degree)
{
if (verbose)
simple_monster_message(*mons, " is covered in liquid fire!");
if (who)
behaviour_event(mons, ME_WHACK, who);
}
return new_flame.degree > old_flame.degree;
}
static bool _curare_hits_player(actor* agent, string name,
string source_name, int bonus_poison)
{
ASSERT(!crawl_state.game_is_arena());
if (player_res_poison() >= 3
|| player_res_poison() > 0 && !one_chance_in(3))
{
canned_msg(MSG_YOU_RESIST);
return false;
}
// We force apply this poison, since the 1-in-3 chance was already passed
poison_player(roll_dice(2, 12) + bonus_poison + 1, source_name, name, true);
mpr("You have difficulty breathing.");
ouch(roll_dice(2, 6), KILLED_BY_CURARE, agent->mid, "curare-induced apnoea");
slow_player(10 + random2(2 + random2(6)));
return true;
}
bool curare_actor(actor* source, actor* target, string name,
string source_name, int bonus_poison)
{
if (target->is_player())
return _curare_hits_player(source, name, source_name, bonus_poison);
else
return _curare_hits_monster(source, target->as_monster(), bonus_poison);
}
// XXX: This is a terrible place for this, but it at least does go with
// curare_actor().
int silver_damages_victim(actor* victim, int damage, string &dmg_msg)
{
int ret = 0;
if (victim->how_chaotic()
|| victim->is_player() && you.form != transformation::none)
{
ret = damage * 3 / 4;
}
else if (victim->is_player())
{
// For mutation damage, we want to count innate mutations for
// demonspawn but not other species.
int multiplier = 5 * you.how_mutated(you.species == SP_DEMONSPAWN, true);
if (multiplier == 0)
return 0;
if (multiplier > 75)
multiplier = 75;
ret = damage * multiplier / 100;
}
else
return 0;
dmg_msg = "The silver sears " + victim->name(DESC_THE) + "!";
return ret;
}
// Used by monsters in "planning" which spell to cast. Fires off a "tracer"
// which tells the monster what it'll hit if it breathes/casts etc.
//
// The output from this tracer function is written into the
// tracer_info variables (friend_info and foe_info).
//
// Note that beam properties must be set, as the tracer will take them
// into account, as well as the monster's intelligence.
void fire_tracer(const monster* mons, targeting_tracer& tracer,
bolt &pbolt, bool explode_only, bool explosion_hole)
{
// If this ASSERT triggers, your spell's setup code probably is doing
// something bad when setup_mons_cast is called with check_validity=true.
ASSERTM(crawl_state.game_started || crawl_state.test || crawl_state.script
|| crawl_state.game_is_arena(),
"invalid game state for tracer '%s'!", pbolt.name.c_str());
// Don't fiddle with any input parameters other than tracer stuff!
pbolt.source = mons->pos();
pbolt.source_id = mons->mid;
pbolt.attitude = mons_attitude(*mons);
pbolt.precalc_agent_properties();
// Init tracer variables.
tracer.foe_info.reset();
tracer.friend_info.reset();
// Clear misc
pbolt.reflections = 0;
pbolt.bounces = 0;
// If there's a specifically requested foe_ratio, honour it.
if (!pbolt.foe_ratio)
{
pbolt.foe_ratio = 80; // default - see mons_should_fire()
if (mons_is_hepliaklqana_ancestor(mons->type))
pbolt.foe_ratio = 100; // do not harm the player!
}
pbolt.in_explosion_phase = false;
// Fire!
if (explode_only)
pbolt.explode(tracer, false, explosion_hole);
else
pbolt.fire(tracer);
}
set<coord_def> create_feat_splash(coord_def center,
int radius,
int number,
int duration,
dungeon_feature_type new_feat)
{
set<coord_def> splash_coords;
for (distance_iterator di(center, true, false, radius); di && number > 0; ++di)
{
const dungeon_feature_type feat = env.grid(*di);
if ((feat == DNGN_FLOOR || feat == DNGN_SHALLOW_WATER)
&& cell_see_cell(center, *di, LOS_NO_TRANS))
{
number--;
int time = random_range(duration, duration * 3 / 2) - (di.radius() * 20);
temp_change_terrain(*di, new_feat, time,
TERRAIN_CHANGE_FLOOD);
splash_coords.insert(*di);
}
}
return splash_coords;
}
void bolt_parent_init(const bolt &parent, bolt &child)
{
child.name = parent.name;
child.short_name = parent.short_name;
child.hit_verb = parent.hit_verb;
child.aux_source = parent.aux_source;
child.source_id = parent.source_id;
child.origin_spell = parent.origin_spell;
child.glyph = parent.glyph;
child.colour = parent.colour;
child.tile_beam = parent.tile_beam;
child.tile_explode = parent.tile_explode;
child.flavour = parent.flavour;
// We don't copy target since that is often overridden.
child.thrower = parent.thrower;
child.source = parent.source;
child.source_name = parent.source_name;
child.attitude = parent.attitude;
child.loudness = parent.loudness;
child.pierce = parent.pierce;
child.aimed_at_spot = parent.aimed_at_spot;
child.is_explosion = parent.is_explosion;
child.ex_size = parent.ex_size;
child.foe_ratio = parent.foe_ratio;
child.tracer = parent.tracer;
_copy_affected_counts(child, parent);
child.range = parent.range;
child.hit = parent.hit;
child.damage = parent.damage;
if (parent.ench_power != -1)
child.ench_power = parent.ench_power;
#ifdef DEBUG_DIAGNOSTICS
child.quiet_debug = parent.quiet_debug;
#endif
}
static void _malign_offering_effect(actor* victim, const actor* agent, int damage)
{
if (!agent || damage < 1)
return;
// The victim may die.
coord_def c = victim->pos();
if (you.see_cell(c) || you.see_cell(agent->pos()))
mprf("%s life force is offered up.", victim->name(DESC_ITS).c_str());
damage = victim->hurt(agent, damage, BEAM_MALIGN_OFFERING, KILLED_BY_BEAM,
"", "by a malign offering");
// Actors that had LOS to the victim (blocked by glass, clouds, etc),
// even if they couldn't actually see each other because of blindness
// or invisibility.
for (actor_near_iterator ai(c, LOS_NO_TRANS); ai; ++ai)
{
if (mons_aligned(agent, *ai) && !(ai->holiness() & MH_NONLIVING)
&& *ai != victim)
{
if (ai->heal(max(1, damage * 2 / 3)) && you.can_see(**ai))
{
mprf("%s %s healed.", ai->name(DESC_THE).c_str(),
ai->conj_verb("are").c_str());
}
}
}
}
static void _vampiric_draining_effect(actor& victim, actor& agent, int damage)
{
if (damage < 1 || !actor_is_susceptible_to_vampirism(victim))
return;
if (you.can_see(victim) || you.can_see(agent))
{
mprf("%s %s life force from %s%s",
agent.name(DESC_THE).c_str(),
agent.conj_verb("draw").c_str(),
victim.name(DESC_THE).c_str(),
attack_strength_punctuation(damage).c_str());
}
if (agent.is_player())
majin_bo_vampirism(*victim.as_monster(), min(damage, victim.stat_hp()));
const int drain_amount = victim.hurt(&agent, damage,
BEAM_VAMPIRIC_DRAINING,
KILLED_BY_BEAM, "",
"by vampiric draining");
if (agent.is_monster())
{
const int hp_gain = drain_amount * 2 / 3;
if (agent.heal(hp_gain))
simple_monster_message(*agent.as_monster(), " is healed by the life force!");
}
else
{
if (you.duration[DUR_DEATHS_DOOR] || you.hp == you.hp_max)
return;
const int hp_gain = div_rand_round(drain_amount, 2);
if (hp_gain)
{
mprf("You feel life coursing into your body%s",
attack_strength_punctuation(hp_gain).c_str());
inc_hp(hp_gain);
}
}
}
/**
* Turn a BEAM_UNRAVELLING beam into a BEAM_UNRAVELLED_MAGIC beam, and make
* it explode appropriately.
*
* @param[in,out] beam The beam being turned into an explosion.
*/
static void _unravelling_explode(bolt &beam)
{
beam.colour = ETC_MUTAGENIC;
beam.flavour = BEAM_UNRAVELLED_MAGIC;
beam.ex_size = 1;
beam.is_explosion = true;
// and it'll explode 'naturally' a little later.
}
bool bolt::is_bouncy(dungeon_feature_type feat) const
{
// Beams with no directionality will assert if we try to bounce them.
if (aimed_at_feet)
return false;
// Don't bounce off open sea.
if (feat_is_endless(feat))
return false;
if (real_flavour == BEAM_CHAOS
&& feat_is_solid(feat))
{
return true;
}
if ((origin_spell == SPELL_REBOUNDING_BLAZE ||
origin_spell == SPELL_REBOUNDING_CHILL)
&& feat_is_solid(feat)
&& !feat_is_tree(feat))
{
return true;
}
if (is_enchantment())
return false;
if (flavour == BEAM_ELECTRICITY
&& origin_spell != SPELL_BLINKBOLT
&& origin_spell != SPELL_MAGNAVOLT
&& !feat_is_metal(feat)
&& !feat_is_tree(feat))
{
return true;
}
if ((flavour == BEAM_FIRE || flavour == BEAM_COLD)
&& feat == DNGN_CRYSTAL_WALL)
{
return true;
}
return false;
}
cloud_type bolt::get_cloud_type() const
{
if (origin_spell == SPELL_NOXIOUS_CLOUD)
return CLOUD_MEPHITIC;
if (origin_spell == SPELL_POISONOUS_CLOUD)
return CLOUD_POISON;
if (origin_spell == SPELL_HOLY_BREATH)
return CLOUD_HOLY;
if (origin_spell == SPELL_FLAMING_CLOUD)
return CLOUD_FIRE;
if (origin_spell == SPELL_CHAOS_BREATH)
return CLOUD_CHAOS;
if (origin_spell == SPELL_MIASMA_BREATH)
return CLOUD_MIASMA;
if (origin_spell == SPELL_FREEZING_CLOUD)
return CLOUD_COLD;
if (origin_spell == SPELL_SPECTRAL_CLOUD)
return CLOUD_SPECTRAL;
if (origin_spell == SPELL_RAVENOUS_SWARM)
return CLOUD_BATS;
return CLOUD_NONE;
}
int bolt::get_cloud_pow() const
{
if (origin_spell == SPELL_FREEZING_CLOUD
|| origin_spell == SPELL_POISONOUS_CLOUD)
{
return random_range(10, 15);
}
if (origin_spell == SPELL_SPECTRAL_CLOUD)
return random_range(12, 20);
if (origin_spell == SPELL_RAVENOUS_SWARM)
return random_range(22, 40);
return 0;
}
int bolt::get_cloud_size(bool min, bool max) const
{
if (origin_spell == SPELL_MEPHITIC_CLOUD
|| origin_spell == SPELL_MIASMA_BREATH
|| origin_spell == SPELL_FREEZING_CLOUD)
{
return 10;
}
if (origin_spell == SPELL_RAVENOUS_SWARM)
{
if (min)
return 10;
else if (max)
return 16;
else
return random_range(10, 16);
}
if (origin_spell == SPELL_RUST_BREATH)
return ench_power;
if (min)
return 8;
if (max)
return 12;
return 8 + random2(5);
}
static void _waterlog_mon(monster &mon, int ench_pow)
{
if (!mon.alive() || mon.res_water_drowning() || mon.has_ench(ENCH_WATERLOGGED))
return;
simple_monster_message(mon, " is engulfed in water.");
const int min_dur = ench_pow + 20;
const int dur = random_range(min_dur, min_dur * 3 / 2);
mon.add_ench(mon_enchant(ENCH_WATERLOGGED, 0, &you, dur));
}
void bolt::special_explode()
{
unwind_var<beam_tracer*> old_tracer(special_explosion->tracer, tracer);
_copy_affected_counts(*special_explosion, *this);
special_explosion->in_explosion_phase = false;
special_explosion->target = pos();
special_explosion->refine_for_explosion();
special_explosion->explode();
_copy_affected_counts(*this, *special_explosion);
}
void bolt::affect_endpoint()
{
// Test if this shot should trigger Dimensional Bullseye.
bool use_bullseye = false;
if (can_trigger_bullseye)
{
// We've already verified that at least one valid triggering target was
// aimed at, but we need to know that we didn't ALSO aim at the bullseye
// target (and that it's still in range)
monster* bullseye_targ = monster_by_mid(you.props[BULLSEYE_TARGET_KEY].get_int());
if (bullseye_targ && hit_count.count(bullseye_targ->mid) == 0
&& you.can_see(*bullseye_targ))
{
use_bullseye = true;
}
}
// hack: we use hit_verb to communicate whether a ranged
// attack hit. (And ranged attacks should only explode if
// they hit the target, to avoid silliness with . targeting.)
if (special_explosion && (is_tracer() || !item || !hit_verb.empty()))
special_explode();
// Leave an object, if applicable.
if (item && !is_tracer() && was_missile)
{
ASSERT(item->defined());
if (item->flags & ISFLAG_SUMMONED || item_mulches)
item_was_destroyed(*item);
// Dimensional bullseye should make objects drop at the bullseye target
// instead of the end of the ray
else if (drop_item && !use_bullseye)
drop_object();
}
if (is_explosion)
{
target = pos();
refine_for_explosion();
explode();
return;
}
const cloud_type cloud = get_cloud_type();
if (is_tracer())
{
if (cloud == CLOUD_NONE)
return;
targeter_cloud tgt(agent(), cloud, range, get_cloud_size(true),
get_cloud_size(false, true));
tgt.set_aim(pos());
for (const auto &entry : tgt.seen)
{
if (entry.second != AFF_YES && entry.second != AFF_MAYBE)
continue;
if (entry.first == you.pos())
tracer_affect_player();
else if (monster* mon = monster_at(entry.first))
if (!ignores_monster(mon))
tracer_affect_monster(mon);
}
return;
}
if (!is_explosion && !noise_generated && loudness)
{
// Digging can target squares on the map boundary, though it
// won't remove them of course.
const coord_def noise_position = clamp_in_bounds(pos());
noisy(loudness, noise_position, source_id);
noise_generated = true;
}
if (cloud != CLOUD_NONE)
big_cloud(cloud, agent(), pos(), get_cloud_pow(), get_cloud_size());
// Not using big_cloud so that the area affected is more predictable to the player.
if (origin_spell == SPELL_RUST_BREATH)
{
int to_place = ench_power;
for (distance_iterator di(pos(), true, false, 2); di && to_place > 0; ++di)
{
if (!cell_is_solid(*di) && cell_see_cell(*di, agent()->pos(), LOS_NO_TRANS))
{
place_cloud(CLOUD_RUST, *di, 5 + ench_power * 2 / 3 + random2(2), agent());
to_place--;
}
}
}
// bail out of bullseye early if its target died somehow
if (use_bullseye && you.duration[DUR_DIMENSIONAL_BULLSEYE] > 0)
{
monster* bullseye_targ = monster_by_mid(you.props[BULLSEYE_TARGET_KEY].get_int());
mpr("Your projectile teleports!");
use_target_as_pos = true;
target = bullseye_targ->pos();
affect_monster(bullseye_targ);
if (drop_item)
{
// This is a little hacky, but the idea is to make the beam think we only
// aimed at our bullseye target before dropping the item (so it will appear
// beneath them). I think this should work fine?
drop_object();
}
if (special_explosion && (is_tracer() || !item || !hit_verb.empty()))
special_explode();
}
// you like special cases, right?
switch (origin_spell)
{
case SPELL_PRIMAL_WAVE:
{
if (you.see_cell(pos()))
mpr("The wave splashes down.");
else
mpr("You hear a splash.");
const bool is_player = agent(true) && agent(true)->is_player();
const int num = is_player ? div_rand_round(ench_power * 3, 20) + 3 + random2(7)
: random_range(3, 12, 2);
const int dur = div_rand_round(ench_power * 4, 3) + 66;
set<coord_def> splash_coords = create_feat_splash(pos(), is_player ? 2 : 1, num, dur);
dprf(DIAG_BEAM, "Creating pool at %d,%d with %d tiles of water for %d auts.", pos().x, pos().y, num, dur);
// Waterlog anything at the center, even if a pool wasn't generated there
splash_coords.insert(pos());
if (!is_player)
break;
for (const coord_def &coord : splash_coords)
{
monster* mons = monster_at(coord);
if (mons)
_waterlog_mon(*mons, ench_power);
}
break;
}
case SPELL_HURL_SLUDGE:
{
// short duration to limit the ability of the player to use it
// against enemies
const int dur = random_range(20, 30);
// TODO: deduplicate with noxious_bog_cell
if (env.grid(pos()) == DNGN_DEEP_WATER || env.grid(pos()) == DNGN_LAVA)
break;
// intentionally don't use TERRAIN_CHANGE_BOG to avoid it vanishing
// when out of LOS
temp_change_terrain(pos(), DNGN_TOXIC_BOG, dur,
TERRAIN_CHANGE_FLOOD,
agent() ? agent()->mid : MID_NOBODY);
break;
}
case SPELL_BLINKBOLT:
{
actor *act = agent(true); // use orig actor even when reflected
if (!act || !act->alive())
return;
for (vector<coord_def>::reverse_iterator citr = path_taken.rbegin();
citr != path_taken.rend(); ++citr)
{
if (act->is_habitable(*citr) && (!act->is_player() || !monster_at(*citr))
&& act->blink_to(*citr, false))
{
return;
}
}
return;
}
case SPELL_SEARING_BREATH:
if (!path_taken.empty())
place_cloud(CLOUD_FIRE, pos(), 5 + random2(5), agent());
break;
case SPELL_MUD_BREATH:
{
mpr("The mud splashes down.");
const int num = 3 + div_rand_round(ench_power * 3, 7) + random2(4);
const int dur = (div_rand_round(ench_power * 1, 3) + 15) * BASELINE_DELAY;
const int rad = (num > 20) ? 3 : (num > 9) ? 2 : 1;
create_feat_splash(pos(), rad, num, dur, DNGN_MUD);
}
break;
case SPELL_FLASHING_BALESTRA:
{
// If the initial bolt is reflected or redirected back at the summoner,
// we can crash on trying to create the summon.
if (!agent(true) || !agent(true)->alive())
break;
monster* blade = create_monster(mgen_data(MONS_DANCING_WEAPON,
SAME_ATTITUDE(agent(true)->as_monster()),
pos(), agent(true)->as_monster()->foe)
.set_summoned(agent(true), SPELL_FLASHING_BALESTRA, summ_dur(1), false)
.set_range(1));
if (blade)
blade->add_ench(ENCH_MIGHT);
}
break;
case SPELL_PHANTOM_BLITZ:
{
if (!agent(true) || !agent(true)->alive())
break;
coord_def spot;
int num_found = 0;
for (fair_adjacent_iterator ai(pos()); ai; ++ai)
{
if (feat_is_solid(env.grid(*ai)) || actor_at(*ai))
continue;
if (one_chance_in(++num_found))
spot = *ai;
}
if (!spot.origin())
{
// Clone the original monster and heal the clone to full.
monster* blitzer = agent(true)->as_monster();
bool obviousness; // dummy argument
monster *mirror = clone_mons(blitzer, true, &obviousness,
blitzer->attitude, spot);
if (!mirror)
break;
mirror->mark_summoned(SPELL_PHANTOM_BLITZ, summ_dur(2), true, true);
mirror->summoner = blitzer->mid;
mirror->foe = blitzer->foe;
mirror->hit_points = blitzer->max_hit_points;
#ifdef USE_TILE
if (mirror->type == MONS_NEKOMATA)
mirror->props[MONSTER_TILE_KEY] = TILEP_MONS_NEKOMATA_PHANTOM;
#endif
}
}
break;
case SPELL_GREATER_ENSNARE:
{
int count = random_range(3, 6);
for (distance_iterator di(pos(), true, true, 1); di && count > 0; ++di)
{
trap_def *trap = trap_at(*di);
if (trap && trap->type != TRAP_WEB
|| !trap && env.grid(*di) != DNGN_FLOOR)
{
continue;
}
if (actor_at(*di))
ensnare(actor_at(*di));
else
{
temp_change_terrain(*di, DNGN_TRAP_WEB, random_range(60, 110),
TERRAIN_CHANGE_WEBS);
}
count--;
}
break;
}
default:
break;
}
}
void bolt::affect_endpoint(beam_tracer& new_tracer)
{
unwind_var<beam_tracer*> old_tracer(tracer, &new_tracer);
affect_endpoint();
}
bool bolt::stop_at_target() const
{
// the pos check is to avoid a ray.cc assert for a ray that goes nowhere
return is_explosion || is_big_cloud() ||
(source_id == MID_PLAYER && origin_spell == SPELL_BLINKBOLT) ||
(aimed_at_spot && (pos() == source || flavour != BEAM_DIGGING));
}
void bolt::drop_object()
{
ASSERT(item != nullptr);
ASSERT(item->defined());
const int idx = copy_item_to_grid(*item, pos(), 1);
if (idx != NON_ITEM
&& idx != -1
&& item->sub_type == MI_THROWING_NET)
{
monster* m = monster_at(pos());
// Player or monster at position is caught in net.
// Don't catch anything if the creature was already caught.
if (get_trapping_net(pos(), true) == NON_ITEM
&& (you.pos() == pos() && you.attribute[ATTR_HELD]
|| m && m->caught()))
{
maybe_split_nets(env.item[idx], pos());
}
}
}
// Returns true if the beam hits the player, fuzzing the beam if necessary
// for monsters without see invis firing tracers at the player.
bool bolt::found_player() const
{
const bool needs_fuzz = is_tracer()
&& !YOU_KILL(thrower)
&& !can_see_invis && you.invisible()
&& (!agent()
|| (agent()->is_monster()
&& !agent()->as_monster()->friendly()
&& agent()->as_monster()->attitude != ATT_MARIONETTE))
// No point in fuzzing to a position that could never be hit.
&& you.see_cell_no_trans(pos());
const int dist = needs_fuzz? 2 : 0;
return grid_distance(pos(), you.pos()) <= dist;
}
void bolt::affect_ground()
{
// Explosions only have an effect during their explosion phase.
// Special cases can be handled here.
if (is_explosion && !in_explosion_phase)
return;
// XXX: This feels like an ugly place to put this, but it doesn't do any
// damage and the cloud placement code is otherwise skipped entirely
// for tracers.
if (is_tracer() && origin_spell == SPELL_NOXIOUS_BREATH && ench_power > 10)
{
for (adjacent_iterator ai(pos()); ai; ++ai)
{
const monster* mon = monster_at(*ai);
if (mon)
tracer->monster_hit(*this, *mon);
}
}
if (is_tracer())
return;
affect_place_clouds();
}
bool bolt::is_fiery() const
{
return get_beam_resist_type(flavour) == BEAM_FIRE;
}
/// Can this bolt burn trees it hits?
bool bolt::can_burn_trees() const
{
// XXX: rethink this
switch (origin_spell)
{
case SPELL_LIGHTNING_BOLT:
case SPELL_BOLT_OF_FIRE:
case SPELL_REBOUNDING_BLAZE:
case SPELL_BOLT_OF_MAGMA:
case SPELL_MAGMA_BARRAGE:
case SPELL_FIREBALL:
case SPELL_FIRE_STORM:
case SPELL_IGNITION:
case SPELL_INNER_FLAME:
case SPELL_STARBURST:
case SPELL_FLAME_WAVE:
case SPELL_FORGE_BLAZEHEART_GOLEM: // core breach!
case SPELL_HELLFIRE_MORTAR:
case SPELL_MONARCH_BOMB:
return true;
case SPELL_UNLEASH_DESTRUCTION:
return flavour == BEAM_FIRE || flavour == BEAM_LAVA;
default:
return false;
}
}
bool bolt::can_affect_wall(const coord_def& p, bool map_knowledge) const
{
dungeon_feature_type wall = env.grid(p);
// digging might affect unseen squares, as far as the player knows
if (map_knowledge && flavour == BEAM_DIGGING &&
!env.map_knowledge(pos()).seen())
{
return true;
}
// digging
if (flavour == BEAM_DIGGING && feat_is_diggable(wall))
return true;
if (can_burn_trees())
return feat_is_flammable(wall);
// Lee's Rapid Deconstruction
if (flavour == BEAM_FRAG)
return true; // smite targeting, we don't care
return false;
}
void bolt::affect_place_clouds()
{
if (in_explosion_phase)
affect_place_explosion_clouds();
const coord_def p = pos();
// Is there already a cloud here?
if (cloud_struct* cloud = cloud_at(p))
{
// fire cancelling cold & vice versa
if ((cloud->type == CLOUD_COLD && is_fiery())
|| (cloud->type == CLOUD_FIRE && flavour == BEAM_COLD))
{
if (player_can_hear(p))
mprf(MSGCH_SOUND, "You hear a sizzling sound!");
delete_cloud(p);
extra_range_used += 5;
return;
}
// blastmote explosions
if (cloud->type == CLOUD_BLASTMOTES && is_fiery())
explode_blastmotes_at(p);
}
const dungeon_feature_type feat = env.grid(p);
if (origin_spell == SPELL_POISONOUS_CLOUD)
place_cloud(CLOUD_POISON, p, random2(5) + 3, agent());
if (origin_spell == SPELL_HOLY_BREATH)
place_cloud(CLOUD_HOLY, p, random2(4) + 2, agent());
if (origin_spell == SPELL_FLAMING_CLOUD)
place_cloud(CLOUD_FIRE, p, random2(4) + 2, agent());
if (origin_spell == SPELL_RAVENOUS_SWARM)
place_cloud(CLOUD_BATS, p, random2(4) + 4, agent());
// Fire/cold over water/lava
if (feat == DNGN_LAVA && flavour == BEAM_COLD
|| feat_is_water(feat) && is_fiery())
{
place_cloud(CLOUD_STEAM, p, 2 + random2(5), agent(), 11);
}
if (feat_is_water(feat) && flavour == BEAM_COLD
&& damage.num * damage.size > 35)
{
place_cloud(CLOUD_COLD, p, damage.num * damage.size / 30 + 1, agent());
}
if (flavour == BEAM_MIASMA)
place_cloud(CLOUD_MIASMA, p, random2(5) + 2, agent());
if (flavour == BEAM_STEAM)
{
if (origin_spell == SPELL_STEAM_BREATH)
place_cloud(CLOUD_STEAM, p, div_rand_round(ench_power, 3) + 3, agent());
else
place_cloud(CLOUD_STEAM, p, random2(5) + 2, agent());
}
//XXX: these use the name for a gameplay effect.
if (name == "poison gas")
place_cloud(CLOUD_POISON, p, random2(4) + 3, agent());
if (origin_spell == SPELL_PETRIFYING_CLOUD)
place_cloud(CLOUD_PETRIFY, p, random2(4) + 4, agent());
if (origin_spell == SPELL_SPECTRAL_CLOUD)
place_cloud(CLOUD_SPECTRAL, p, random2(6) + 5, agent());
if (origin_spell == SPELL_DEATH_RATTLE)
place_cloud(CLOUD_MIASMA, p, random2(4) + 4, agent());
if (origin_spell == SPELL_CAUSTIC_BREATH)
{
if (!actor_at(p))
{
place_cloud(CLOUD_ACID, p, 3 + random_range(ench_power / 2,
ench_power * 4 / 5),
agent());
}
}
if (origin_spell == SPELL_NOXIOUS_BREATH)
{
place_cloud(CLOUD_MEPHITIC, p,
2 + random_range(ench_power / 2, ench_power * 4 / 5), agent());
for (adjacent_iterator ai(pos()); ai; ++ai)
{
if (feat_is_solid(env.grid(*ai)))
continue;
if (x_chance_in_y(max(0, ench_power - 10), ench_power - 5))
{
place_cloud(CLOUD_MEPHITIC, *ai,
2 + random_range(ench_power / 3, ench_power / 2), agent());
}
}
}
if (origin_spell == SPELL_RUST_BREATH)
place_cloud(CLOUD_RUST, p, 5 + ench_power * 2 / 3 + random2(2), agent());
if (origin_spell == SPELL_GOLDEN_BREATH)
place_cloud(CLOUD_POISON, p, random_range(4, 8), agent());
// Only place clouds on creatures who are immune to them
if (origin_spell == SPELL_MOURNING_WAIL)
{
if (!actor_at(p) || actor_at(p)->res_negative_energy() == 3)
place_cloud(CLOUD_MISERY, p, random2(4) + 2, agent());
}
if (origin_spell == SPELL_MARCH_OF_SORROWS)
{
place_cloud(CLOUD_MISERY, p, random2(5) + 8, agent());
if (actor_at(p) && !mons_aligned(actor_at(p), agent()))
{
for (adjacent_iterator ai(pos()); ai; ++ai)
{
if (feat_is_solid(env.grid(*ai)))
continue;
place_cloud(CLOUD_MISERY, *ai, random2(4) + 2, agent());
}
}
}
}
void bolt::affect_place_explosion_clouds()
{
const coord_def p = pos();
// First check: fire/cold over water/lava.
if (env.grid(p) == DNGN_LAVA && flavour == BEAM_COLD
|| feat_is_water(env.grid(p)) && is_fiery())
{
place_cloud(CLOUD_STEAM, p, 2 + random2(5), agent());
return;
}
if (flavour == BEAM_MEPHITIC)
{
const coord_def center = (aimed_at_feet ? source : ray.pos());
if (p == center || x_chance_in_y(125 + ench_power, 225))
{
place_cloud(CLOUD_MEPHITIC, p, roll_dice(2,
8 + div_rand_round(ench_power, 20)), agent());
}
}
// Blazeheart core detonation
if (origin_spell == SPELL_FORGE_BLAZEHEART_GOLEM)
place_cloud(CLOUD_FIRE, p, 2 + random2avg(5,2), agent());
if (origin_spell == SPELL_FIRE_STORM)
{
place_cloud(CLOUD_FIRE, p, 2 + random2avg(5,2), agent());
if (!cell_is_solid(p) && !monster_at(p) && one_chance_in(4))
{
const god_type god =
(crawl_state.is_god_acting()) ? crawl_state.which_god_acting()
: GOD_NO_GOD;
const beh_type att =
(whose_kill() == KC_OTHER ? BEH_HOSTILE : BEH_FRIENDLY);
actor* summ = agent();
mgen_data mg(MONS_FIRE_VORTEX, att, p, MHITNOT, MG_NONE, god);
mg.set_summoned(summ, SPELL_FIRE_STORM, summ_dur(1), false, false);
// Spell-summoned monsters need to have a live summoner.
if (summ == nullptr || !summ->alive())
{
if (!source_name.empty())
mg.non_actor_summoner = source_name;
else if (god != GOD_NO_GOD)
mg.non_actor_summoner = god_name(god);
}
mons_place(mg);
}
}
}
// A little helper function to handle the calling of ouch()...
void bolt::internal_ouch(int dam)
{
monster* monst = monster_by_mid(source_id);
const char *what = aux_source.empty() ? name.c_str() : aux_source.c_str();
if (YOU_KILL(thrower) && you.duration[DUR_QUAD_DAMAGE])
dam *= 4;
// The order of this is important.
if (monst && mons_is_wrath_avatar(*monst))
{
ouch(dam, KILLED_BY_DIVINE_WRATH, MID_NOBODY,
aux_source.empty() ? nullptr : aux_source.c_str(), true,
source_name.empty() ? nullptr : source_name.c_str());
}
else if (is_death_effect)
{
ouch(dam, KILLED_BY_DEATH_EXPLOSION, source_id,
aux_source.c_str(), true,
source_name.empty() ? nullptr : source_name.c_str());
}
else if (flavour == BEAM_MINDBURST || flavour == BEAM_DESTRUCTION)
{
ouch(dam, KILLED_BY_DISINT, source_id, what, true,
source_name.empty() ? nullptr : source_name.c_str());
}
else if (YOU_KILL(thrower) && aux_source.empty())
{
if (reflections > 0)
ouch(dam, KILLED_BY_REFLECTION, reflector, name.c_str());
else if (bounces > 0)
ouch(dam, KILLED_BY_BOUNCE, MID_PLAYER, name.c_str());
else
{
if (self_targeted() && effect_known)
ouch(dam, KILLED_BY_SELF_AIMED, MID_PLAYER, name.c_str());
else
ouch(dam, KILLED_BY_TARGETING, MID_PLAYER, name.c_str());
}
}
else if (MON_KILL(thrower))
{
ouch(dam, KILLED_BY_BEAM, source_id,
aux_source.c_str(), true,
source_name.empty() ? nullptr : source_name.c_str());
}
else // KILL_NON_ACTOR || (YOU_KILL && aux_source)
ouch(dam, KILLED_BY_WILD_MAGIC, source_id, aux_source.c_str());
}
// [ds] Apply a fuzz if the monster lacks see invisible and is trying to target
// an invisible player. This makes invisibility slightly more powerful.
bool bolt::fuzz_invis_tracer()
{
// Did the monster have a rough idea of where you are?
int dist = grid_distance(target, you.pos());
// No, ditch this.
if (dist > 2)
return false;
// Apply fuzz now.
coord_def fuzz;
fuzz.x = random_range(-2, 2);
fuzz.y = random_range(-2, 2);
coord_def newtarget = target + fuzz;
if (in_bounds(newtarget))
target = newtarget;
// Fire away!
return true;
}
// A first step towards to-hit sanity for beams. We're still being
// very kind to the player, but it should be fairer to monsters than
// 4.0.
static int _test_beam_hit(int attack, int defence, defer_rand &r)
{
if (attack == AUTOMATIC_HIT)
return true;
attack = r[1].random2(attack);
defence = r[2].random2avg(defence, 2);
dprf(DIAG_BEAM, "Beam attack: %d, defence: %d", attack, defence);
return attack - defence;
}
bool bolt::is_harmless(const monster* mon) const
{
// For enchantments, this is already handled in nasty_to().
if (is_enchantment())
return !nasty_to(mon);
// The others are handled here.
switch (flavour)
{
case BEAM_VISUAL:
case BEAM_DIGGING:
return true;
case BEAM_HOLY:
return mon->res_holy_energy() >= 3;
case BEAM_FOUL_FLAME:
return mon->res_foul_flame() >= 3;
case BEAM_STEAM:
return mon->res_steam() >= 3;
case BEAM_FIRE:
return mon->res_fire() >= 3;
case BEAM_COLD:
return mon->res_cold() >= 3;
case BEAM_MIASMA:
return mon->res_miasma();
case BEAM_NEG:
return mon->res_negative_energy() == 3;
case BEAM_ELECTRICITY:
return mon->res_elec() >= 3;
case BEAM_POISON:
return mon->res_poison() >= 3;
case BEAM_ACID:
return mon->res_corr() >= 3;
case BEAM_MEPHITIC:
return mon->res_poison() > 0 || mon->clarity();
case BEAM_UMBRAL_TORCHLIGHT:
return (bool)!(mon->holiness() & (MH_NATURAL | MH_DEMONIC | MH_HOLY));
default:
return false;
}
}
// N.b. only called for player-originated beams and those used by the
// player's allies. This may not currently be comprehensive with ally spells
// that could affect some, but not all, players.
bool bolt::harmless_to_player() const
{
dprf(DIAG_BEAM, "beam flavour: %d", flavour);
// Marionettes can't hurt the player with anything, so don't worry about it.
if (agent() && agent()->real_attitude() == ATT_MARIONETTE)
return true;
if (you.cloud_immune() && is_big_cloud())
return true;
if (origin_spell == SPELL_COMBUSTION_BREATH
|| origin_spell == SPELL_NULLIFYING_BREATH
|| origin_spell == SPELL_RIMEBLIGHT
|| origin_spell == SPELL_RUST_BREATH && you.form == transformation::fortress_crab)
{
return true;
}
switch (flavour)
{
case BEAM_VISUAL:
case BEAM_DIGGING:
return true;
// Positive enchantments.
case BEAM_HASTE:
case BEAM_HEALING:
case BEAM_MIGHT:
case BEAM_AGILITY:
case BEAM_INVISIBILITY:
case BEAM_RESISTANCE:
case BEAM_DOUBLE_HEALTH:
return true;
case BEAM_HOLY:
return you.res_holy_energy() >= 3;
case BEAM_FOUL_FLAME:
return you.res_foul_flame() >= 3;
case BEAM_MIASMA:
return you.res_miasma();
case BEAM_NEG:
return player_prot_life(false) >= 3;
case BEAM_POISON:
return player_res_poison(false) >= 3
|| is_big_cloud() && player_res_poison(false) > 0;
case BEAM_MEPHITIC:
return player_res_poison(false) > 0 || you.clarity();
case BEAM_PETRIFY:
return you.res_petrify() || you.petrified();
#if TAG_MAJOR_VERSION == 34
case BEAM_COLD:
return is_big_cloud() && you.has_mutation(MUT_FREEZING_CLOUD_IMMUNITY);
#endif
case BEAM_VIRULENCE:
return player_res_poison(false) >= 3;
case BEAM_ROOTS:
return mons_att_wont_attack(attitude) || !agent()->can_constrict(you, CONSTRICT_ROOTS);
case BEAM_VILE_CLUTCH:
return mons_att_wont_attack(attitude) || !agent()->can_constrict(you, CONSTRICT_BVC);
case BEAM_UMBRAL_TORCHLIGHT:
return agent(true)->is_player()
|| (bool)!(you.holiness() & (MH_NATURAL | MH_DEMONIC | MH_HOLY));
case BEAM_QAZLAL:
return true;
default:
return false;
}
}
bool bolt::is_reflectable(const actor &whom) const
{
if (range_used() > range)
return false;
return whom.reflection();
}
bool bolt::is_big_cloud() const
{
return testbits(get_spell_flags(origin_spell), spflag::cloud);
}
coord_def bolt::leg_source() const
{
if (bounces > 0 && map_bounds(bounce_pos))
return bounce_pos;
else
return source;
}
// Reflect a beam back the direction it came. This is used
// by shields of reflection.
void bolt::reflect()
{
reflections++;
target = leg_source();
source = pos();
// Reset bounce_pos, so that if we somehow reflect again before reaching
// the wall that we won't keep heading towards the wall.
bounce_pos.reset();
if (pos() == you.pos())
{
reflector = MID_PLAYER;
count_action(CACT_BLOCK, -1, BLOCK_REFLECT);
}
else if (monster* m = monster_at(pos()))
reflector = m->mid;
else
{
reflector = MID_NOBODY;
#ifdef DEBUG
dprf(DIAG_BEAM, "Bolt reflected by neither player nor "
"monster (bolt = %s, item = %s)", name.c_str(),
item ? item->name(DESC_PLAIN).c_str() : "none");
#endif
}
flavour = real_flavour;
choose_ray();
}
void bolt::tracer_affect_player()
{
if (flavour == BEAM_UNRAVELLING && player_is_debuffable())
is_explosion = true;
const actor* ag = agent();
const bool harmless = harmless_to_player();
// Check whether thrower can see player, unless thrower == player.
if (YOU_KILL(thrower))
{
if (!harmless)
tracer->actor_affected(true, you.experience_level);
}
else if (can_see_invis
|| !you.invisible()
|| ag && ag->as_monster()->friendly()
|| fuzz_invis_tracer())
{
// Do we really want to count friendly monsters hitting the player
// with a harmless bolt as them hitting an enemy? -- Wizard Ike
bool friendly_fire = mons_att_wont_attack(attitude)
&& !harmless;
int power = you.experience_level;
tracer->actor_affected(friendly_fire, power);
}
if (!harmless)
tracer->player_hit();
extra_range_used += range_used_on_hit();
}
int bolt::apply_lighting(int base_hit, const actor &targ) const
{
if (targ.invisible() && !can_see_invis)
base_hit /= 2;
// We multiply these lighting effects by 2, since normally they're applied post-roll
// where the effect (on average) counts doubled
if (targ.backlit(false))
base_hit += BACKLIGHT_TO_HIT_BONUS * 2;
// Malus is already negative so must still be ADDED to the base_hit
if (!nightvision && targ.umbra())
base_hit += UMBRA_TO_HIT_MALUS * 2;
return base_hit;
}
/* Determine whether the beam hit or missed the player, and tell them if it
* missed.
*
* @return true if the beam missed, false if the beam hit the player.
*/
bool bolt::misses_player()
{
if (flavour == BEAM_VISUAL)
return true;
if ((is_explosion || aimed_at_feet)
&& origin_spell != SPELL_CALL_DOWN_LIGHTNING
&& origin_spell != SPELL_MOMENTUM_STRIKE)
{
return false;
}
int dodge = you.evasion();
int real_tohit = hit;
if (real_tohit != AUTOMATIC_HIT)
real_tohit = apply_lighting(real_tohit, you);
const int SH = player_shield_class();
if ((player_omnireflects() && is_omnireflectable()
|| is_blockable())
&& you.shielded()
&& !you.shield_exhausted()
&& !aimed_at_feet
&& (SH > 0 || you.duration[DUR_DIVINE_SHIELD]))
{
bool blocked = false;
if (hit == AUTOMATIC_HIT)
{
// 50% chance of blocking ench-type effects at 10 displayed sh
blocked = x_chance_in_y(SH, omnireflect_chance_denom(SH));
dprf(DIAG_BEAM, "%smnireflected: %d/%d chance",
blocked ? "O" : "Not o", SH, omnireflect_chance_denom(SH));
}
else
{
// We use the original to-hit here.
// (so that effects increasing dodge chance don't increase
// block...?)
const int testhit = random2(hit * 130 / 100);
const int block = you.shield_bonus();
dprf(DIAG_BEAM, "Beamshield: hit: %d, block %d", testhit, block);
blocked = testhit < block;
}
// Divine shield only blocks conventionally blockable things, even if
// the player is using the Warlock's Mirror.
if (blocked || (you.duration[DUR_DIVINE_SHIELD] && is_blockable()))
{
const string refl_name = name.empty() &&
origin_spell != SPELL_NO_SPELL ?
spell_title(origin_spell) :
name;
const item_def *shield = you.shield();
if (is_reflectable(you))
{
if (shield && shield_reflects(*shield))
{
mprf("Your %s blocks the %s... and reflects it back!",
shield->name(DESC_PLAIN).c_str(),
refl_name.c_str());
}
else
{
mprf("You block the %s... and reflect it back!",
refl_name.c_str());
}
reflect();
}
else
{
mprf("You block the %s.", name.c_str());
finish_beam();
}
you.shield_block_succeeded(agent());
// Use up a charge of Divine Shield, if active.
tso_expend_divine_shield_charge();
return true;
}
// Some training just for the "attempt".
practise_shield_block(false);
}
if (is_enchantment())
return false;
if (!self_targeted())
practise_being_shot_at();
defer_rand r;
const int repel = you.missile_repulsion() ? REPEL_MISSILES_EV_BONUS : 0;
dodge += repel;
const int hit_margin = you.duration[DUR_AUTODODGE] ? -1000
: _test_beam_hit(real_tohit, dodge, r);
if (hit_margin < 0)
{
if (hit_margin > -repel)
{
mprf("The %s is repelled.", name.c_str());
count_action(CACT_DODGE, DODGE_REPEL);
}
else
{
mprf("The %s misses you.", name.c_str());
count_action(CACT_DODGE, DODGE_EVASION);
}
}
else
return false;
return true;
}
void bolt::affect_player_enchantment(bool resistible)
{
if (resistible
&& has_saving_throw()
&& you.check_willpower(agent(true), ench_power) > 0)
{
// You resisted it.
// Give a message.
bool need_msg = true;
if (thrower != KILL_YOU_MISSILE)
{
const monster* mon = monster_by_mid(source_id);
if (mon && !mon->observable())
{
mprf("Something tries to affect you, but you %s.",
you.willpower() == WILL_INVULN ? "are unaffected"
: "resist");
need_msg = false;
}
}
if (need_msg)
{
if (you.willpower() == WILL_INVULN)
canned_msg(MSG_YOU_UNAFFECTED);
else
{
// the message reflects the level of difficulty resisting.
const int margin = you.willpower() - ench_power;
mprf("You%s", you.resist_margin_phrase(margin).c_str());
}
}
// punish the monster if we're a willful demon
if (you.get_mutation_level(MUT_DEMONIC_WILL))
{
monster* mon = monster_by_mid(source_id);
if (mon && mon->alive())
{
const int dam = 3 + random2(1 + div_rand_round(ench_power, 10));
mprf("Your will lashes out at %s%s",
mon->name(DESC_THE).c_str(),
attack_strength_punctuation(dam).c_str());
mon->hurt(&you, dam);
}
}
// You *could* have gotten a free teleportation in the Abyss,
// but no, you resisted.
if (flavour == BEAM_TELEPORT && player_in_branch(BRANCH_ABYSS))
xom_is_stimulated(200);
extra_range_used += range_used_on_hit();
return;
}
// Never affects the player.
if (flavour == BEAM_INFESTATION
|| flavour == BEAM_ENFEEBLE)
{
return;
}
// You didn't resist it.
if (animate)
_ench_animation(effect_known ? real_flavour : BEAM_MAGIC);
bool nasty = true, nice = false;
const bool blame_player = god_cares() && YOU_KILL(thrower);
switch (flavour)
{
case BEAM_HIBERNATION:
case BEAM_SLEEP:
you.put_to_sleep(nullptr, (4 + random2avg(8, 3)) * BASELINE_DELAY,
flavour == BEAM_HIBERNATION);
break;
case BEAM_CORONA:
you.backlight();
obvious_effect = true;
break;
case BEAM_POLYMORPH:
obvious_effect = you.polymorph(20 + roll_dice(3, 10));
break;
case BEAM_MALMUTATE:
case BEAM_UNRAVELLED_MAGIC:
mpr("Strange energies course through your body.");
you.malmutate(agent(), aux_source.empty() ? get_source_name() :
(get_source_name() + "/" + aux_source));
obvious_effect = true;
break;
case BEAM_SLOW:
case BEAM_SHADOW_TORPOR:
slow_player(10 + random2(ench_power));
obvious_effect = true;
break;
case BEAM_HASTE:
haste_player(40 + random2(ench_power));
did_god_conduct(DID_HASTY, 10, blame_player);
obvious_effect = true;
nasty = false;
nice = true;
break;
case BEAM_HEALING:
potionlike_effect(POT_HEAL_WOUNDS, ench_power, true);
obvious_effect = true;
nasty = false;
nice = true;
break;
case BEAM_MIGHT:
potionlike_effect(POT_MIGHT, ench_power);
obvious_effect = true;
nasty = false;
nice = true;
break;
case BEAM_INVISIBILITY:
potionlike_effect(POT_INVISIBILITY, ench_power);
obvious_effect = true;
nasty = false;
nice = true;
break;
case BEAM_PARALYSIS:
you.paralyse(agent(), random_range(2, 5));
obvious_effect = true;
break;
case BEAM_PETRIFY:
you.petrify(agent());
obvious_effect = true;
break;
case BEAM_VEX:
you.vex(agent(), random_range(3, 6));
obvious_effect = true;
break;
case BEAM_CONFUSION:
confuse_player(5 + random2(3));
obvious_effect = true;
break;
case BEAM_WEAKNESS:
you.weaken(agent(), 8 + random2(4));
obvious_effect = true;
break;
case BEAM_TELEPORT:
you_teleport();
// An enemy helping you escape while in the Abyss, or an
// enemy stabilizing a teleport that was about to happen.
if (!mons_att_wont_attack(attitude) && player_in_branch(BRANCH_ABYSS))
xom_is_stimulated(200);
obvious_effect = true;
break;
case BEAM_BLINK:
uncontrolled_blink();
obvious_effect = true;
break;
case BEAM_BLINK_CLOSE:
blink_other_close(&you, source);
obvious_effect = true;
break;
case BEAM_BECKONING:
obvious_effect = beckon(you, *this);
break;
case BEAM_CHARM:
mprf(MSGCH_WARN, "Your will is overpowered!");
confuse_player(5 + random2(3));
obvious_effect = true;
break; // charming - confusion?
case BEAM_BANISH:
if (YOU_KILL(thrower))
{
mpr("This spell isn't strong enough to banish yourself.");
break;
}
you.banish(agent(), get_source_name(),
agent()->get_experience_level());
obvious_effect = true;
break;
case BEAM_PAIN:
{
if (aux_source.empty())
aux_source = "by nerve-wracking pain";
const int dam = resist_adjust_damage(&you, flavour, damage.roll());
if (dam)
{
mpr("Pain shoots through your body!");
internal_ouch(dam);
obvious_effect = true;
}
else
canned_msg(MSG_YOU_UNAFFECTED);
break;
}
case BEAM_AGONY:
torment_player(agent(), TORMENT_AGONY);
obvious_effect = true;
break;
case BEAM_DISPEL_UNDEAD:
if (you.undead_state() == US_ALIVE)
{
canned_msg(MSG_YOU_UNAFFECTED);
break;
}
mpr("You convulse!");
if (aux_source.empty())
aux_source = "by dispel undead";
internal_ouch(damage.roll());
obvious_effect = true;
break;
case BEAM_MINDBURST:
mpr("Your mind is blasted!");
if (aux_source.empty())
aux_source = "mindburst bolt";
{
int amt = damage.roll();
internal_ouch(amt);
if (you.has_blood())
blood_spray(you.pos(), MONS_PLAYER, amt / 5);
}
obvious_effect = true;
break;
case BEAM_PORKALATOR:
if (!transform(20 + roll_dice(3, 10), transformation::pig, true))
{
mpr("You feel a momentary urge to oink.");
break;
}
you.transform_uncancellable = true;
obvious_effect = true;
break;
case BEAM_BERSERK:
you.go_berserk(blame_player);
obvious_effect = true;
break;
case BEAM_SENTINEL_MARK:
you.sentinel_mark();
obvious_effect = true;
break;
case BEAM_DIMENSION_ANCHOR:
mprf("You feel %sfirmly anchored in space.",
you.duration[DUR_DIMENSION_ANCHOR] ? "more " : "");
you.increase_duration(DUR_DIMENSION_ANCHOR, 12 + random2(15), 50);
if (you.duration[DUR_TELEPORT])
{
you.duration[DUR_TELEPORT] = 0;
mpr("Your teleport is interrupted.");
}
you.redraw_evasion = true;
obvious_effect = true;
break;
case BEAM_VULNERABILITY:
you.strip_willpower(agent(), 12 + random2(18));
obvious_effect = true;
break;
case BEAM_VITRIFY:
if (!you.duration[DUR_VITRIFIED])
mpr("Your body becomes as fragile as glass!");
else
mpr("You feel your fragility will last longer.");
you.increase_duration(DUR_VITRIFIED, random_range(8, 18), 50);
obvious_effect = true;
break;
case BEAM_VITRIFYING_GAZE:
if (!you.duration[DUR_VITRIFIED])
mpr("Your body becomes as fragile as glass!");
else
mpr("You feel your fragility will last longer.");
you.increase_duration(DUR_VITRIFIED, random_range(4, 8), 50);
obvious_effect = true;
break;
case BEAM_MALIGN_OFFERING:
{
const int dam = resist_adjust_damage(&you, flavour, damage.roll());
if (dam)
{
_malign_offering_effect(&you, agent(), dam);
obvious_effect = true;
}
else
canned_msg(MSG_YOU_UNAFFECTED);
break;
}
case BEAM_ROOTS:
{
const int turns = 1 + random_range(div_rand_round(ench_power, 20),
div_rand_round(ench_power, 12) + 1);
if (start_ranged_constriction(*agent(), you, turns, CONSTRICT_ROOTS))
obvious_effect = true;
break;
}
case BEAM_VILE_CLUTCH:
{
const int turns = 3 + random_range(div_rand_round(ench_power, 50),
div_rand_round(ench_power, 35) + 1);
if (start_ranged_constriction(*agent(), you, turns, CONSTRICT_BVC))
obvious_effect = true;
break;
}
case BEAM_VAMPIRIC_DRAINING:
{
const int dam = resist_adjust_damage(&you, flavour, damage.roll());
if (dam && actor_is_susceptible_to_vampirism(you))
{
_vampiric_draining_effect(you, *agent(), dam);
obvious_effect = true;
}
else
canned_msg(MSG_YOU_UNAFFECTED);
break;
}
case BEAM_VIRULENCE:
// Those completely immune cannot be made more susceptible this way
if (you.res_poison(false) >= 3)
{
canned_msg(MSG_YOU_UNAFFECTED);
break;
}
mpr("You feel yourself grow more vulnerable to poison.");
you.increase_duration(DUR_POISON_VULN, 12 + random2(18), 50);
obvious_effect = true;
break;
case BEAM_AGILITY:
you.be_agile(ench_power);
obvious_effect = true;
nasty = false;
nice = true;
break;
case BEAM_SAP_MAGIC:
mprf(MSGCH_WARN, "Your magic feels %stainted.",
you.duration[DUR_SAP_MAGIC] ? "more " : "");
flash_tile(you.pos(), GREEN, 120, TILE_BOLT_SAP_MAGIC);
you.increase_duration(DUR_SAP_MAGIC, random_range(20, 30), 50);
break;
case BEAM_DRAIN_MAGIC:
{
int amount = min(you.magic_points, random2avg(ench_power / 8, 3));
if (!amount)
break;
mprf(MSGCH_WARN, "You feel your power leaking away.");
drain_mp(amount);
obvious_effect = true;
break;
}
case BEAM_TUKIMAS_DANCE:
cast_tukimas_dance(ench_power, &you);
obvious_effect = true;
break;
case BEAM_RESISTANCE:
potionlike_effect(POT_RESISTANCE, min(ench_power, 200));
obvious_effect = true;
nasty = false;
nice = true;
break;
case BEAM_UNRAVELLING:
if (!player_is_debuffable())
break;
// If the player is unravelling themselves voluntarily, allow it to work.
debuff_player(agent() && agent()->is_player());
_unravelling_explode(*this);
obvious_effect = true;
break;
case BEAM_SOUL_SPLINTER:
obvious_effect = true;
if (you.holiness() & (MH_NATURAL | MH_DEMONIC | MH_HOLY))
make_soul_wisp(*agent(), you);
else
canned_msg(MSG_YOU_UNAFFECTED);
break;
default:
// _All_ enchantments should be enumerated here!
mpr("Software bugs nibble your toes!");
break;
}
if (nasty)
{
if (mons_att_wont_attack(attitude))
{
friends_hurt++;
if (source_id == MID_PLAYER)
{
// Beam from player rebounded and hit player.
if (!self_targeted())
xom_is_stimulated(200);
}
else
{
// Beam from an ally or neutral.
xom_is_stimulated(100);
}
}
else
foes_hurt++;
}
else if (nice)
{
if (mons_att_wont_attack(attitude))
friends_helped++;
else
{
foes_helped++;
xom_is_stimulated(100);
}
}
handle_enchant_chaining(you.pos());
// Regardless of effect, we need to know if this is a stopper
// or not - it seems all of the above are.
extra_range_used += range_used_on_hit();
}
void bolt::affect_actor(actor *act)
{
if (act->is_monster())
affect_monster(act->as_monster());
else
affect_player();
}
struct pie_effect
{
const char* desc;
function<bool(const actor& def)> valid;
function<void (actor& def, const bolt &beam)> effect;
int weight;
};
static const vector<pie_effect> pie_effects = {
{
"plum",
[](const actor &defender) {
return defender.is_player();
},
[](actor &/*defender*/, const bolt &/*beam*/) {
if (you.duration[DUR_VERTIGO])
mpr("You feel your light-headedness will last longer.");
else
mpr("You feel light-headed.");
you.increase_duration(DUR_VERTIGO, 10 + random2(11), 50);
},
10
},
{
"lemon",
[](const actor &defender) {
return defender.is_player() && (you.can_drink()
|| you.duration[DUR_NO_POTIONS]); // allow stacking
},
[](actor &/*defender*/, const bolt &/*beam*/) {
if (you.duration[DUR_NO_POTIONS])
mpr("You feel your inability to drink will last longer.");
else
mpr("You feel unable to drink.");
you.increase_duration(DUR_NO_POTIONS, 10 + random2(11), 50);
},
10
},
{
"blueberry",
nullptr,
[](actor &defender, const bolt &beam) {
if (defender.is_monster())
{
monster *mons = defender.as_monster();
silence_monster(*mons, beam.agent(), (4 + random2(7)) * BASELINE_DELAY);
}
else
{
if (you.duration[DUR_SILENCE])
mpr("You feel your silence will last longer.");
else
mpr("An unnatural silence engulfs you.");
silence_player(4 + random2(7));
}
},
10
},
{
"cherry",
[](const actor &defender) {
return defender.is_player() || defender.res_fire() < 3;
},
[](actor &defender, const bolt &beam) {
if (defender.is_monster())
{
monster *mons = defender.as_monster();
simple_monster_message(*mons,
" looks more vulnerable to fire.");
mons->add_ench(mon_enchant(ENCH_FIRE_VULN, 0,
beam.agent(),
15 + random2(11) * BASELINE_DELAY));
}
else
{
if (you.duration[DUR_FIRE_VULN])
{
mpr("You feel your vulnerability to fire will last "
"longer.");
}
else
mpr("Cherry-coloured flames burn away your fire "
"resistance!");
you.increase_duration(DUR_FIRE_VULN, 15 + random2(11), 50);
}
},
6
},
{
"peanut brittle",
nullptr,
[](actor &defender, const bolt &beam) {
if (defender.is_monster())
{
monster *mons = defender.as_monster();
simple_monster_message(*mons,
" becomes as fragile as glass!");
mons->add_ench(mon_enchant(ENCH_VITRIFIED, 0, beam.agent(),
random_range(16, 36) * BASELINE_DELAY));
}
else
{
if (you.duration[DUR_VITRIFIED])
mpr("You feel your fragility will last longer.");
else
mpr("Your body becomes as fragile as glass!");
you.increase_duration(DUR_VITRIFIED, random_range(16, 36), 50);
}
},
4
},
{
"glitter",
[](const actor &defender) {
return defender.can_be_dazzled();
},
[](actor &defender, const bolt &beam) {
if (defender.is_player())
blind_player(random_range(16, 36), ETC_GLITTER);
else
dazzle_target(&defender, beam.agent(), 149);
},
5
},
};
static pie_effect _random_pie_effect(const actor &defender)
{
vector<pair<const pie_effect&, int>> weights;
for (const pie_effect &effect : pie_effects)
if (!effect.valid || effect.valid(defender))
weights.push_back({effect, effect.weight});
ASSERT(!weights.empty());
return *random_choose_weighted(weights);
}
void bolt::affect_player()
{
hit_count[MID_PLAYER]++;
if (ignores_player())
return;
// If this is a friendly monster, firing a penetrating beam in the player's
// direction, always stop immediately before them if this attack wouldn't
// be harmless to them.
if (agent() && agent()->is_monster() && mons_att_wont_attack(attitude)
&& !harmless_to_player() && pierce && !is_explosion)
{
ray.regress();
finish_beam();
return;
}
// Explosions only have an effect during their explosion phase.
// Special cases can be handled here.
if (is_explosion && !in_explosion_phase)
{
// Trigger the explosion.
finish_beam();
return;
}
if (is_tracer())
{
tracer_affect_player();
return;
}
// Trigger an interrupt, so travel will stop on misses which
// generate smoke.
if (!YOU_KILL(thrower))
{
if (agent() && agent()->is_monster())
{
interrupt_activity(activity_interrupt::monster_attacks,
agent()->as_monster());
}
else
interrupt_activity(activity_interrupt::monster_attacks);
}
if (flavour == BEAM_MISSILE && item)
{
ranged_attack attk(agent(true), &you, launcher,
item, use_target_as_pos,
agent(), item_mulches);
attk.attack();
// fsim purposes - throw_it detects if an attack connected through
// hit_verb
if (attk.ev_margin >= 0 && hit_verb.empty())
hit_verb = attk.attack_verb;
if (attk.reflected)
reflect();
extra_range_used += attk.range_used;
return;
}
// Visible beams reveal invisible monsters; otherwise animations confer
// an information advantage for sighted players
if (visible() && agent() && agent()->is_monster())
agent()->as_monster()->unseen_pos = agent()->pos();
if (misses_player())
return;
if (!is_explosion && !noise_generated)
{
heard = noisy(loudness, pos(), source_id) || heard;
noise_generated = true;
}
const bool engulfs = is_explosion || is_big_cloud();
if (is_enchantment())
{
if (real_flavour == BEAM_CHAOS || real_flavour == BEAM_RANDOM)
{
if (hit_verb.empty())
hit_verb = engulfs ? "engulfs" : "hits";
mprf("The %s %s %s!", name.c_str(), hit_verb.c_str(),
you.hp > 0 ? "you" : "your lifeless body");
}
affect_player_enchantment();
return;
}
msg_generated = true;
// FIXME: Lots of duplicated code here (compare handling of
// monsters)
int pre_ac_dam = 0;
// Roll the damage.
pre_ac_dam += damage.roll();
int pre_res_dam = apply_AC(&you, pre_ac_dam);
#ifdef DEBUG_DIAGNOSTICS
dprf(DIAG_BEAM, "Player damage: before AC=%d; after AC=%d",
pre_ac_dam, pre_res_dam);
#endif
practise_being_shot();
bool was_affected = false;
int old_hp = you.hp;
pre_res_dam = max(0, pre_res_dam);
// If the beam is of the MMISSILE type (Earth magic) we might bleed on the
// floor.
if (!engulfs && flavour == BEAM_MMISSILE)
{
// assumes DVORP_PIERCING, factor: 0.5
int blood = min(you.hp, pre_res_dam / 2);
bleed_onto_floor(you.pos(), MONS_PLAYER, blood, true);
}
// Apply resistances to damage, but don't print "You resist" messages yet
int final_dam = check_your_resists(pre_res_dam, flavour, "", this, false);
// Tell the player the beam hit
if (hit_verb.empty())
hit_verb = engulfs ? "engulfs" : "hits";
if (flavour != BEAM_VISUAL && !is_enchantment())
{
mprf("The %s %s %s%s%s", name.c_str(), hit_verb.c_str(),
you.hp > 0 ? "you" : "your lifeless body",
final_dam || damage.num == 0 ? "" : " but does no damage",
attack_strength_punctuation(final_dam).c_str());
}
// Now print the messages associated with checking resistances, so that
// these come after the beam actually hitting.
// Note that this must be called with the pre-resistance damage, so that
// poison effects etc work properly.
check_your_resists(pre_res_dam, flavour, "", this, true);
if (flavour == BEAM_STUN_BOLT
&& !you.duration[DUR_PARALYSIS]
&& (you.res_elec() <= 0 || coinflip()))
{
const bool was_parad = you.duration[DUR_PARALYSIS];
you.paralyse(agent(), 1);
was_affected = (!was_parad && you.duration[DUR_PARALYSIS]) || was_affected;
}
if (flavour == BEAM_LIGHT && you.can_be_dazzled())
blind_player(random_range(7, 12), WHITE);
if (flavour == BEAM_MIASMA && final_dam > 0)
was_affected = miasma_player(agent(), name);
if (flavour == BEAM_DESTRUCTION) // MINDBURST already handled
blood_spray(you.pos(), MONS_PLAYER, final_dam / 5);
// Confusion effect for spore explosions
if (flavour == BEAM_SPORE && final_dam
&& !(you.holiness() & MH_UNDEAD)
&& !you.is_unbreathing())
{
confuse_player(2 + random2(3));
}
if (flavour == BEAM_UNRAVELLED_MAGIC)
affect_player_enchantment();
// Sticky flame.
if (origin_spell == SPELL_STICKY_FLAME
|| flavour == BEAM_STICKY_FLAME)
{
// ench_power here is equal to 12 * caster HD for pyre arrow and
// 8 * caster HD for sticky flame (mostly since player ghosts tend to
// have higher HD)
const int intensity = 2 + ench_power / 14;
if (!player_res_sticky_flame())
{
sticky_flame_player(intensity, random_range(11, 21),
get_source_name(), aux_source);
was_affected = true;
}
}
// need to trigger qaz resists after reducing damage from ac/resists.
// for some reason, strength 2 is the standard. This leads to qaz's
// resists triggering 2 in 5 times at max piety.
// perhaps this should scale with damage?
// what to do for hybrid damage? E.g. bolt of magma, icicle, poison arrow?
// Right now just ignore the physical component.
// what about acid?
you.expose_to_element(flavour, 2, agent(), false);
// Manticore spikes
if (origin_spell == SPELL_THROW_BARBS && final_dam > 0)
barb_player(random_range(4, 8), 4);
if (origin_spell == SPELL_GRAVE_CLAW)
{
mpr("You are skewered in place!");
you.increase_duration(DUR_NO_MOMENTUM, random_range(2, 4));
}
if (flavour == BEAM_ENSNARE)
was_affected = ensnare(&you) || was_affected;
if (origin_spell == SPELL_QUICKSILVER_BOLT)
debuff_player();
if (origin_spell == SPELL_NULLIFYING_BREATH)
{
debuff_player();
int amount = min(you.magic_points, random2avg(ench_power, 3));
if (amount > 0)
{
mprf(MSGCH_WARN, "You feel your power leaking away.");
drain_mp(amount);
}
}
dprf(DIAG_BEAM, "Damage: %d", final_dam);
if (final_dam > 0 || old_hp < you.hp || was_affected)
{
if (mons_att_wont_attack(attitude))
{
friends_hurt++;
// Beam from player rebounded and hit player.
// Xom's amusement at the player's being damaged is handled
// elsewhere.
if (source_id == MID_PLAYER)
{
if (!self_targeted())
xom_is_stimulated(200);
}
else if (was_affected)
xom_is_stimulated(100);
}
else
foes_hurt++;
}
internal_ouch(final_dam);
// Acid. (Apply this afterward, to avoid bad message ordering.)
if (flavour == BEAM_ACID && coinflip())
you.corrode(agent());
if (flavour == BEAM_CRYSTALLIZING)
crystallize_player();
if (origin_spell == SPELL_SOJOURNING_BOLT
&& final_dam > 0 && x_chance_in_y(2, 3))
{
you.teleport();
if (you.duration[DUR_TELEPORT])
{
mprf(MSGCH_DANGER, "You feel a distressing malevolence running through your instability!");
you.props[SJ_TELEPORTITIS_SOURCE].get_int() = agent(true) ? agent(true)->mid : MID_NOBODY;
}
}
if (origin_spell == SPELL_THROW_PIE && final_dam > 0)
{
const pie_effect effect = _random_pie_effect(you);
mprf("%s!", effect.desc);
effect.effect(you, *this);
}
extra_range_used += range_used_on_hit();
knockback_actor(&you, final_dam);
pull_actor(&you, final_dam);
if (origin_spell == SPELL_FLASH_FREEZE
|| origin_spell == SPELL_CREEPING_FROST
|| name == "blast of ice"
|| origin_spell == SPELL_HOARFROST_BULLET
|| origin_spell == SPELL_GLACIATE && !is_explosion)
{
if (!you.duration[DUR_FROZEN])
{
mprf(MSGCH_WARN, "You are encased in ice.");
you.duration[DUR_FROZEN] = (random_range(3, 5)) * BASELINE_DELAY;
}
}
if (you.form == transformation::aqua
&& is_fiery() && x_chance_in_y(final_dam, you.hp_max * 2 / 3))
{
const int pow = div_rand_round(final_dam * 100 / you.hp_max, 10);
mpr("A part of your body evaporates into steam!");
big_cloud(CLOUD_STEAM, monster_by_mid(MID_YOU_FAULTLESS), you.pos(),
random_range(1, 4) + pow, random_range(2, 7));
}
}
bool bolt::ignores_player() const
{
// Digging -- don't care.
if (flavour == BEAM_DIGGING)
return true;
if (origin_spell == SPELL_COMBUSTION_BREATH
|| origin_spell == SPELL_NULLIFYING_BREATH
|| origin_spell == SPELL_RIMEBLIGHT
|| origin_spell == SPELL_SHADOW_PRISM
|| origin_spell == SPELL_SHADOW_SHOT)
{
return true;
}
// XXX: Mostly to stop the targeter being weird with trying to keep you
// out of splash damage.
if (origin_spell == SPELL_MERCURY_ARROW && agent() && agent()->is_player())
return true;
if (origin_spell == SPELL_HOARFROST_BULLET && is_explosion
&& agent() && agent()->wont_attack())
{
return true;
}
if (agent() && agent()->is_monster()
&& (mons_is_hepliaklqana_ancestor(agent()->as_monster()->type)
|| mons_is_player_shadow(*agent()->as_monster())
|| agent()->real_attitude() == ATT_MARIONETTE
|| agent()->type == MONS_PLATINUM_PARAGON))
{
// friends!
return true;
}
if (source_id == MID_PLAYER_SHADOW_DUMMY)
return true;
if (flavour == BEAM_ROOTS || flavour == BEAM_VILE_CLUTCH)
{
return agent()->wont_attack()
|| !agent()->can_constrict(you, flavour == BEAM_ROOTS ? CONSTRICT_ROOTS
: CONSTRICT_BVC);
}
if (flavour == BEAM_QAZLAL || flavour == BEAM_HAEMOCLASM)
return true;
// The player is immune to their own Destruction (both from Carnage / Annihilation
// explosions, but also reflected lightning bolts or shots from hellmouths)
if (origin_spell == SPELL_UNLEASH_DESTRUCTION
&& (!agent() || agent()->wont_attack()))
{
return true;
}
if ((origin_spell == SPELL_PERCUSSIVE_TEMPERING
|| origin_spell == SPELL_FORTRESS_BLAST)
&& attitude == ATT_FRIENDLY)
{
return true;
}
return false;
}
int bolt::apply_AC(const actor *victim, int hurted)
{
// Apply automatic AC rules if ac_rule was not manually specified.
if (ac_rule == ac_type::normal)
{
if (flavour == BEAM_DAMNATION)
ac_rule = ac_type::none;
else if (get_beam_resist_type(flavour) == BEAM_ELECTRICITY)
ac_rule = ac_type::half;
else if (flavour == BEAM_FRAG)
ac_rule = ac_type::triple;
}
// beams don't obey GDR -> max_damage is 0
return victim->apply_ac(hurted, 0, ac_rule, !is_tracer());
}
void bolt::update_hurt_or_helped(monster* mon)
{
if (!mons_atts_aligned(attitude, mons_attitude(*mon)))
{
if (nasty_to(mon))
foes_hurt++;
else if (nice_to(monster_info(mon)))
{
foes_helped++;
// Accidentally helped a foe.
if (!is_tracer() && !effect_known && mons_is_threatening(*mon))
{
const int interest =
(flavour == BEAM_INVISIBILITY && can_see_invis) ? 25 : 100;
xom_is_stimulated(interest);
}
}
}
else
{
if (nasty_to(mon))
{
friends_hurt++;
// Harmful beam from this monster rebounded and hit the monster.
if (!is_tracer() && mon->mid == source_id)
xom_is_stimulated(100);
}
else if (nice_to(monster_info(mon)))
friends_helped++;
}
}
void bolt::tracer_enchantment_affect_monster(monster* mon)
{
bool has_friendly_past_target = check_for_friendly_past_target(mon);
if (has_friendly_past_target)
return;
// Only count tracers as hitting creatures they could potentially affect
if (ench_flavour_affects_monster(agent(), flavour, mon, true)
&& !(has_saving_throw() && mons_invuln_will(*mon)))
{
// Update friend or foe encountered.
bool friendly_fire = mons_atts_aligned(attitude, mons_attitude(*mon));
int power = mon->get_experience_level();
tracer->actor_affected(friendly_fire, power);
}
tracer->monster_hit(*this, *mon);
extra_range_used += range_used_on_hit();
}
// Return false if we should skip handling this monster.
bool bolt::determine_damage(monster* mon, int& preac, int& postac, int& final)
{
preac = postac = final = 0;
// [ds] Changed how tracers determined damage: the old tracer
// model took the average damage potential, subtracted the average
// AC damage reduction and called that the average damage output.
// This could easily predict an average damage output of 0 for
// high AC monsters, with the result that monsters often didn't
// bother using ranged attacks at high AC targets.
//
// The new model rounds up average damage at every stage, so it
// will predict a damage output of 1 even if the average damage
// expected is much closer to 0. This will allow monsters to use
// ranged attacks vs high AC targets.
// [1KB] What ds' code actually does is taking the max damage minus
// average AC. This does work well, even using no AC would. An
// attack that _usually_ does no damage but can possibly do some means
// we'll ultimately get it through. And monsters with weak ranged
// almost always would do no better in melee.
//
// This is not an entirely beneficial change; the old tracer
// damage system would make monsters with weak ranged attacks
// close in to their foes, while the new system will make it more
// likely that such monsters will hang back and make ineffective
// ranged attacks. Thus the new tracer damage calculation will
// hurt monsters with low-damage ranged attacks and high-damage
// melee attacks. I judge this an acceptable compromise (for now).
//
const int preac_max_damage = damage.num * damage.size;
// preac: damage before AC modifier
// postac: damage after AC modifier
// final: damage after AC and resists
// All these are invalid if we return false.
if (is_tracer())
{
// Was mean between min and max;
preac = preac_max_damage;
}
else
preac = damage.roll();
int tracer_postac_max = preac_max_damage;
postac = apply_AC(mon, preac);
if (is_tracer())
{
postac = div_round_up(tracer_postac_max, 2);
const int adjusted_postac_max =
mons_adjust_flavoured(mon, *this, tracer_postac_max, false);
final = div_round_up(adjusted_postac_max, 2);
}
else
{
postac = max(0, postac);
// Don't do side effects (beam might miss or be a tracer).
final = mons_adjust_flavoured(mon, *this, postac, false);
}
// Sanity check. Importantly for
// tracer_nonenchantment_affect_monster, final > 0
// implies preac > 0.
ASSERT(0 <= postac);
ASSERT(postac <= preac);
ASSERT(0 <= final);
ASSERT(preac > 0 || final == 0);
return true;
}
bool bolt::check_for_friendly_past_target(monster* mon)
{
// If prompts for overshooting the target are disabled, instead
// just let the caller know that there was something there. They
// should be responsible and keep the player from shooting friends.
// (We skip this for explosions, since stopping at our target is not
// guaranteed to spare allies behind the target)
if (!passed_target || overshoot_prompt || is_explosion
|| !you.can_see(*mon) || !tracer->should_stop() || is_harmless(mon))
{
return false;
}
string adj, suffix;
bool penance;
bool should_stop_at_target = bad_attack(mon, adj, suffix, penance, target);
if (should_stop_at_target && special_explosion)
{
targeting_tracer special_tracer;
bolt special_explosion_copy = *special_explosion;
special_explosion_copy.tracer = &special_tracer;
special_explosion_copy.in_explosion_phase = false;
special_explosion_copy.target = target;
special_explosion_copy.refine_for_explosion();
special_explosion_copy.explode();
// Only stop at our target if it would stop us hitting allies.
should_stop_at_target = special_tracer.friend_info.count == 0;
}
if (should_stop_at_target)
{
finish_beam();
friendly_past_target = true;
use_target_as_pos = true;
}
return should_stop_at_target;
}
// Whether or not this non-enchantment effect would have a relevant non-damage
// side effect when used on a given monster.
//
// XXX: This function is a stop-gap! It is knowingly incomplete, but addresses
// the immediate problem of monsters refusing to use certain spells on
// other monsters, even though they would be useful.
// TODO: Expand and unify this with actually applying beam side-effects
bool bolt::has_relevant_side_effect(monster* mon)
{
if (flavour == BEAM_STICKY_FLAME
&& !mon->res_sticky_flame() && mon->res_fire() < 3)
{
return true;
}
else if (flavour == BEAM_ENSNARE || flavour == BEAM_LIGHT)
return true;
if ((origin_spell == SPELL_NOXIOUS_CLOUD || origin_spell == SPELL_POISONOUS_CLOUD
|| origin_spell == SPELL_NOXIOUS_BREATH)
&& mon->res_poison() < 1)
{
return true;
}
else if (origin_spell == SPELL_RAVENOUS_SWARM && !(mon->holiness() & MH_UNDEAD))
return true;
return false;
}
void bolt::tracer_nonenchantment_affect_monster(monster* mon)
{
bool has_friendly_past_target = check_for_friendly_past_target(mon);
if (has_friendly_past_target)
return;
// Special explosions (current exploding missiles) aren't
// auto-hit, so we need to explode them at every possible
// end-point?
if (special_explosion)
{
bolt orig = *special_explosion;
affect_endpoint();
*special_explosion = orig;
}
int preac = 0, post = 0, final = 0;
bool side_effect = has_relevant_side_effect(mon);
// The projectile applying sticky flame often does no damage, but this
// doesn't mean it's harmless.
if (!determine_damage(mon, preac, post, final) && !side_effect)
return;
// Check only if actual damage and the monster is worth caring about.
// Living spells do count as threats, but are fine being collateral damage.
if ((final > 0 || side_effect)
&& (mons_is_threatening(*mon) || mons_class_is_test(mon->type))
&& mon->type != MONS_LIVING_SPELL)
{
ASSERT(side_effect || preac > 0);
// Add some 'fake damage' for a relevant side-effect, so tracer power
// will actually see it.
// XXX: This is ugly and numerically arbitrary...
if (side_effect)
{
final += 10;
preac += 10;
}
// Monster could be hurt somewhat, but only apply the
// monster's power based on how badly it is affected.
// For example, if a fire giant (power 16) threw a
// fireball at another fire giant, and it only took
// 1/3 damage, then power of 5 would be applied.
bool friendly_fire;
int power;
if (!mons_atts_aligned(attitude, mons_attitude(*mon)))
{
friendly_fire = false;
power = 2 * final * mon->get_experience_level() / preac;
}
else
{
friendly_fire = true;
power = 0;
// Discourage summoned monsters firing on their summoner.
const monster* mon_source = agent() ? agent()->as_monster() : nullptr;
if (mon_source && mon_source->summoner == mon->mid)
power = 100;
// Marionettes will avoid harming other 'allies', but are
// deliberately reckless about themselves.
else if (!(mon_source == mon && mon_source->attitude == ATT_MARIONETTE))
power = 2 * final * mon->get_experience_level() / preac;
}
tracer->actor_affected(friendly_fire, power);
}
// Check for bad targets in case the user wants to cancel
tracer->monster_hit(*this, *mon);
// Either way, we could hit this monster, so update range used.
extra_range_used += range_used_on_hit();
if (origin_spell == SPELL_COMBUSTION_BREATH && !in_explosion_phase)
_combustion_breath_explode(this, mon->pos());
}
void bolt::tracer_affect_monster(monster* mon)
{
// Ignore unseen monsters.
if ((agent() && !agent()->can_see(*mon))
|| !cell_see_cell(source, mon->pos(), LOS_NO_TRANS))
{
return;
}
if (flavour == BEAM_UNRAVELLING && monster_can_be_unravelled(*mon))
is_explosion = true;
// Trigger explosion on exploding beams.
if (is_explosion && !in_explosion_phase)
{
finish_beam();
return;
}
if (is_enchantment())
tracer_enchantment_affect_monster(mon);
else
tracer_nonenchantment_affect_monster(mon);
}
void bolt::enchantment_affect_monster(monster* mon)
{
god_conduct_trigger conducts[3];
bool hit_woke_orc = false;
if (nasty_to(mon))
{
if (YOU_KILL(thrower))
{
set_attack_conducts(conducts, *mon, you.can_see(*mon));
if (have_passive(passive_t::convert_orcs)
&& mons_genus(mon->type) == MONS_ORC
&& mon->asleep() && you.see_cell(mon->pos()))
{
hit_woke_orc = true;
}
if (flavour != BEAM_HIBERNATION)
you.pet_target = mon->mindex();
}
}
// Doing this here so that the player gets to see monsters
// "flicker and vanish" when turning invisible....
if (animate)
{
_ench_animation(effect_known ? real_flavour
: BEAM_MAGIC,
mon, effect_known);
}
// Try to hit the monster with the enchantment. The behaviour_event above
// may have caused a pacified monster to leave the level, so only try to
// enchant it if it's still here. If the monster did leave the level, set
// obvious_effect so we don't get "Nothing appears to happen".
int res_margin = 0;
const mon_resist_type ench_result = mon->alive()
? try_enchant_monster(mon, res_margin)
: (obvious_effect = true, MON_OTHER);
if (mon->alive()) // Aftereffects.
{
// Message or record the success/failure.
switch (ench_result)
{
case MON_RESIST:
if (simple_monster_message(*mon,
mon->resist_margin_phrase(res_margin).c_str()))
{
msg_generated = true;
// Hack: assume that BEAM_BANISH comes from Lugonu's Banishment
// and hence causes malmutation on resist.
if (real_flavour == BEAM_BANISH && agent() && agent()->is_player())
mon->malmutate(agent());
}
break;
case MON_UNAFFECTED:
if (simple_monster_message(*mon, " is unaffected."))
msg_generated = true;
break;
case MON_AFFECTED:
case MON_OTHER: // Should this really be here?
update_hurt_or_helped(mon);
break;
}
if (hit_woke_orc)
beogh_follower_convert(mon, true);
}
handle_enchant_chaining(mon->pos());
extra_range_used += range_used_on_hit();
// Nasty enchantments will annoy the monster, and are considered
// naughty (even if a monster resisted).
if (mon && mon->alive() && nasty_to(mon))
behaviour_event(mon, ME_ANNOY, agent());
else
behaviour_event(mon, ME_ALERT, agent());
}
static void _add_chain_candidates(const bolt& beam, coord_def pos,
set<coord_def> &candidates)
{
for (adjacent_iterator ai(pos); ai; ++ai)
{
if (!cell_see_cell(beam.source, *ai, LOS_NO_TRANS))
continue;
actor* act = actor_at(*ai);
// Ignore friendlies, firewood, and things we can fire through.
if (!act || mons_aligned(beam.agent(), act))
continue;
monster *mon = act->as_monster();
if (mon && (shoot_through_monster(beam.agent(), mon)
|| mon->is_peripheral()))
{
continue;
}
candidates.insert(*ai);
}
}
void fill_chain_targets(const bolt& beam, coord_def centre,
vector<coord_def> &targs, bool random)
{
set<coord_def> candidates;
_add_chain_candidates(beam, centre, candidates);
if (candidates.empty())
return;
const size_t MAX_CHAIN_BOUNCES = 2;
if (candidates.size() >= MAX_CHAIN_BOUNCES)
{
for (coord_def candidate : candidates)
targs.push_back(candidate);
if (!random)
return;
shuffle_array(targs);
targs.resize(MAX_CHAIN_BOUNCES);
return;
}
// OK. Can we bounce further out?
set<coord_def> scs;
for (coord_def candidate : candidates) // only runs once
{
targs.push_back(candidate);
// Ensure adjacent targets show up before later-ring ones.
_add_chain_candidates(beam, candidate, scs);
}
if (random)
shuffle_array(targs);
scs.erase(centre);
if (scs.empty())
return;
// OK, we found some later bounces.
if (random)
{
vector<coord_def> subcand_array(scs.begin(), scs.end());
// Assumes MAX_CHAIN_BOUNCES = 2. Sorry!
targs.push_back(*random_iterator(subcand_array));
return;
}
for (coord_def sc : scs)
targs.push_back(sc);
}
void bolt::handle_enchant_chaining(coord_def centre)
{
// Handle ray bounces
if (!(origin_spell == SPELL_PETRIFY || origin_spell == SPELL_RIMEBLIGHT)
|| hit_count.size() != 1)
{
return;
}
vector<coord_def> chain_targs;
fill_chain_targets(*this, centre, chain_targs, true);
if (chain_targs.empty())
return;
// Bounces are at 2/3 power
unwind_var<int> ep(ench_power, ench_power * 2 / 3);
for (coord_def c : chain_targs)
affect_actor(actor_at(c));
}
static void _print_pre_death_message(const monster &mon, bool goldify,
spell_type origin_spell)
{
if (mon.is_insubstantial()
|| (origin_spell != SPELL_GLACIATE && origin_spell != SPELL_GLACIAL_BREATH))
{
return;
}
if (goldify)
simple_monster_message(mon, " shatters and turns to gold!");
else
simple_monster_message(mon, " is frozen into a solid block of ice!");
}
void bolt::kill_monster(monster &mon)
{
// Preserve name of the source monster if it winds up killing
// itself.
if (mon.mid == source_id && source_name.empty())
source_name = mon.name(DESC_A, true);
const coord_def where = mon.pos();
const monster_type species = mons_species(mons_base_type(mon));
const bool goldify = mons_will_goldify(mon);
_print_pre_death_message(mon, goldify, origin_spell);
int kindex = actor_to_death_source(agent());
killer_type ref_killer = thrower;
if (!YOU_KILL(thrower) && reflector == MID_PLAYER)
{
ref_killer = KILL_YOU_MISSILE;
kindex = YOU_FAULTLESS;
}
if (flavour == BEAM_BLOODRITE)
mon.props[MAKHLEB_BLOODRITE_KILL_KEY] = true;
item_def *corpse = monster_die(mon, ref_killer, kindex);
if (origin_spell != SPELL_GLACIATE && origin_spell != SPELL_GLACIAL_BREATH
|| goldify)
{
return;
}
if (corpse)
destroy_item(corpse->index());
if (monster *pillar = create_monster(
mgen_data(MONS_BLOCK_OF_ICE,
BEH_HOSTILE,
where,
MHITNOT,
MG_FORCE_PLACE).set_base(species),
false))
{
// Make glacial breath ice blocks more sturdy, since they're supposed
// to make useful obstacles
if (origin_spell == SPELL_GLACIAL_BREATH)
{
pillar->max_hit_points = 15 + div_rand_round(ench_power * 5, 2);
pillar->hit_points = pillar->max_hit_points;
}
const int time_left = random_range(7, 17) * BASELINE_DELAY;
mon_enchant temp_en(ENCH_SLOWLY_DYING, 1, 0, time_left);
pillar->add_ench(temp_en);
}
}
void bolt::monster_post_hit(monster* mon, int dmg)
{
// Suppress the message for tremorstones.
if (YOU_KILL(thrower) && you.see_cell(mon->pos())
&& name != "burst of rock shards")
{
print_wounds(*mon);
}
// Don't annoy friendlies or good neutrals if the player's beam
// did no damage. Hostiles will still take umbrage.
if (dmg > 0 || !mon->wont_attack() || !YOU_KILL(thrower))
{
behaviour_event(mon, ME_ANNOY, agent());
// behaviour_event can make a monster leave the level or vanish.
if (!mon->alive())
return;
}
if (YOU_KILL(thrower) && !mon->wont_attack() && !mon->is_firewood())
you.pet_target = mon->mindex();
// We check player Sticky Flame by name and other effects by flavour, since
// the player spell has impact damage that the others do not, and thus is
// BEAM_FIRE instead.
//
// Possibly this should be refactored.
if (origin_spell == SPELL_STICKY_FLAME)
{
const int dur = 3 + random_range(div_rand_round(ench_power, 20),
max(1, div_rand_round(ench_power, 10)));
sticky_flame_monster(mon, agent(), dur);
}
else if (flavour == BEAM_STICKY_FLAME)
{
// Current numbers of monster sticky flame versus other monsters are
// more arbitrary.
sticky_flame_monster(mon, agent(), 3 + random2(ench_power / 20));
}
if (origin_spell == SPELL_QUICKSILVER_BOLT)
debuff_monster(*mon);
if (origin_spell == SPELL_NULLIFYING_BREATH)
{
debuff_monster(*mon);
if (mon->antimagic_susceptible())
{
const int dur = (5 + random_range(div_rand_round(ench_power, 2),
div_rand_round(ench_power * 3, 4) + 1))
* BASELINE_DELAY;
mon->add_ench(mon_enchant(ENCH_ANTIMAGIC, 0, agent(), dur));
}
}
if (origin_spell == SPELL_SOJOURNING_BOLT
&& x_chance_in_y(2, 3) && !(mon->no_tele()))
{
monster_teleport(mon, false, false, false, agent());
}
if (flavour == BEAM_CRYSTALLIZING)
crystallize_monster(mon, agent());
if (dmg)
beogh_follower_convert(mon, true);
knockback_actor(mon, dmg);
pull_actor(mon, dmg);
if (origin_spell == SPELL_COMBUSTION_BREATH && !in_explosion_phase)
_combustion_breath_explode(this, mon->pos());
if (origin_spell == SPELL_FLASH_FREEZE
|| origin_spell == SPELL_HOARFROST_BULLET
|| name == "blast of ice"
|| origin_spell == SPELL_GLACIATE && !is_explosion
|| origin_spell == SPELL_UNLEASH_DESTRUCTION
&& flavour == BEAM_COLD
&& you.has_mutation(MUT_MAKHLEB_DESTRUCTION_COC))
{
if (!mon->has_ench(ENCH_FROZEN))
{
simple_monster_message(*mon, " is flash-frozen.");
mon->add_ench(mon_enchant(ENCH_FROZEN, 0, agent()));
}
}
if (origin_spell == SPELL_UNLEASH_DESTRUCTION
&& flavour == BEAM_FIRE
&& you.has_mutation(MUT_MAKHLEB_DESTRUCTION_GEH))
{
const int dur = 3 + div_rand_round(dmg, 3);
if (!mon->has_ench(ENCH_FIRE_VULN))
{
mprf("%s fire resistance burns away.",
mon->name(DESC_ITS).c_str());
mon->add_ench(mon_enchant(ENCH_FIRE_VULN, 1, agent(),
dur * BASELINE_DELAY));
}
}
if (origin_spell == SPELL_THROW_BARBS && dmg > 0
&& !(mon->is_insubstantial()))
{
mon->add_ench(mon_enchant(ENCH_BARBS, 1, agent(),
random_range(5, 7) * BASELINE_DELAY));
}
if (origin_spell == SPELL_THROW_PIE && dmg > 0)
{
const pie_effect effect = _random_pie_effect(*mon);
if (you.see_cell(mon->pos()))
mprf("%s!", effect.desc);
effect.effect(*mon, *this);
}
if (flavour == BEAM_STUN_BOLT
&& !mon->has_ench(ENCH_PARALYSIS)
&& mon->res_elec() <= 0
&& !mon->stasis())
{
simple_monster_message(*mon, " is paralysed.");
mon->add_ench(mon_enchant(ENCH_PARALYSIS, 1, agent(), BASELINE_DELAY));
}
if (flavour == BEAM_LIGHT
&& mon->can_be_dazzled()
&& !mon->has_ench(ENCH_BLIND))
{
const int dur = max(1, div_rand_round(54, mon->get_hit_dice())) * BASELINE_DELAY;
auto ench = mon_enchant(ENCH_BLIND, 1, agent(),
random_range(dur, dur * 2));
if (mon->add_ench(ench))
simple_monster_message(*mon, " is blinded.");
}
if (origin_spell == SPELL_PRIMAL_WAVE && agent() && agent()->is_player())
_waterlog_mon(*mon, ench_power);
if (origin_spell == SPELL_HURL_TORCHLIGHT && agent() && agent()->is_player()
&& mon->friendly() && mon->holiness() & MH_UNDEAD)
{
int dur = random_range(2 + you.skill_rdiv(SK_INVOCATIONS, 1, 5),
4 + you.skill_rdiv(SK_INVOCATIONS, 1, 3))
* BASELINE_DELAY;
mon->add_ench(mon_enchant(ENCH_MIGHT, 0, &you, dur));
mon->speed_increment += 10;
simple_monster_message(*mon, " is empowered.");
}
if (origin_spell == SPELL_GRAVE_CLAW && !mon->has_ench(ENCH_BOUND))
{
simple_monster_message(*mon, " is pinned in place!");
mon->add_ench(mon_enchant(ENCH_BOUND, 0, agent(), random_range(2, 4) * BASELINE_DELAY));
}
if (origin_spell == SPELL_KINETIC_GRAPNEL && dmg > 0)
mon->add_ench(mon_enchant(ENCH_KINETIC_GRAPNEL, 0, agent(), random_range(30, 50)));
// Watery Grave
if (name == "grasping water" && !mon->is_unbreathing())
_waterlog_mon(*mon, ench_power);
}
static int _knockback_dist(spell_type origin, int pow)
{
switch (origin)
{
case SPELL_ISKENDERUNS_MYSTIC_BLAST:
return 2 + div_rand_round(pow, 50);
case SPELL_FORCE_LANCE:
return 4;
default:
return 1;
}
}
static int _collision_damage(spell_type spell, int pow)
{
switch (spell)
{
case SPELL_PRIMAL_WAVE:
case SPELL_MUD_BREATH:
return 0;
default:
return default_collision_damage(pow, true).roll();
}
}
void bolt::knockback_actor(actor *act, int dam)
{
if (!can_knockback(dam)) return;
const int max_dist = _knockback_dist(origin_spell, ench_power);
const monster_type montyp = act->is_monster() ? act->type
: you.mons_species();
const int weight = max_corpse_chunks(montyp);
const int roll = origin_spell == SPELL_FORCE_LANCE ? 42
: origin_spell == SPELL_ISKENDERUNS_MYSTIC_BLAST ? 17
: 25;
const int dist = binomial(max_dist, roll - weight, roll); // This is silly! -- PF
// not sure this belongs here, but it can't be done in agent::knockback
// if the caster is dead, we can't get their former position for knockback
auto caster = agent();
if (!caster) return;
act->knockback(*caster, dist, _collision_damage(origin_spell, ench_power), name);
}
void bolt::pull_actor(actor *act, int dam)
{
if (!act || !can_pull(*act, dam) || act->resists_dislodge("being pulled"))
return;
// How far we'll try to pull the actor to make them adjacent to the source.
const int distance = (act->pos() - source).rdist() - 1;
ASSERT(distance > 0);
const coord_def oldpos = act->pos();
ASSERT(ray.pos() == oldpos);
coord_def newpos = oldpos;
for (int dist_travelled = 0; dist_travelled < distance; ++dist_travelled)
{
const ray_def oldray(ray);
ray.regress();
newpos = ray.pos();
if (newpos == oldray.pos()
|| cell_is_solid(newpos)
|| actor_at(newpos)
|| !act->can_pass_through(newpos)
|| !act->is_habitable(newpos))
{
ray = oldray;
break;
}
act->move_to_pos(newpos);
if (act->is_player())
stop_delay(true);
}
if (newpos == oldpos)
return;
if (you.can_see(*act))
{
mprf("%s %s yanked forward by the %s.", act->name(DESC_THE).c_str(),
act->conj_verb("are").c_str(), name.c_str());
}
if (act->pos() != newpos)
act->collide(newpos, agent(), default_collision_damage(ench_power, true).roll());
act->apply_location_effects(oldpos, killer(),
actor_to_death_source(agent()));
}
// Return true if the player's god will be unforgiving about the effects
// of this beam.
bool bolt::god_cares() const
{
return effect_known || effect_wanton;
}
// Return true if the block succeeded (including reflections.)
bool bolt::attempt_block(monster* mon)
{
const int shield_block = mon->shield_bonus();
if (shield_block <= 0)
return false;
const int sh_hit = random2(hit * 130 / 100);
if (sh_hit >= shield_block || mon->shield_exhausted())
return false;
item_def *shield = mon->mslot_item(MSLOT_SHIELD);
if (is_reflectable(*mon))
{
if (mon->observable())
{
if (shield && shield_reflects(*shield))
{
mprf("%s blocks the %s with %s %s... and reflects it back!",
mon->name(DESC_THE).c_str(),
name.c_str(),
mon->pronoun(PRONOUN_POSSESSIVE).c_str(),
shield->name(DESC_PLAIN).c_str());
}
else
{
mprf("The %s reflects off an invisible shield around %s!",
name.c_str(),
mon->name(DESC_THE).c_str());
}
}
else if (you.see_cell(pos()))
mprf("The %s bounces off of thin air!", name.c_str());
reflect();
}
else if (you.see_cell(pos()))
{
mprf("%s blocks the %s.",
mon->name(DESC_THE).c_str(), name.c_str());
finish_beam();
}
mon->shield_block_succeeded(agent());
return true;
}
/// Is the given monster a bush or bush-like 'monster', and can the given beam
/// travel through it without harm?
bool bolt::bush_immune(const monster &mons) const
{
return
// Briars allow bolts fired from aligned actors to pass but block
// those from unaligned actors. If this bolt has no agent, we're
// assuming alignment.
(mons.type == MONS_BRIAR_PATCH && mons_aligned(&mons, agent())
// Bushes pass bolts regardless of alignment of the actor.
|| mons_species(mons.type) == MONS_BUSH)
// We allow hitting the bush-like monster with a bolt when it's the
// target.
&& target != mons.pos();
}
// Is there a visible monster at this position which will keep the beam from
// continuing onward? (And, if so, is it firewood or something else we'd never
// actually want to bother hitting?)
bool bolt::at_blocking_monster() const
{
const monster *mon = monster_at(pos());
if (!mon || !you.can_see(*mon))
return false;
if (!pierce && !ignores_monster(mon) && mon->is_firewood())
return true;
if (have_passive(passive_t::neutral_slimes)
&& mons_is_slime(*mon)
&& flavour != BEAM_VILE_CLUTCH)
{
return true;
}
return false;
}
void bolt::affect_monster(monster* mon)
{
// Don't hit dead or fake monsters.
if (!mon->alive() || mon->type == MONS_GOD_WRATH_AVATAR)
return;
hit_count[mon->mid]++;
// Jiyva absorbs attacks on slimes.
if (agent()
&& flavour != BEAM_VILE_CLUTCH
&& have_passive(passive_t::neutral_slimes)
&& mons_is_slime(*mon))
{
if (!is_tracer() && you.see_cell(mon->pos()))
{
mprf(MSGCH_GOD, GOD_JIYVA,
"%s absorbs the %s as it strikes your slime.",
god_speaker(GOD_JIYVA).c_str(), name.c_str());
}
finish_beam();
return;
}
// Print messages for monsters avoiding attacks.
if (!is_tracer())
shoot_through_monster(agent(), mon, true);
if (flavour == BEAM_WATER && mon->type == MONS_WATER_ELEMENTAL && !is_tracer())
{
if (you.see_cell(mon->pos()))
mprf("The %s passes through %s.", name.c_str(), mon->name(DESC_THE).c_str());
}
if (ignores_monster(mon))
return;
// Handle tracers separately.
if (is_tracer())
{
tracer_affect_monster(mon);
return;
}
// Visual - wake monsters.
if (flavour == BEAM_VISUAL)
{
behaviour_event(mon, ME_DISTURB, agent(), source);
return;
}
if (flavour == BEAM_MISSILE && item)
{
// Test if this qualifies to trigger Dimensional Bullseye later on.
if (agent()->is_player() && you.duration[DUR_DIMENSIONAL_BULLSEYE]
&& !can_trigger_bullseye
&& !mon->is_firewood() && mon->summoner != MID_PLAYER)
{
can_trigger_bullseye = true;
}
actor *ag = agent(true);
// if the immediate agent is now dead, check to see if we can get a
// usable agent by factoring in reflections.
// At this point, it is possible that the agent is the dummy monster
// associated with YOU_FAULTLESS. This case will cause
// "INVALID YOU_FAULTLESS" to show up in dprfs and mess up the to-hit,
// but it otherwise works.
// TODO: is there a good way of handling the to-hit correctly? (And why
// should the to-hit be affected by reflections at all?)
// An alternative would be to stop the missile at this point.
if (!ag)
ag = agent(false);
// if that didn't work, blanket fall back on YOU_FAULTLESS. This covers
// a number of other weird penetration cases.
if (!ag)
ag = &env.mons[YOU_FAULTLESS];
ASSERT(ag);
ranged_attack attk(ag, mon, launcher,
item, use_target_as_pos, agent(), item_mulches);
attk.attack();
// fsim purposes - throw_it detects if an attack connected through
// hit_verb
if (attk.ev_margin >= 0 && hit_verb.empty())
hit_verb = attk.attack_verb;
if (attk.reflected)
reflect();
extra_range_used += attk.range_used;
return;
}
// Explosions always 'hit'.
const bool engulfs = (is_explosion || is_big_cloud());
if (is_enchantment())
{
if (real_flavour == BEAM_CHAOS || real_flavour == BEAM_RANDOM)
{
if (hit_verb.empty())
hit_verb = engulfs ? "engulfs" : "hits";
if (you.see_cell(mon->pos()))
{
mprf("The %s %s %s.", name.c_str(), hit_verb.c_str(),
mon->name(DESC_THE).c_str());
}
else if (heard && !hit_noise_msg.empty())
mprf(MSGCH_SOUND, "%s", hit_noise_msg.c_str());
}
// no to-hit check
enchantment_affect_monster(mon);
return;
}
if (is_explosion && !in_explosion_phase)
{
// It hit a monster, so the beam should terminate.
// Don't actually affect the monster; the explosion
// will take care of that.
finish_beam();
return;
}
// We need to know how much the monster _would_ be hurt by this,
// before we decide if it actually hits.
int preac, postac, final;
if (!determine_damage(mon, preac, postac, final))
return;
#ifdef DEBUG_DIAGNOSTICS
dprf(DIAG_BEAM, "Monster: %s; Damage: pre-AC: %d; post-AC: %d; post-resist: %d",
mon->name(DESC_PLAIN).c_str(), preac, postac, final);
#endif
// Player beams which hit friendlies or good neutrals will annoy
// them and be considered naughty if they do damage (this is so as
// not to penalise players that fling fireballs into a melee with
// fire elementals on their side - the elementals won't give a sh*t,
// after all).
god_conduct_trigger conducts[3];
if (nasty_to(mon))
{
if (agent() && agent()->is_player() && final > 0)
set_attack_conducts(conducts, *mon, you.can_see(*mon));
}
if (engulfs && flavour == BEAM_SPORE // XXX: engulfs is redundant?
&& !mon->is_unbreathing())
{
apply_enchantment_to_monster(mon);
}
if (flavour == BEAM_UNRAVELLED_MAGIC)
{
int unused; // res_margin
try_enchant_monster(mon, unused);
}
// Make a copy of the to-hit before we modify it.
int beam_hit = hit;
if (beam_hit != AUTOMATIC_HIT)
beam_hit = apply_lighting(beam_hit, *mon);
// The monster may block the beam.
if (!engulfs && is_blockable() && attempt_block(mon))
return;
defer_rand r;
const int repel = mon->missile_repulsion() ? REPEL_MISSILES_EV_BONUS : 0;
int rand_ev = random2(mon->evasion() + repel);
int hit_margin = _test_beam_hit(beam_hit, rand_ev, r);
if (you.duration[DUR_BLIND] && beam_hit != AUTOMATIC_HIT && agent()
&& agent()->is_player())
{
const int distance = you.pos().distance_from(mon->pos());
if (x_chance_in_y(player_blind_miss_chance(distance), 100))
hit_margin = -1;
}
// FIXME: We're randomising mon->evasion, which is further
// randomised inside test_beam_hit. This is so we stay close to the
// 4.0 to-hit system (which had very little love for monsters).
if (!engulfs && hit_margin < 0)
{
// If the PLAYER cannot see the monster, don't tell them anything!
if (mon->observable())
{
// if it would have hit otherwise...
if (hit_margin > -repel)
{
msg::stream << mon->name(DESC_THE) << " "
<< "repels the " << name
<< '!' << endl;
}
else
{
msg::stream << "The " << name << " misses "
<< mon->name(DESC_THE) << '.' << endl;
}
}
return;
}
update_hurt_or_helped(mon);
// We'll say ballistomycete spore explosions don't trigger the ally attack
// conduct for Fedhas worshipers. Mostly because you can accidentally blow
// up a group of 8 plants and get placed under penance until the end of
// time otherwise. I'd prefer to do this elsewhere but the beam information
// goes out of scope.
if (you_worship(GOD_FEDHAS) && flavour == BEAM_SPORE)
conducts[0].set();
if (!is_explosion && !noise_generated)
{
heard = noisy(loudness, pos(), source_id) || heard;
noise_generated = true;
}
if (!mon->alive())
return;
// The beam hit.
if (you.see_cell(mon->pos()))
{
// Monsters are never currently helpless in ranged combat.
if (hit_verb.empty())
hit_verb = engulfs ? "engulfs" : "hits";
// If the beam did no damage because of resistances,
// mons_adjust_flavoured below will print "%s completely resists", so
// no need to also say "does no damage" here.
mprf("The %s %s %s%s%s",
name.c_str(),
hit_verb.c_str(),
mon->name(DESC_THE).c_str(),
postac || damage.num == 0 ? "" : " but does no damage",
attack_strength_punctuation(final).c_str());
}
else if (heard && !hit_noise_msg.empty())
mprf(MSGCH_SOUND, "%s", hit_noise_msg.c_str());
// Spell vampirism
if (agent() && agent()->is_player() && is_player_book_spell(origin_spell))
majin_bo_vampirism(*mon, min(final, mon->stat_hp()));
// Apply flavoured specials.
mons_adjust_flavoured(mon, *this, postac, true);
// Arc out from the original target AFTER damage done to the main target
if (origin_spell == SPELL_GALVANIC_BREATH)
do_galvanic_jolt(*agent(), pos(), damage);
// mons_adjust_flavoured may kill the monster directly.
if (mon->alive())
{
// If the beam is of the MMISSILE type (Earth magic) we might bleed on
// the floor.
if (!engulfs && flavour == BEAM_MMISSILE && !mon->is_summoned())
{
// Using raw_damage instead of the flavoured one!
// assumes DVORP_PIERCING, factor: 0.5
const int blood = min(postac/2, mon->hit_points);
bleed_onto_floor(mon->pos(), mon->type, blood, true);
}
// Now hurt monster.
mon->hurt(agent(), final, flavour, KILLED_BY_BEAM, "", "", false);
// Haemoclasm explosions will always chain-explode if they kill something
if (!mon->alive() && flavour == BEAM_HAEMOCLASM && !mon->is_firewood()
&& you.has_mutation(MUT_MAKHLEB_MARK_HAEMOCLASM))
{
mon->props[MAKHLEB_HAEMOCLASM_KEY] = true;
}
}
if (mon->alive())
monster_post_hit(mon, final);
// The monster (e.g. a spectral weapon) might have self-destructed in its
// behaviour_event called from mon->hurt() above. If that happened, it
// will have been cleaned up already (and is therefore invalid now).
else if (!invalid_monster(mon))
kill_monster(*mon);
extra_range_used += range_used_on_hit();
}
bool bolt::ignores_monster(const monster* mon) const
{
// This is the lava digging tracer. It will stop at anything which cannot
// survive having lava put beneath it (ie: ignore everything else)
if (origin_spell == SPELL_HELLFIRE_MORTAR)
return mon && (mon->airborne() || monster_habitable_feat(mon, DNGN_LAVA));
// Digging doesn't affect monsters (should it harm earth elementals?).
if (flavour == BEAM_DIGGING)
return true;
// The targeters might call us with nullptr in the event of a remembered
// monster that is no longer there. Treat it as opaque.
if (!mon)
return false;
// Player shadows (or a dummy for a shadow spell tracer) can shoot through
// other shadows (ie: where they are currently standing while contemplating
// being somewhere else).
if (mon->type == MONS_PLAYER_SHADOW
&& ((agent() && agent()->type == MONS_PLAYER_SHADOW)
|| source_id == MID_PLAYER_SHADOW_DUMMY))
{
return true;
}
// Shadow spells have no friendly fire, even against monsters.
// (These should be the only ones that don't avoid that in other ways.)
if ((origin_spell == SPELL_SHADOW_PRISM || origin_spell == SPELL_SHADOW_BEAM
|| origin_spell == SPELL_SHADOW_SHOT
|| origin_spell == SPELL_SHADOW_TORPOR
|| (origin_spell == SPELL_SHADOW_BALL && in_explosion_phase))
&& mons_atts_aligned(attitude, mons_attitude(*mon)))
{
return true;
}
// All kinds of beams go past orbs of destruction, the player can shoot
// through friendly battlespheres, their own ancestor, plants if they're
// worshipping Fedhas, etc.
if (shoot_through_monster(agent(), *mon))
return true;
// Missiles go past bushes and briar patches, unless aimed directly at them
if (bush_immune(*mon))
return true;
// Fire storm creates these, so we'll avoid affecting them.
if (origin_spell == SPELL_FIRE_STORM && mon->type == MONS_FIRE_VORTEX)
return true;
// Don't blow up blocks of ice with the spell that creates them.
if (origin_spell == SPELL_GLACIATE && mon->type == MONS_BLOCK_OF_ICE)
return true;
if (flavour == BEAM_WATER && mon->type == MONS_WATER_ELEMENTAL)
return true;
// Rimeblight explosions won't hurt allies OR the monster that is exploding
if (origin_spell == SPELL_RIMEBLIGHT && is_explosion)
return mon->friendly() || mon->good_neutral() || mon->pos() == source;
if (origin_spell == SPELL_HOARFROST_BULLET)
return in_explosion_phase && mons_aligned(agent(), mon);
// Explosions caused by Mark of Carnage don't cause friendly fire, and Mark
// of the Legion allows firing through allies at all times.
if ((origin_spell == SPELL_UNLEASH_DESTRUCTION && mon->friendly())
&& (is_explosion || you.has_mutation(MUT_MAKHLEB_MARK_LEGION)))
{
return true;
}
if ((flavour == BEAM_HAEMOCLASM || flavour == BEAM_BLOODRITE) && mon->friendly())
return true;
if (flavour == BEAM_QAZLAL && mon->was_created_by(you, MON_SUMM_AID))
return true;
if (origin_spell == SPELL_UPHEAVAL && agent() && agent() == mon)
return true;
if ((origin_spell == SPELL_PERCUSSIVE_TEMPERING
|| origin_spell == SPELL_FORTRESS_BLAST)
&& mons_atts_aligned(attitude, mon->temp_attitude()))
{
return true;
}
return false;
}
bool bolt::self_targeted() const
{
// aimed_at_feet isn't enough to determine this. Examples: wrath uses a
// fake monster at the player's position, xom's chesspiece fakes smite
// targeting by setting the monster as the source position.
const actor* a = agent(true);
// TODO: are there cases that should count as self-targeted without an
// agent?
return aimed_at_feet && a && a->pos() == source
&& (!a->is_monster() || !mons_is_wrath_avatar(*a->as_monster()));
}
bool bolt::has_saving_throw() const
{
if (self_targeted() || no_saving_throw)
return false;
switch (flavour)
{
case BEAM_HASTE:
case BEAM_MIGHT:
case BEAM_BERSERK:
case BEAM_HEALING:
case BEAM_INVISIBILITY:
case BEAM_DISPEL_UNDEAD:
case BEAM_BLINK_CLOSE:
case BEAM_BLINK:
case BEAM_BECKONING:
case BEAM_MALIGN_OFFERING:
case BEAM_AGILITY:
case BEAM_RESISTANCE:
case BEAM_MALMUTATE:
case BEAM_SAP_MAGIC:
case BEAM_UNRAVELLING:
case BEAM_UNRAVELLED_MAGIC:
case BEAM_INFESTATION:
case BEAM_IRRESISTIBLE_CONFUSION:
case BEAM_VILE_CLUTCH:
case BEAM_ROOTS:
case BEAM_VAMPIRIC_DRAINING:
case BEAM_CONCENTRATE_VENOM:
case BEAM_ENFEEBLE:
case BEAM_VITRIFYING_GAZE:
case BEAM_RIMEBLIGHT:
case BEAM_SHADOW_TORPOR:
return false;
case BEAM_VULNERABILITY:
return !one_chance_in(3); // Ignores will 1/3 of the time
default:
return true;
}
}
bool ench_flavour_affects_monster(actor *agent, beam_type flavour,
const monster* mon, bool intrinsic_only)
{
bool rc = true;
switch (flavour)
{
case BEAM_MALMUTATE:
case BEAM_UNRAVELLED_MAGIC:
rc = mon->can_mutate();
break;
case BEAM_SLOW:
case BEAM_HASTE:
case BEAM_PARALYSIS:
case BEAM_SHADOW_TORPOR:
rc = !mon->stasis();
break;
case BEAM_CONFUSION:
case BEAM_IRRESISTIBLE_CONFUSION:
case BEAM_VEX:
rc = !mon->clarity();
break;
case BEAM_POLYMORPH:
rc = mon->can_polymorph();
break;
case BEAM_DISPEL_UNDEAD:
rc = bool(mon->holiness() & MH_UNDEAD);
break;
case BEAM_PAIN:
rc = mon->res_negative_energy(intrinsic_only) < 3;
break;
case BEAM_AGONY:
case BEAM_CURSE_OF_AGONY:
rc = !mon->res_torment();
break;
case BEAM_HIBERNATION:
rc = mon->can_hibernate(false, intrinsic_only);
break;
case BEAM_SLEEP:
rc = mon->can_sleep();
break;
case BEAM_PORKALATOR:
rc = (mon->holiness() & MH_DEMONIC && mon->type != MONS_HELL_HOG)
|| (mon->holiness() & MH_NATURAL && mon->type != MONS_HOG)
|| (mon->holiness() & MH_HOLY && mon->type != MONS_HOLY_SWINE);
break;
case BEAM_SENTINEL_MARK:
rc = false;
break;
case BEAM_MALIGN_OFFERING:
rc = (mon->res_negative_energy(intrinsic_only) < 3);
break;
case BEAM_VAMPIRIC_DRAINING:
rc = actor_is_susceptible_to_vampirism(*mon)
&& (mon->res_negative_energy(intrinsic_only) < 3);
break;
case BEAM_VIRULENCE:
rc = (mon->res_poison() < 3);
break;
case BEAM_DRAIN_MAGIC:
rc = mon->antimagic_susceptible();
break;
case BEAM_INNER_FLAME:
rc = !mon->has_ench(ENCH_INNER_FLAME);
break;
case BEAM_PETRIFY:
rc = !mon->res_petrify();
break;
case BEAM_INFESTATION:
rc = (mons_gives_xp(*mon, you) || mon->props.exists(KIKU_WRETCH_KEY))
&& !mon->friendly()
&& !mon->has_ench(ENCH_INFESTATION);
break;
case BEAM_VILE_CLUTCH:
case BEAM_ROOTS:
ASSERT(agent);
{
const auto constr_typ = flavour == BEAM_ROOTS ? CONSTRICT_ROOTS : CONSTRICT_BVC;
rc = !mons_aligned(agent, mon) && agent->can_constrict(*mon, constr_typ);
}
break;
// Special allies whose loyalty can't be so easily bent
case BEAM_CHARM:
rc = !never_harm_monster(agent, mon)
&& !mons_aligned(agent, mon);
break;
case BEAM_MINDBURST:
rc = mons_intel(*mon) > I_BRAINLESS;
break;
case BEAM_ENFEEBLE:
rc = mons_has_attacks(*mon)
|| mon->antimagic_susceptible()
|| !mons_invuln_will(*mon);
break;
case BEAM_RIMEBLIGHT:
rc = !mon->has_ench(ENCH_RIMEBLIGHT);
break;
case BEAM_SOUL_SPLINTER:
rc = mons_can_be_spectralised(*mon, true, true)
&& !mon->props.exists(SOUL_SPLINTERED_KEY);
break;
default:
break;
}
return rc;
}
bool enchant_actor_with_flavour(actor* victim, const actor *foe,
beam_type flavour, int powc)
{
bolt dummy;
dummy.flavour = flavour;
dummy.ench_power = powc;
dummy.set_agent(foe);
dummy.animate = false;
if (victim->is_player())
dummy.affect_player_enchantment(false);
else
dummy.apply_enchantment_to_monster(victim->as_monster());
return dummy.obvious_effect;
}
bool enchant_monster_invisible(monster* mon, const string &how)
{
// Store the monster name before it becomes an "it". - bwr
const string monster_name = mon->name(DESC_THE);
const bool could_see = you.can_see(*mon);
if (mon->has_ench(ENCH_INVIS) || !mon->add_ench(ENCH_INVIS))
return false;
if (could_see)
{
const bool is_visible = mon->visible_to(&you);
// Can't use simple_monster_message(*) here, since it checks
// for visibility of the monster (and it's now invisible).
// - bwr
mprf("%s %s%s",
monster_name.c_str(),
how.c_str(),
is_visible ? " for a moment."
: "!");
if (!is_visible && !mons_is_safe(mon))
autotoggle_autopickup(true);
}
return true;
}
mon_resist_type bolt::try_enchant_monster(monster* mon, int &res_margin)
{
// Early out if the enchantment is meaningless.
if (!ench_flavour_affects_monster(agent(), flavour, mon))
return MON_UNAFFECTED;
// Check willpower.
if (has_saving_throw())
{
if (mons_invuln_will(*mon))
return MON_UNAFFECTED;
// (Very) ugly things and shapeshifters will never resist
// polymorph beams.
if (flavour == BEAM_POLYMORPH
&& (mon->type == MONS_UGLY_THING
|| mon->type == MONS_VERY_UGLY_THING
|| mon->is_shapeshifter()))
{
;
}
// Chaos effects don't get a resistance check to match melee chaos.
else if (real_flavour != BEAM_CHAOS)
{
if (mon->check_willpower(agent(true), ench_power) > 0)
{
// Note only actually used by messages in this case.
res_margin = mon->willpower() - ench_power_stepdown(ench_power);
return MON_RESIST;
}
}
}
return apply_enchantment_to_monster(mon);
}
mon_resist_type bolt::apply_enchantment_to_monster(monster* mon)
{
// Gigantic-switches-R-Us
switch (flavour)
{
case BEAM_TELEPORT:
if (mon->no_tele())
return MON_UNAFFECTED;
if (mon->observable())
obvious_effect = true;
monster_teleport(mon, false, false, false, agent());
return MON_AFFECTED;
case BEAM_BLINK:
if (mon->no_tele())
return MON_UNAFFECTED;
if (mon->observable())
obvious_effect = true;
monster_blink(mon);
return MON_AFFECTED;
case BEAM_BLINK_CLOSE:
if (mon->no_tele())
return MON_UNAFFECTED;
if (mon->observable())
obvious_effect = true;
blink_other_close(mon, source);
return MON_AFFECTED;
case BEAM_BECKONING:
obvious_effect = beckon(*mon, *this);
return obvious_effect ? MON_AFFECTED : MON_OTHER; // ?
case BEAM_POLYMORPH:
if (mon->polymorph(0))
obvious_effect = true;
if (YOU_KILL(thrower))
{
const int level = 2 + random2(3);
did_god_conduct(DID_DELIBERATE_MUTATING, level, god_cares());
}
return MON_AFFECTED;
case BEAM_MALMUTATE:
case BEAM_UNRAVELLED_MAGIC:
if (mon->malmutate(agent())) // exact source doesn't matter
obvious_effect = true;
if (YOU_KILL(thrower))
{
const int level = 2 + random2(3);
did_god_conduct(DID_DELIBERATE_MUTATING, level, god_cares());
}
return MON_AFFECTED;
case BEAM_BANISH:
mon->banish(agent());
obvious_effect = true;
return MON_AFFECTED;
case BEAM_DISPEL_UNDEAD:
{
const int dam = damage.roll();
if (you.see_cell(mon->pos()))
{
mprf("%s is dispelled%s",
mon->name(DESC_THE).c_str(),
attack_strength_punctuation(dam).c_str());
obvious_effect = true;
}
mon->hurt(agent(), dam);
return MON_AFFECTED;
}
case BEAM_VAMPIRIC_DRAINING:
{
const int dam = resist_adjust_damage(mon, flavour, damage.roll());
if (dam && actor_is_susceptible_to_vampirism(*mon))
{
_vampiric_draining_effect(*mon, *agent(), dam);
obvious_effect = true;
return MON_AFFECTED;
}
else
return MON_UNAFFECTED;
}
case BEAM_PAIN:
{
const int dam = resist_adjust_damage(mon, flavour, damage.roll());
if (!dam)
return MON_UNAFFECTED;
if (you.see_cell(mon->pos()))
{
mprf("%s writhes in agony%s",
mon->name(DESC_THE).c_str(),
attack_strength_punctuation(dam).c_str());
obvious_effect = true;
}
mon->hurt(agent(), dam, flavour);
return MON_AFFECTED;
}
case BEAM_SOUL_SPLINTER:
if (you.see_cell(mon->pos()))
obvious_effect = true;
if (make_soul_wisp(*agent(), *mon))
return MON_AFFECTED;
else
return MON_UNAFFECTED;
case BEAM_AGONY:
torment_cell(mon->pos(), agent(), TORMENT_AGONY);
obvious_effect = true;
return MON_AFFECTED;
case BEAM_CURSE_OF_AGONY:
// Don't allow stacking number of charges in a opaque fashion
// by recasting the spell on already-cursed enemies.
// (But allow refreshing duration, if someone wants)
if (mon->has_ench(ENCH_CURSE_OF_AGONY))
mon->del_ench(ENCH_CURSE_OF_AGONY, true, false);
if (mon->add_ench(mon_enchant(ENCH_CURSE_OF_AGONY, 2, agent(),
random_range(6, 8) * BASELINE_DELAY)))
{
obvious_effect = true;
simple_monster_message(*mon, " is cursed with the promise of agony.");
}
return MON_AFFECTED;
case BEAM_MINDBURST:
{
const int dam = damage.roll();
if (you.see_cell(mon->pos()))
{
if (mon->type == MONS_GLOWING_ORANGE_BRAIN)
{
mprf("%s is blasted smooth%s",
mon->name(DESC_THE).c_str(),
attack_strength_punctuation(dam).c_str());
} else {
const bool plural = mon->heads() > 1;
mprf("%s mind%s blasted%s",
mon->name(DESC_ITS).c_str(),
plural ? "s are" : " is",
attack_strength_punctuation(dam).c_str());
}
obvious_effect = true;
}
mon->hurt(agent(), dam, flavour);
return MON_AFFECTED;
}
case BEAM_HIBERNATION:
if (mon->can_hibernate())
{
if (simple_monster_message(*mon, " looks drowsy..."))
obvious_effect = true;
// Since 1 turn will pass for the player's own action here, EH will
// put a monster to sleep for between ~20-55 aut, slanted towards
// the low end.
const int dur = max(30, 10 + random2avg(55, 3));
mon->put_to_sleep(agent(), dur, true);
return MON_AFFECTED;
}
return MON_UNAFFECTED;
case BEAM_CORONA:
if (backlight_monster(mon, agent()))
{
obvious_effect = true;
return MON_AFFECTED;
}
return MON_UNAFFECTED;
case BEAM_SLOW:
{
const int dur = 1 + div_rand_round(ench_power, 2)
+ random2(1 + ench_power);
obvious_effect = do_slow_monster(*mon, agent(), dur * BASELINE_DELAY);
return MON_AFFECTED;
}
case BEAM_HASTE:
if (YOU_KILL(thrower))
did_god_conduct(DID_HASTY, 6, god_cares());
if (mon->stasis())
return MON_AFFECTED;
if (!mon->has_ench(ENCH_HASTE)
&& mon->add_ench(ENCH_HASTE))
{
if (!mons_is_immotile(*mon)
&& simple_monster_message(*mon, " seems to speed up."))
{
obvious_effect = true;
}
}
return MON_AFFECTED;
case BEAM_MIGHT:
if (!mon->has_ench(ENCH_MIGHT)
&& mons_has_attacks(*mon)
&& mon->add_ench(ENCH_MIGHT))
{
if (simple_monster_message(*mon, " seems to grow stronger."))
obvious_effect = true;
}
return MON_AFFECTED;
case BEAM_DOUBLE_HEALTH:
if (!mon->has_ench(ENCH_DOUBLED_HEALTH)
&& mon->add_ench(ENCH_DOUBLED_HEALTH))
{
if (simple_monster_message(*mon, " surges with doubled health!"))
obvious_effect = true;
}
return MON_AFFECTED;
case BEAM_WEAKNESS:
mon->weaken(agent(), 8 + random2(4));
obvious_effect = true;
return MON_AFFECTED;
case BEAM_BERSERK:
if (!mon->berserk_or_frenzied())
{
// currently from potion, hence voluntary
mon->go_berserk(true);
// can't return this from go_berserk, unfortunately
obvious_effect = you.can_see(*mon);
}
return MON_AFFECTED;
case BEAM_HEALING:
// No KILL_YOU_CONF, or we get "You heal ..."
if (thrower == KILL_YOU || thrower == KILL_YOU_MISSILE)
{
const int pow = min(50, 3 + damage.roll());
const int amount = pow + roll_dice(2, pow) - 2;
if (heal_monster(*mon, amount))
obvious_effect = true;
msg_generated = true; // to avoid duplicate "nothing happens"
}
else if (mon->heal(3 + damage.roll()))
{
if (mon->hit_points == mon->max_hit_points)
{
if (simple_monster_message(*mon, " wounds heal themselves!", true))
obvious_effect = true;
}
else if (simple_monster_message(*mon, " is healed somewhat."))
obvious_effect = true;
}
return MON_AFFECTED;
case BEAM_PARALYSIS:
apply_bolt_paralysis(mon);
return MON_AFFECTED;
case BEAM_PETRIFY:
if (mon->res_petrify())
return MON_UNAFFECTED;
apply_bolt_petrify(mon);
return MON_AFFECTED;
case BEAM_VEX:
if (mon->vex(agent(), random_range(3, 6)))
return MON_AFFECTED;
else
return MON_UNAFFECTED;
case BEAM_SPORE:
case BEAM_CONFUSION:
case BEAM_IRRESISTIBLE_CONFUSION:
{
if (mon->clarity())
{
if (you.can_see(*mon))
obvious_effect = true;
return MON_AFFECTED;
}
// irresistible confusion has a shorter duration and is weaker
// against strong monsters
int dur = ench_power;
if (flavour == BEAM_IRRESISTIBLE_CONFUSION)
dur = max(10, dur - mon->get_hit_dice());
else
dur = _ench_pow_to_dur(dur);
if (mon->add_ench(mon_enchant(ENCH_CONFUSION, 0, agent(), dur)))
{
// FIXME: Put in an exception for things you won't notice
// becoming confused.
if (simple_monster_message(*mon, " appears confused."))
obvious_effect = true;
}
return MON_AFFECTED;
}
case BEAM_SLEEP:
if (mon->asleep())
return MON_UNAFFECTED;
mon->put_to_sleep(agent(), random_range(4, 7) * BASELINE_DELAY);
if (simple_monster_message(*mon, " falls asleep!"))
obvious_effect = true;
return MON_AFFECTED;
case BEAM_INVISIBILITY:
{
if (enchant_monster_invisible(mon, "flickers and vanishes"))
obvious_effect = true;
return MON_AFFECTED;
}
case BEAM_CHARM:
if (agent() && agent()->is_monster())
{
enchant_type good = (agent()->wont_attack()) ? ENCH_CHARM
: ENCH_HEXED;
enchant_type bad = (agent()->wont_attack()) ? ENCH_HEXED
: ENCH_CHARM;
const bool could_see = you.can_see(*mon);
if (mon->has_ench(bad))
{
obvious_effect = mon->del_ench(bad);
return MON_AFFECTED;
}
if (simple_monster_message(*mon, " is charmed!"))
obvious_effect = true;
mon->add_ench(mon_enchant(good, 0, agent()));
if (!obvious_effect && could_see && !you.can_see(*mon))
obvious_effect = true;
return MON_AFFECTED;
}
// Being a puppet on magic strings is a nasty thing.
// Mindless creatures shouldn't probably mind, but because of complex
// behaviour of charmed neutrals, let's disallow that for now.
mon->attitude = ATT_HOSTILE;
// XXX: Another hackish thing for Pikel's band neutrality.
if (mons_is_mons_class(mon, MONS_PIKEL))
pikel_band_neutralise();
if (simple_monster_message(*mon, " is charmed."))
obvious_effect = true;
mon->add_ench(mon_enchant(ENCH_CHARM, 0, agent()));
if (you.can_see(*mon))
obvious_effect = true;
return MON_AFFECTED;
case BEAM_PORKALATOR:
{
// Monsters which use the ghost structure can't be properly
// restored from hog form.
if (mons_is_ghost_demon(mon->type))
return MON_UNAFFECTED;
monster orig_mon(*mon);
if (monster_polymorph(mon, mon->holiness() & MH_DEMONIC ?
MONS_HELL_HOG : mon->holiness() & MH_HOLY ?
MONS_HOLY_SWINE : MONS_HOG))
{
obvious_effect = true;
// Don't restore items to monster if it reverts.
orig_mon.inv = mon->inv;
// monsters can't cast spells in hog form either -doy
mon->spells.clear();
// For monster reverting to original form.
mon->props[ORIG_MONSTER_KEY] = orig_mon;
}
return MON_AFFECTED;
}
case BEAM_INNER_FLAME:
if (!mon->has_ench(ENCH_INNER_FLAME)
&& mon->add_ench(mon_enchant(ENCH_INNER_FLAME, 0, agent())))
{
if (simple_monster_message(*mon,
(mon->body_size(PSIZE_BODY) > SIZE_LARGE)
? " is filled with an intense inner flame!"
: " is filled with an inner flame."))
{
obvious_effect = true;
}
}
return MON_AFFECTED;
case BEAM_DIMENSION_ANCHOR:
if (!mon->has_ench(ENCH_DIMENSION_ANCHOR)
&& mon->add_ench(mon_enchant(ENCH_DIMENSION_ANCHOR, 0, agent(),
random_range(20, 30) * BASELINE_DELAY)))
{
if (simple_monster_message(*mon, " is firmly anchored in space."))
obvious_effect = true;
}
return MON_AFFECTED;
case BEAM_VULNERABILITY:
if (!mon->has_ench(ENCH_LOWERED_WL))
{
if (mon->strip_willpower(agent(), random_range(20, 30)))
obvious_effect = true;
}
return MON_AFFECTED;
case BEAM_VITRIFY:
if (!mon->has_ench(ENCH_VITRIFIED)
&& mon->add_ench(mon_enchant(ENCH_VITRIFIED, 0, agent(),
random_range(8, 18) * BASELINE_DELAY)))
{
if (you.can_see(*mon))
{
mprf("%s becomes as fragile as glass!",
mon->name(DESC_THE).c_str());
obvious_effect = true;
}
}
return MON_AFFECTED;
case BEAM_VITRIFYING_GAZE:
{
bool had_status = mon->has_ench(ENCH_VITRIFIED);
if (mon->add_ench(mon_enchant(ENCH_VITRIFIED, 0, agent(),
random_range(4, 8) * BASELINE_DELAY)))
{
if (you.can_see(*mon))
{
if (had_status)
{
mprf("%s looks even more glass-like.",
mon->name(DESC_THE).c_str());
}
else
{
mprf("%s becomes as fragile as glass!",
mon->name(DESC_THE).c_str());
}
obvious_effect = true;
}
}
return MON_AFFECTED;
}
case BEAM_MALIGN_OFFERING:
{
const int dam = resist_adjust_damage(mon, flavour, damage.roll());
if (dam)
{
_malign_offering_effect(mon, agent(), dam);
obvious_effect = true;
return MON_AFFECTED;
}
else
{
simple_monster_message(*mon, " is unaffected.");
return MON_UNAFFECTED;
}
}
case BEAM_VIRULENCE:
if (!mon->has_ench(ENCH_POISON_VULN)
&& mon->add_ench(mon_enchant(ENCH_POISON_VULN, 0, agent(),
random_range(20, 30) * BASELINE_DELAY)))
{
if (simple_monster_message(*mon,
" grows more vulnerable to poison."))
{
obvious_effect = true;
}
}
return MON_AFFECTED;
case BEAM_AGILITY:
if (!mon->has_ench(ENCH_AGILE)
&& !mon->is_stationary()
&& mon->add_ench(ENCH_AGILE))
{
if (simple_monster_message(*mon, " suddenly seems more agile."))
obvious_effect = true;
}
return MON_AFFECTED;
case BEAM_SAP_MAGIC:
if (!mon->has_ench(ENCH_SAP_MAGIC)
&& mon->add_ench(mon_enchant(ENCH_SAP_MAGIC, 0, agent())))
{
if (you.can_see(*mon))
{
mprf("%s seems less certain of %s magic.",
mon->name(DESC_THE).c_str(), mon->pronoun(PRONOUN_POSSESSIVE).c_str());
obvious_effect = true;
}
}
return MON_AFFECTED;
case BEAM_DRAIN_MAGIC:
{
if (!mon->antimagic_susceptible())
break;
const int dur =
random2(div_rand_round(ench_power, mon->get_hit_dice()) + 1)
* BASELINE_DELAY;
if (!dur)
break;
mon->add_ench(mon_enchant(ENCH_ANTIMAGIC, 0,
agent(), // doesn't matter
dur));
if (you.can_see(*mon))
{
mprf("%s magic leaks into the air.",
apostrophise(mon->name(DESC_THE)).c_str());
}
obvious_effect = true;
break;
}
case BEAM_TUKIMAS_DANCE:
cast_tukimas_dance(ench_power, mon);
obvious_effect = true;
break;
case BEAM_RESISTANCE:
if (!mon->has_ench(ENCH_RESISTANCE)
&& mon->add_ench(ENCH_RESISTANCE))
{
if (simple_monster_message(*mon, " suddenly seems more resistant."))
obvious_effect = true;
}
return MON_AFFECTED;
case BEAM_UNRAVELLING:
if (!monster_can_be_unravelled(*mon))
return MON_UNAFFECTED;
if (mon->is_abjurable())
{
mprf("The magic binding %s to this plane unravels!",
mon->name(DESC_THE).c_str());
monster_die(*mon, KILL_RESET, actor_to_death_source(agent()));
}
else
debuff_monster(*mon);
_unravelling_explode(*this);
return MON_AFFECTED;
case BEAM_INFESTATION:
{
const int dur = (5 + random2avg(div_rand_round(ench_power,2), 2))
* BASELINE_DELAY;
mon->add_ench(mon_enchant(ENCH_INFESTATION, 0, &you, dur));
if (simple_monster_message(*mon, " is infested!"))
obvious_effect = true;
return MON_AFFECTED;
}
case BEAM_VILE_CLUTCH:
{
const int dur = 4 + random_range(div_rand_round(ench_power, 35),
div_rand_round(ench_power, 25) + 1);
if (start_ranged_constriction(*agent(), *mon, dur, CONSTRICT_BVC))
obvious_effect = true;
return MON_AFFECTED;
}
case BEAM_ROOTS:
{
const int dur = 3 + random_range(div_rand_round(ench_power, 22),
div_rand_round(ench_power, 16) + 1);
if (start_ranged_constriction(*agent(), *mon, dur, CONSTRICT_ROOTS))
obvious_effect = true;
return MON_AFFECTED;
}
case BEAM_CONCENTRATE_VENOM:
if (!mon->has_ench(ENCH_CONCENTRATE_VENOM)
&& mon->add_ench(ENCH_CONCENTRATE_VENOM))
{
if (simple_monster_message(*mon, " venom grows more potent.", true))
obvious_effect = true;
}
return MON_AFFECTED;
case BEAM_ENFEEBLE:
if (enfeeble_monster(*mon, ench_power))
obvious_effect = true;
return MON_AFFECTED;
case BEAM_RIMEBLIGHT:
if (apply_rimeblight(*mon, ench_power, true))
{
mprf("A stygian plague fills %s body.",
apostrophise(mon->name(DESC_THE)).c_str());
obvious_effect = true;
}
return MON_AFFECTED;
case BEAM_SHADOW_TORPOR:
{
int dur = max(30, ench_power / 2 + 40 - random2(mon->get_hit_dice() * 4));
obvious_effect = do_slow_monster(*mon, agent(), dur);
return MON_AFFECTED;
}
default:
break;
}
return MON_AFFECTED;
}
// Extra range used on hit.
int bolt::range_used_on_hit() const
{
if (is_tracer() && source_id == MID_PLAYER && hit < AUTOMATIC_HIT)
return 0;
// Non-beams can only affect one thing (player/monster).
if (!pierce)
return BEAM_STOP;
// These beams fully penetrate regardless of anything else.
if (flavour == BEAM_DAMNATION
|| flavour == BEAM_DIGGING
|| flavour == BEAM_VILE_CLUTCH
|| flavour == BEAM_ROOTS
|| flavour == BEAM_SHADOW_TORPOR)
{
return 0;
}
// explosions/clouds and enchants that aren't Line Pass stop.
if (is_enchantment() && name != "line pass"
|| is_explosion
|| is_big_cloud())
{
return BEAM_STOP;
}
// Lightning that isn't an explosion goes through things.
return 0;
}
// Information for how various explosions look & sound.
struct explosion_sfx
{
// A message printed when the player sees the explosion.
const char *seeMsg;
// What the player hears when the explosion goes off unseen.
const char *sound;
};
// A map from origin_spells to special explosion info for each.
const map<spell_type, explosion_sfx> spell_explosions = {
{ SPELL_HURL_DAMNATION, {
"The sphere of damnation explodes!",
"the wailing of the damned",
} },
{ SPELL_CALL_DOWN_DAMNATION, {
"The sphere of damnation explodes!",
"the wailing of the damned",
} },
{ SPELL_FIREBALL, {
"The fireball explodes!",
"an explosion",
} },
{ SPELL_ORB_OF_ELECTRICITY, {
"The orb of electricity explodes!",
"a clap of thunder",
} },
{ SPELL_FIRE_STORM, {
"A raging storm of fire appears!",
"a raging storm",
} },
{ SPELL_MEPHITIC_CLOUD, {
"The flask of dizzying concoctions shatters into a vile cloud!",
"a loud shattering of glass",
} },
{ SPELL_GHOSTLY_FIREBALL, {
"The ghostly flame explodes!",
"the shriek of haunting fire",
} },
{ SPELL_VIOLENT_UNRAVELLING, {
"The enchantments explode!",
"a sharp crackling", // radiation = geiger counter
} },
{ SPELL_ICEBLAST, {
"The mass of ice explodes!",
"an explosion",
} },
{ SPELL_PERMAFROST_ERUPTION, {
"Piercing cold boils outward!",
"an explosion", // maybe?
} },
{ SPELL_GHOSTLY_SACRIFICE, {
"The ghostly flame explodes!",
"the shriek of haunting fire",
} },
{ SPELL_SERACFALL, {
"The mass of ice explodes!",
"an explosion",
} },
{ SPELL_FLAME_WAVE, {
"A wave of flame ripples out!",
"the roar of flame",
} },
{ SPELL_FASTROOT, {
"The roots erupt in riotous growth!",
"creaking and crackling",
} },
{ SPELL_BLASTMOTE, {
"The cloud of blastmotes explodes!",
"a concussive explosion",
} },
{ SPELL_HURL_TORCHLIGHT, {
"The gout of umbral fire explodes!",
"the shriek of umbral fire",
} },
{ SPELL_WARP_SPACE, {
"Space twists violently!",
"shrill echo",
} },
{ SPELL_COMBUSTION_BREATH, {
"The embers explode!",
"a fiery explosion",
} },
{ SPELL_NULLIFYING_BREATH, {
"The antimagic surges outward!",
"a quiet echo",
} },
{ SPELL_HOARFROST_BULLET, {
"The shards fragment into shrapnel!",
"an explosion",
} },
{ SPELL_SHADOW_BALL, {
"The flickering shadows explode!",
"a quiet whistle",
} },
};
// Takes a bolt and refines it for use in the explosion function.
// Explosions which do not follow from beams bypass this function.
void bolt::refine_for_explosion()
{
ASSERT(!special_explosion);
string seeMsg;
string hearMsg;
if (ex_size == 0)
ex_size = 1;
glyph = dchar_glyph(DCHAR_FIRED_BURST);
// Assume that the player can see/hear the explosion, or
// gets burned by it anyway. :)
msg_generated = true;
if (item != nullptr)
{
seeMsg = "The " + item->name(DESC_PLAIN, false, false, false)
+ " explodes!";
hearMsg = "You hear an explosion!";
}
else
{
const explosion_sfx *explosion = map_find(spell_explosions,
origin_spell);
if (explosion)
{
seeMsg = explosion->seeMsg;
hearMsg = make_stringf("You hear %s!", explosion->sound);
}
else
{
seeMsg = "The beam explodes into a cloud of software bugs!";
hearMsg = "You hear the sound of one hand!";
}
}
if (origin_spell == SPELL_ORB_OF_ELECTRICITY)
{
colour = LIGHTCYAN;
ex_size = 2;
}
else if (origin_spell == SPELL_NULLIFYING_BREATH)
{
colour = MAGENTA;
ex_size = 2;
}
if (!is_tracer() && !seeMsg.empty() && !hearMsg.empty())
{
heard = player_can_hear(target);
// Check for see/hear/no msg.
if (you.see_cell(target) || target == you.pos())
mpr(seeMsg);
else
{
if (!heard)
msg_generated = false;
else
mprf(MSGCH_SOUND, "%s", hearMsg.c_str());
}
}
}
typedef vector< vector<coord_def> > sweep_type;
static sweep_type _radial_sweep(int r)
{
sweep_type result;
// Center first.
result.emplace_back(1, coord_def(0,0));
for (int rad = 1; rad <= r; ++rad)
{
sweep_type::value_type work;
for (int d = -rad; d <= rad; ++d)
{
// Don't put the corners in twice!
if (d != rad && d != -rad)
{
work.emplace_back(-rad, d);
work.emplace_back(+rad, d);
}
work.emplace_back(d, -rad);
work.emplace_back(d, +rad);
}
result.push_back(work);
}
return result;
}
/** How much noise does an explosion this big make?
*
* @param the size of the explosion (radius, not diameter)
* @returns how much noise it would make.
*/
int explosion_noise(int rad)
{
return 10 + rad * 5;
}
#define MAX_EXPLOSION_RADIUS 9
// Returns true if we saw something happening.
bool bolt::explode(bool show_more, bool hole_in_the_middle)
{
ASSERT(!special_explosion);
ASSERT(!in_explosion_phase);
ASSERT(ex_size >= 0);
// explode() can be called manually without setting real_flavour.
// FIXME: The entire flavour/real_flavour thing needs some
// rewriting!
if (real_flavour == BEAM_CHAOS
|| real_flavour == BEAM_RANDOM)
{
flavour = real_flavour;
}
else
real_flavour = flavour;
const int r = min(ex_size, MAX_EXPLOSION_RADIUS);
in_explosion_phase = true;
// being hit by bounces doesn't exempt you from the explosion (not that it
// currently ever matters)
hit_count.clear();
if (is_sanctuary(pos()) && flavour != BEAM_VISUAL)
{
if (!is_tracer() && you.see_cell(pos()) && !name.empty())
{
mprf(MSGCH_GOD, "By Zin's power, the %s is contained.",
name.c_str());
return true;
}
return false;
}
#ifdef DEBUG_DIAGNOSTICS
if (!quiet_debug)
{
dprf(DIAG_BEAM, "explosion at (%d, %d) : g=%d c=%d f=%d hit=%d dam=%dd%d r=%d",
pos().x, pos().y, glyph, colour, flavour, hit, damage.num, damage.size, r);
}
#endif
if (!is_tracer() && flavour != BEAM_VISUAL)
{
loudness = explosion_noise(r);
// Not an "explosion", but still a bit noisy at the target location.
if (origin_spell == SPELL_INFESTATION
|| origin_spell == SPELL_DAZZLING_FLASH
|| origin_spell == SPELL_NULLIFYING_BREATH)
{
loudness = spell_effect_noise(origin_spell);
}
else if (origin_spell == SPELL_FLAME_WAVE)
{
loudness = spell_effect_noise(origin_spell)
+ (r - 1) * 2; // at radius 1, base noise
}
// These explosions are too punishing for the player (and also a bit too
// Qazlal-like in my opinion) if they make full uncontrollable noise
// all the time.
else if (flavour == BEAM_HAEMOCLASM)
loudness = 5;
// Make bloated husks quieter, both for balance (they're waking up
// whole levels!) and for theme (it's not a huge fireball, it's a big
// gas leak).
if (name == "blast of putrescent gases")
loudness = loudness * 2 / 3;
// Shadow spells are silent
else if (origin_spell == SPELL_SHADOW_BALL
|| origin_spell == SPELL_SHADOW_PRISM)
{
loudness = 0;
}
// Lee's Rapid Deconstruction can target the tiles on the map
// boundary.
const coord_def noise_position = clamp_in_bounds(pos());
bool heard_expl = noisy(loudness, noise_position, source_id);
heard = heard || heard_expl;
if (heard_expl && !explode_noise_msg.empty() && !you.see_cell(pos()))
mprf(MSGCH_SOUND, "%s", explode_noise_msg.c_str());
}
// Run DFS to determine which cells are influenced
explosion_map exp_map;
exp_map.init(INT_MAX);
determine_affected_cells(exp_map, coord_def(), 0, r, true, true);
// We get a bit fancy, drawing all radius 0 effects, then radius
// 1, radius 2, etc. It looks a bit better that way.
const vector< vector<coord_def> > sweep = _radial_sweep(r);
const coord_def centre(9,9);
// Draw pass.
if (!is_tracer() && animate)
{
for (const auto &line : sweep)
{
bool pass_visible = false;
for (const coord_def &delta : line)
{
if (delta.origin() && hole_in_the_middle)
continue;
if (exp_map(delta + centre) < INT_MAX)
pass_visible |= explosion_draw_cell(delta + pos());
}
// redraw for an entire explosion block, so redraw_per_cell is not
// relevant
if (pass_visible && !Options.reduce_animations)
animation_delay(explode_delay, true);
}
}
// Affect pass.
int cells_seen = 0;
for (const auto &line : sweep)
{
for (const coord_def &delta : line)
{
if (delta.origin() && hole_in_the_middle)
continue;
if (exp_map(delta + centre) < INT_MAX)
{
if (you.see_cell(delta + pos()))
++cells_seen;
explosion_affect_cell(delta + pos());
}
}
}
// Delay after entire explosion has been drawn.
if (!is_tracer() && cells_seen > 0 && show_more && animate)
animation_delay(explode_delay * 3, Options.reduce_animations);
return cells_seen > 0;
}
bool bolt::explode(beam_tracer& new_tracer, bool show_more,
bool hole_in_the_middle)
{
unwind_var<beam_tracer*> old_tracer(tracer, &new_tracer);
return explode(show_more, hole_in_the_middle);
}
/**
* Draw one tile of an explosion, if that cell is visible.
*
* @param p The cell to draw, in grid coordinates.
* @return True if the cell was actually drawn.
*/
bool bolt::explosion_draw_cell(const coord_def& p)
{
if (you.see_cell(p))
{
const coord_def drawpos = grid2view(p);
// bounds check
if (in_los_bounds_v(drawpos))
{
#ifdef USE_TILE
// Use default value if none specified.
if (tile_explode == 0)
{
if (tile_beam != 0)
tile_explode = tile_beam;
else
tile_explode = tileidx_zap(colour);
}
view_add_tile_overlay(p, vary_bolt_tile(tile_explode, source, target, p));
#endif
const unsigned short c = colour == BLACK ?
random_colour(true) : element_colour(colour, false, p);
view_add_glyph_overlay(p, {dchar_glyph(DCHAR_EXPLOSION), c});
return true;
}
}
return false;
}
void bolt::explosion_affect_cell(const coord_def& p)
{
// pos() = target during an explosion, so restore it after affecting
// the cell.
const coord_def orig_pos = target;
fake_flavour();
target = p;
affect_cell();
flavour = real_flavour;
target = orig_pos;
}
// Uses DFS
void bolt::determine_affected_cells(explosion_map& m, const coord_def& delta,
int count, int r,
bool stop_at_statues, bool stop_at_walls)
{
const coord_def centre(9,9);
const coord_def loc = pos() + delta;
// A bunch of tests for edge cases.
if (delta.rdist() > centre.rdist()
|| delta.rdist() > r
|| count > 10*r
|| !map_bounds(loc)
|| is_sanctuary(loc) && flavour != BEAM_VISUAL)
{
return;
}
const dungeon_feature_type dngn_feat = env.grid(loc);
bool at_wall = false;
// Check to see if we're blocked by a wall or a tree. Can't use
// feat_is_solid here, since that includes statues which are a separate
// check, nor feat_is_opaque, since that excludes transparent walls, which
// we want. -ebering
// XXX: We could just include trees as wall features, but this currently
// would have some unintended side-effects. Would be ideal to deal with
// those and simplify feat_is_wall() to return true for trees. -gammafunk
if (feat_is_wall(dngn_feat)
|| feat_is_tree(dngn_feat)
&& (!feat_is_flammable(dngn_feat)
|| !can_burn_trees()
|| have_passive(passive_t::shoot_through_plants) // would be nice to message
|| env.markers.property_at(loc, MAT_ANY, "veto_destroy") == "veto")
|| feat_is_closed_door(dngn_feat))
{
// Special case: explosion originates from rock/statue
// (e.g. Lee's Rapid Deconstruction) - in this case, ignore
// solid cells at the center of the explosion.
if (stop_at_walls && !(delta.origin() && can_affect_wall(loc)))
return;
// But remember that we are at a wall.
if (flavour != BEAM_DIGGING)
at_wall = true;
}
if (feat_is_solid(dngn_feat) && !feat_is_wall(dngn_feat)
&& !can_affect_wall(loc) && stop_at_statues)
{
return;
}
m(delta + centre) = min(count, m(delta + centre));
// Now recurse in every direction.
for (int i = 0; i < 8; ++i)
{
const coord_def new_delta = delta + Compass[i];
if (new_delta.rdist() > centre.rdist())
continue;
// If we were at a wall, only move to visible squares.
coord_def caster_pos = actor_by_mid(source_id) ?
actor_by_mid(source_id)->pos() :
you.pos();
if (at_wall && !cell_see_cell(caster_pos, loc + Compass[i], LOS_NO_TRANS))
continue;
int cadd = 5;
// Circling around the center is always free.
if (delta.rdist() == 1 && new_delta.rdist() == 1)
cadd = 0;
// Otherwise changing direction (e.g. looking around a wall) costs more.
else if (delta.x * Compass[i].x < 0 || delta.y * Compass[i].y < 0)
cadd = 17;
// Is that cell already covered?
if (m(new_delta + centre) <= count + cadd)
continue;
determine_affected_cells(m, new_delta, count + cadd, r,
stop_at_statues, stop_at_walls);
}
}
// Returns true if the beam is harmful ((mostly) ignoring monster
// resists) -- mon is given for 'special' cases where,
// for example, "Heal" might actually hurt undead, or
// "Holy Word" being ignored by holy monsters, etc.
//
// Only enchantments should need the actual monster type
// to determine this; non-enchantments are pretty
// straightforward.
bool bolt::nasty_to(const monster* mon) const
{
// Cleansing flame.
if (flavour == BEAM_HOLY)
return mon->res_holy_energy() < 3;
// Foul flame.
if (flavour == BEAM_FOUL_FLAME)
return mon->res_foul_flame() < 3;
// The orbs are made of pure disintegration energy. This also has the side
// effect of not stopping us from firing further orbs when the previous one
// is still flying.
if (flavour == BEAM_DESTRUCTION)
return mon->type != MONS_ORB_OF_DESTRUCTION;
// Take care of other non-enchantments.
if (!is_enchantment())
return true;
// Positive effects.
if (nice_to(monster_info(mon)))
return false;
switch (flavour)
{
// Don't immediately break Cause Fear when cast by a Dith worshipper)
case BEAM_SHADOW_TORPOR:
case BEAM_DIGGING:
return false;
case BEAM_INNER_FLAME:
// Co-aligned inner flame is fine.
return !mons_aligned(mon, agent());
case BEAM_TELEPORT:
case BEAM_BECKONING:
case BEAM_INFESTATION:
case BEAM_VILE_CLUTCH:
case BEAM_ROOTS:
case BEAM_SLOW:
case BEAM_PARALYSIS:
case BEAM_PETRIFY:
case BEAM_POLYMORPH:
case BEAM_DISPEL_UNDEAD:
case BEAM_PAIN:
case BEAM_AGONY:
case BEAM_CURSE_OF_AGONY:
case BEAM_HIBERNATION:
case BEAM_MINDBURST:
case BEAM_VAMPIRIC_DRAINING:
case BEAM_ENFEEBLE:
case BEAM_RIMEBLIGHT:
case BEAM_CHARM:
return ench_flavour_affects_monster(agent(), flavour, mon);
case BEAM_TUKIMAS_DANCE:
return tukima_affects(*mon); // XXX: move to ench_flavour_affects?
case BEAM_UNRAVELLING:
return monster_can_be_unravelled(*mon); // XXX: as tukima's
default:
break;
}
// everything else is considered nasty by everyone
return true;
}
// Return true if the bolt is considered nice by mon.
// This is not the inverse of nasty_to(): the bolt needs to be
// actively positive.
bool bolt::nice_to(const monster_info& mi) const
{
// Polymorphing a (very) ugly thing will mutate it into a different
// (very) ugly thing.
if (flavour == BEAM_POLYMORPH)
{
return mi.type == MONS_UGLY_THING
|| mi.type == MONS_VERY_UGLY_THING;
}
if (flavour == BEAM_HASTE
|| flavour == BEAM_HEALING
|| flavour == BEAM_DOUBLE_HEALTH
|| flavour == BEAM_MIGHT
|| flavour == BEAM_AGILITY
|| flavour == BEAM_INVISIBILITY
|| flavour == BEAM_RESISTANCE
|| flavour == BEAM_CONCENTRATE_VENOM)
{
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////
// bolt
// TODO: Eventually it'd be nice to have a proper factory for these things
// (extended from setup_mons_cast() and zapping() which act as limited ones).
killer_type bolt::killer() const
{
if (flavour == BEAM_BANISH)
return KILL_BANISHED;
switch (thrower)
{
case KILL_YOU:
case KILL_YOU_MISSILE:
return (flavour == BEAM_PARALYSIS
|| flavour == BEAM_PETRIFY) ? KILL_YOU : KILL_YOU_MISSILE;
case KILL_MON:
case KILL_MON_MISSILE:
return KILL_MON_MISSILE;
case KILL_YOU_CONF:
return KILL_YOU_CONF;
default:
return KILL_MON_MISSILE;
}
}
void bolt::set_target(const dist &d)
{
if (!d.isValid)
return;
target = d.target;
chose_ray = d.choseRay;
if (d.choseRay)
ray = d.ray;
if (d.isEndpoint)
aimed_at_spot = true;
}
void bolt::setup_retrace()
{
if (pos().x && pos().y)
target = pos();
swap(source, target);
chose_ray = false;
affects_nothing = true;
aimed_at_spot = true;
extra_range_used = 0;
}
void bolt::set_agent(const actor *actor)
{
// nullptr actor is fine by us.
if (!actor)
return;
source_id = actor->mid;
if (actor->is_player())
thrower = KILL_YOU_MISSILE;
else
thrower = KILL_MON_MISSILE;
}
/**
* Who caused this beam?
*
* @param ignore_reflection If true, look all the way back to the original
* source; if false (the default), treat the latest
* actor to reflect this as the source.
* @returns The actor that can be treated as the source. May be null if
* it's a now-dead monster, or if neither the player nor a monster
* caused it (for example, divine retribution).
*/
actor* bolt::agent(bool ignore_reflection) const
{
killer_type nominal_ktype = thrower;
mid_t nominal_source = source_id;
// If the beam was reflected report a different point of origin
if (reflections > 0 && !ignore_reflection)
{
if (reflector == MID_PLAYER || source_id == MID_PLAYER)
return &env.mons[YOU_FAULTLESS];
nominal_source = reflector;
}
if (YOU_KILL(nominal_ktype))
return &you;
else
{
actor* act = actor_by_mid(nominal_source);
if (act)
return act;
// If this is an explosion caused by a dead friendly monster, set its
// agent to MID_ANON_FRIEND, so that the player gets XP attribution for
// the damage.
else if (monster* mon = cached_monster_copy_by_mid(nominal_source))
{
if (mon->friendly())
return monster_by_mid(MID_ANON_FRIEND);
}
return nullptr;
}
}
bool bolt::is_enchantment() const
{
return flavour >= BEAM_FIRST_ENCHANTMENT
&& flavour <= BEAM_LAST_ENCHANTMENT;
}
string bolt::get_short_name() const
{
if (!short_name.empty())
return short_name;
if (item != nullptr && item->defined())
return item->name(DESC_A, false, false, false, false);
if (real_flavour == BEAM_RANDOM
|| real_flavour == BEAM_CHAOS)
{
return _beam_type_name(real_flavour);
}
if (flavour == BEAM_FIRE
&& (origin_spell == SPELL_STICKY_FLAME
|| origin_spell == SPELL_PYRE_ARROW))
{
return "sticky fire";
}
if (flavour == BEAM_ELECTRICITY && pierce)
return "lightning";
if (name == "bolt of dispelling energy")
return "dispelling energy";
if (flavour == BEAM_NONE || flavour == BEAM_MISSILE
|| flavour == BEAM_MMISSILE)
{
return name;
}
return _beam_type_name(flavour);
}
static string _beam_type_name(beam_type type)
{
switch (type)
{
case BEAM_NONE: return "none";
case BEAM_MISSILE: return "missile";
case BEAM_MMISSILE: return "magic missile";
case BEAM_FIRE: return "fire";
case BEAM_COLD: return "cold";
case BEAM_WATER: return "water";
case BEAM_MAGIC: return "magic";
case BEAM_ELECTRICITY: return "electricity";
case BEAM_MEPHITIC: return "noxious fumes";
case BEAM_POISON: return "poison";
case BEAM_NEG: return "negative energy";
case BEAM_ACID: return "acid";
case BEAM_LIGHT: return "light";
case BEAM_MIASMA: return "miasma";
case BEAM_SPORE: return "spores";
case BEAM_POISON_ARROW: return "poison sting";
case BEAM_DAMNATION: return "damnation";
case BEAM_STICKY_FLAME: return "sticky fire";
case BEAM_STEAM: return "steam";
case BEAM_ENERGY: return "energy";
case BEAM_HOLY: return "cleansing flame";
case BEAM_FOUL_FLAME: return "foul flame";
case BEAM_FRAG: return "fragments";
case BEAM_LAVA: return "magma";
case BEAM_ICE: return "ice";
case BEAM_THUNDER: return "thunder";
case BEAM_STUN_BOLT: return "stunning bolt";
case BEAM_DESTRUCTION: return "destruction";
case BEAM_RANDOM: return "random";
case BEAM_CHAOS: return "chaos";
case BEAM_SLOW: return "slow";
case BEAM_HASTE: return "haste";
case BEAM_MIGHT: return "might";
case BEAM_HEALING: return "healing";
case BEAM_PARALYSIS: return "paralysis";
case BEAM_CONFUSION: return "confusion";
case BEAM_INVISIBILITY: return "invisibility";
case BEAM_DIGGING: return "digging";
case BEAM_TELEPORT: return "teleportation";
case BEAM_POLYMORPH: return "polymorph";
case BEAM_MALMUTATE: return "malmutation";
case BEAM_CHARM: return "charming";
case BEAM_BANISH: return "banishment";
case BEAM_PAIN: return "pain";
case BEAM_AGONY: return "agony";
case BEAM_CURSE_OF_AGONY: return "curse of agony";
case BEAM_DISPEL_UNDEAD: return "dispel undead";
case BEAM_MINDBURST: return "mindburst";
case BEAM_BLINK: return "blink";
case BEAM_BLINK_CLOSE: return "blink close";
case BEAM_BECKONING: return "beckoning";
case BEAM_PETRIFY: return "petrify";
case BEAM_CORONA: return "backlight";
case BEAM_PORKALATOR: return "porkalator";
case BEAM_HIBERNATION: return "hibernation";
case BEAM_SLEEP: return "sleep";
case BEAM_BERSERK: return "berserk";
case BEAM_VISUAL: return "visual effects";
case BEAM_TORMENT_DAMAGE: return "torment damage";
case BEAM_AIR: return "air";
case BEAM_INNER_FLAME: return "inner flame";
case BEAM_PETRIFYING_CLOUD: return "calcifying dust";
case BEAM_ENSNARE: return "magic web";
case BEAM_SENTINEL_MARK: return "sentinel's mark";
case BEAM_DIMENSION_ANCHOR: return "dimension anchor";
case BEAM_VULNERABILITY: return "vulnerability";
case BEAM_MALIGN_OFFERING: return "malign offering";
case BEAM_VIRULENCE: return "virulence";
case BEAM_AGILITY: return "agility";
case BEAM_SAP_MAGIC: return "sap magic";
case BEAM_DRAIN_MAGIC: return "drain magic";
case BEAM_TUKIMAS_DANCE: return "tukima's dance";
case BEAM_DEATH_RATTLE: return "breath of the dead";
case BEAM_RESISTANCE: return "resistance";
case BEAM_UNRAVELLING: return "unravelling";
case BEAM_UNRAVELLED_MAGIC: return "unravelled magic";
case BEAM_SHARED_PAIN: return "shared pain";
case BEAM_IRRESISTIBLE_CONFUSION:return "confusion";
case BEAM_INFESTATION: return "infestation";
case BEAM_VILE_CLUTCH: return "vile clutch";
case BEAM_VAMPIRIC_DRAINING: return "vampiric draining";
case BEAM_CONCENTRATE_VENOM: return "concentrate venom";
case BEAM_ENFEEBLE: return "enfeeble";
case BEAM_SOUL_SPLINTER: return "soul splinter";
case BEAM_ROOTS: return "roots";
case BEAM_VITRIFY: return "vitrification";
case BEAM_VITRIFYING_GAZE: return "vitrification";
case BEAM_WEAKNESS: return "weakness";
case BEAM_DEVASTATION: return "devastation";
case BEAM_UMBRAL_TORCHLIGHT: return "umbral torchlight";
case BEAM_CRYSTALLIZING: return "crystallizing";
case BEAM_WARPING: return "spatial disruption";
case BEAM_QAZLAL: return "upheaval targetter";
case BEAM_RIMEBLIGHT: return "rimeblight";
case BEAM_SHADOW_TORPOR: return "shadow torpor";
case BEAM_HAEMOCLASM: return "gore";
case BEAM_BLOODRITE: return "blood";
case BEAM_DOUBLE_HEALTH: return "health-doubling";
case BEAM_VEX: return "vexing";
case BEAM_SEISMIC: return "seismic shockwave";
case BEAM_BOLAS: return "entwining bolas";
case BEAM_MERCURY: return "mercury";
case BEAM_BAT_CLOUD: return "cloud of bats";
case NUM_BEAMS: die("invalid beam type");
}
die("unknown beam type");
}
string bolt::get_source_name() const
{
if (!source_name.empty())
return source_name;
const actor *a = agent();
if (a)
return a->name(DESC_A, true);
return "";
}
/**
* Can this bolt potentially knock back a creature it hits?
*
* @param dam The damage dealt. If non-negative, check that dam > 0 for bolts
* like force lance that only push back upon damage.
* @return True iff the bolt could knock something back.
*/
bool bolt::can_knockback(int dam) const
{
switch (origin_spell)
{
case SPELL_PRIMAL_WAVE:
case SPELL_MUD_BREATH:
return true;
case SPELL_FORCE_LANCE:
case SPELL_ISKENDERUNS_MYSTIC_BLAST:
return dam != 0;
default:
return false;
}
}
/**
* Can this bolt pull an actor?
*
* If a bolt is capable of pulling actors and the given actor can be pulled,
* return true. May print messages.
*
* @param act The target actor. Check if the actor is non-stationary and not
* already adjacent.
* @param dam The damage dealt. Check that dam > 0.
* @return True if the bolt could pull the actor, false otherwise.
*/
bool bolt::can_pull(const actor &act, int dam) const
{
if (act.is_stationary() || adjacent(source, act.pos()))
return false;
return origin_spell == SPELL_HARPOON_SHOT && dam;
}
ai_action::goodness targeting_tracer::good_to_fire(int foe_ratio) const
{
// Use of foeRatio:
// The higher this number, the more monsters will _avoid_ collateral
// damage to their friends.
// Setting this to zero will in fact have all monsters ignore their
// friends when considering collateral damage.
// Quick check - did we in fact hit anything?
if (foe_info.count == 0)
return ai_action::neutral();
const int total_pow = foe_info.power + friend_info.power;
// Only fire if they do acceptably low collateral damage.
if (!friend_info.power
|| foe_info.power >= div_round_up(foe_ratio * total_pow, 100))
{
return ai_action::good();
}
return ai_action::bad();
}
void clear_zap_info_on_exit()
{
for (const zap_info &zap : zap_data)
{
delete zap.player_damage;
delete zap.player_tohit;
delete zap.monster_damage;
delete zap.monster_tohit;
}
}
int ench_power_stepdown(int pow)
{
return stepdown(pow, 35);
}
/// Translate a given ench power to a duration, in aut, and randomize it.
int _ench_pow_to_dur(int pow)
{
// ~15 turns at 25 pow, ~21 turns at 50 pow, ~27 turns at 100 pow
int base_dur = stepdown(pow * BASELINE_DELAY, 70);
return div_rand_round(base_dur, 2) + random2(1 + base_dur);
}
/**
* Given some shield value, what is the chance that omnireflect will activate
* on an AUTOMATIC_HIT attack?
*
* E.g., if 40 is returned, there is a SH in 40 chance of a given attack being
* reflected.
*
* @param SH The SH (shield) value of the omnireflect user.
* @return A denominator to the chance of omnireflect activating.
*/
int omnireflect_chance_denom(int SH)
{
return SH + 20;
}
/// Set up a beam aiming from the given monster to their target.
bolt setup_targeting_beam(const monster &mons)
{
bolt beem;
beem.source = mons.pos();
beem.target = mons.target;
beem.source_id = mons.mid;
return beem;
}
bool player_beam_tracer::has_hit_foe() noexcept
{
return foe_count != 0;
}
bool player_beam_tracer::should_stop() noexcept
{
return bad_attack_targets.empty() && bad_charm_target == nullptr
&& god_hated_target == nullptr;
}
void player_beam_tracer::actor_affected(bool friendly_fire, int power) noexcept
{
UNUSED(power);
if (!friendly_fire)
++foe_count;
}
void player_beam_tracer::player_hit() noexcept
{
hit_self_count++;
}
void player_beam_tracer::monster_hit(const bolt& beam, const monster& mon)
{
if (!you.can_see(mon))
return;
if (beam.is_harmless(&mon))
return;
bool penance = false;
string adj, suffix;
if (bad_attack(&mon, adj, suffix, penance))
{
bool found = false;
for (bad_target target : bad_attack_targets)
{
if (target.mon == &mon)
{
found = true;
break;
}
}
if (!found)
{
bad_attack_targets.push_back({ &mon, std::move(adj),
std::move(suffix), penance });
}
}
else if (_stop_because_god_hates_target_prompt(&mon, beam.origin_spell, true))
god_hated_target = &mon;
// Handle charming monsters when a nasty dur is up: give a prompt for
// attempting to charm monsters that might be affected.
else if (beam.flavour == BEAM_CHARM)
{
monclass_flags_t flags = monster_info(&mon).airborne() ? M_FLIES
: M_NO_FLAGS;
resists_t mon_resists = monster_info(&mon).resists();
const string reason = stop_summoning_reason(mon_resists, flags);
if (!reason.empty())
bad_charm_target = &mon;
}
}
void player_beam_tracer::cancel() noexcept
{
cancelled = true;
}
bool targeting_tracer::has_hit_foe() noexcept
{
return foe_info.count != 0;
}
void targeting_tracer::actor_affected(bool friendly_fire, int power) noexcept
{
if (friendly_fire)
{
friend_info.count++;
friend_info.power += power;
}
else
{
foe_info.count++;
foe_info.power += power;
}
}
// returns true if the player wishes to cancel firing the bolt, false otherwise
bool cancel_beam_prompt(const bolt& beam,
const player_beam_tracer& tracer)
{
if (tracer.cancelled)
return true;
const spell_type spell = beam.origin_spell;
if (tracer.god_hated_target
&& _stop_because_god_hates_target_prompt(tracer.god_hated_target,
spell))
{
return true;
}
if (tracer.bad_charm_target)
{
const monster* mon = tracer.bad_charm_target;
monclass_flags_t flags = monster_info(mon).airborne() ? M_FLIES
: M_NO_FLAGS;
const string verb = make_stringf("charm %s",
mon->name(DESC_THE).c_str());
if (stop_summoning_prompt(monster_info(mon).resists(), flags, verb))
return true;
}
if (tracer.hit_self_count > 0)
{
string prompt;
if (tracer.hit_self_count > 1)
{
prompt = make_stringf("That %s could hit you up to %d times."
" Continue anyway?",
beam.item ? beam.name.c_str() : "beam",
tracer.hit_self_count);
}
else
{
prompt = make_stringf("That %s is likely to hit you."
" Continue anyway?",
beam.item ? beam.name.c_str() : "beam");
}
if (!yesno(prompt.c_str(), false, 'n'))
{
canned_msg(MSG_OK);
return true;
}
}
if (!tracer.bad_attack_targets.empty())
{
attacked_monster_list victims;
for (auto& target : tracer.bad_attack_targets)
victims.add(*target.mon, target.adj, target.suffix, target.penance);
string mon_name = victims.describe();
string verb = "fire ";
if (tracer.bad_attack_targets.size() == 1)
{
const monster* mon = tracer.bad_attack_targets[0].mon;
if (beam.target == mon->pos() && spell != SPELL_STARBURST)
verb += "at ";
else
{
verb += "in " + apostrophise(mon_name) + " direction";
mon_name = "";
}
}
else
verb += "towards ";
const bool penance = victims.penance();
const string prompt = make_stringf("Really %s%s%s?%s",
verb.c_str(), mon_name.c_str(),
victims.suffix(),
penance ? " This would place you under penance!" : "");
if (!yesno(prompt.c_str(), false, 'n'))
{
canned_msg(MSG_OK);
return true;
}
}
return false;
}
void bolt::set_is_tracer(bool value) noexcept
{
if (!value)
{
tracer = nullptr;
return;
}
static beam_tracer default_tracer;
tracer = &default_tracer;
}
// Returns the effective willpower an actor with a given willpower would have
// against hexes from a given source.
int apply_willpower_bypass(const actor& source, int willpower)
{
if (source.wearing_ego(OBJ_ARMOUR, SPARM_GUILE))
willpower = max(0, willpower - 2 * WL_PIP);
if (source.is_player() && you.form == transformation::sphinx)
willpower = max(0, willpower - WL_PIP);
return willpower;
}
int apply_willpower_bypass(const monster_info& source, int willpower)
{
if (source.inv[MSLOT_SHIELD]
&& get_armour_ego_type(*source.inv[MSLOT_SHIELD]) == SPARM_GUILE)
{
willpower = max(0, willpower - 2 * WL_PIP);
}
return willpower;
}
|