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
|
/* File: misc.c */
/* Purpose: misc code */
/*
* Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
*
* This software may be copied and distributed for educational, research, and
* not for profit purposes provided that this copyright and statement are
* included in all such copies.
*/
#include "angband.h"
/*
* Converts stat num into a six-char (right justified) string
*/
void cnv_stat(int val, char *out_val)
{
if (!linear_stats)
{
/* Above 18 */
if (val > 18)
{
int bonus = (val - 18);
if (bonus >= 220)
{
sprintf(out_val, "18/%3s", "***");
}
else if (bonus >= 100)
{
sprintf(out_val, "18/%03d", bonus);
}
else
{
sprintf(out_val, " 18/%02d", bonus);
}
}
/* From 3 to 18 */
else
{
sprintf(out_val, " %2d", val);
}
}
else
{
/* Above 18 */
if (val > 18)
{
int bonus = (val - 18);
if (bonus >= 220)
{
sprintf(out_val, " 40");
}
else
{
sprintf(out_val, " %2d", 18 + (bonus / 10));
}
}
/* From 3 to 18 */
else
{
sprintf(out_val, " %2d", val);
}
}
}
/*
* Modify a stat value by a "modifier", return new value
*
* Stats go up: 3,4,...,17,18,18/10,18/20,...,18/220
* Or even: 18/13, 18/23, 18/33, ..., 18/220
*
* Stats go down: 18/220, 18/210,..., 18/10, 18, 17, ..., 3
* Or even: 18/13, 18/03, 18, 17, ..., 3
*/
s16b modify_stat_value(int value, int amount)
{
int i;
/* Reward */
if (amount > 0)
{
/* Apply each point */
for (i = 0; i < amount; i++)
{
/* One point at a time */
if (value < 18) value++;
/* Ten "points" at a time */
else value += 10;
}
}
/* Penalty */
else if (amount < 0)
{
/* Apply each point */
for (i = 0; i < (0 - amount); i++)
{
/* Ten points at a time */
if (value >= 18 + 10) value -= 10;
/* Hack -- prevent weirdness */
else if (value > 18) value = 18;
/* One point at a time */
else if (value > 3) value--;
}
}
/* Return new value */
return (value);
}
/*
* Print character info at given row, column in a 13 char field
*/
static void prt_field(cptr info, int row, int col)
{
/* Dump 13 spaces to clear */
c_put_str(TERM_WHITE, " ", row, col);
/* Dump the info itself */
c_put_str(TERM_L_BLUE, info, row, col);
}
/*
* Prints players max/cur piety
*/
static void prt_piety(void)
{
char tmp[32];
/* Do not show piety unless it matters */
if (!p_ptr->pgod) return;
c_put_str(TERM_L_WHITE, "Pt ", ROW_PIETY, COL_PIETY);
sprintf(tmp, "%9ld", p_ptr->grace);
c_put_str((p_ptr->praying) ? TERM_L_BLUE : TERM_GREEN, tmp, ROW_PIETY,
COL_PIETY + 3);
}
/*
* Prints the player's current sanity.
*/
static void prt_sane(void)
{
char tmp[32];
byte color;
int perc;
if (p_ptr->msane == 0)
{
perc = 100;
}
else
{
perc = (100 * p_ptr->csane) / p_ptr->msane;
}
c_put_str(TERM_ORANGE, "SN ", ROW_SANITY, COL_SANITY);
sprintf(tmp, "%4d/%4d", p_ptr->csane, p_ptr->msane);
if (perc >= 100)
{
color = TERM_L_GREEN;
}
else if (perc > (10 * hitpoint_warn))
{
color = TERM_YELLOW;
}
else
{
color = TERM_RED;
}
c_put_str(color, tmp, ROW_SANITY, COL_SANITY + 3);
}
/*
* Print character stat in given row, column
*/
static void prt_stat(int stat)
{
char tmp[32];
cnv_stat(p_ptr->stat_use[stat], tmp);
/* Display "injured" stat */
if (p_ptr->stat_cur[stat] < p_ptr->stat_max[stat])
{
int colour;
if (p_ptr->stat_cnt[stat])
colour = TERM_ORANGE;
else
colour = TERM_YELLOW;
put_str(format("%s: ", stat_names_reduced[stat]), ROW_STAT + stat, 0);
c_put_str(colour, tmp, ROW_STAT + stat, COL_STAT + 6);
}
/* Display "healthy" stat */
else
{
put_str(format("%s: ", stat_names[stat]), ROW_STAT + stat, 0);
c_put_str(TERM_L_GREEN, tmp, ROW_STAT + stat, COL_STAT + 6);
}
/* Display "boosted" stat */
if (p_ptr->stat_cur[stat] > p_ptr->stat_max[stat])
{
put_str(format("%s: ", stat_names[stat]), ROW_STAT + stat, 0);
c_put_str(TERM_VIOLET, tmp, ROW_STAT + stat, COL_STAT + 6);
}
/* Indicate natural maximum */
if (p_ptr->stat_max[stat] == 18 + 100)
{
put_str("!", ROW_STAT + stat, 3);
}
}
/*
* Prints "title", including "wizard" or "winner" as needed.
*/
static void prt_title(void)
{
cptr p = "";
/* Mimic shape */
if (p_ptr->mimic_form)
{
call_lua("get_mimic_info", "(d,s)", "s", p_ptr->mimic_form, "show_name", &p);
}
/* Wizard */
else if (wizard)
{
p = "[=-WIZARD-=]";
}
/* Winner */
else if (total_winner == WINNER_NORMAL)
{
p = "***WINNER***";
}
/* Ultra Winner */
else if (total_winner == WINNER_ULTRA)
{
p = "***GOD***";
}
/* Normal */
else
{
p = cp_ptr->titles[(p_ptr->lev - 1) / 5] + c_text;
}
prt_field(p, ROW_TITLE, COL_TITLE);
}
/*
* Prints level
*/
static void prt_level(void)
{
char tmp[32];
sprintf(tmp, "%6d", p_ptr->lev);
if (p_ptr->lev >= p_ptr->max_plv)
{
put_str("LEVEL ", ROW_LEVEL, 0);
c_put_str(TERM_L_GREEN, tmp, ROW_LEVEL, COL_LEVEL + 6);
}
else
{
put_str("Level ", ROW_LEVEL, 0);
c_put_str(TERM_YELLOW, tmp, ROW_LEVEL, COL_LEVEL + 6);
}
}
/*
* Display the experience
*/
static void prt_exp(void)
{
char out_val[32];
if (!exp_need)
{
(void)sprintf(out_val, "%8ld", (long)p_ptr->exp);
}
else
{
if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->lev >= max_plev))
{
(void)sprintf(out_val, "********");
}
else
{
(void)sprintf(out_val, "%8ld", (long)(player_exp[p_ptr->lev - 1] * p_ptr->expfact / 100L) - p_ptr->exp);
}
}
if (p_ptr->exp >= p_ptr->max_exp)
{
put_str("EXP ", ROW_EXP, 0);
c_put_str(TERM_L_GREEN, out_val, ROW_EXP, COL_EXP + 4);
}
else
{
put_str("Exp ", ROW_EXP, 0);
c_put_str(TERM_YELLOW, out_val, ROW_EXP, COL_EXP + 4);
}
}
/*
* Prints current gold
*/
static void prt_gold(void)
{
char tmp[32];
put_str("AU ", ROW_GOLD, COL_GOLD);
sprintf(tmp, "%9ld", (long)p_ptr->au);
c_put_str(TERM_L_GREEN, tmp, ROW_GOLD, COL_GOLD + 3);
}
/*
* Prints current AC
*/
static void prt_ac(void)
{
char tmp[32];
put_str("Cur AC ", ROW_AC, COL_AC);
sprintf(tmp, "%5d", p_ptr->dis_ac + p_ptr->dis_to_a);
c_put_str(TERM_L_GREEN, tmp, ROW_AC, COL_AC + 7);
}
/*
* Prints Cur/Max hit points
*/
static void prt_hp(void)
{
char tmp[32];
byte color;
if (player_char_health) lite_spot(p_ptr->py, p_ptr->px);
if (p_ptr->necro_extra & CLASS_UNDEAD)
{
c_put_str(TERM_L_DARK, "DP ", ROW_HP, COL_HP);
sprintf(tmp, "%4d/%4d", p_ptr->chp, p_ptr->mhp);
if (p_ptr->chp >= p_ptr->mhp)
{
color = TERM_L_BLUE;
}
else if (p_ptr->chp > (p_ptr->mhp * hitpoint_warn) / 10)
{
color = TERM_VIOLET;
}
else
{
color = TERM_L_RED;
}
c_put_str(color, tmp, ROW_HP, COL_HP + 3);
}
else
{
c_put_str(TERM_RED, "HP ", ROW_HP, COL_HP);
sprintf(tmp, "%4d/%4d", p_ptr->chp, p_ptr->mhp);
if (p_ptr->chp >= p_ptr->mhp)
{
color = TERM_L_GREEN;
}
else if (p_ptr->chp > (p_ptr->mhp * hitpoint_warn) / 10)
{
color = TERM_YELLOW;
}
else
{
color = TERM_RED;
}
c_put_str(color, tmp, ROW_HP, COL_HP + 3);
}
}
/*
* Prints Cur/Max monster hit points
*/
static void prt_mh(void)
{
char tmp[32];
byte color;
object_type *o_ptr;
monster_race *r_ptr;
/* Get the carried monster */
o_ptr = &p_ptr->inventory[INVEN_CARRY];
if (!o_ptr->pval2)
{
put_str(" ", ROW_MH, COL_MH);
return;
}
r_ptr = &r_info[o_ptr->pval];
put_str("MH ", ROW_MH, COL_MH);
sprintf(tmp, "%4d/%4d", o_ptr->pval2, (int)o_ptr->pval3);
if (o_ptr->pval2 >= o_ptr->pval3)
{
color = TERM_L_GREEN;
}
else if (o_ptr->pval2 > (o_ptr->pval3 * hitpoint_warn) / 10)
{
color = TERM_YELLOW;
}
else
{
color = TERM_RED;
}
c_put_str(color, tmp, ROW_MH, COL_MH + 3);
}
/*
* Prints players max/cur spell points
*/
static void prt_sp(void)
{
char tmp[32];
byte color;
c_put_str(TERM_L_GREEN, "SP ", ROW_SP, COL_SP);
sprintf(tmp, "%4d/%4d", p_ptr->csp, p_ptr->msp);
if (p_ptr->csp >= p_ptr->msp)
{
color = TERM_L_GREEN;
}
else if (p_ptr->csp > (p_ptr->msp * hitpoint_warn) / 10)
{
color = TERM_YELLOW;
}
else
{
color = TERM_RED;
}
c_put_str(color, tmp, ROW_SP, COL_SP + 3);
}
/*
* Prints depth in stat area
*/
static void prt_depth(void)
{
char depths[32];
dungeon_info_type *d_ptr = &d_info[dungeon_type];
if (p_ptr->wild_mode)
{
strcpy(depths, " ");
}
else if (p_ptr->inside_arena)
{
strcpy(depths, "Arena");
}
else if (get_dungeon_name(depths))
{
/* Empty */
}
else if (dungeon_flags2 & DF2_SPECIAL)
{
strcpy(depths, "Special");
}
else if (p_ptr->inside_quest)
{
strcpy(depths, "Quest");
}
else if (!dun_level)
{
if (wf_info[wild_map[p_ptr->wilderness_y][p_ptr->wilderness_x].feat].name + wf_name)
strcpy(depths, wf_info[wild_map[p_ptr->wilderness_y][p_ptr->wilderness_x].feat].name + wf_name);
else
strcpy(depths, "Town/Wild");
}
else if (depth_in_feet)
{
if (dungeon_flags1 & DF1_TOWER)
{
(void)strnfmt(depths, 32, "%c%c%c -%d ft",
d_ptr->short_name[0],
d_ptr->short_name[1],
d_ptr->short_name[2],
dun_level * 50);
}
else
{
(void)strnfmt(depths, 32, "%c%c%c %d ft",
d_ptr->short_name[0],
d_ptr->short_name[1],
d_ptr->short_name[2],
dun_level * 50);
}
}
else
{
if (dungeon_flags1 & DF1_TOWER)
{
(void)strnfmt(depths, 32, "%c%c%c -%d",
d_ptr->short_name[0],
d_ptr->short_name[1],
d_ptr->short_name[2],
dun_level);
}
else
{
(void)strnfmt(depths, 32, "%c%c%c %d",
d_ptr->short_name[0],
d_ptr->short_name[1],
d_ptr->short_name[2],
dun_level);
}
}
/* Right-Adjust the "depth", and clear old values */
if (p_ptr->word_recall)
c_prt(TERM_ORANGE, format("%13s", depths), ROW_DEPTH, COL_DEPTH);
else
prt(format("%13s", depths), ROW_DEPTH, COL_DEPTH);
}
/*
* Prints status of hunger
*/
static void prt_hunger(void)
{
/* Fainting / Starving */
if (p_ptr->food < PY_FOOD_FAINT)
{
c_put_str(TERM_RED, "Weak ", ROW_HUNGRY, COL_HUNGRY);
}
/* Weak */
else if (p_ptr->food < PY_FOOD_WEAK)
{
c_put_str(TERM_ORANGE, "Weak ", ROW_HUNGRY, COL_HUNGRY);
}
/* Hungry */
else if (p_ptr->food < PY_FOOD_ALERT)
{
c_put_str(TERM_YELLOW, "Hungry", ROW_HUNGRY, COL_HUNGRY);
}
/* Normal */
else if (p_ptr->food < PY_FOOD_FULL)
{
c_put_str(TERM_L_GREEN, " ", ROW_HUNGRY, COL_HUNGRY);
}
/* Full */
else if (p_ptr->food < PY_FOOD_MAX)
{
c_put_str(TERM_L_GREEN, "Full ", ROW_HUNGRY, COL_HUNGRY);
}
/* Gorged */
else
{
c_put_str(TERM_GREEN, "Gorged", ROW_HUNGRY, COL_HUNGRY);
}
}
/*
* Prints Blind status
*/
static void prt_blind(void)
{
if (p_ptr->blind)
{
c_put_str(TERM_ORANGE, "Blind", ROW_BLIND, COL_BLIND);
}
else
{
put_str(" ", ROW_BLIND, COL_BLIND);
}
}
/*
* Prints Confusion status
*/
static void prt_confused(void)
{
if (p_ptr->confused)
{
c_put_str(TERM_ORANGE, "Conf", ROW_CONFUSED, COL_CONFUSED);
}
else
{
put_str(" ", ROW_CONFUSED, COL_CONFUSED);
}
}
/*
* Prints Fear status
*/
static void prt_afraid(void)
{
if (p_ptr->afraid)
{
c_put_str(TERM_ORANGE, "Afraid", ROW_AFRAID, COL_AFRAID);
}
else
{
put_str(" ", ROW_AFRAID, COL_AFRAID);
}
}
/*
* Prints Poisoned status
*/
static void prt_poisoned(void)
{
if (p_ptr->poisoned)
{
c_put_str(TERM_ORANGE, "Poison", ROW_POISONED, COL_POISONED);
}
else
{
put_str(" ", ROW_POISONED, COL_POISONED);
}
}
/*
* Prints trap detection status
*/
static void prt_dtrap(void)
{
if (cave[p_ptr->py][p_ptr->px].info & CAVE_DETECT)
{
c_put_str(TERM_L_GREEN, "DTrap", ROW_DTRAP, COL_DTRAP);
}
else
{
put_str(" ", ROW_DTRAP, COL_DTRAP);
}
}
/*
* Prints Searching, Resting, Paralysis, or 'count' status
* Display is always exactly 10 characters wide (see below)
*
* This function was a major bottleneck when resting, so a lot of
* the text formatting code was optimized in place below.
*/
static void prt_state(void)
{
byte attr = TERM_WHITE;
char text[16];
/* Paralysis */
if (p_ptr->paralyzed)
{
attr = TERM_RED;
strcpy(text, "Paralyzed!");
}
/* Resting */
else if (resting)
{
int i;
/* Start with "Rest" */
strcpy(text, "Rest ");
/* Extensive (timed) rest */
if (resting >= 1000)
{
i = resting / 100;
text[9] = '0';
text[8] = '0';
text[7] = '0' + (i % 10);
if (i >= 10)
{
i = i / 10;
text[6] = '0' + (i % 10);
if (i >= 10)
{
text[5] = '0' + (i / 10);
}
}
}
/* Long (timed) rest */
else if (resting >= 100)
{
i = resting;
text[9] = '0' + (i % 10);
i = i / 10;
text[8] = '0' + (i % 10);
text[7] = '0' + (i / 10);
}
/* Medium (timed) rest */
else if (resting >= 10)
{
i = resting;
text[9] = '0' + (i % 10);
text[8] = '0' + (i / 10);
}
/* Short (timed) rest */
else if (resting > 0)
{
i = resting;
text[9] = '0' + (i);
}
/* Rest until healed */
else if (resting == -1)
{
text[5] = text[6] = text[7] = text[8] = text[9] = '*';
}
/* Rest until done */
else if (resting == -2)
{
text[5] = text[6] = text[7] = text[8] = text[9] = '&';
}
}
/* Repeating */
else if (command_rep)
{
if (command_rep > 999)
{
(void)sprintf(text, "Rep. %3d00", command_rep / 100);
}
else
{
(void)sprintf(text, "Repeat %3d", command_rep);
}
}
/* Searching */
else if (p_ptr->searching)
{
strcpy(text, "Searching ");
}
/* Nothing interesting */
else
{
strcpy(text, " ");
}
/* Display the info (or blanks) */
c_put_str(attr, text, ROW_STATE, COL_STATE);
}
/*
* Prints the speed of a character. -CJS-
*/
static void prt_speed(void)
{
int i = p_ptr->pspeed;
byte attr = TERM_WHITE;
char buf[32] = "";
/* Hack -- Visually "undo" the Search Mode Slowdown */
if (p_ptr->searching) i += 10;
/* Fast */
if (i > 110)
{
attr = TERM_L_GREEN;
sprintf(buf, "Fast (+%d)", (i - 110));
}
/* Slow */
else if (i < 110)
{
attr = TERM_L_UMBER;
sprintf(buf, "Slow (-%d)", (110 - i));
}
/* Display the speed */
c_put_str(attr, format("%-10s", buf), ROW_SPEED, COL_SPEED);
}
static void prt_study(void)
{
if (p_ptr->skill_points)
{
put_str("Skill", ROW_STUDY, COL_STUDY);
}
else
{
put_str(" ", ROW_STUDY, COL_STUDY);
}
}
static void prt_cut(void)
{
int c = p_ptr->cut;
if (c > 1000)
{
c_put_str(TERM_L_RED, "Mortal wound", ROW_CUT, COL_CUT);
}
else if (c > 200)
{
c_put_str(TERM_RED, "Deep gash ", ROW_CUT, COL_CUT);
}
else if (c > 100)
{
c_put_str(TERM_RED, "Severe cut ", ROW_CUT, COL_CUT);
}
else if (c > 50)
{
c_put_str(TERM_ORANGE, "Nasty cut ", ROW_CUT, COL_CUT);
}
else if (c > 25)
{
c_put_str(TERM_ORANGE, "Bad cut ", ROW_CUT, COL_CUT);
}
else if (c > 10)
{
c_put_str(TERM_YELLOW, "Light cut ", ROW_CUT, COL_CUT);
}
else if (c)
{
c_put_str(TERM_YELLOW, "Graze ", ROW_CUT, COL_CUT);
}
else
{
put_str(" ", ROW_CUT, COL_CUT);
}
}
static void prt_stun(void)
{
int s = p_ptr->stun;
if (s > 100)
{
c_put_str(TERM_RED, "Knocked out ", ROW_STUN, COL_STUN);
}
else if (s > 50)
{
c_put_str(TERM_ORANGE, "Heavy stun ", ROW_STUN, COL_STUN);
}
else if (s)
{
c_put_str(TERM_ORANGE, "Stun ", ROW_STUN, COL_STUN);
}
else
{
put_str(" ", ROW_STUN, COL_STUN);
}
}
/*
* Redraw the "monster health bar" -DRS-
* Rather extensive modifications by -BEN-
*
* The "monster health bar" provides visual feedback on the "health"
* of the monster currently being "tracked". There are several ways
* to "track" a monster, including targetting it, attacking it, and
* affecting it (and nobody else) with a ranged attack.
*
* Display the monster health bar (affectionately known as the
* "health-o-meter"). Clear health bar if nothing is being tracked.
* Auto-track current target monster when bored. Note that the
* health-bar stops tracking any monster that "disappears".
*/
static void health_redraw(void)
{
#ifdef DRS_SHOW_HEALTH_BAR
/* Not tracking */
if (!health_who)
{
/* Erase the health bar */
Term_erase(COL_INFO, ROW_INFO, 12);
}
/* Tracking an unseen monster */
else if (!m_list[health_who].ml)
{
/* Indicate that the monster health is "unknown" */
Term_putstr(COL_INFO, ROW_INFO, 12, TERM_WHITE, "[----------]");
}
/* Tracking a hallucinatory monster */
else if (p_ptr->image)
{
/* Indicate that the monster health is "unknown" */
Term_putstr(COL_INFO, ROW_INFO, 12, TERM_WHITE, "[----------]");
}
/* Tracking a dead monster (???) */
else if (!m_list[health_who].hp < 0)
{
/* Indicate that the monster health is "unknown" */
Term_putstr(COL_INFO, ROW_INFO, 12, TERM_WHITE, "[----------]");
}
/* Tracking a visible monster */
else
{
int pct, len;
monster_type *m_ptr = &m_list[health_who];
/* Default to almost dead */
byte attr = TERM_RED;
/* Extract the "percent" of health */
pct = 100L * m_ptr->hp / m_ptr->maxhp;
/* Badly wounded */
if (pct >= 10) attr = TERM_L_RED;
/* Wounded */
if (pct >= 25) attr = TERM_ORANGE;
/* Somewhat Wounded */
if (pct >= 60) attr = TERM_YELLOW;
/* Healthy */
if (pct >= 100) attr = TERM_L_GREEN;
/* Afraid */
if (m_ptr->monfear) attr = TERM_VIOLET;
/* Asleep */
if (m_ptr->csleep) attr = TERM_BLUE;
/* Poisoned */
if (m_ptr->poisoned) attr = TERM_GREEN;
/* Bleeding */
if (m_ptr->bleeding) attr = TERM_RED;
/* Convert percent into "health" */
len = (pct < 10) ? 1 : (pct < 90) ? (pct / 10 + 1) : 10;
/* Default to "unknown" */
Term_putstr(COL_INFO, ROW_INFO, 12, TERM_WHITE, "[----------]");
/* Dump the current "health" (use '*' symbols) */
Term_putstr(COL_INFO + 1, ROW_INFO, len, attr, "**********");
}
#endif
}
/*
* Display basic info (mostly left of map)
*/
static void prt_frame_basic(void)
{
int i;
/* Race and Class */
prt_field(rp_ptr->title + rp_name, ROW_RACE, COL_RACE);
prt_field(spp_ptr->title + c_name, ROW_CLASS, COL_CLASS);
/* Title */
prt_title();
/* Level/Experience */
prt_level();
prt_exp();
/* All Stats */
for (i = 0; i < 6; i++) prt_stat(i);
/* Armor */
prt_ac();
/* Hitpoints */
prt_hp();
/* Current sanity */
prt_sane();
/* Spellpoints */
prt_sp();
/* Piety */
prt_piety();
/* Monster hitpoints */
prt_mh();
/* Gold */
prt_gold();
/* Current depth */
prt_depth();
/* Special */
health_redraw();
}
/*
* Display extra info (mostly below map)
*/
static void prt_frame_extra(void)
{
/* Cut/Stun */
prt_cut();
prt_stun();
/* Food */
prt_hunger();
/* Various */
prt_blind();
prt_confused();
prt_afraid();
prt_poisoned();
prt_dtrap();
/* State */
prt_state();
/* Speed */
prt_speed();
/* Study spells */
prt_study();
}
/*
* Hack -- display inventory in sub-windows
*/
static void fix_inven(void)
{
int j;
/* Scan windows */
for (j = 0; j < 8; j++)
{
term *old = Term;
/* No window */
if (!angband_term[j]) continue;
/* No relevant flags */
if (!(window_flag[j] & (PW_INVEN))) continue;
/* Activate */
Term_activate(angband_term[j]);
/* Display inventory */
display_inven();
/* Fresh */
Term_fresh();
/* Restore */
Term_activate(old);
}
}
/*
* Hack -- display equipment in sub-windows
*/
static void fix_equip(void)
{
int j;
/* Scan windows */
for (j = 0; j < 8; j++)
{
term *old = Term;
/* No window */
if (!angband_term[j]) continue;
/* No relevant flags */
if (!(window_flag[j] & (PW_EQUIP))) continue;
/* Activate */
Term_activate(angband_term[j]);
/* Display equipment */
display_equip();
/* Fresh */
Term_fresh();
/* Restore */
Term_activate(old);
}
}
/*
* Hack -- display character in sub-windows
*/
static void fix_player(void)
{
int j;
/* Scan windows */
for (j = 0; j < 8; j++)
{
term *old = Term;
/* No window */
if (!angband_term[j]) continue;
/* No relevant flags */
if (!(window_flag[j] & (PW_PLAYER))) continue;
/* Activate */
Term_activate(angband_term[j]);
/* Display player */
display_player(0);
/* Fresh */
Term_fresh();
/* Restore */
Term_activate(old);
}
}
/*
* Hack -- display recent messages in sub-windows
*
* XXX XXX XXX Adjust for width and split messages
*/
void fix_message(void)
{
int j, i;
int w, h;
int x, y;
/* Scan windows */
for (j = 0; j < 8; j++)
{
term *old = Term;
/* No window */
if (!angband_term[j]) continue;
/* No relevant flags */
if (!(window_flag[j] & (PW_MESSAGE))) continue;
/* Activate */
Term_activate(angband_term[j]);
/* Get size */
Term_get_size(&w, &h);
/* Dump messages */
for (i = 0; i < h; i++)
{
/* Dump the message on the appropriate line */
display_message(0, (h - 1) - i, strlen(message_str((s16b)i)), message_color((s16b)i), message_str((s16b)i));
/* Cursor */
Term_locate(&x, &y);
/* Clear to end of line */
Term_erase(x, y, 255);
}
/* Fresh */
Term_fresh();
/* Restore */
Term_activate(old);
}
}
/*
* Hack -- display recent IRC messages in sub-windows
*
* XXX XXX XXX Adjust for width and split messages
*/
void fix_irc_message(void)
{
int j, i, k;
int w, h;
int x, y;
/* Scan windows */
for (j = 0; j < 8; j++)
{
term *old = Term;
/* No window */
if (!angband_term[j]) continue;
/* No relevant flags */
if (!(window_flag[j] & (PW_IRC))) continue;
/* Activate */
Term_activate(angband_term[j]);
/* Get size */
Term_get_size(&w, &h);
Term_clear();
/* Dump messages */
k = 0;
for (i = 0; ; i++)
{
byte type = message_type((s16b)i);
if (k >= h) break;
if (MESSAGE_NONE == type) break;
if (MESSAGE_IRC != type) continue;
/* Dump the message on the appropriate line */
display_message(0, (h - 1) - k, strlen(message_str((s16b)i)), message_color((s16b)i), message_str((s16b)i));
/* Cursor */
Term_locate(&x, &y);
/* Clear to end of line */
Term_erase(x, y, 255);
k++;
}
/* Fresh */
Term_fresh();
/* Restore */
Term_activate(old);
}
}
/*
* Hack -- display overhead view in sub-windows
*
* Note that the "player" symbol does NOT appear on the map.
*/
static void fix_overhead(void)
{
int j;
int cy, cx;
/* Scan windows */
for (j = 0; j < 8; j++)
{
term *old = Term;
/* No window */
if (!angband_term[j]) continue;
/* No relevant flags */
if (!(window_flag[j] & (PW_OVERHEAD))) continue;
/* Activate */
Term_activate(angband_term[j]);
/* Redraw map */
display_map(&cy, &cx);
/* Fresh */
Term_fresh();
/* Restore */
Term_activate(old);
}
}
/*
* Hack -- display monster recall in sub-windows
*/
static void fix_monster(void)
{
int j;
/* Scan windows */
for (j = 0; j < 8; j++)
{
term *old = Term;
/* No window */
if (!angband_term[j]) continue;
/* No relevant flags */
if (!(window_flag[j] & (PW_MONSTER))) continue;
/* Activate */
Term_activate(angband_term[j]);
/* Display monster race info */
if (monster_race_idx) display_roff(monster_race_idx, monster_ego_idx);
/* Fresh */
Term_fresh();
/* Restore */
Term_activate(old);
}
}
/*
* Hack -- display object recall in sub-windows
*/
static void fix_object(void)
{
int j;
/* Scan windows */
for (j = 0; j < 8; j++)
{
term *old = Term;
/* No window */
if (!angband_term[j]) continue;
/* No relevant flags */
if (!(window_flag[j] & (PW_OBJECT))) continue;
/* Activate */
Term_activate(angband_term[j]);
/* Clear */
Term_clear();
/* Display object info */
if (tracked_object)
if (!object_out_desc(tracked_object, NULL, FALSE, FALSE)) text_out("You see nothing special.");
/* Fresh */
Term_fresh();
/* Restore */
Term_activate(old);
}
}
/* Show the monster list in a window */
static void fix_m_list(void)
{
int i, j;
/* Scan windows */
for (j = 0; j < 8; j++)
{
term *old = Term;
int c = 0;
/* No window */
if (!angband_term[j]) continue;
/* No relevant flags */
if (!(window_flag[j] & (PW_M_LIST))) continue;
/* Activate */
Term_activate(angband_term[j]);
/* Clear */
Term_clear();
/* Hallucination */
if (p_ptr->image)
{
c_prt(TERM_WHITE, "You can not see clearly", 0, 0);
/* Fresh */
Term_fresh();
/* Restore */
Term_activate(old);
return;
}
/* reset visible count */
for (i = 1; i < max_r_idx; i++)
{
monster_race *r_ptr = &r_info[i];
r_ptr->total_visible = 0;
}
/* Count up the number visible in each race */
for (i = 1; i < m_max; i++)
{
monster_type *m_ptr = &m_list[i];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
/* Skip dead monsters */
if (m_ptr->hp < 0) continue;
/* Skip unseen monsters */
if (r_ptr->flags9 & RF9_MIMIC)
{
object_type *o_ptr;
/* Acquire object */
o_ptr = &o_list[m_ptr->hold_o_idx];
/* Memorized objects */
if (!o_ptr->marked) continue;
}
else
{
if (!m_ptr->ml) continue;
}
/* Increase for this race */
r_ptr->total_visible++;
/* Increase total Count */
c++;
}
/* Are monsters visible? */
if (c)
{
int w, h, num = 0;
(void)Term_get_size(&w, &h);
c_prt(TERM_WHITE, format("You can see %d monster%s", c, (c > 1 ? "s:" : ":")), 0, 0);
for (i = 1; i < max_r_idx; i++)
{
monster_race *r_ptr = &r_info[i];
/* Default Colour */
byte attr = TERM_SLATE;
/* Only visible monsters */
if (!r_ptr->total_visible) continue;
/* Uniques */
if (r_ptr->flags1 & RF1_UNIQUE)
{
attr = TERM_L_BLUE;
}
/* Have we ever killed one? */
if (r_ptr->r_tkills)
{
if (r_ptr->level > dun_level)
{
attr = TERM_VIOLET;
if (r_ptr->flags1 & RF1_UNIQUE)
{
attr = TERM_RED;
}
}
}
else
{
if (!(r_ptr->flags1 & RF1_UNIQUE)) attr = TERM_GREEN;
}
/* Dump the monster name */
if (r_ptr->total_visible == 1)
{
c_prt(attr, (r_name + r_ptr->name), (num % (h - 1)) + 1, (num / (h - 1) * 26));
}
else
{
c_prt(attr, format("%s (x%d)", r_name + r_ptr->name, r_ptr->total_visible), (num % (h - 1)) + 1, (num / (h - 1)) * 26);
}
num++;
}
}
else
{
c_prt(TERM_WHITE, "You see no monsters.", 0, 0);
}
/* Fresh */
Term_fresh();
/* Restore */
Term_activate(old);
}
}
/*
* Calculate number of spells player should have, and forget,
* or remember, spells until that number is properly reflected.
*
* Note that this function induces various "status" messages,
* which must be bypasses until the character is created.
*/
static void calc_spells(void)
{
p_ptr->new_spells = 0;
}
/* Ugly hack */
bool calc_powers_silent = FALSE;
/* Calc the player powers */
static void calc_powers(void)
{
int i, p = 0;
bool *old_powers;
/* Hack -- wait for creation */
if (!character_generated) return;
/* Hack -- handle "xtra" mode */
if (character_xtra) return;
C_MAKE(old_powers, power_max, bool);
/* Save old powers */
for (i = 0; i < power_max; i++) old_powers[i] = p_ptr->powers[i];
/* Get intrinsincs */
for (i = 0; i < POWER_MAX_INIT; i++) p_ptr->powers[i] = p_ptr->powers_mod[i];
for (; i < power_max; i++) p_ptr->powers[i] = 0;
/* Hooked powers */
process_hooks(HOOK_CALC_POWERS, "()");
/* Add objects powers */
for (i = INVEN_WIELD; i < INVEN_TOTAL; i++)
{
object_type *o_ptr = &p_ptr->inventory[i];
if (!o_ptr->k_idx) continue;
p = object_power(o_ptr);
if (p != -1) p_ptr->powers[p] = TRUE;
}
if ((!p_ptr->tim_mimic) && (!p_ptr->body_monster))
{
/* Add in racial and subracial powers */
for (i = 0; i < 4; i++)
{
p = rp_ptr->powers[i];
if (p != -1) p_ptr->powers[p] = TRUE;
p = rmp_ptr->powers[i];
if (p != -1) p_ptr->powers[p] = TRUE;
}
}
else if (p_ptr->mimic_form)
call_lua("calc_mimic_power", "(d)", "", p_ptr->mimic_form);
/* Add in class powers */
for (i = 0; i < 4; i++)
{
p = cp_ptr->powers[i];
if (p != -1) p_ptr->powers[p] = TRUE;
}
if (p_ptr->disembodied)
{
p = PWR_INCARNATE;
p_ptr->powers[p] = TRUE;
}
/* Now lets warn the player */
for (i = 0; i < power_max; i++)
{
s32b old = old_powers[i];
s32b new = p_ptr->powers[i];
if (new > old)
{
if (!calc_powers_silent) cmsg_print(TERM_GREEN, powers_type[i].gain_text);
}
else if (new < old)
{
if (!calc_powers_silent) cmsg_print(TERM_RED, powers_type[i].lose_text);
}
}
calc_powers_silent = FALSE;
C_FREE(old_powers, power_max, bool);
}
/*
* Calculate the player's sanity
*/
void calc_sanity(void)
{
int bonus, msane;
/* Hack -- use the con/hp table for sanity/wis */
bonus = ((int)(adj_con_mhp[p_ptr->stat_ind[A_WIS]]) - 128);
/* Hack -- assume 5 sanity points per level. */
msane = 5 * (p_ptr->lev + 1) + (bonus * p_ptr->lev / 2);
if (msane < p_ptr->lev + 1) msane = p_ptr->lev + 1;
if (p_ptr->msane != msane)
{
/* Sanity carries over between levels. */
p_ptr->csane += (msane - p_ptr->msane);
p_ptr->msane = msane;
if (p_ptr->csane >= msane)
{
p_ptr->csane = msane;
p_ptr->csane_frac = 0;
}
p_ptr->redraw |= (PR_SANITY);
p_ptr->window |= (PW_PLAYER);
}
}
/*
* Calculate maximum mana. You do not need to know any spells.
* Note that mana is lowered by heavy (or inappropriate) armor.
*
* This function induces status messages.
*/
static void calc_mana(void)
{
int msp, levels, cur_wgt, max_wgt;
u32b f1, f2, f3, f4, f5, esp;
object_type *o_ptr;
levels = p_ptr->lev;
/* Hack -- no negative mana */
if (levels < 0) levels = 0;
/* Extract total mana */
msp = get_skill_scale(SKILL_MAGIC, 200) +
(adj_mag_mana[
(p_ptr->stat_ind[A_INT] > p_ptr->stat_ind[A_WIS]) ?
p_ptr->stat_ind[A_INT] : p_ptr->stat_ind[A_WIS]
] * levels / 4);
/* Hack -- usually add one mana */
if (msp) msp++;
/* Possessors mana is different */
if (p_ptr->body_monster && (!p_ptr->disembodied))
{
monster_race *r_ptr = &r_info[p_ptr->body_monster];
int f = 100 / (r_ptr->freq_spell ? r_ptr->freq_spell : 1);
msp = 21 - f;
if (msp < 1) msp = 1;
}
/* Apply race mod mana */
msp = msp * rmp_ptr->mana / 100;
/* Apply class mana */
msp += msp * cp_ptr->mana / 100;
/* Apply Eru mana */
GOD(GOD_ERU)
{
s32b tmp = p_ptr->grace;
if (tmp >= 35000) tmp = 35000;
tmp /= 100;
msp += msp * tmp / 1000;
}
/* Only mages are affected */
if (forbid_gloves())
{
/* Assume player is not encumbered by gloves */
p_ptr->cumber_glove = FALSE;
/* Get the gloves */
o_ptr = &p_ptr->inventory[INVEN_HANDS];
/* Examine the gloves */
object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp);
/* Normal gloves hurt mage-type spells */
if (o_ptr->k_idx &&
!(f2 & (TR2_FREE_ACT)) &&
!((f1 & (TR1_DEX)) && (o_ptr->pval > 0)) &&
!(f5 & TR5_SPELL_CONTAIN))
{
/* Encumbered */
p_ptr->cumber_glove = TRUE;
/* Reduce mana */
msp = (3 * msp) / 4;
}
}
/* Augment mana */
if (munchkin_multipliers)
{
if (p_ptr->to_m) msp += msp * p_ptr->to_m / 5;
}
else
{
if (p_ptr->to_m) msp += msp * p_ptr->to_m / 10;
}
/* Assume player not encumbered by armor */
p_ptr->cumber_armor = FALSE;
/* Weigh the armor */
cur_wgt = 0;
cur_wgt += p_ptr->inventory[INVEN_BODY].weight;
cur_wgt += p_ptr->inventory[INVEN_HEAD].weight;
cur_wgt += p_ptr->inventory[INVEN_ARM].weight;
cur_wgt += p_ptr->inventory[INVEN_OUTER].weight;
cur_wgt += p_ptr->inventory[INVEN_HANDS].weight;
cur_wgt += p_ptr->inventory[INVEN_FEET].weight;
/* Determine the weight allowance */
max_wgt = 200 + get_skill_scale(SKILL_COMBAT, 500);
/* Heavy armor penalizes mana */
if (((cur_wgt - max_wgt) / 10) > 0)
{
/* Encumbered */
p_ptr->cumber_armor = TRUE;
/* Reduce mana */
msp -= ((cur_wgt - max_wgt) / 10);
}
/* When meditating your mana is increased ! */
if (p_ptr->meditation)
{
msp += 50;
p_ptr->csp += 50;
}
/* Sp mods? */
if (process_hooks_ret(HOOK_CALC_MANA, "d", "(d)", msp))
{
msp = process_hooks_return[0].num;
}
/* Mana can never be negative */
if (msp < 0) msp = 0;
/* Maximum mana has changed */
if (p_ptr->msp != msp)
{
/* Save new limit */
p_ptr->msp = msp;
/* Enforce new limit */
if (p_ptr->csp >= msp)
{
p_ptr->csp = msp;
p_ptr->csp_frac = 0;
}
/* Display mana later */
p_ptr->redraw |= (PR_MANA);
/* Window stuff */
p_ptr->window |= (PW_PLAYER);
}
/* Hack -- handle "xtra" mode */
if (character_xtra) return;
/* Take note when "glove state" changes */
if (p_ptr->old_cumber_glove != p_ptr->cumber_glove)
{
/* Message */
if (p_ptr->cumber_glove)
{
msg_print("Your covered hands feel unsuitable for spellcasting.");
}
else
{
msg_print("Your hands feel more suitable for spellcasting.");
}
/* Save it */
p_ptr->old_cumber_glove = p_ptr->cumber_glove;
}
/* Take note when "armor state" changes */
if (p_ptr->old_cumber_armor != p_ptr->cumber_armor)
{
/* Message */
if (p_ptr->cumber_armor)
{
msg_print("The weight of your armor encumbers your movement.");
}
else
{
msg_print("You feel able to move more freely.");
}
/* Save it */
p_ptr->old_cumber_armor = p_ptr->cumber_armor;
}
}
/*
* Calculate the players (maximal) hit points
* Adjust current hitpoints if necessary
*/
void calc_hitpoints(void)
{
int bonus, mhp;
/* Un-inflate "half-hitpoint bonus per level" value */
bonus = ((int)(adj_con_mhp[p_ptr->stat_ind[A_CON]]) - 128);
/* Calculate hitpoints */
mhp = player_hp[p_ptr->lev - 1] + (bonus * p_ptr->lev / 2);
/* Always have at least one hitpoint per level */
if (mhp < p_ptr->lev + 1) mhp = p_ptr->lev + 1;
/* Factor in the pernament hp modifications */
mhp += p_ptr->hp_mod;
if (mhp < 1) mhp = 1;
/* Hack: Sorcery impose a hp penality */
if (mhp && (get_skill(SKILL_SORCERY)))
{
mhp -= mhp * get_skill_scale(SKILL_SORCERY, 50) / 100;
if (mhp < 1) mhp = 1;
}
/* Factor in the melkor hp modifications */
GOD(GOD_MELKOR)
{
mhp -= (p_ptr->melkor_sacrifice * 10);
if (mhp < 1) mhp = 1;
}
/* Factor in the hero / superhero settings */
if (p_ptr->hero) mhp += 10;
if (p_ptr->shero) mhp += 30;
/* Augment Hitpoint */
if (munchkin_multipliers)
{
mhp += mhp * p_ptr->to_l / 5;
}
else
{
mhp += mhp * p_ptr->to_l / 10;
}
if (mhp < 1) mhp = 1;
if (p_ptr->body_monster)
{
monster_race *r_ptr = &r_info[p_ptr->body_monster];
u32b rhp = maxroll(r_ptr->hdice, r_ptr->hside);
/* Adjust the hp with the possession skill */
rhp = (rhp * (20 + get_skill_scale(SKILL_POSSESSION, 80))) / 100;
mhp = (rhp + sroot(rhp) + mhp) / 3;
}
if (p_ptr->disembodied) mhp = 1;
/* HACK - being undead means less DP */
if (p_ptr->necro_extra & CLASS_UNDEAD)
{
int divisor = p_ptr->lev / 4;
/* Beware of the horrible division by zero ! :) */
if (divisor == 0) divisor = 1;
/* Actually decrease the max hp */
mhp /= divisor;
/* Never less than 1 */
if (mhp < 1) mhp = 1;
}
/* Hp mods? */
if (process_hooks_ret(HOOK_CALC_HP, "d", "(d)", mhp))
{
mhp = process_hooks_return[0].num;
}
/* Never less than 1 */
if (mhp < 1) mhp = 1;
/* New maximum hitpoints */
if (p_ptr->mhp != mhp)
{
/* XXX XXX XXX New hitpoint maintenance */
/* Enforce maximum */
if (p_ptr->chp >= mhp)
{
p_ptr->chp = mhp;
p_ptr->chp_frac = 0;
}
/* Save the new max-hitpoints */
p_ptr->mhp = mhp;
/* Display hitpoints (later) */
p_ptr->redraw |= (PR_HP);
/* Window stuff */
p_ptr->window |= (PW_PLAYER);
}
}
/*
* Extract and set the current "lite radius"
*
* SWD: Experimental modification: multiple light sources have additive effect.
*
*/
static void calc_torch(void)
{
int i;
object_type *o_ptr;
u32b f1, f2, f3, f4, f5, esp;
/* Assume no light */
p_ptr->cur_lite = 0;
/* Loop through all wielded items */
for (i = INVEN_WIELD; i < INVEN_TOTAL; i++)
{
o_ptr = &p_ptr->inventory[i];
/* Skip empty slots */
if (!o_ptr->k_idx) continue;
/* Extract the flags */
object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp);
/* does this item glow? */
if (((f4 & TR4_FUEL_LITE) && (o_ptr->timeout > 0)) || (!(f4 & TR4_FUEL_LITE)))
{
if (f3 & TR3_LITE1) p_ptr->cur_lite++;
if (f4 & TR4_LITE2) p_ptr->cur_lite += 2;
if (f4 & TR4_LITE3) p_ptr->cur_lite += 3;
}
}
if (p_ptr->tim_lite) p_ptr->cur_lite += 2;
if (p_ptr->holy) p_ptr->cur_lite += 1;
/* max radius is 5 without rewriting other code -- */
/* see cave.c:update_lite() and defines.h:LITE_MAX */
if (p_ptr->cur_lite > 5) p_ptr->cur_lite = 5;
/* check if the player doesn't have a lite source, */
/* but does glow as an intrinsic. */
if (p_ptr->cur_lite == 0 && p_ptr->lite) p_ptr->cur_lite = 1;
/* Hooked powers */
process_hooks(HOOK_CALC_LITE, "()");
/* end experimental mods */
/* Reduce lite in the small-scale wilderness map */
if (p_ptr->wild_mode)
{
/* Reduce the lite radius if needed */
if (p_ptr->cur_lite > WILDERNESS_SEE_RADIUS)
{
p_ptr->cur_lite = WILDERNESS_SEE_RADIUS;
}
}
/* Reduce lite when running if requested */
if (running && view_reduce_lite)
{
/* Reduce the lite radius if needed */
if (p_ptr->cur_lite > 1) p_ptr->cur_lite = 1;
}
/* Notice changes in the "lite radius" */
if (p_ptr->old_lite != p_ptr->cur_lite)
{
/* Update the view */
p_ptr->update |= (PU_VIEW);
/* Update the monsters */
p_ptr->update |= (PU_MONSTERS);
/* Remember the old lite */
p_ptr->old_lite = p_ptr->cur_lite;
}
}
/*
* Computes current weight limit.
*/
int weight_limit(void)
{
int i;
/* Weight limit based only on strength */
i = adj_str_wgt[p_ptr->stat_ind[A_STR]] * 100;
if (process_hooks_ret(HOOK_CALC_WEIGHT, "d", "(d)", i))
i = process_hooks_return[0].num;
/* Return the result */
return (i);
}
void calc_wield_monster()
{
object_type *o_ptr;
monster_race *r_ptr;
/* Get the carried monster */
o_ptr = &p_ptr->inventory[INVEN_CARRY];
if (o_ptr->k_idx)
{
r_ptr = &r_info[o_ptr->pval];
if (r_ptr->flags2 & RF2_INVISIBLE)
p_ptr->invis += 20;
if (r_ptr->flags2 & RF2_REFLECTING)
p_ptr->reflect = TRUE;
if (r_ptr->flags7 & RF7_CAN_FLY)
p_ptr->ffall = TRUE;
if (r_ptr->flags7 & RF7_AQUATIC)
p_ptr->water_breath = TRUE;
}
}
/*
* Calc which body parts the player have, based on the
* monster he incarnate, note that that's bnot a hack
* since body parts of the player when in it's own body
* are also defined in r_info(monster 0)
*/
void calc_body()
{
monster_race *r_ptr = &r_info[p_ptr->body_monster];
int i, b_weapon, b_legs, b_arms;
byte *body_parts, bp[BODY_MAX];
if (!p_ptr->body_monster)
{
body_parts = bp;
for (i = 0; i < BODY_MAX; i++)
{
int b;
b = rp_ptr->body_parts[i] + rmp_ptr->body_parts[i];
if (b < 0) b = 0;
if (p_ptr->mimic_form == resolve_mimic_name("Bear"))
{
if (i == BODY_ARMS) b = 0;
else if (i == BODY_LEGS) b = 0;
}
bp[i] = b;
}
}
else
{
body_parts = bp;
for (i = 0; i < BODY_MAX; i++)
{
int b;
b = r_ptr->body_parts[i];
if (b < 0) b = 0;
bp[i] = b;
}
}
/* Do we need more parts ? ;) */
for (i = 0; i < BODY_MAX; i++)
p_ptr->extra_body_parts[i] = 0;
process_hooks(HOOK_BODY_PARTS, "()");
for (i = 0; i < BODY_MAX; i++)
{
int b;
b = bp[i] + cp_ptr->body_parts[i] + p_ptr->extra_body_parts[i];
if (b < 0) b = 0;
if (b > max_body_part[i]) b = max_body_part[i];
bp[i] = b;
}
b_weapon = body_parts[BODY_WEAPON];
b_arms = body_parts[BODY_ARMS];
b_legs = body_parts[BODY_LEGS];
if (p_ptr->mimic_extra & CLASS_ARMS)
{
b_weapon++;
b_arms++;
if (b_weapon > 3) b_weapon = 3;
if (b_arms > 3) b_arms = 3;
}
if (p_ptr->mimic_extra & CLASS_LEGS)
{
b_legs++;
if (b_legs > 2) b_legs = 2;
}
for (i = 0; i < INVEN_TOTAL - INVEN_WIELD; i++)
p_ptr->body_parts[i] = 0;
for (i = 0; i < b_weapon; i++)
p_ptr->body_parts[INVEN_WIELD - INVEN_WIELD + i] = INVEN_WIELD;
if (body_parts[BODY_WEAPON])
p_ptr->body_parts[INVEN_BOW - INVEN_WIELD] = INVEN_BOW;
for (i = 0; i < body_parts[BODY_TORSO]; i++)
{
p_ptr->body_parts[INVEN_BODY - INVEN_WIELD + i] = INVEN_BODY;
p_ptr->body_parts[INVEN_OUTER - INVEN_WIELD + i] = INVEN_OUTER;
p_ptr->body_parts[INVEN_LITE - INVEN_WIELD + i] = INVEN_LITE;
p_ptr->body_parts[INVEN_AMMO - INVEN_WIELD + i] = INVEN_AMMO;
p_ptr->body_parts[INVEN_CARRY - INVEN_WIELD + i] = INVEN_CARRY;
}
for (i = 0; i < body_parts[BODY_FINGER]; i++)
p_ptr->body_parts[INVEN_RING - INVEN_WIELD + i] = INVEN_RING;
for (i = 0; i < body_parts[BODY_HEAD]; i++)
{
p_ptr->body_parts[INVEN_HEAD - INVEN_WIELD + i] = INVEN_HEAD;
p_ptr->body_parts[INVEN_NECK - INVEN_WIELD + i] = INVEN_NECK;
}
for (i = 0; i < b_arms; i++)
{
p_ptr->body_parts[INVEN_ARM - INVEN_WIELD + i] = INVEN_ARM;
p_ptr->body_parts[INVEN_HANDS - INVEN_WIELD + i] = INVEN_HANDS;
}
if (body_parts[BODY_ARMS])
p_ptr->body_parts[INVEN_TOOL - INVEN_WIELD] = INVEN_TOOL;
for (i = 0; i < b_legs; i++)
p_ptr->body_parts[INVEN_FEET - INVEN_WIELD + i] = INVEN_FEET;
/* Ok now if the player lost a body part, he must drop the object he had on it */
for (i = 0; i < INVEN_TOTAL - INVEN_WIELD; i++)
{
if ((!p_ptr->body_parts[i]) && (p_ptr->inventory[i + INVEN_WIELD].k_idx))
{
/* Drop it NOW ! */
inven_takeoff(i + INVEN_WIELD, 255, TRUE);
}
}
}
/* Should be called by every calc_bonus call */
void calc_body_bonus()
{
monster_race *r_ptr = &r_info[p_ptr->body_monster];
/* If in the player body nothing have to be done */
if (!p_ptr->body_monster) return;
if (p_ptr->disembodied)
{
p_ptr->wraith_form = TRUE;
return;
}
p_ptr->ac += r_ptr->ac;
p_ptr->pspeed = r_ptr->speed;
if (r_ptr->flags1 & RF1_NEVER_MOVE) p_ptr->immovable = TRUE;
if (r_ptr->flags2 & RF2_STUPID) p_ptr->stat_add[A_INT] -= 1;
if (r_ptr->flags2 & RF2_SMART) p_ptr->stat_add[A_INT] += 1;
if (r_ptr->flags2 & RF2_REFLECTING) p_ptr->reflect = TRUE;
if (r_ptr->flags2 & RF2_INVISIBLE) p_ptr->invis += 20;
if (r_ptr->flags2 & RF2_REGENERATE) p_ptr->regenerate = TRUE;
if (r_ptr->flags2 & RF2_AURA_FIRE) p_ptr->sh_fire = TRUE;
if (r_ptr->flags2 & RF2_AURA_ELEC) p_ptr->sh_elec = TRUE;
if (r_ptr->flags2 & RF2_PASS_WALL) p_ptr->wraith_form = TRUE;
if (r_ptr->flags3 & RF3_SUSCEP_FIRE) p_ptr->sensible_fire = TRUE;
if (r_ptr->flags3 & RF3_IM_ACID) p_ptr->resist_acid = TRUE;
if (r_ptr->flags3 & RF3_IM_ELEC) p_ptr->resist_elec = TRUE;
if (r_ptr->flags3 & RF3_IM_FIRE) p_ptr->resist_fire = TRUE;
if (r_ptr->flags3 & RF3_IM_POIS) p_ptr->resist_pois = TRUE;
if (r_ptr->flags3 & RF3_IM_COLD) p_ptr->resist_cold = TRUE;
if (r_ptr->flags3 & RF3_RES_NETH) p_ptr->resist_neth = TRUE;
if (r_ptr->flags3 & RF3_RES_NEXU) p_ptr->resist_nexus = TRUE;
if (r_ptr->flags3 & RF3_RES_DISE) p_ptr->resist_disen = TRUE;
if (r_ptr->flags3 & RF3_NO_FEAR) p_ptr->resist_fear = TRUE;
if (r_ptr->flags3 & RF3_NO_SLEEP) p_ptr->free_act = TRUE;
if (r_ptr->flags3 & RF3_NO_CONF) p_ptr->resist_conf = TRUE;
if (r_ptr->flags7 & RF7_CAN_FLY) p_ptr->ffall = TRUE;
if (r_ptr->flags7 & RF7_AQUATIC) p_ptr->water_breath = TRUE;
}
byte calc_mimic()
{
s32b blow = 0;
call_lua("calc_mimic", "(d)", "d", p_ptr->mimic_form, &blow);
return blow;
}
/* Returns the blow information based on class */
void analyze_blow(int *num, int *wgt, int *mul)
{
*num = cp_ptr->blow_num;
*wgt = cp_ptr->blow_wgt;
*mul = cp_ptr->blow_mul;
/* Count bonus abilities */
if (has_ability(AB_MAX_BLOW1)) (*num)++;
if (has_ability(AB_MAX_BLOW2)) (*num)++;
}
/* Are all the weapons wielded of the right type ? */
int get_weaponmastery_skill()
{
int i, skill = 0;
object_type *o_ptr;
i = 0;
/* All weapons must be of the same type */
while ((p_ptr->body_parts[i] == INVEN_WIELD) && (i < INVEN_TOTAL))
{
o_ptr = &p_ptr->inventory[INVEN_WIELD + i];
if (!o_ptr->k_idx)
{
i++;
continue;
}
switch (o_ptr->tval)
{
case TV_DAEMON_BOOK:
case TV_SWORD:
if ((!skill) || (skill == SKILL_SWORD)) skill = SKILL_SWORD;
else skill = -1;
break;
case TV_AXE:
if ((!skill) || (skill == SKILL_AXE)) skill = SKILL_AXE;
else skill = -1;
break;
case TV_HAFTED:
if ((!skill) || (skill == SKILL_HAFTED)) skill = SKILL_HAFTED;
else skill = -1;
break;
case TV_POLEARM:
if ((!skill) || (skill == SKILL_POLEARM)) skill = SKILL_POLEARM;
else skill = -1;
break;
}
i++;
}
/* Everything is ok */
return skill;
}
/* Are all the ranged weapons wielded of the right type ? */
int get_archery_skill()
{
int i, skill = 0;
object_type *o_ptr;
i = INVEN_BOW - INVEN_WIELD;
/* All weapons must be of the same type */
while (p_ptr->body_parts[i] == INVEN_BOW)
{
o_ptr = &p_ptr->inventory[INVEN_WIELD + i];
if (p_ptr->inventory[INVEN_WIELD + i].tval == TV_BOW)
{
switch (p_ptr->inventory[INVEN_WIELD + i].sval / 10)
{
case 0:
if ((!skill) || (skill == SKILL_SLING)) skill = SKILL_SLING;
else skill = -1;
break;
case 1:
if ((!skill) || (skill == SKILL_BOW)) skill = SKILL_BOW;
else skill = -1;
break;
case 2:
if ((!skill) || (skill == SKILL_XBOW)) skill = SKILL_XBOW;
else skill = -1;
break;
}
}
else
{
if ((!skill) || (skill == SKILL_BOOMERANG)) skill = SKILL_BOOMERANG;
else skill = -1;
}
i++;
}
/* Everything is ok */
return skill;
}
/* Apply gods */
void calc_gods()
{
/* Boost WIS if the player follows Eru */
GOD(GOD_ERU)
{
if (p_ptr->grace > 10000) p_ptr->stat_add[A_WIS] += 1;
if (p_ptr->grace > 20000) p_ptr->stat_add[A_WIS] += 1;
if (p_ptr->grace > 30000) p_ptr->stat_add[A_WIS] += 1;
}
/* Boost str, con, chr and reduce int, wis if the player follows Melkor */
GOD(GOD_MELKOR)
{
if (p_ptr->grace > 10000) p_ptr->stat_add[A_STR] += 1;
if (p_ptr->grace > 20000) p_ptr->stat_add[A_STR] += 1;
if (p_ptr->grace > 30000) p_ptr->stat_add[A_STR] += 1;
if (p_ptr->grace > 10000) p_ptr->stat_add[A_CON] += 1;
if (p_ptr->grace > 20000) p_ptr->stat_add[A_CON] += 1;
if (p_ptr->grace > 30000) p_ptr->stat_add[A_CON] += 1;
if (p_ptr->grace > 10000) p_ptr->stat_add[A_CHR] += 1;
if (p_ptr->grace > 20000) p_ptr->stat_add[A_CHR] += 1;
if (p_ptr->grace > 30000) p_ptr->stat_add[A_CHR] += 1;
if (p_ptr->grace > 10000) p_ptr->stat_add[A_INT] -= 1;
if (p_ptr->grace > 20000) p_ptr->stat_add[A_INT] -= 1;
if (p_ptr->grace > 30000) p_ptr->stat_add[A_INT] -= 1;
if (p_ptr->grace > 10000) p_ptr->stat_add[A_WIS] -= 1;
if (p_ptr->grace > 20000) p_ptr->stat_add[A_WIS] -= 1;
if (p_ptr->grace > 30000) p_ptr->stat_add[A_WIS] -= 1;
PRAY_GOD(GOD_MELKOR)
{
if (p_ptr->grace > 5000) p_ptr->invis += 30;
if (p_ptr->grace > 15000) p_ptr->immune_fire = TRUE;
}
p_ptr->resist_fire = TRUE;
}
/* Gifts of Manwe if the player is praying to Manwe */
PRAY_GOD(GOD_MANWE)
{
s32b add = p_ptr->grace;
/* provides speed every 5000 grace */
if (add > 35000) add = 35000;
add /= 5000;
p_ptr->pspeed += add;
/* Provides fly & FA */
if (p_ptr->grace >= 7000) p_ptr->free_act = TRUE;
if (p_ptr->grace >= 15000) p_ptr->fly = TRUE;
}
/* Manwe bonus not requiring the praying status */
GOD(GOD_MANWE)
{
if (p_ptr->grace >= 2000) p_ptr->ffall = TRUE;
}
/* Boost Str and Con if the player is following Tulkas */
GOD(GOD_TULKAS)
{
if (p_ptr->grace > 5000) p_ptr->stat_add[A_CON] += 1;
if (p_ptr->grace > 10000) p_ptr->stat_add[A_CON] += 1;
if (p_ptr->grace > 15000) p_ptr->stat_add[A_CON] += 1;
if (p_ptr->grace > 10000) p_ptr->stat_add[A_STR] += 1;
if (p_ptr->grace > 15000) p_ptr->stat_add[A_STR] += 1;
if (p_ptr->grace > 20000) p_ptr->stat_add[A_STR] += 1;
}
}
/* Apply flags */
static int extra_blows;
static int extra_shots;
void apply_flags(u32b f1, u32b f2, u32b f3, u32b f4, u32b f5, u32b esp, s16b pval, s16b tval, s16b to_h, s16b to_d, s16b to_a)
{
/* Affect stats */
if (f1 & (TR1_STR)) p_ptr->stat_add[A_STR] += pval;
if (f1 & (TR1_INT)) p_ptr->stat_add[A_INT] += pval;
if (f1 & (TR1_WIS)) p_ptr->stat_add[A_WIS] += pval;
if (f1 & (TR1_DEX)) p_ptr->stat_add[A_DEX] += pval;
if (f1 & (TR1_CON)) p_ptr->stat_add[A_CON] += pval;
if (f1 & (TR1_CHR)) p_ptr->stat_add[A_CHR] += pval;
if (f5 & (TR5_LUCK)) p_ptr->luck_cur += pval;
/* Affect spell power */
if (f1 & (TR1_SPELL)) p_ptr->to_s += pval;
/* Affect mana capacity */
if (f1 & (TR1_MANA)) p_ptr->to_m += pval;
/* Affect life capacity */
if (f2 & (TR2_LIFE)) p_ptr->to_l += pval;
/* Affect stealth */
if (f1 & (TR1_STEALTH)) p_ptr->skill_stl += pval;
/* Affect searching ability (factor of five) */
if (f1 & (TR1_SEARCH)) p_ptr->skill_srh += (pval * 5);
/* Affect searching frequency (factor of five) */
if (f1 & (TR1_SEARCH)) p_ptr->skill_fos += (pval * 5);
/* Affect infravision */
if (f1 & (TR1_INFRA)) p_ptr->see_infra += pval;
/* Affect digging (factor of 20) */
if (f1 & (TR1_TUNNEL)) p_ptr->skill_dig += (pval * 20);
/* Affect speed */
if (f1 & (TR1_SPEED)) p_ptr->pspeed += pval;
/* Affect blows */
if (f1 & (TR1_BLOWS)) extra_blows += pval;
if (f5 & (TR5_CRIT)) p_ptr->xtra_crit += pval;
/* Hack -- Sensible fire */
if (f2 & (TR2_SENS_FIRE)) p_ptr->sensible_fire = TRUE;
/* Hack -- cause earthquakes */
if (f1 & (TR1_IMPACT)) p_ptr->impact = TRUE;
/* Affect invisibility */
if (f2 & (TR2_INVIS)) p_ptr->invis += (pval * 10);
/* Boost shots */
if (f3 & (TR3_XTRA_SHOTS)) extra_shots++;
/* Various flags */
if (f3 & (TR3_AGGRAVATE)) p_ptr->aggravate = TRUE;
if (f3 & (TR3_TELEPORT)) p_ptr->teleport = TRUE;
if (f5 & (TR5_DRAIN_MANA)) p_ptr->drain_mana++;
if (f5 & (TR5_DRAIN_HP)) p_ptr->drain_life++;
if (f3 & (TR3_DRAIN_EXP)) p_ptr->exp_drain = TRUE;
if (f3 & (TR3_BLESSED)) p_ptr->bless_blade = TRUE;
if (f3 & (TR3_XTRA_MIGHT)) p_ptr->xtra_might += pval;
if (f3 & (TR3_SLOW_DIGEST)) p_ptr->slow_digest = TRUE;
if (f3 & (TR3_REGEN)) p_ptr->regenerate = TRUE;
if (esp) p_ptr->telepathy |= esp;
if ((tval != TV_LITE) && (f3 & (TR3_LITE1))) p_ptr->lite = TRUE;
if ((tval != TV_LITE) && (f4 & (TR4_LITE2))) p_ptr->lite = TRUE;
if ((tval != TV_LITE) && (f4 & (TR4_LITE3))) p_ptr->lite = TRUE;
if (f3 & (TR3_SEE_INVIS)) p_ptr->see_inv = TRUE;
if (f2 & (TR2_FREE_ACT)) p_ptr->free_act = TRUE;
if (f2 & (TR2_HOLD_LIFE)) p_ptr->hold_life = TRUE;
if (f3 & (TR3_WRAITH)) p_ptr->wraith_form = TRUE;
if (f3 & (TR3_FEATHER)) p_ptr->ffall = TRUE;
if (f4 & (TR4_FLY)) p_ptr->fly = TRUE;
if (f4 & (TR4_CLIMB)) p_ptr->climb = TRUE;
/* Immunity flags */
if (f2 & (TR2_IM_FIRE)) p_ptr->immune_fire = TRUE;
if (f2 & (TR2_IM_ACID)) p_ptr->immune_acid = TRUE;
if (f2 & (TR2_IM_COLD)) p_ptr->immune_cold = TRUE;
if (f2 & (TR2_IM_ELEC)) p_ptr->immune_elec = TRUE;
/* Resistance flags */
if (f2 & (TR2_RES_ACID)) p_ptr->resist_acid = TRUE;
if (f2 & (TR2_RES_ELEC)) p_ptr->resist_elec = TRUE;
if (f2 & (TR2_RES_FIRE)) p_ptr->resist_fire = TRUE;
if (f2 & (TR2_RES_COLD)) p_ptr->resist_cold = TRUE;
if (f2 & (TR2_RES_POIS)) p_ptr->resist_pois = TRUE;
if (f2 & (TR2_RES_FEAR)) p_ptr->resist_fear = TRUE;
if (f2 & (TR2_RES_CONF)) p_ptr->resist_conf = TRUE;
if (f2 & (TR2_RES_SOUND)) p_ptr->resist_sound = TRUE;
if (f2 & (TR2_RES_LITE)) p_ptr->resist_lite = TRUE;
if (f2 & (TR2_RES_DARK)) p_ptr->resist_dark = TRUE;
if (f2 & (TR2_RES_CHAOS)) p_ptr->resist_chaos = TRUE;
if (f2 & (TR2_RES_DISEN)) p_ptr->resist_disen = TRUE;
if (f2 & (TR2_RES_SHARDS)) p_ptr->resist_shard = TRUE;
if (f2 & (TR2_RES_NEXUS)) p_ptr->resist_nexus = TRUE;
if (f2 & (TR2_RES_BLIND)) p_ptr->resist_blind = TRUE;
if (f2 & (TR2_RES_NETHER)) p_ptr->resist_neth = TRUE;
if (f4 & (TR4_IM_NETHER)) p_ptr->immune_neth = TRUE;
if (f2 & (TR2_REFLECT)) p_ptr->reflect = TRUE;
if (f3 & (TR3_SH_FIRE)) p_ptr->sh_fire = TRUE;
if (f3 & (TR3_SH_ELEC)) p_ptr->sh_elec = TRUE;
if (f3 & (TR3_NO_MAGIC)) p_ptr->anti_magic = TRUE;
if (f3 & (TR3_NO_TELE)) p_ptr->anti_tele = TRUE;
/* Sustain flags */
if (f2 & (TR2_SUST_STR)) p_ptr->sustain_str = TRUE;
if (f2 & (TR2_SUST_INT)) p_ptr->sustain_int = TRUE;
if (f2 & (TR2_SUST_WIS)) p_ptr->sustain_wis = TRUE;
if (f2 & (TR2_SUST_DEX)) p_ptr->sustain_dex = TRUE;
if (f2 & (TR2_SUST_CON)) p_ptr->sustain_con = TRUE;
if (f2 & (TR2_SUST_CHR)) p_ptr->sustain_chr = TRUE;
if (f4 & (TR4_PRECOGNITION)) p_ptr->precognition = TRUE;
if (f4 & (TR4_ANTIMAGIC_50))
{
s32b tmp;
tmp = 10 + get_skill_scale(SKILL_ANTIMAGIC, 40)
- to_h - to_d - pval - to_a;
if (tmp > 0) p_ptr->antimagic += tmp;
tmp = 1 + get_skill_scale(SKILL_ANTIMAGIC, 4)
- (to_h + to_d + pval + to_a) / 15;
if (tmp > 0) p_ptr->antimagic_dis += tmp;
}
if (f4 & (TR4_ANTIMAGIC_30))
{
s32b tmp;
tmp = 7 + get_skill_scale(SKILL_ANTIMAGIC, 33)
- to_h - to_d - pval - to_a;
if (tmp > 0) p_ptr->antimagic += tmp;
tmp = 1 + get_skill_scale(SKILL_ANTIMAGIC, 2)
- (to_h + to_d + pval + to_a) / 15;
if (tmp > 0) p_ptr->antimagic_dis += tmp;
}
if (f4 & (TR4_ANTIMAGIC_20))
{
s32b tmp;
tmp = 5 + get_skill_scale(SKILL_ANTIMAGIC, 15)
- to_h - to_d - pval - to_a;
if (tmp > 0) p_ptr->antimagic += tmp;
p_ptr->antimagic_dis += 2;
}
if (f4 & (TR4_ANTIMAGIC_10))
{
s32b tmp;
tmp = 1 + get_skill_scale(SKILL_ANTIMAGIC, 9)
- to_h - to_d - pval - to_a;
if (tmp > 0) p_ptr->antimagic += tmp;
p_ptr->antimagic_dis += 1;
}
if (f4 & (TR4_AUTO_ID))
{
p_ptr->auto_id = TRUE;
}
/* The new code implementing Tolkien's concept of "Black Breath"
* takes advantage of the existing drain_exp character flag, renamed
* "black_breath". This flag can also be set by a unlucky blow from
* an undead. -LM-
*/
if (f4 & (TR4_BLACK_BREATH)) p_ptr->black_breath = TRUE;
if (f5 & (TR5_IMMOVABLE)) p_ptr->immovable = TRUE;
/* Breaths */
if (f5 & (TR5_WATER_BREATH)) p_ptr->water_breath = TRUE;
if (f5 & (TR5_MAGIC_BREATH))
{
p_ptr->magical_breath = TRUE;
p_ptr->water_breath = TRUE;
}
}
/*
* Calculate the players current "state", taking into account
* not only race/class intrinsics, but also objects being worn
* and temporary spell effects.
*
* See also calc_mana() and calc_hitpoints().
*
* Take note of the new "speed code", in particular, a very strong
* player will start slowing down as soon as he reaches 150 pounds,
* but not until he reaches 450 pounds will he be half as fast as
* a normal kobold. This both hurts and helps the player, hurts
* because in the old days a player could just avoid 300 pounds,
* and helps because now carrying 300 pounds is not very painful.
*
* The "weapon" and "bow" do *not* add to the bonuses to hit or to
* damage, since that would affect non-combat things. These values
* are actually added in later, at the appropriate place.
*
* This function induces various "status" messages, unless silent is
* TRUE.
*/
void calc_bonuses(bool silent)
{
int i, j, hold;
int old_invis;
int old_speed;
u32b old_telepathy;
int old_see_inv;
int old_dis_ac;
int old_dis_to_a;
object_type *o_ptr;
u32b f1, f2, f3, f4, f5, esp;
/* Save the old speed */
old_speed = p_ptr->pspeed;
/* Save the old vision stuff */
old_telepathy = p_ptr->telepathy;
old_see_inv = p_ptr->see_inv;
/* Save the old armor class */
old_dis_ac = p_ptr->dis_ac;
old_dis_to_a = p_ptr->dis_to_a;
/* Save the old invisibility */
old_invis = p_ptr->invis;
/* Clear extra blows/shots */
extra_blows = extra_shots = 0;
/* Clear the stat modifiers */
for (i = 0; i < 6; i++) p_ptr->stat_add[i] = 0;
/* Mana multiplier */
p_ptr->to_m = 0;
/* Life multiplier */
p_ptr->to_l = 0;
/* Spell power */
p_ptr->to_s = 0;
/* Clear the Displayed/Real armor class */
p_ptr->dis_ac = p_ptr->ac = 0;
/* Clear the Displayed/Real Bonuses */
p_ptr->dis_to_h = p_ptr->to_h = p_ptr->to_h_melee = p_ptr->to_h_ranged = 0;
p_ptr->dis_to_d = p_ptr->to_d = p_ptr->to_d_melee = p_ptr->to_d_ranged = 0;
p_ptr->dis_to_a = p_ptr->to_a = 0;
/* Start with "normal" speed */
p_ptr->pspeed = 110;
/* Start with 0% additionnal crits */
p_ptr->xtra_crit = 0;
/* Start with a single blow per turn */
p_ptr->num_blow = 1;
/* Start with a single shot per turn */
p_ptr->num_fire = 1;
/* Starts with single throwing damage */
p_ptr->throw_mult = 1;
/* Reset the "xtra" tval */
p_ptr->tval_xtra = 0;
/* Reset the "ammo" tval */
p_ptr->tval_ammo = 0;
/* Clear all the flags */
p_ptr->invis = 0;
p_ptr->immovable = FALSE;
p_ptr->aggravate = FALSE;
p_ptr->teleport = FALSE;
p_ptr->exp_drain = FALSE;
p_ptr->drain_mana = 0;
p_ptr->drain_life = 0;
p_ptr->bless_blade = FALSE;
p_ptr->xtra_might = 0;
p_ptr->auto_id = FALSE;
p_ptr->impact = FALSE;
p_ptr->see_inv = FALSE;
p_ptr->free_act = FALSE;
p_ptr->slow_digest = FALSE;
p_ptr->regenerate = FALSE;
p_ptr->fly = FALSE;
p_ptr->climb = FALSE;
p_ptr->ffall = FALSE;
p_ptr->hold_life = FALSE;
p_ptr->telepathy = 0;
p_ptr->lite = FALSE;
p_ptr->sustain_str = FALSE;
p_ptr->sustain_int = FALSE;
p_ptr->sustain_wis = FALSE;
p_ptr->sustain_con = FALSE;
p_ptr->sustain_dex = FALSE;
p_ptr->sustain_chr = FALSE;
p_ptr->resist_acid = FALSE;
p_ptr->resist_elec = FALSE;
p_ptr->resist_fire = FALSE;
p_ptr->resist_cold = FALSE;
p_ptr->resist_pois = FALSE;
p_ptr->resist_conf = FALSE;
p_ptr->resist_sound = FALSE;
p_ptr->resist_lite = FALSE;
p_ptr->resist_dark = FALSE;
p_ptr->resist_chaos = FALSE;
p_ptr->resist_disen = FALSE;
p_ptr->resist_shard = FALSE;
p_ptr->resist_nexus = FALSE;
p_ptr->resist_blind = FALSE;
p_ptr->resist_neth = FALSE;
p_ptr->immune_neth = FALSE;
p_ptr->resist_fear = FALSE;
p_ptr->resist_continuum = FALSE;
p_ptr->reflect = FALSE;
p_ptr->sh_fire = FALSE;
p_ptr->sh_elec = FALSE;
p_ptr->anti_magic = FALSE;
p_ptr->anti_tele = FALSE;
p_ptr->water_breath = FALSE;
p_ptr->magical_breath = FALSE;
p_ptr->sensible_fire = FALSE;
p_ptr->sensible_lite = FALSE;
p_ptr->immune_acid = FALSE;
p_ptr->immune_elec = FALSE;
p_ptr->immune_fire = FALSE;
p_ptr->immune_cold = FALSE;
p_ptr->precognition = FALSE;
p_ptr->wraith_form = FALSE;
/* The anti magic field surrounding the player */
p_ptr->antimagic = 0;
p_ptr->antimagic_dis = 0;
/* Base infravision (purely racial) */
p_ptr->see_infra = rp_ptr->infra + rmp_ptr->infra;
/* Base skill -- disarming */
p_ptr->skill_dis = 0;
/* Base skill -- magic devices */
p_ptr->skill_dev = 0;
/* Base skill -- saving throw */
p_ptr->skill_sav = 0;
/* Base skill -- stealth */
p_ptr->skill_stl = 0;
/* Base skill -- searching ability */
p_ptr->skill_srh = 0;
/* Base skill -- searching frequency */
p_ptr->skill_fos = 0;
/* Base skill -- combat (normal) */
p_ptr->skill_thn = 0;
/* Base skill -- combat (shooting) */
p_ptr->skill_thb = 0;
/* Base skill -- combat (throwing) */
p_ptr->skill_tht = 0;
/* Base skill -- digging */
p_ptr->skill_dig = 0;
/* Xtra player flags */
p_ptr->xtra_f1 = 0;
p_ptr->xtra_f2 = 0;
p_ptr->xtra_f3 = 0;
p_ptr->xtra_f4 = 0;
p_ptr->xtra_f5 = 0;
p_ptr->xtra_esp = 0;
/* Hide the skills that should auto hide */
for (i = 0; i < max_s_idx; i++)
{
if (s_info[i].flags1 & SKF1_AUTO_HIDE)
s_info[i].hidden = TRUE;
}
/* Base Luck */
p_ptr->luck_cur = p_ptr->luck_base;
/* Mimic override body's bonuses */
if (p_ptr->mimic_form)
{
extra_blows += calc_mimic();
}
else
{
calc_body_bonus();
}
/* Let the scripts do what they need */
process_hooks(HOOK_CALC_BONUS, "()");
/* The powers gived by the wielded monster */
calc_wield_monster();
for (i = 1; i <= p_ptr->lev; i++)
{
apply_flags(cp_ptr->oflags1[i], cp_ptr->oflags2[i], cp_ptr->oflags3[i], cp_ptr->oflags4[i], cp_ptr->oflags5[i], cp_ptr->oesp[i], cp_ptr->opval[i], 0, 0, 0, 0);
}
if (p_ptr->melee_style == SKILL_HAND)
{
/* Unencumbered Monks become faster every 10 levels */
if (!(monk_heavy_armor()))
p_ptr->pspeed += get_skill_scale(SKILL_HAND, 5);
/* Free action if unencumbered at level 25 */
if ((get_skill(SKILL_HAND) > 24) && !(monk_heavy_armor()))
p_ptr->free_act = TRUE;
}
if (get_skill(SKILL_ANTIMAGIC))
{
p_ptr->antimagic += get_skill(SKILL_ANTIMAGIC);
p_ptr->antimagic_dis += get_skill_scale(SKILL_ANTIMAGIC, 10) + 1;
if (p_ptr->antimagic_extra & CLASS_ANTIMAGIC)
{
p_ptr->anti_tele = TRUE;
p_ptr->resist_continuum = TRUE;
}
}
if (get_skill(SKILL_DAEMON) > 20) p_ptr->resist_conf = TRUE;
if (get_skill(SKILL_DAEMON) > 30) p_ptr->resist_fear = TRUE;
if ( get_skill(SKILL_MINDCRAFT) >= 40 ) p_ptr->telepathy = ESP_ALL;
if (p_ptr->astral)
{
p_ptr->wraith_form = TRUE;
}
/***** Races ****/
if ((!p_ptr->mimic_form) && (!p_ptr->body_monster))
{
int i;
for (i = 1; i <= p_ptr->lev; i++)
{
apply_flags(rp_ptr->oflags1[i], rp_ptr->oflags2[i], rp_ptr->oflags3[i], rp_ptr->oflags4[i], rp_ptr->oflags5[i], rp_ptr->oesp[i], rp_ptr->opval[i], 0, 0, 0, 0);
apply_flags(rmp_ptr->oflags1[i], rmp_ptr->oflags2[i], rmp_ptr->oflags3[i], rmp_ptr->oflags4[i], rmp_ptr->oflags5[i], rmp_ptr->oesp[i], rmp_ptr->opval[i], 0, 0, 0, 0);
}
if (PRACE_FLAG(PR1_HURT_LITE))
p_ptr->sensible_lite = TRUE;
}
/* The extra flags */
apply_flags(p_ptr->xtra_f1, p_ptr->xtra_f2, p_ptr->xtra_f3, p_ptr->xtra_f4, p_ptr->xtra_f5, p_ptr->xtra_esp, 0, 0, 0, 0, 0);
/* Hack -- apply racial/class stat maxes */
if (p_ptr->maximize)
{
/* Apply the racial modifiers */
for (i = 0; i < 6; i++)
{
/* Modify the stats for "race" */
p_ptr->stat_add[i] += (rp_ptr->r_adj[i] + rmp_ptr->r_adj[i] + cp_ptr->c_adj[i]);
}
}
/* Scan the usable inventory */
for (i = INVEN_WIELD; i < INVEN_TOTAL; i++)
{
o_ptr = &p_ptr->inventory[i];
/* Skip non-objects */
if (!o_ptr->k_idx) continue;
/* Extract the item flags */
object_flags_no_set = TRUE;
object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp);
object_flags_no_set = FALSE;
/* MEGA ugly hack -- set spacetime distortion resistance */
if (o_ptr->name1 == ART_ANCHOR)
{
p_ptr->resist_continuum = TRUE;
}
/* Hack - don't give the Black Breath when merely inspecting a weapon */
if (silent)
{
f4 &= ~TR4_BLACK_BREATH;
}
apply_flags(f1, f2, f3, f4, f5, esp, o_ptr->pval, o_ptr->tval, o_ptr->to_h, o_ptr->to_d, o_ptr->to_a);
if (o_ptr->name1)
{
apply_set(o_ptr->name1, a_info[o_ptr->name1].set);
}
/* Modify the base armor class */
p_ptr->ac += o_ptr->ac;
/* The base armor class is always known */
p_ptr->dis_ac += o_ptr->ac;
/* Apply the bonuses to armor class */
p_ptr->to_a += o_ptr->to_a;
/* Apply the mental bonuses to armor class, if known */
if (object_known_p(o_ptr)) p_ptr->dis_to_a += o_ptr->to_a;
/* Hack -- do not apply "weapon" bonuses */
if (p_ptr->body_parts[i - INVEN_WIELD] == INVEN_WIELD) continue;
/* Hack -- do not apply "bow" bonuses */
if (p_ptr->body_parts[i - INVEN_WIELD] == INVEN_BOW) continue;
/* Hack -- do not apply "ammo" bonuses */
if (p_ptr->body_parts[i - INVEN_WIELD] == INVEN_AMMO) continue;
/* Hack -- do not apply "tool" bonuses */
if (p_ptr->body_parts[i - INVEN_WIELD] == INVEN_TOOL) continue;
/* Apply the bonuses to hit/damage */
p_ptr->to_h += o_ptr->to_h;
p_ptr->to_d += o_ptr->to_d;
/* Apply the mental bonuses tp hit/damage, if known */
if (object_known_p(o_ptr)) p_ptr->dis_to_h += o_ptr->to_h;
if (object_known_p(o_ptr)) p_ptr->dis_to_d += o_ptr->to_d;
}
/* Monks get extra ac for armour _not worn_ */
if ((p_ptr->melee_style == SKILL_HAND) && !(monk_heavy_armor()))
{
if (!(p_ptr->inventory[INVEN_BODY].k_idx))
{
p_ptr->to_a += get_skill_scale(SKILL_HAND, 75);
p_ptr->dis_to_a += get_skill_scale(SKILL_HAND, 75);
}
if (!(p_ptr->inventory[INVEN_OUTER].k_idx) && (get_skill(SKILL_HAND) > 15))
{
p_ptr->to_a += ((get_skill(SKILL_HAND) - 13) / 3);
p_ptr->dis_to_a += ((get_skill(SKILL_HAND) - 13) / 3);
}
if (!(p_ptr->inventory[INVEN_ARM].k_idx) && (get_skill(SKILL_HAND) > 10))
{
p_ptr->to_a += ((get_skill(SKILL_HAND) - 8) / 3);
p_ptr->dis_to_a += ((get_skill(SKILL_HAND) - 8) / 3);
}
if (!(p_ptr->inventory[INVEN_HEAD].k_idx) && (get_skill(SKILL_HAND) > 4))
{
p_ptr->to_a += (get_skill(SKILL_HAND) - 2) / 3;
p_ptr->dis_to_a += (get_skill(SKILL_HAND) - 2) / 3;
}
if (!(p_ptr->inventory[INVEN_HANDS].k_idx))
{
p_ptr->to_a += (get_skill(SKILL_HAND) / 2);
p_ptr->dis_to_a += (get_skill(SKILL_HAND) / 2);
}
if (!(p_ptr->inventory[INVEN_FEET].k_idx))
{
p_ptr->to_a += (get_skill(SKILL_HAND) / 3);
p_ptr->dis_to_a += (get_skill(SKILL_HAND) / 3);
}
}
/* Hack -- aura of fire also provides light */
if (p_ptr->sh_fire) p_ptr->lite = TRUE;
if (PRACE_FLAG(PR1_AC_LEVEL))
{
p_ptr->to_a += 20 + (p_ptr->lev / 5);
p_ptr->dis_to_a += 20 + (p_ptr->lev / 5);
}
/* Take care of gods */
calc_gods();
/* Calculate stats */
for (i = 0; i < 6; i++)
{
int top, use, ind;
/* Extract the new "stat_use" value for the stat */
top = modify_stat_value(p_ptr->stat_max[i], p_ptr->stat_add[i]);
/* Notice changes */
if (p_ptr->stat_top[i] != top)
{
/* Save the new value */
p_ptr->stat_top[i] = top;
/* Redisplay the stats later */
p_ptr->redraw |= (PR_STATS);
/* Window stuff */
p_ptr->window |= (PW_PLAYER);
}
/* Extract the new "stat_use" value for the stat */
use = modify_stat_value(p_ptr->stat_cur[i], p_ptr->stat_add[i]);
/* Notice changes */
if (p_ptr->stat_use[i] != use)
{
/* Save the new value */
p_ptr->stat_use[i] = use;
/* Redisplay the stats later */
p_ptr->redraw |= (PR_STATS);
/* Window stuff */
p_ptr->window |= (PW_PLAYER);
}
/* Values: 3, 4, ..., 17 */
if (use <= 18) ind = (use - 3);
/* Ranges: 18/00-18/09, ..., 18/210-18/219 */
else if (use <= 18 + 219) ind = (15 + (use - 18) / 10);
/* Range: 18/220+ */
else ind = (37);
/* Notice changes */
if (p_ptr->stat_ind[i] != ind)
{
/* Save the new index */
p_ptr->stat_ind[i] = ind;
/* Change in CON affects Hitpoints */
if (i == A_CON)
{
p_ptr->update |= (PU_HP);
}
/* Change in WIS affects Sanity Points */
else if (i == A_WIS)
{
p_ptr->update |= (PU_MANA | PU_SANITY);
}
/* Change in spell stat affects Mana/Spells */
if (i == A_INT)
{
p_ptr->update |= (PU_MANA | PU_SPELLS);
}
/* Window stuff */
p_ptr->window |= (PW_PLAYER);
}
}
/* Provide the damage we get from sacrifice */
GOD(GOD_MELKOR)
{
int x = wisdom_scale(4);
if (x < 1) x = 1;
p_ptr->dis_to_d += x * p_ptr->melkor_sacrifice;
p_ptr->to_d += x * p_ptr->melkor_sacrifice;
}
/* jk - add in the tactics */
p_ptr->dis_to_h += tactic_info[(byte)p_ptr->tactic].to_hit;
p_ptr->to_h += tactic_info[(byte)p_ptr->tactic].to_hit;
p_ptr->dis_to_d += tactic_info[(byte)p_ptr->tactic].to_dam;
p_ptr->to_d += tactic_info[(byte)p_ptr->tactic].to_dam;
p_ptr->dis_to_a += tactic_info[(byte)p_ptr->tactic].to_ac;
p_ptr->to_a += tactic_info[(byte)p_ptr->tactic].to_ac;
p_ptr->skill_stl += tactic_info[(byte)p_ptr->tactic].to_stealth;
p_ptr->skill_dis += tactic_info[(byte)p_ptr->tactic].to_disarm;
p_ptr->skill_sav += tactic_info[(byte)p_ptr->tactic].to_saving;
p_ptr->pspeed += move_info[(byte)p_ptr->movement].to_speed;
p_ptr->skill_srh += move_info[(byte)p_ptr->movement].to_search;
p_ptr->skill_fos += move_info[(byte)p_ptr->movement].to_percep;
p_ptr->skill_stl += move_info[(byte)p_ptr->movement].to_stealth;
/* Apply temporary "stun" */
if (p_ptr->stun > 50)
{
p_ptr->to_h -= 20;
p_ptr->dis_to_h -= 20;
p_ptr->to_d -= 20;
p_ptr->dis_to_d -= 20;
}
else if (p_ptr->stun)
{
p_ptr->to_h -= 5;
p_ptr->dis_to_h -= 5;
p_ptr->to_d -= 5;
p_ptr->dis_to_d -= 5;
}
/* Invulnerability */
if (p_ptr->invuln)
{
p_ptr->to_a += 100;
p_ptr->dis_to_a += 100;
}
/* Breath */
if (p_ptr->tim_water_breath)
{
p_ptr->water_breath = TRUE;
}
if (p_ptr->tim_magic_breath)
{
p_ptr->magical_breath = TRUE;
}
/* wraith_form */
if (p_ptr->tim_wraith)
{
if (p_ptr->disembodied)
{
p_ptr->to_a += 10;
p_ptr->dis_to_a += 10;
}
else
{
p_ptr->to_a += 50;
p_ptr->dis_to_a += 50;
p_ptr->reflect = TRUE;
}
p_ptr->wraith_form = TRUE;
}
/* Temporary holy aura */
if (p_ptr->holy)
{
p_ptr->hold_life = TRUE;
p_ptr->luck_cur += 5;
}
/* Temporary blessing */
if (p_ptr->blessed)
{
p_ptr->to_a += 5;
p_ptr->dis_to_a += 5;
p_ptr->to_h += 10;
p_ptr->dis_to_h += 10;
}
/* Temporary invisibility */
if (p_ptr->tim_invisible)
{
p_ptr->invis += p_ptr->tim_inv_pow;
}
/* Temporary shield */
if (p_ptr->shield)
{
p_ptr->to_a += p_ptr->shield_power;
p_ptr->dis_to_a += p_ptr->shield_power;
}
/* Temporary "Hero" */
if (p_ptr->hero)
{
p_ptr->to_h += 12;
p_ptr->dis_to_h += 12;
}
/* Temporary "roots" */
if (p_ptr->tim_roots)
{
set_stun(0);
p_ptr->to_d_melee += p_ptr->tim_roots_dam;
p_ptr->to_a += p_ptr->tim_roots_ac;
p_ptr->dis_to_a += p_ptr->tim_roots_ac;
}
/* Temporary "Beserk" */
if (p_ptr->shero)
{
p_ptr->to_h += 24;
p_ptr->dis_to_h += 24;
p_ptr->to_a -= 10;
p_ptr->dis_to_a -= 10;
}
/* Temporary "Accurancy" */
if (p_ptr->strike)
{
p_ptr->to_d += 15;
p_ptr->dis_to_d += 15;
p_ptr->to_h += 15;
p_ptr->dis_to_h += 15;
}
/* Temporary "Meditation" */
if (p_ptr->meditation)
{
p_ptr->to_d -= 25;
p_ptr->dis_to_d -= 25;
p_ptr->to_h -= 25;
p_ptr->dis_to_h -= 25;
}
/* Temporary "Reflection" */
if (p_ptr->tim_reflect)
{
p_ptr->reflect = TRUE;
}
/* Temporary "Time Resistance" */
if (p_ptr->tim_res_time)
{
p_ptr->resist_continuum = TRUE;
}
/* Temporary "Levitation" and "Flying" */
if (p_ptr->tim_ffall)
{
p_ptr->ffall = TRUE;
}
if (p_ptr->tim_fly)
{
p_ptr->fly = TRUE;
}
/* Temporary "Fire Aura" */
if (p_ptr->tim_fire_aura)
{
p_ptr->sh_fire = TRUE;
}
/* Oppose Light & Dark */
if (p_ptr->oppose_ld)
{
p_ptr->resist_lite = TRUE;
p_ptr->resist_dark = TRUE;
}
/* Oppose Chaos & Confusion */
if (p_ptr->oppose_cc)
{
p_ptr->resist_chaos = TRUE;
p_ptr->resist_conf = TRUE;
}
/* Oppose Sound & Shards */
if (p_ptr->oppose_ss)
{
p_ptr->resist_sound = TRUE;
p_ptr->resist_shard = TRUE;
}
/* Oppose Nexus */
if (p_ptr->oppose_nex)
{
p_ptr->resist_nexus = TRUE;
}
/* Mental barrier */
if (p_ptr->tim_mental_barrier)
{
p_ptr->sustain_int = TRUE;
p_ptr->sustain_wis = TRUE;
}
/* Temporary "fast" */
if (p_ptr->fast)
{
p_ptr->pspeed += p_ptr->speed_factor;
}
/* Temporary "light speed" */
if (p_ptr->lightspeed)
{
p_ptr->pspeed += 50;
}
/* Temporary "slow" */
if (p_ptr->slow)
{
p_ptr->pspeed -= 10;
}
if (p_ptr->tim_esp)
{
p_ptr->telepathy |= ESP_ALL;
}
/* Temporary see invisible */
if (p_ptr->tim_invis)
{
p_ptr->see_inv = TRUE;
}
/* Temporary infravision boost */
if (p_ptr->tim_infra)
{
p_ptr->see_infra++;
}
/* Hack -- Magic breath -> Water breath */
if (p_ptr->magical_breath)
{
p_ptr->water_breath = TRUE;
}
/* Hack -- Can Fly -> Can Levitate */
if (p_ptr->fly)
{
p_ptr->ffall = TRUE;
}
/* Hack -- Res Chaos -> Res Conf */
if (p_ptr->resist_chaos)
{
p_ptr->resist_conf = TRUE;
}
/* Hack -- Hero/Shero -> Res fear */
if (p_ptr->hero || p_ptr->shero)
{
p_ptr->resist_fear = TRUE;
}
/* Hack -- Telepathy Change */
if (p_ptr->telepathy != old_telepathy)
{
p_ptr->update |= (PU_MONSTERS);
}
/* Hack -- See Invis Change */
if (p_ptr->see_inv != old_see_inv)
{
p_ptr->update |= (PU_MONSTERS);
}
/* Extract the current weight (in tenth pounds) */
j = calc_total_weight();
/* Extract the "weight limit" (in tenth pounds) */
i = weight_limit();
/* XXX XXX XXX Apply "encumbrance" from weight */
if (j > i / 2) p_ptr->pspeed -= ((j - (i / 2)) / (i / 10));
/* Bloating slows the player down (a little) */
if (p_ptr->food >= PY_FOOD_MAX) p_ptr->pspeed -= 10;
/* Searching slows the player down */
if (p_ptr->searching) p_ptr->pspeed -= 10;
/* In order to get a "nice" mana path druids need to ahve a 0 speed */
if ((p_ptr->druid_extra2 == CLASS_MANA_PATH) && (p_ptr->pspeed > 110))
p_ptr->pspeed = 110;
/* Display the speed (if needed) */
if (p_ptr->pspeed != old_speed) p_ptr->redraw |= (PR_SPEED);
/* Actual Modifier Bonuses (Un-inflate stat bonuses) */
p_ptr->to_a += ((int)(adj_dex_ta[p_ptr->stat_ind[A_DEX]]) - 128);
p_ptr->to_d += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
p_ptr->to_h += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
p_ptr->to_h += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
/* Displayed Modifier Bonuses (Un-inflate stat bonuses) */
p_ptr->dis_to_a += ((int)(adj_dex_ta[p_ptr->stat_ind[A_DEX]]) - 128);
p_ptr->dis_to_d += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
p_ptr->dis_to_h += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
p_ptr->dis_to_h += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
/* Redraw armor (if needed) */
if ((p_ptr->dis_ac != old_dis_ac) || (p_ptr->dis_to_a != old_dis_to_a))
{
/* Redraw */
p_ptr->redraw |= (PR_ARMOR);
/* Window stuff */
p_ptr->window |= (PW_PLAYER);
}
/* Obtain the "hold" value */
hold = adj_str_hold[p_ptr->stat_ind[A_STR]];
/* Examine the "current bow" */
o_ptr = &p_ptr->inventory[INVEN_BOW];
/* Assume not heavy */
p_ptr->heavy_shoot = FALSE;
/* It is hard to carholdry a heavy bow */
if (hold < o_ptr->weight / 10)
{
/* Hard to wield a heavy bow */
p_ptr->to_h += 2 * (hold - o_ptr->weight / 10);
p_ptr->dis_to_h += 2 * (hold - o_ptr->weight / 10);
/* Heavy Bow */
p_ptr->heavy_shoot = TRUE;
}
/* Take note of required "tval" for missiles */
switch (o_ptr->sval)
{
case SV_SLING:
{
p_ptr->tval_ammo = TV_SHOT;
break;
}
case SV_SHORT_BOW:
case SV_LONG_BOW:
{
p_ptr->tval_ammo = TV_ARROW;
break;
}
case SV_LIGHT_XBOW:
case SV_HEAVY_XBOW:
{
p_ptr->tval_ammo = TV_BOLT;
break;
}
}
/* Compute "extra shots" if needed */
if (o_ptr->k_idx && !p_ptr->heavy_shoot)
{
int archery = get_archery_skill();
if (archery != -1)
{
p_ptr->to_h_ranged += get_skill_scale(archery, 25);
p_ptr->num_fire += (get_skill(archery) / 16);
p_ptr->xtra_might += (get_skill(archery) / 25);
switch (archery)
{
case SKILL_SLING:
if (p_ptr->tval_ammo == TV_SHOT) p_ptr->xtra_might += get_skill(archery) / 30;
break;
case SKILL_BOW:
if (p_ptr->tval_ammo == TV_ARROW) p_ptr->xtra_might += get_skill(archery) / 30;
break;
case SKILL_XBOW:
if (p_ptr->tval_ammo == TV_BOLT) p_ptr->xtra_might += get_skill(archery) / 30;
break;
}
}
/* Add in the "bonus shots" */
p_ptr->num_fire += extra_shots;
/* Require at least one shot */
if (p_ptr->num_fire < 1) p_ptr->num_fire = 1;
}
if (PRACE_FLAG(PR1_XTRA_MIGHT_BOW) && p_ptr->tval_ammo == TV_ARROW)
p_ptr->xtra_might += 1;
if (PRACE_FLAG(PR1_XTRA_MIGHT_SLING) && p_ptr->tval_ammo == TV_SHOT)
p_ptr->xtra_might += 1;
if (PRACE_FLAG(PR1_XTRA_MIGHT_XBOW) && p_ptr->tval_ammo == TV_BOLT)
p_ptr->xtra_might += 1;
/* Examine the "current tool" */
o_ptr = &p_ptr->inventory[INVEN_TOOL];
/* Boost digging skill by tool weight */
if (o_ptr->k_idx && (o_ptr->tval == TV_DIGGING))
{
p_ptr->skill_dig += (o_ptr->weight / 10);
}
/* Examine the main weapon */
o_ptr = &p_ptr->inventory[INVEN_WIELD];
/* Assume not heavy */
p_ptr->heavy_wield = FALSE;
/* Normal weapons */
if (o_ptr->k_idx && !p_ptr->heavy_wield)
{
int str_index, dex_index;
int num = 0, wgt = 0, mul = 0, div = 0;
analyze_blow(&num, &wgt, &mul);
/* Enforce a minimum "weight" (tenth pounds) */
div = ((o_ptr->weight < wgt) ? wgt : o_ptr->weight);
/* Access the strength vs weight */
str_index = (adj_str_blow[p_ptr->stat_ind[A_STR]] * mul / div);
/* Maximal value */
if (str_index > 11) str_index = 11;
/* Index by dexterity */
dex_index = (adj_dex_blow[p_ptr->stat_ind[A_DEX]]);
/* Maximal value */
if (dex_index > 11) dex_index = 11;
/* Use the blows table */
p_ptr->num_blow = blows_table[str_index][dex_index];
/* Maximal value */
if (p_ptr->num_blow > num) p_ptr->num_blow = num;
/* Add in the "bonus blows" */
p_ptr->num_blow += extra_blows;
/* Special class bonus blows */
p_ptr->num_blow += p_ptr->lev * cp_ptr->extra_blows / 50;
/* Weapon specialization bonus blows */
if (get_weaponmastery_skill() != -1)
p_ptr->num_blow += get_skill_scale(get_weaponmastery_skill(), 2);
/* Bonus blows for plain weaponmastery skill */
p_ptr->num_blow += get_skill_scale(SKILL_MASTERY, 3);
/* Require at least one blow */
if (p_ptr->num_blow < 1) p_ptr->num_blow = 1;
}
/* Different calculation for bear form with empty hands */
else if ((p_ptr->melee_style == SKILL_HAND) && monk_empty_hands())
{
int plev = get_skill(SKILL_HAND);
p_ptr->num_blow = 0;
if (plev > 9) p_ptr->num_blow++;
if (plev > 19) p_ptr->num_blow++;
if (plev > 29) p_ptr->num_blow++;
if (plev > 34) p_ptr->num_blow++;
if (plev > 39) p_ptr->num_blow++;
if (plev > 44) p_ptr->num_blow++;
if (plev > 49) p_ptr->num_blow++;
if (monk_heavy_armor()) p_ptr->num_blow /= 2;
p_ptr->num_blow += 1 + extra_blows;
if (!monk_heavy_armor())
{
p_ptr->to_h += (plev / 3);
p_ptr->to_d += (plev / 3);
p_ptr->dis_to_h += (plev / 3);
p_ptr->dis_to_d += (plev / 3);
}
}
/* Monsters that only have their "natural" attacks */
else if (!r_info[p_ptr->body_monster].body_parts[BODY_WEAPON])
{
int str_index, dex_index;
int num = 0, wgt = 0, mul = 0;
monster_race *r_ptr = race_info_idx(p_ptr->body_monster, 0);
analyze_blow(&num, &wgt, &mul);
/* Access the strength vs weight */
str_index = (adj_str_blow[p_ptr->stat_ind[A_STR]] * mul / 3);
/* Maximal value */
if (str_index > 11) str_index = 11;
/* Index by dexterity */
dex_index = (adj_dex_blow[p_ptr->stat_ind[A_DEX]]);
/* Maximal value */
if (dex_index > 11) dex_index = 11;
/* Use the blows table */
p_ptr->num_blow = blows_table[str_index][dex_index];
/* Add in the "bonus blows" */
p_ptr->num_blow += extra_blows;
/* Maximal value */
if (p_ptr->num_blow > 4) p_ptr->num_blow = 4;
/* Require at least one blow */
if (p_ptr->num_blow < 1) p_ptr->num_blow = 1;
/* Limit as defined by monster body */
for (num = 0; num < p_ptr->num_blow; num++)
if (!r_ptr->blow[num].effect)
break;
p_ptr->num_blow = num;
}
/* Different calculation for monks with empty hands */
else if ((!p_ptr->body_monster) && (p_ptr->mimic_form == resolve_mimic_name("Bear")) && (p_ptr->melee_style == SKILL_BEAR))
{
int plev = get_skill(SKILL_BEAR);
p_ptr->num_blow = 0;
p_ptr->num_blow += 2 + (plev / 5) + extra_blows;
p_ptr->to_h -= (plev / 5);
p_ptr->dis_to_h -= (plev / 5);
p_ptr->to_d += (plev / 2);
p_ptr->dis_to_d += (plev / 2);
}
/* Assume okay */
p_ptr->icky_wield = FALSE;
monk_armour_aux = FALSE;
if (get_weaponmastery_skill() != -1)
{
int lev = get_skill(get_weaponmastery_skill());
p_ptr->to_h_melee += lev;
p_ptr->to_d_melee += lev / 2;
}
if (get_skill(SKILL_COMBAT))
{
int lev = get_skill_scale(SKILL_COMBAT, 10);
p_ptr->to_d += lev;
p_ptr->dis_to_d += lev;
}
if (get_skill(SKILL_DODGE))
{
/* Get the armor weight */
int cur_wgt = 0;
cur_wgt += p_ptr->inventory[INVEN_BODY].weight;
cur_wgt += p_ptr->inventory[INVEN_HEAD].weight;
cur_wgt += p_ptr->inventory[INVEN_ARM].weight;
cur_wgt += p_ptr->inventory[INVEN_OUTER].weight;
cur_wgt += p_ptr->inventory[INVEN_HANDS].weight;
cur_wgt += p_ptr->inventory[INVEN_FEET].weight;
/* Base dodge chance */
p_ptr->dodge_chance = get_skill_scale(SKILL_DODGE, 150) + get_skill(SKILL_HAND);
/* Armor weight bonus/penalty */
p_ptr->dodge_chance -= cur_wgt * 2;
/* Encumberance bonus/penalty */
p_ptr->dodge_chance = p_ptr->dodge_chance - (calc_total_weight() / 100);
/* Never below 0 */
if (p_ptr->dodge_chance < 0) p_ptr->dodge_chance = 0;
}
else
{
p_ptr->dodge_chance = 0;
}
/* Parse all the weapons */
i = 0;
while (p_ptr->body_parts[i] == INVEN_WIELD)
{
o_ptr = &p_ptr->inventory[INVEN_WIELD + i];
/* 2handed weapon and shield = less damage */
if (p_ptr->inventory[INVEN_WIELD + i].k_idx && p_ptr->inventory[INVEN_ARM + i].k_idx)
{
/* Extract the item flags */
object_flags(&p_ptr->inventory[INVEN_WIELD + i], &f1, &f2, &f3, &f4, &f5, &esp);
if (f4 & TR4_COULD2H)
{
int tmp;
/* Reduce the bonuses */
tmp = o_ptr->to_h / 2;
if (tmp < 0) tmp = -tmp;
p_ptr->to_h_melee -= tmp;
tmp = o_ptr->to_d / 2;
if (tmp < 0) tmp = -tmp;
tmp += (o_ptr->dd * o_ptr->ds) / 2;
p_ptr->to_d_melee -= tmp;
}
}
/* Priest weapon penalty for non-blessed edged weapons */
if (((forbid_non_blessed()) && (!p_ptr->bless_blade) &&
((o_ptr->tval == TV_AXE) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM))) && (o_ptr->k_idx))
{
/* Reduce the real bonuses */
p_ptr->to_h -= 15;
p_ptr->to_d -= 15;
/* Reduce the mental bonuses */
p_ptr->dis_to_h -= 15;
p_ptr->dis_to_d -= 15;
/* Icky weapon */
p_ptr->icky_wield = TRUE;
}
/* Sorcerer can't wield a weapon unless it's a mage staff */
if (get_skill(SKILL_SORCERY))
{
int malus = get_skill_scale(SKILL_SORCERY, 100);
if ((o_ptr->tval != TV_MSTAFF) && (o_ptr->k_idx))
{
/* Reduce the real bonuses */
p_ptr->to_h -= malus;
p_ptr->to_d -= malus;
/* Reduce the mental bonuses */
p_ptr->dis_to_h -= malus;
p_ptr->dis_to_d -= malus;
/* Icky weapon */
p_ptr->icky_wield = TRUE;
}
else
{
/* Reduce the real bonuses */
p_ptr->to_h -= malus / 10;
p_ptr->to_d -= malus / 10;
/* Reduce the mental bonuses */
p_ptr->dis_to_h -= malus / 10;
p_ptr->dis_to_d -= malus / 10;
}
}
/* Check next weapon */
i++;
}
if (monk_heavy_armor())
{
monk_armour_aux = TRUE;
}
/* Affect Skill -- stealth (bonus one) */
p_ptr->skill_stl += 1;
/* Affect Skill -- disarming (DEX and INT) */
p_ptr->skill_dis += adj_dex_dis[p_ptr->stat_ind[A_DEX]];
p_ptr->skill_dis += adj_int_dis[p_ptr->stat_ind[A_INT]];
/* Affect Skill -- magic devices (INT) */
p_ptr->skill_dev += get_skill_scale(SKILL_DEVICE, 20);
/* Affect Skill -- saving throw (WIS) */
p_ptr->skill_sav += adj_wis_sav[p_ptr->stat_ind[A_WIS]];
/* Affect Skill -- digging (STR) */
p_ptr->skill_dig += adj_str_dig[p_ptr->stat_ind[A_STR]];
/* Affect Skill -- disarming (skill) */
p_ptr->skill_dis += (get_skill_scale(SKILL_DISARMING, 75));
/* Affect Skill -- magic devices (skill) */
p_ptr->skill_dev += (get_skill_scale(SKILL_DEVICE, 150));
/* Affect Skill -- saving throw (skill and level) */
p_ptr->skill_sav += (get_skill_scale(SKILL_SPIRITUALITY, 75));
/* Affect Skill -- stealth (skill) */
p_ptr->skill_stl += (get_skill_scale(SKILL_STEALTH, 25));
/* Affect Skill -- search ability (Sneakiness skill) */
p_ptr->skill_srh += (get_skill_scale(SKILL_SNEAK, 35));
/* Affect Skill -- search frequency (Sneakiness skill) */
p_ptr->skill_fos += (get_skill_scale(SKILL_SNEAK, 25));
/* Affect Skill -- combat (Combat skill + mastery) */
p_ptr->skill_thn += (50 * (((7 * get_skill(p_ptr->melee_style)) + (3 * get_skill(SKILL_COMBAT))) / 10) / 10);
/* Affect Skill -- combat (shooting) (Level, by Class) */
p_ptr->skill_thb += (50 * (((7 * get_skill(SKILL_ARCHERY)) + (3 * get_skill(SKILL_COMBAT))) / 10) / 10);
/* Affect Skill -- combat (throwing) (Level) */
p_ptr->skill_tht += (50 * p_ptr->lev / 10);
/* Limit Skill -- stealth from 0 to 30 */
if (p_ptr->skill_stl > 30) p_ptr->skill_stl = 30;
if (p_ptr->skill_stl < 0) p_ptr->skill_stl = 0;
/* Limit Skill -- digging from 1 up */
if (p_ptr->skill_dig < 1) p_ptr->skill_dig = 1;
if ((p_ptr->anti_magic) && (p_ptr->skill_sav < 95)) p_ptr->skill_sav = 95;
/* Hack -- handle "xtra" mode */
if (character_xtra) return;
/* Take note when "heavy bow" changes */
if (p_ptr->old_heavy_shoot != p_ptr->heavy_shoot)
{
if (silent)
{
/* do nothing */
}
/* Message */
else if (p_ptr->heavy_shoot)
{
msg_print("You have trouble wielding such a heavy bow.");
}
else if (p_ptr->inventory[INVEN_BOW].k_idx)
{
msg_print("You have no trouble wielding your bow.");
}
else
{
msg_print("You feel relieved to put down your heavy bow.");
}
/* Save it */
p_ptr->old_heavy_shoot = p_ptr->heavy_shoot;
}
/* Take note when "heavy weapon" changes */
if (p_ptr->old_heavy_wield != p_ptr->heavy_wield)
{
if (silent)
{
/* do nothing */
}
/* Message */
else if (p_ptr->heavy_wield)
{
msg_print("You have trouble wielding such a heavy weapon.");
}
else if (p_ptr->inventory[INVEN_WIELD].k_idx)
{
msg_print("You have no trouble wielding your weapon.");
}
else
{
msg_print("You feel relieved to put down your heavy weapon.");
}
/* Save it */
p_ptr->old_heavy_wield = p_ptr->heavy_wield;
}
/* Take note when "illegal weapon" changes */
if (p_ptr->old_icky_wield != p_ptr->icky_wield)
{
if (silent)
{
/* do nothing */
}
/* Message */
else if (p_ptr->icky_wield)
{
msg_print("You do not feel comfortable with your weapon.");
}
else if (p_ptr->inventory[INVEN_WIELD].k_idx)
{
msg_print("You feel comfortable with your weapon.");
}
else
{
msg_print("You feel more comfortable after removing your weapon.");
}
/* Save it */
p_ptr->old_icky_wield = p_ptr->icky_wield;
}
if (monk_armour_aux != monk_notify_aux)
{
if ((p_ptr->melee_style != SKILL_HAND) || silent)
{
/* do nothing */
}
else if (monk_heavy_armor())
msg_print("The weight of your armor disrupts your balance.");
else
msg_print("You regain your balance.");
monk_notify_aux = monk_armour_aux;
}
/* Resist lite & senseible lite negates one an other */
if (p_ptr->resist_lite && p_ptr->sensible_lite)
{
p_ptr->resist_lite = p_ptr->sensible_lite = FALSE;
}
/* resistance to fire cancel sensibility to fire */
if (p_ptr->resist_fire || p_ptr->oppose_fire || p_ptr->immune_fire)
p_ptr->sensible_fire = FALSE;
/* Minimum saving throw */
if(p_ptr->skill_sav <= 10)
p_ptr->skill_sav = 10;
else
p_ptr->skill_sav += 10;
/* Let the scripts do what they need */
process_hooks(HOOK_CALC_BONUS_END, "(d)", silent);
}
/*
* Handle "p_ptr->notice"
*/
void notice_stuff(void)
{
/* Notice stuff */
if (!p_ptr->notice) return;
/* Combine the pack */
if (p_ptr->notice & (PN_COMBINE))
{
p_ptr->notice &= ~(PN_COMBINE);
combine_pack();
}
/* Reorder the pack */
if (p_ptr->notice & (PN_REORDER))
{
p_ptr->notice &= ~(PN_REORDER);
reorder_pack();
}
}
/*
* Handle "p_ptr->update"
*/
void update_stuff(void)
{
/* Update stuff */
if (!p_ptr->update) return;
if (p_ptr->update & (PU_BODY))
{
p_ptr->update &= ~(PU_BODY);
calc_body();
}
if (p_ptr->update & (PU_BONUS))
{
/* Ok now THAT is an ugly hack */
p_ptr->update &= ~(PU_POWERS);
calc_powers();
p_ptr->update &= ~(PU_BONUS);
calc_bonuses(FALSE);
}
if (p_ptr->update & (PU_TORCH))
{
p_ptr->update &= ~(PU_TORCH);
calc_torch();
}
if (p_ptr->update & (PU_HP))
{
p_ptr->update &= ~(PU_HP);
calc_hitpoints();
}
if (p_ptr->update & (PU_SANITY))
{
p_ptr->update &= ~(PU_SANITY);
calc_sanity();
}
if (p_ptr->update & (PU_MANA))
{
p_ptr->update &= ~(PU_MANA);
calc_mana();
}
if (p_ptr->update & (PU_SPELLS))
{
p_ptr->update &= ~(PU_SPELLS);
calc_spells();
}
if (p_ptr->update & (PU_POWERS))
{
p_ptr->update &= ~(PU_POWERS);
calc_powers();
}
/* Character is not ready yet, no screen updates */
if (!character_generated) return;
/* Character is in "icky" mode, no screen updates */
if (character_icky) return;
if (p_ptr->update & (PU_UN_VIEW))
{
p_ptr->update &= ~(PU_UN_VIEW);
forget_view();
}
if (p_ptr->update & (PU_VIEW))
{
p_ptr->update &= ~(PU_VIEW);
update_view();
}
if (p_ptr->update & (PU_FLOW))
{
p_ptr->update &= ~(PU_FLOW);
update_flow();
}
if (p_ptr->update & (PU_DISTANCE))
{
p_ptr->update &= ~(PU_DISTANCE);
p_ptr->update &= ~(PU_MONSTERS);
update_monsters(TRUE);
}
if (p_ptr->update & (PU_MONSTERS))
{
p_ptr->update &= ~(PU_MONSTERS);
update_monsters(FALSE);
}
if (p_ptr->update & (PU_MON_LITE))
{
p_ptr->update &= ~(PU_MON_LITE);
if (monster_lite) update_mon_lite();
}
}
/*
* Handle "p_ptr->redraw"
*/
void redraw_stuff(void)
{
/* Redraw stuff */
if (!p_ptr->redraw) return;
/* Character is not ready yet, no screen updates */
if (!character_generated) return;
/* Character is in "icky" mode, no screen updates */
if (character_icky) return;
/* Should we tell lua to redisplay too ? */
process_hooks(HOOK_REDRAW, "()");
/* Hack -- clear the screen */
if (p_ptr->redraw & (PR_WIPE))
{
p_ptr->redraw &= ~(PR_WIPE);
msg_print(NULL);
Term_clear();
}
if (p_ptr->redraw & (PR_MAP))
{
p_ptr->redraw &= ~(PR_MAP);
prt_map();
}
if (p_ptr->redraw & (PR_BASIC))
{
p_ptr->redraw &= ~(PR_BASIC);
p_ptr->redraw &= ~(PR_MISC | PR_TITLE | PR_STATS);
p_ptr->redraw &= ~(PR_LEV | PR_EXP | PR_GOLD);
p_ptr->redraw &= ~(PR_ARMOR | PR_HP | PR_MANA | PR_PIETY | PR_MH);
p_ptr->redraw &= ~(PR_DEPTH | PR_HEALTH);
prt_frame_basic();
}
if (p_ptr->redraw & (PR_MISC))
{
p_ptr->redraw &= ~(PR_MISC);
prt_field(rp_ptr->title + rp_name, ROW_RACE, COL_RACE);
prt_field(spp_ptr->title + c_name, ROW_CLASS, COL_CLASS);
}
if (p_ptr->redraw & (PR_TITLE))
{
p_ptr->redraw &= ~(PR_TITLE);
prt_title();
}
if (p_ptr->redraw & (PR_LEV))
{
p_ptr->redraw &= ~(PR_LEV);
prt_level();
}
if (p_ptr->redraw & (PR_EXP))
{
p_ptr->redraw &= ~(PR_EXP);
prt_exp();
}
if (p_ptr->redraw & (PR_STATS))
{
p_ptr->redraw &= ~(PR_STATS);
prt_stat(A_STR);
prt_stat(A_INT);
prt_stat(A_WIS);
prt_stat(A_DEX);
prt_stat(A_CON);
prt_stat(A_CHR);
}
if (p_ptr->redraw & (PR_ARMOR))
{
p_ptr->redraw &= ~(PR_ARMOR);
prt_ac();
}
if (p_ptr->redraw & (PR_HP))
{
p_ptr->redraw &= ~(PR_HP);
prt_hp();
}
if (p_ptr->redraw & (PR_MANA))
{
p_ptr->redraw &= ~(PR_MANA);
prt_sp();
}
if (p_ptr->redraw & (PR_PIETY))
{
p_ptr->redraw &= ~(PR_PIETY);
prt_piety();
}
if (p_ptr->redraw & (PR_MH))
{
p_ptr->redraw &= ~(PR_MH);
prt_mh();
}
if (p_ptr->redraw & (PR_GOLD))
{
p_ptr->redraw &= ~(PR_GOLD);
prt_gold();
}
if (p_ptr->redraw & (PR_DEPTH))
{
p_ptr->redraw &= ~(PR_DEPTH);
prt_depth();
}
if (p_ptr->redraw & (PR_HEALTH))
{
p_ptr->redraw &= ~(PR_HEALTH);
health_redraw();
}
if (p_ptr->redraw & (PR_EXTRA))
{
p_ptr->redraw &= ~(PR_EXTRA);
p_ptr->redraw &= ~(PR_CUT | PR_STUN);
p_ptr->redraw &= ~(PR_HUNGER);
p_ptr->redraw &= ~(PR_BLIND | PR_CONFUSED);
p_ptr->redraw &= ~(PR_AFRAID | PR_POISONED);
p_ptr->redraw &= ~(PR_STATE | PR_SPEED | PR_STUDY | PR_SANITY);
prt_frame_extra();
}
if (p_ptr->redraw & (PR_CUT))
{
p_ptr->redraw &= ~(PR_CUT);
prt_cut();
}
if (p_ptr->redraw & (PR_STUN))
{
p_ptr->redraw &= ~(PR_STUN);
prt_stun();
}
if (p_ptr->redraw & (PR_HUNGER))
{
p_ptr->redraw &= ~(PR_HUNGER);
prt_hunger();
}
if (p_ptr->redraw & (PR_BLIND))
{
p_ptr->redraw &= ~(PR_BLIND);
prt_blind();
}
if (p_ptr->redraw & (PR_CONFUSED))
{
p_ptr->redraw &= ~(PR_CONFUSED);
prt_confused();
}
if (p_ptr->redraw & (PR_AFRAID))
{
p_ptr->redraw &= ~(PR_AFRAID);
prt_afraid();
}
if (p_ptr->redraw & (PR_POISONED))
{
p_ptr->redraw &= ~(PR_POISONED);
prt_poisoned();
}
if (p_ptr->redraw & (PR_DTRAP))
{
p_ptr->redraw &= ~(PR_DTRAP);
prt_dtrap();
}
if (p_ptr->redraw & (PR_STATE))
{
p_ptr->redraw &= ~(PR_STATE);
prt_state();
}
if (p_ptr->redraw & (PR_SPEED))
{
p_ptr->redraw &= ~(PR_SPEED);
prt_speed();
}
if (p_ptr->redraw & (PR_STUDY))
{
p_ptr->redraw &= ~(PR_STUDY);
prt_study();
}
if (p_ptr->redraw & (PR_SANITY))
{
p_ptr->redraw &= ~(PR_SANITY);
prt_sane();
}
}
/*
* Handle "p_ptr->window"
*/
void window_stuff(void)
{
int j;
u32b mask = 0L;
/* Nothing to do */
if (!p_ptr->window) return;
/* Scan windows */
for (j = 0; j < 8; j++)
{
/* Save usable flags */
if (angband_term[j]) mask |= window_flag[j];
}
/* Apply usable flags */
p_ptr->window &= mask;
/* Nothing to do */
if (!p_ptr->window) return;
/* Display p_ptr->inventory */
if (p_ptr->window & (PW_INVEN))
{
p_ptr->window &= ~(PW_INVEN);
fix_inven();
}
/* Display equipment */
if (p_ptr->window & (PW_EQUIP))
{
p_ptr->window &= ~(PW_EQUIP);
fix_equip();
}
/* Display player */
if (p_ptr->window & (PW_PLAYER))
{
p_ptr->window &= ~(PW_PLAYER);
fix_player();
}
/* Display monster list */
if (p_ptr->window & (PW_M_LIST))
{
p_ptr->window &= ~(PW_M_LIST);
fix_m_list();
}
/* Display overhead view */
if (p_ptr->window & (PW_MESSAGE))
{
p_ptr->window &= ~(PW_MESSAGE);
fix_message();
}
/* Display overhead view */
if (p_ptr->window & (PW_IRC))
{
p_ptr->window &= ~(PW_IRC);
fix_irc_message();
}
/* Display overhead view */
if (p_ptr->window & (PW_OVERHEAD))
{
p_ptr->window &= ~(PW_OVERHEAD);
fix_overhead();
}
/* Display monster recall */
if (p_ptr->window & (PW_MONSTER))
{
p_ptr->window &= ~(PW_MONSTER);
fix_monster();
}
/* Display object recall */
if (p_ptr->window & (PW_OBJECT))
{
p_ptr->window &= ~(PW_OBJECT);
fix_object();
}
}
/*
* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window"
*/
void handle_stuff(void)
{
/* Update stuff */
if (p_ptr->update) update_stuff();
/* Redraw stuff */
if (p_ptr->redraw) redraw_stuff();
/* Window stuff */
if (p_ptr->window) window_stuff();
}
bool monk_empty_hands(void)
{
int i;
object_type *o_ptr;
if (p_ptr->melee_style != SKILL_HAND) return FALSE;
i = 0;
while (p_ptr->body_parts[i] == INVEN_WIELD)
{
o_ptr = &p_ptr->inventory[INVEN_WIELD + i];
if (o_ptr->k_idx) return FALSE;
i++;
}
return TRUE;
}
bool monk_heavy_armor(void)
{
u16b monk_arm_wgt = 0;
if (p_ptr->melee_style != SKILL_HAND) return FALSE;
/* Weight the armor */
monk_arm_wgt += p_ptr->inventory[INVEN_BODY].weight;
monk_arm_wgt += p_ptr->inventory[INVEN_HEAD].weight;
monk_arm_wgt += p_ptr->inventory[INVEN_ARM].weight;
monk_arm_wgt += p_ptr->inventory[INVEN_OUTER].weight;
monk_arm_wgt += p_ptr->inventory[INVEN_HANDS].weight;
monk_arm_wgt += p_ptr->inventory[INVEN_FEET].weight;
return (monk_arm_wgt > (100 + (get_skill(SKILL_HAND) * 4))) ;
}
static int get_artifact_idx(int level)
{
int count = 0, i;
bool OK = FALSE;
while (count < 1000)
{
artifact_type *a_ptr;
count++;
i = randint(max_a_idx - 1);
a_ptr = &a_info[i];
if (!a_ptr->tval) continue;
/* It is found/lost */
if (a_ptr->cur_num) continue;
/* OoD */
if (a_ptr->level > level) continue;
/* Avoid granting SPECIAL_GENE artifacts */
if (a_ptr->flags4 & TR4_SPECIAL_GENE) continue;
OK = TRUE;
break;
}
/* No matches found */
if (OK == FALSE)
{
#if 0 /* pelpel */
/* XXX XXX XXX Grant the Phial */
i = 1;
#endif /* pelpel */
/* Grant a randart */
i = 0;
}
return i;
}
/* Chose a fate */
void gain_fate(byte fate)
{
int i;
int level;
for (i = 0; i < MAX_FATES; i++)
{
if (!fates[i].fate)
{
fates[i].level = 0;
cmsg_print(TERM_VIOLET, "More of your prophecy has been unearthed!");
cmsg_print(TERM_VIOLET, "You should see a soothsayer quickly.");
if (fate)
fates[i].fate = fate;
else
/* If lucky (current luck > 0) avoid death fate */
switch (rand_int(p_ptr->luck_cur > 0 ? 17 : 18))
{
case 6:
case 2:
case 3:
case 7:
case 8:
case 9:
case 13:
fates[i].fate = FATE_FIND_O;
break;
case 1:
case 4:
case 5:
case 10:
case 11:
case 12:
case 14:
fates[i].fate = FATE_FIND_R;
break;
case 15:
case 16:
fates[i].fate = FATE_FIND_A;
break;
case 17:
fates[i].fate = FATE_DIE;
break;
case 0:
{
/* The deepest the better */
int chance = dun_level / 4;
/* No more than 1/2 chances */
if (chance > 50) chance = 50;
/* It's HARD to get now */
if (magik(chance))
{
fates[i].fate = FATE_NO_DIE_MORTAL;
}
else
{
fates[i].fate = FATE_FIND_O;
}
break;
}
}
switch (fates[i].fate)
{
case FATE_FIND_O:
{
while (TRUE)
{
object_kind *k_ptr;
obj_theme theme;
/* No themes */
theme.treasure = 100;
theme.combat = 100;
theme.magic = 100;
theme.tools = 100;
init_match_theme(theme);
/* Apply restriction */
get_obj_num_hook = kind_is_legal;
/* Rebuild allocation table */
get_obj_num_prep();
fates[i].o_idx = get_obj_num(max_dlv[dungeon_type] + randint(10));
/* Invalidate the cached allocation table */
alloc_kind_table_valid = FALSE;
k_ptr = &k_info[fates[i].o_idx];
if (!(k_ptr->flags3 & TR3_INSTA_ART) && !(k_ptr->flags3 & TR3_NORM_ART)) break;
}
level = rand_range(max_dlv[dungeon_type] - 20, max_dlv[dungeon_type] + 20);
fates[i].level = (level < 1) ? 1 : (level > 98) ? 98 : level;
fates[i].serious = rand_int(2);
fates[i].know = FALSE;
if (wizard) msg_format("New fate : Find object %d on level %d", fates[i].o_idx, fates[i].level);
break;
}
case FATE_FIND_R:
/* Prepare allocation table */
get_mon_num_prep();
fates[i].r_idx = get_mon_num(max_dlv[dungeon_type] + randint(10));
level = rand_range(max_dlv[dungeon_type] - 20, max_dlv[dungeon_type] + 20);
fates[i].level = (level < 1) ? 1 : (level > 98) ? 98 : level;
fates[i].serious = rand_int(2);
fates[i].know = FALSE;
if (wizard) msg_format("New fate : Meet monster %d on level %d", fates[i].r_idx, fates[i].level);
break;
case FATE_FIND_A:
fates[i].a_idx = get_artifact_idx(max_dlv[dungeon_type] + randint(10));
level = rand_range(max_dlv[dungeon_type] - 20, max_dlv[dungeon_type] + 20);
fates[i].level = (level < 1) ? 1 : (level > 98) ? 98 : level;
fates[i].serious = TRUE;
fates[i].know = FALSE;
if (wizard) msg_format("New fate : Find artifact %d on level %d", fates[i].a_idx, fates[i].level);
break;
case FATE_DIE:
level = rand_range(max_dlv[dungeon_type] - 20, max_dlv[dungeon_type] + 20);
fates[i].level = (level < 1) ? 1 : (level > 98) ? 98 : level;
fates[i].serious = TRUE;
fates[i].know = FALSE;
if ((wizard) || (p_ptr->precognition)) msg_format("New fate : Death on level %d", fates[i].level);
break;
case FATE_NO_DIE_MORTAL:
fates[i].serious = TRUE;
p_ptr->no_mortal = TRUE;
if ((wizard) || (p_ptr->precognition)) msg_format("New fate : Never to die by the hand of a mortal being.");
break;
}
break;
}
}
}
void fate_desc(char *desc, int fate)
{
char buf[120];
if (fates[fate].serious)
{
strcpy(desc, "You are fated to ");
}
else
{
strcpy(desc, "You may ");
}
switch (fates[fate].fate)
{
case FATE_FIND_O:
{
object_type *o_ptr, forge;
char o_name[80];
o_ptr = &forge;
object_prep(o_ptr, fates[fate].o_idx);
object_desc_store(o_name, o_ptr, 1, 0);
sprintf(buf, "find %s on level %d.", o_name, fates[fate].level);
strcat(desc, buf);
break;
}
case FATE_FIND_A:
{
object_type *q_ptr, forge;
char o_name[80];
artifact_type *a_ptr = &a_info[fates[fate].a_idx];
int I_kind;
/* Failed artefact allocation XXX XXX XXX */
if (fates[fate].a_idx == 0)
{
strcpy(o_name, "something special");
}
/* Legal artefacts */
else
{
/* Get local object */
q_ptr = &forge;
/* Wipe the object */
object_wipe(q_ptr);
/* Acquire the "kind" index */
I_kind = lookup_kind(a_ptr->tval, a_ptr->sval);
/* Create the artifact */
object_prep(q_ptr, I_kind);
/* Save the name */
q_ptr->name1 = fates[fate].a_idx;
/* Extract the fields */
q_ptr->pval = a_ptr->pval;
q_ptr->ac = a_ptr->ac;
q_ptr->dd = a_ptr->dd;
q_ptr->ds = a_ptr->ds;
q_ptr->to_a = a_ptr->to_a;
q_ptr->to_h = a_ptr->to_h;
q_ptr->to_d = a_ptr->to_d;
q_ptr->weight = a_ptr->weight;
/* Hack -- acquire "cursed" flag */
if (a_ptr->flags3 & (TR3_CURSED)) q_ptr->ident |= (IDENT_CURSED);
random_artifact_resistance(q_ptr);
object_desc_store(o_name, q_ptr, 1, 0);
}
sprintf(buf, "find %s on level %d.", o_name, fates[fate].level);
strcat(desc, buf);
break;
}
case FATE_FIND_R:
{
char m_name[80];
monster_race_desc(m_name, fates[fate].r_idx, 0);
sprintf(buf, "meet %s on level %d.", m_name, fates[fate].level);
strcat(desc, buf);
break;
}
case FATE_DIE:
{
sprintf(buf, "die on level %d.", fates[fate].level);
strcat(desc, buf);
break;
}
case FATE_NO_DIE_MORTAL:
{
strcat(desc, "never to die by the hand of a mortal being.");
break;
}
}
}
void dump_fates(FILE *outfile)
{
int i;
char buf[120];
if (!outfile) return;
for (i = 0; i < MAX_FATES; i++)
{
if ((fates[i].fate) && (fates[i].know))
{
fate_desc(buf, i);
fprintf(outfile, "%s\n", buf);
}
}
}
/*
* Return a luck number between a certain range
*/
int luck(int min, int max)
{
int luck = p_ptr->luck_cur;
int range = max - min;
if (luck < -30) luck = -30;
if (luck > 30) luck = 30;
luck += 30;
luck *= range;
luck /= 60;
return (luck + min);
}
|