Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 3058 lines (2818 sloc) 80.722 kb
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
/* SCCS Id: @(#)apply.c 3.4 2003/11/18 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */

#include "hack.h"
#include "edog.h"

#ifdef OVLB

static const char tools[] = { TOOL_CLASS, WEAPON_CLASS, WAND_CLASS, 0 };
static const char tools_too[] = { ALL_CLASSES, TOOL_CLASS, POTION_CLASS,
WEAPON_CLASS, WAND_CLASS, GEM_CLASS, 0 };

#ifdef TOURIST
STATIC_DCL int FDECL(use_camera, (struct obj *));
#endif
STATIC_DCL int FDECL(use_towel, (struct obj *));
STATIC_DCL boolean FDECL(its_dead, (int,int,int *));
STATIC_DCL int FDECL(use_stethoscope, (struct obj *));
STATIC_DCL void FDECL(use_whistle, (struct obj *));
STATIC_DCL void FDECL(use_magic_whistle, (struct obj *));
STATIC_DCL void FDECL(use_leash, (struct obj *));
STATIC_DCL int FDECL(use_mirror, (struct obj *));
STATIC_DCL void FDECL(use_bell, (struct obj **));
STATIC_DCL void FDECL(use_candelabrum, (struct obj *));
STATIC_DCL void FDECL(use_candle, (struct obj **));
STATIC_DCL void FDECL(use_lamp, (struct obj *));
STATIC_DCL void FDECL(light_cocktail, (struct obj *));
STATIC_DCL void FDECL(use_tinning_kit, (struct obj *));
STATIC_DCL void FDECL(use_figurine, (struct obj **));
STATIC_DCL void FDECL(use_grease, (struct obj *));
STATIC_DCL void FDECL(use_trap, (struct obj *));
STATIC_DCL void FDECL(use_stone, (struct obj *));
STATIC_PTR int NDECL(set_trap); /* occupation callback */
STATIC_DCL int FDECL(use_whip, (struct obj *));
STATIC_DCL int FDECL(use_pole, (struct obj *));
STATIC_DCL int FDECL(use_cream_pie, (struct obj *));
STATIC_DCL int FDECL(use_grapple, (struct obj *));
STATIC_DCL int FDECL(do_break_wand, (struct obj *));
STATIC_DCL boolean FDECL(figurine_location_checks,
(struct obj *, coord *, BOOLEAN_P));
STATIC_DCL boolean NDECL(uhave_graystone);
STATIC_DCL void FDECL(add_class, (char *, CHAR_P));

#ifdef AMIGA
void FDECL( amii_speaker, ( struct obj *, char *, int ) );
#endif

static const char no_elbow_room[] = "don't have enough elbow-room to maneuver.";

#ifdef TOURIST
STATIC_OVL int
use_camera(obj)
struct obj *obj;
{
register struct monst *mtmp;

if(Underwater) {
pline("Using your camera underwater would void the warranty.");
return(0);
}
if(!getdir((char *)0)) return(0);

if (obj->spe <= 0) {
pline(nothing_happens);
return (1);
}
consume_obj_charge(obj, TRUE);

if (obj->cursed && !rn2(2)) {
(void) zapyourself(obj, TRUE);
} else if (u.uswallow) {
You("take a picture of %s %s.", s_suffix(mon_nam(u.ustuck)),
mbodypart(u.ustuck, STOMACH));
} else if (u.dz) {
You("take a picture of the %s.",
(u.dz > 0) ? surface(u.ux,u.uy) : ceiling(u.ux,u.uy));
} else if (!u.dx && !u.dy) {
(void) zapyourself(obj, TRUE);
} else if ((mtmp = bhit(u.dx, u.dy, COLNO, FLASHED_LIGHT,
(int FDECL((*),(MONST_P,OBJ_P)))0,
(int FDECL((*),(OBJ_P,OBJ_P)))0,
obj)) != 0) {
obj->ox = u.ux, obj->oy = u.uy;
(void) flash_hits_mon(mtmp, obj);
}
return 1;
}
#endif

STATIC_OVL int
use_towel(obj)
struct obj *obj;
{
if(!freehand()) {
You("have no free %s!", body_part(HAND));
return 0;
} else if (obj->owornmask) {
You("cannot use it while you're wearing it!");
return 0;
} else if (obj->cursed) {
long old;
switch (rn2(3)) {
case 2:
old = Glib;
Glib += rn1(10, 3);
Your("%s %s!", makeplural(body_part(HAND)),
(old ? "are filthier than ever" : "get slimy"));
return 1;
case 1:
if (!ublindf) {
old = u.ucreamed;
u.ucreamed += rn1(10, 3);
pline("Yecch! Your %s %s gunk on it!", body_part(FACE),
(old ? "has more" : "now has"));
make_blinded(Blinded + (long)u.ucreamed - old, TRUE);
} else {
const char *what = (ublindf->otyp == LENSES) ?
"lenses" : "blindfold";
if (ublindf->cursed) {
You("push your %s %s.", what,
rn2(2) ? "cock-eyed" : "crooked");
} else {
struct obj *saved_ublindf = ublindf;
You("push your %s off.", what);
Blindf_off(ublindf);
dropx(saved_ublindf);
}
}
return 1;
case 0:
break;
}
}

if (Glib) {
Glib = 0;
You("wipe off your %s.", makeplural(body_part(HAND)));
return 1;
} else if(u.ucreamed) {
Blinded -= u.ucreamed;
u.ucreamed = 0;

if (!Blinded) {
pline("You've got the glop off.");
Blinded = 1;
make_blinded(0L,TRUE);
} else {
Your("%s feels clean now.", body_part(FACE));
}
return 1;
}

Your("%s and %s are already clean.",
body_part(FACE), makeplural(body_part(HAND)));

return 0;
}

/* maybe give a stethoscope message based on floor objects */
STATIC_OVL boolean
its_dead(rx, ry, resp)
int rx, ry, *resp;
{
struct obj *otmp;
struct trap *ttmp;

if (!can_reach_floor()) return FALSE;

/* additional stethoscope messages from jyoung@apanix.apana.org.au */
if (Hallucination && sobj_at(CORPSE, rx, ry)) {
/* (a corpse doesn't retain the monster's sex,
so we're forced to use generic pronoun here) */
You_hear("a voice say, \"It's dead, Jim.\"");
*resp = 1;
return TRUE;
} else if (Role_if(PM_HEALER) && ((otmp = sobj_at(CORPSE, rx, ry)) != 0 ||
(otmp = sobj_at(STATUE, rx, ry)) != 0)) {
/* possibly should check uppermost {corpse,statue} in the pile
if both types are present, but it's not worth the effort */
if (vobj_at(rx, ry)->otyp == STATUE) otmp = vobj_at(rx, ry);
if (otmp->otyp == CORPSE) {
You("determine that %s unfortunate being is dead.",
(rx == u.ux && ry == u.uy) ? "this" : "that");
} else {
ttmp = t_at(rx, ry);
pline("%s appears to be in %s health for a statue.",
The(mons[otmp->corpsenm].mname),
(ttmp && ttmp->ttyp == STATUE_TRAP) ?
"extraordinary" : "excellent");
}
return TRUE;
}
return FALSE;
}

static const char hollow_str[] = "a hollow sound. This must be a secret %s!";

/* Strictly speaking it makes no sense for usage of a stethoscope to
not take any time; however, unless it did, the stethoscope would be
almost useless. As a compromise, one use per turn is free, another
uses up the turn; this makes curse status have a tangible effect. */
STATIC_OVL int
use_stethoscope(obj)
register struct obj *obj;
{
static long last_used_move = -1;
static short last_used_movement = 0;
struct monst *mtmp;
struct rm *lev;
int rx, ry, res;
boolean interference = (u.uswallow && is_whirly(u.ustuck->data) &&
!rn2(Role_if(PM_HEALER) ? 10 : 3));

if (nohands(youmonst.data)) { /* should also check for no ears and/or deaf */
You("have no hands!"); /* not `body_part(HAND)' */
return 0;
} else if (!freehand()) {
You("have no free %s.", body_part(HAND));
return 0;
}
if (!getdir((char *)0)) return 0;

res = (moves == last_used_move) &&
(youmonst.movement == last_used_movement);
last_used_move = moves;
last_used_movement = youmonst.movement;

#ifdef STEED
if (u.usteed && u.dz > 0) {
if (interference) {
pline("%s interferes.", Monnam(u.ustuck));
mstatusline(u.ustuck);
} else
mstatusline(u.usteed);
return res;
} else
#endif
if (u.uswallow && (u.dx || u.dy || u.dz)) {
mstatusline(u.ustuck);
return res;
} else if (u.uswallow && interference) {
pline("%s interferes.", Monnam(u.ustuck));
mstatusline(u.ustuck);
return res;
} else if (u.dz) {
if (Underwater)
You_hear("faint splashing.");
else if (u.dz < 0 || !can_reach_floor())
You_cant("reach the %s.",
(u.dz > 0) ? surface(u.ux,u.uy) : ceiling(u.ux,u.uy));
else if (its_dead(u.ux, u.uy, &res))
; /* message already given */
else if (Is_stronghold(&u.uz))
You_hear("the crackling of hellfire.");
else
pline_The("%s seems healthy enough.", surface(u.ux,u.uy));
return res;
} else if (obj->cursed && !rn2(2)) {
You_hear("your heart beat.");
return res;
}
if (Stunned || (Confusion && !rn2(5))) confdir();
if (!u.dx && !u.dy) {
ustatusline();
return res;
}
rx = u.ux + u.dx; ry = u.uy + u.dy;
if (!isok(rx,ry)) {
You_hear("a faint typing noise.");
return 0;
}
if ((mtmp = m_at(rx,ry)) != 0) {
mstatusline(mtmp);
if (mtmp->mundetected) {
mtmp->mundetected = 0;
if (cansee(rx,ry)) newsym(mtmp->mx,mtmp->my);
}
if (!canspotmon(mtmp))
map_invisible(rx,ry);
return res;
}
if (glyph_is_invisible(levl[rx][ry].glyph)) {
unmap_object(rx, ry);
newsym(rx, ry);
pline_The("invisible monster must have moved.");
}
lev = &levl[rx][ry];
switch(lev->typ) {
case SDOOR:
You_hear(hollow_str, "door");
cvt_sdoor_to_door(lev); /* ->typ = DOOR */
if (Blind) feel_location(rx,ry);
else newsym(rx,ry);
return res;
case SCORR:
You_hear(hollow_str, "passage");
lev->typ = CORR;
unblock_point(rx,ry);
if (Blind) feel_location(rx,ry);
else newsym(rx,ry);
return res;
}

if (!its_dead(rx, ry, &res))
You("hear nothing special."); /* not You_hear() */
return res;
}

static const char whistle_str[] = "produce a %s whistling sound.";

STATIC_OVL void
use_whistle(obj)
struct obj *obj;
{
You(whistle_str, obj->cursed ? "shrill" : "high");
wake_nearby();
}

STATIC_OVL void
use_magic_whistle(obj)
struct obj *obj;
{
register struct monst *mtmp, *nextmon;

if(obj->cursed && !rn2(2)) {
You("produce a high-pitched humming noise.");
wake_nearby();
} else {
int pet_cnt = 0;
You(whistle_str, Hallucination ? "normal" : "strange");
for(mtmp = fmon; mtmp; mtmp = nextmon) {
nextmon = mtmp->nmon; /* trap might kill mon */
if (DEADMONSTER(mtmp)) continue;
if (mtmp->mtame) {
if (mtmp->mtrapped) {
/* no longer in previous trap (affects mintrap) */
mtmp->mtrapped = 0;
fill_pit(mtmp->mx, mtmp->my);
}
mnexto(mtmp);
if (canspotmon(mtmp)) ++pet_cnt;
if (mintrap(mtmp) == 2) change_luck(-1);
}
}
if (pet_cnt > 0) makeknown(obj->otyp);
}
}

boolean
um_dist(x,y,n)
register xchar x, y, n;
{
return((boolean)(abs(u.ux - x) > n || abs(u.uy - y) > n));
}

int
number_leashed()
{
register int i = 0;
register struct obj *obj;

for(obj = invent; obj; obj = obj->nobj)
if(obj->otyp == LEASH && obj->leashmon != 0) i++;
return(i);
}

void
o_unleash(otmp) /* otmp is about to be destroyed or stolen */
register struct obj *otmp;
{
register struct monst *mtmp;

for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
if(mtmp->m_id == (unsigned)otmp->leashmon)
mtmp->mleashed = 0;
otmp->leashmon = 0;
}

void
m_unleash(mtmp, feedback) /* mtmp is about to die, or become untame */
register struct monst *mtmp;
boolean feedback;
{
register struct obj *otmp;

if (feedback) {
if (canseemon(mtmp))
pline("%s pulls free of %s leash!", Monnam(mtmp), mhis(mtmp));
else
Your("leash falls slack.");
}
for(otmp = invent; otmp; otmp = otmp->nobj)
if(otmp->otyp == LEASH &&
otmp->leashmon == (int)mtmp->m_id)
otmp->leashmon = 0;
mtmp->mleashed = 0;
}

void
unleash_all() /* player is about to die (for bones) */
{
register struct obj *otmp;
register struct monst *mtmp;

for(otmp = invent; otmp; otmp = otmp->nobj)
if(otmp->otyp == LEASH) otmp->leashmon = 0;
for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
mtmp->mleashed = 0;
}

#define MAXLEASHED 2

/* ARGSUSED */
STATIC_OVL void
use_leash(obj)
struct obj *obj;
{
coord cc;
register struct monst *mtmp;
int spotmon;

if(!obj->leashmon && number_leashed() >= MAXLEASHED) {
You("cannot leash any more pets.");
return;
}

if(!get_adjacent_loc((char *)0, (char *)0, u.ux, u.uy, &cc)) return;

if((cc.x == u.ux) && (cc.y == u.uy)) {
#ifdef STEED
if (u.usteed && u.dz > 0) {
mtmp = u.usteed;
spotmon = 1;
goto got_target;
}
#endif
pline("Leash yourself? Very funny...");
return;
}

if(!(mtmp = m_at(cc.x, cc.y))) {
There("is no creature there.");
return;
}

spotmon = canspotmon(mtmp);
#ifdef STEED
 got_target:
#endif

if(!mtmp->mtame) {
if(!spotmon)
There("is no creature there.");
else
pline("%s %s leashed!", Monnam(mtmp), (!obj->leashmon) ?
"cannot be" : "is not");
return;
}
if(!obj->leashmon) {
if(mtmp->mleashed) {
pline("This %s is already leashed.",
spotmon ? l_monnam(mtmp) : "monster");
return;
}
You("slip the leash around %s%s.",
spotmon ? "your " : "", l_monnam(mtmp));
mtmp->mleashed = 1;
obj->leashmon = (int)mtmp->m_id;
mtmp->msleeping = 0;
return;
}
if(obj->leashmon != (int)mtmp->m_id) {
pline("This leash is not attached to that creature.");
return;
} else {
if(obj->cursed) {
pline_The("leash would not come off!");
obj->bknown = TRUE;
return;
}
mtmp->mleashed = 0;
obj->leashmon = 0;
You("remove the leash from %s%s.",
spotmon ? "your " : "", l_monnam(mtmp));
}
return;
}

struct obj *
get_mleash(mtmp) /* assuming mtmp->mleashed has been checked */
register struct monst *mtmp;
{
register struct obj *otmp;

otmp = invent;
while(otmp) {
if(otmp->otyp == LEASH && otmp->leashmon == (int)mtmp->m_id)
return(otmp);
otmp = otmp->nobj;
}
return((struct obj *)0);
}

#endif /* OVLB */
#ifdef OVL1

boolean
next_to_u()
{
register struct monst *mtmp;
register struct obj *otmp;

for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (DEADMONSTER(mtmp)) continue;
if(mtmp->mleashed) {
if (distu(mtmp->mx,mtmp->my) > 2) mnexto(mtmp);
if (distu(mtmp->mx,mtmp->my) > 2) {
for(otmp = invent; otmp; otmp = otmp->nobj)
if(otmp->otyp == LEASH &&
otmp->leashmon == (int)mtmp->m_id) {
if(otmp->cursed) return(FALSE);
You_feel("%s leash go slack.",
(number_leashed() > 1) ? "a" : "the");
mtmp->mleashed = 0;
otmp->leashmon = 0;
}
}
}
}
#ifdef STEED
/* no pack mules for the Amulet */
if (u.usteed && mon_has_amulet(u.usteed)) return FALSE;
#endif
return(TRUE);
}

#endif /* OVL1 */
#ifdef OVL0

void
check_leash(x, y)
register xchar x, y;
{
register struct obj *otmp;
register struct monst *mtmp;

for (otmp = invent; otmp; otmp = otmp->nobj) {
if (otmp->otyp != LEASH || otmp->leashmon == 0) continue;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (DEADMONSTER(mtmp)) continue;
if ((int)mtmp->m_id == otmp->leashmon) break;
}
if (!mtmp) {
impossible("leash in use isn't attached to anything?");
otmp->leashmon = 0;
continue;
}
if (dist2(u.ux,u.uy,mtmp->mx,mtmp->my) >
dist2(x,y,mtmp->mx,mtmp->my)) {
if (!um_dist(mtmp->mx, mtmp->my, 3)) {
; /* still close enough */
} else if (otmp->cursed && !breathless(mtmp->data)) {
if (um_dist(mtmp->mx, mtmp->my, 5) ||
(mtmp->mhp -= rnd(2)) <= 0) {
long save_pacifism = u.uconduct.killer;

Your("leash chokes %s to death!", mon_nam(mtmp));
/* hero might not have intended to kill pet, but
that's the result of his actions; gain experience,
lose pacifism, take alignment and luck hit, make
corpse less likely to remain tame after revival */
xkilled(mtmp, 0); /* no "you kill it" message */
/* life-saving doesn't ordinarily reset this */
if (mtmp->mhp > 0) u.uconduct.killer = save_pacifism;
} else {
pline("%s chokes on the leash!", Monnam(mtmp));
/* tameness eventually drops to 1 here (never 0) */
if (mtmp->mtame && rn2(mtmp->mtame)) mtmp->mtame--;
}
} else {
if (um_dist(mtmp->mx, mtmp->my, 5)) {
pline("%s leash snaps loose!", s_suffix(Monnam(mtmp)));
m_unleash(mtmp, FALSE);
} else {
You("pull on the leash.");
if (mtmp->data->msound != MS_SILENT)
switch (rn2(3)) {
case 0: growl(mtmp); break;
case 1: yelp(mtmp); break;
default: whimper(mtmp); break;
}
}
}
}
}
}

#endif /* OVL0 */
#ifdef OVLB

#define WEAK 3 /* from eat.c */

static const char look_str[] = "look %s.";

STATIC_OVL int
use_mirror(obj)
struct obj *obj;
{
register struct monst *mtmp;
register char mlet;
boolean vis;

if(!getdir((char *)0)) return 0;
if(obj->cursed && !rn2(2)) {
if (!Blind)
pline_The("mirror fogs up and doesn't reflect!");
return 1;
}
if(!u.dx && !u.dy && !u.dz) {
if(!Blind && !Invisible) {
if (u.umonnum == PM_FLOATING_EYE) {
if (!Free_action) {
pline(Hallucination ?
"Yow! The mirror stares back!" :
"Yikes! You've frozen yourself!");
nomul(-rnd((MAXULEV+6) - u.ulevel));
} else You("stiffen momentarily under your gaze.");
} else if (youmonst.data->mlet == S_VAMPIRE)
You("don't have a reflection.");
else if (u.umonnum == PM_UMBER_HULK) {
pline("Huh? That doesn't look like you!");
make_confused(HConfusion + d(3,4),FALSE);
} else if (Hallucination)
You(look_str, hcolor((char *)0));
else if (Sick)
You(look_str, "peaked");
else if (u.uhs >= WEAK)
You(look_str, "undernourished");
else You("look as %s as ever.",
ACURR(A_CHA) > 14 ?
(poly_gender()==1 ? "beautiful" : "handsome") :
"ugly");
} else {
You_cant("see your %s %s.",
ACURR(A_CHA) > 14 ?
(poly_gender()==1 ? "beautiful" : "handsome") :
"ugly",
body_part(FACE));
}
return 1;
}
if(u.uswallow) {
if (!Blind) You("reflect %s %s.", s_suffix(mon_nam(u.ustuck)),
mbodypart(u.ustuck, STOMACH));
return 1;
}
if(Underwater) {
You(Hallucination ?
"give the fish a chance to fix their makeup." :
"reflect the murky water.");
return 1;
}
if(u.dz) {
if (!Blind)
You("reflect the %s.",
(u.dz > 0) ? surface(u.ux,u.uy) : ceiling(u.ux,u.uy));
return 1;
}
mtmp = bhit(u.dx, u.dy, COLNO, INVIS_BEAM,
(int FDECL((*),(MONST_P,OBJ_P)))0,
(int FDECL((*),(OBJ_P,OBJ_P)))0,
obj);
if (!mtmp || !haseyes(mtmp->data))
return 1;

vis = canseemon(mtmp);
mlet = mtmp->data->mlet;
if (mtmp->msleeping) {
if (vis)
pline ("%s is too tired to look at your mirror.",
Monnam(mtmp));
} else if (!mtmp->mcansee) {
if (vis)
pline("%s can't see anything right now.", Monnam(mtmp));
/* some monsters do special things */
} else if (mlet == S_VAMPIRE || mlet == S_GHOST) {
if (vis)
pline ("%s doesn't have a reflection.", Monnam(mtmp));
} else if(!mtmp->mcan && !mtmp->minvis &&
mtmp->data == &mons[PM_MEDUSA]) {
if (mon_reflects(mtmp, "The gaze is reflected away by %s %s!"))
return 1;
if (vis)
pline("%s is turned to stone!", Monnam(mtmp));
stoned = TRUE;
killed(mtmp);
} else if(!mtmp->mcan && !mtmp->minvis &&
mtmp->data == &mons[PM_FLOATING_EYE]) {
int tmp = d((int)mtmp->m_lev, (int)mtmp->data->mattk[0].damd);
if (!rn2(4)) tmp = 120;
if (vis)
pline("%s is frozen by its reflection.", Monnam(mtmp));
else You_hear("%s stop moving.",something);
mtmp->mcanmove = 0;
if ( (int) mtmp->mfrozen + tmp > 127)
mtmp->mfrozen = 127;
else mtmp->mfrozen += tmp;
} else if(!mtmp->mcan && !mtmp->minvis &&
mtmp->data == &mons[PM_UMBER_HULK]) {
if (vis)
pline ("%s confuses itself!", Monnam(mtmp));
mtmp->mconf = 1;
} else if(!mtmp->mcan && !mtmp->minvis && (mlet == S_NYMPH
|| mtmp->data==&mons[PM_SUCCUBUS])) {
if (vis) {
pline ("%s admires herself in your mirror.", Monnam(mtmp));
pline ("She takes it!");
} else pline ("It steals your mirror!");
setnotworn(obj); /* in case mirror was wielded */
freeinv(obj);
(void) mpickobj(mtmp,obj);
if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE);
} else if (!is_unicorn(mtmp->data) && !humanoid(mtmp->data) &&
(!mtmp->minvis || perceives(mtmp->data)) && rn2(5)) {
if (vis)
pline("%s is frightened by its reflection.", Monnam(mtmp));
monflee(mtmp, d(2,4), FALSE, FALSE);
} else if (!Blind) {
if (mtmp->minvis && !See_invisible)
;
else if ((mtmp->minvis && !perceives(mtmp->data))
|| !haseyes(mtmp->data))
pline("%s doesn't seem to notice its reflection.",
Monnam(mtmp));
else
pline("%s ignores %s reflection.",
Monnam(mtmp), mhis(mtmp));
}
return 1;
}

STATIC_OVL void
use_bell(optr)
struct obj **optr;
{
register struct obj *obj = *optr;
struct monst *mtmp;
boolean wakem = FALSE, learno = FALSE,
ordinary = (obj->otyp != BELL_OF_OPENING || !obj->spe),
invoking = (obj->otyp == BELL_OF_OPENING &&
invocation_pos(u.ux, u.uy) && !On_stairs(u.ux, u.uy));

You("ring %s.", the(xname(obj)));

if (Underwater || (u.uswallow && ordinary)) {
#ifdef AMIGA
amii_speaker( obj, "AhDhGqEqDhEhAqDqFhGw", AMII_MUFFLED_VOLUME );
#endif
pline("But the sound is muffled.");

} else if (invoking && ordinary) {
/* needs to be recharged... */
pline("But it makes no sound.");
learno = TRUE; /* help player figure out why */

} else if (ordinary) {
#ifdef AMIGA
amii_speaker( obj, "ahdhgqeqdhehaqdqfhgw", AMII_MUFFLED_VOLUME );
#endif
if (obj->cursed && !rn2(4) &&
/* note: once any of them are gone, we stop all of them */
!(mvitals[PM_WOOD_NYMPH].mvflags & G_GONE) &&
!(mvitals[PM_WATER_NYMPH].mvflags & G_GONE) &&
!(mvitals[PM_MOUNTAIN_NYMPH].mvflags & G_GONE) &&
(mtmp = makemon(mkclass(S_NYMPH, 0),
u.ux, u.uy, NO_MINVENT)) != 0) {
You("summon %s!", a_monnam(mtmp));
if (!obj_resists(obj, 93, 100)) {
pline("%s shattered!", Tobjnam(obj, "have"));
useup(obj);
*optr = 0;
} else switch (rn2(3)) {
default:
break;
case 1:
mon_adjust_speed(mtmp, 2, (struct obj *)0);
break;
case 2: /* no explanation; it just happens... */
nomovemsg = "";
nomul(-rnd(2));
break;
}
}
wakem = TRUE;

} else {
/* charged Bell of Opening */
consume_obj_charge(obj, TRUE);

if (u.uswallow) {
if (!obj->cursed)
(void) openit();
else
pline(nothing_happens);

} else if (obj->cursed) {
coord mm;

mm.x = u.ux;
mm.y = u.uy;
mkundead(&mm, FALSE, NO_MINVENT);
wakem = TRUE;

} else if (invoking) {
pline("%s an unsettling shrill sound...",
Tobjnam(obj, "issue"));
#ifdef AMIGA
amii_speaker( obj, "aefeaefeaefeaefeaefe", AMII_LOUDER_VOLUME );
#endif
obj->age = moves;
learno = TRUE;
wakem = TRUE;

} else if (obj->blessed) {
int res = 0;

#ifdef AMIGA
amii_speaker( obj, "ahahahDhEhCw", AMII_SOFT_VOLUME );
#endif
if (uchain) {
unpunish();
res = 1;
}
res += openit();
switch (res) {
case 0: pline(nothing_happens); break;
case 1: pline("%s opens...", Something);
learno = TRUE; break;
default: pline("Things open around you...");
learno = TRUE; break;
}

} else { /* uncursed */
#ifdef AMIGA
amii_speaker( obj, "AeFeaeFeAefegw", AMII_OKAY_VOLUME );
#endif
if (findit() != 0) learno = TRUE;
else pline(nothing_happens);
}

} /* charged BofO */

if (learno) {
makeknown(BELL_OF_OPENING);
obj->known = 1;
}
if (wakem) wake_nearby();
}

STATIC_OVL void
use_candelabrum(obj)
register struct obj *obj;
{
const char *s = (obj->spe != 1) ? "candles" : "candle";

if(Underwater) {
You("cannot make fire under water.");
return;
}
if(obj->lamplit) {
You("snuff the %s.", s);
end_burn(obj, TRUE);
return;
}
if(obj->spe <= 0) {
pline("This %s has no %s.", xname(obj), s);
return;
}
if(u.uswallow || obj->cursed) {
if (!Blind)
pline_The("%s %s for a moment, then %s.",
s, vtense(s, "flicker"), vtense(s, "die"));
return;
}
if(obj->spe < 7) {
There("%s only %d %s in %s.",
vtense(s, "are"), obj->spe, s, the(xname(obj)));
if (!Blind)
pline("%s lit. %s dimly.",
obj->spe == 1 ? "It is" : "They are",
Tobjnam(obj, "shine"));
} else {
pline("%s's %s burn%s", The(xname(obj)), s,
(Blind ? "." : " brightly!"));
}
if (!invocation_pos(u.ux, u.uy)) {
pline_The("%s %s being rapidly consumed!", s, vtense(s, "are"));
obj->age /= 2;
} else {
if(obj->spe == 7) {
if (Blind)
pline("%s a strange warmth!", Tobjnam(obj, "radiate"));
else
pline("%s with a strange light!", Tobjnam(obj, "glow"));
}
obj->known = 1;
}
begin_burn(obj, FALSE);
}

STATIC_OVL void
use_candle(optr)
struct obj **optr;
{
register struct obj *obj = *optr;
register struct obj *otmp;
const char *s = (obj->quan != 1) ? "candles" : "candle";
char qbuf[QBUFSZ];

if(u.uswallow) {
You(no_elbow_room);
return;
}
if(Underwater) {
pline("Sorry, fire and water don't mix.");
return;
}

otmp = carrying(CANDELABRUM_OF_INVOCATION);
if(!otmp || otmp->spe == 7) {
use_lamp(obj);
return;
}

Sprintf(qbuf, "Attach %s", the(xname(obj)));
Sprintf(eos(qbuf), " to %s?",
safe_qbuf(qbuf, sizeof(" to ?"), the(xname(otmp)),
the(simple_typename(otmp->otyp)), "it"));
if(yn(qbuf) == 'n') {
if (!obj->lamplit)
You("try to light %s...", the(xname(obj)));
use_lamp(obj);
return;
} else {
if ((long)otmp->spe + obj->quan > 7L)
obj = splitobj(obj, 7L - (long)otmp->spe);
else *optr = 0;
You("attach %ld%s %s to %s.",
obj->quan, !otmp->spe ? "" : " more",
s, the(xname(otmp)));
if (!otmp->spe || otmp->age > obj->age)
otmp->age = obj->age;
otmp->spe += (int)obj->quan;
if (otmp->lamplit && !obj->lamplit)
pline_The("new %s magically %s!", s, vtense(s, "ignite"));
else if (!otmp->lamplit && obj->lamplit)
pline("%s out.", (obj->quan > 1L) ? "They go" : "It goes");
if (obj->unpaid)
verbalize("You %s %s, you bought %s!",
otmp->lamplit ? "burn" : "use",
(obj->quan > 1L) ? "them" : "it",
(obj->quan > 1L) ? "them" : "it");
if (obj->quan < 7L && otmp->spe == 7)
pline("%s now has seven%s candles attached.",
The(xname(otmp)), otmp->lamplit ? " lit" : "");
/* candelabrum's light range might increase */
if (otmp->lamplit) obj_merge_light_sources(otmp, otmp);
/* candles are no longer a separate light source */
if (obj->lamplit) end_burn(obj, TRUE);
/* candles are now gone */
useupall(obj);
}
}

boolean
snuff_candle(otmp) /* call in drop, throw, and put in box, etc. */
register struct obj *otmp;
{
register boolean candle = Is_candle(otmp);

if ((candle || otmp->otyp == CANDELABRUM_OF_INVOCATION) &&
otmp->lamplit) {
char buf[BUFSZ];
xchar x, y;
register boolean many = candle ? otmp->quan > 1L : otmp->spe > 1;

(void) get_obj_location(otmp, &x, &y, 0);
if (otmp->where == OBJ_MINVENT ? cansee(x,y) : !Blind)
pline("%s %scandle%s flame%s extinguished.",
Shk_Your(buf, otmp),
(candle ? "" : "candelabrum's "),
(many ? "s'" : "'s"), (many ? "s are" : " is"));
end_burn(otmp, TRUE);
return(TRUE);
}
return(FALSE);
}

/* called when lit lamp is hit by water or put into a container or
you've been swallowed by a monster; obj might be in transit while
being thrown or dropped so don't assume that its location is valid */
boolean
snuff_lit(obj)
struct obj *obj;
{
xchar x, y;

if (obj->lamplit) {
if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP ||
obj->otyp == BRASS_LANTERN || obj->otyp == POT_OIL) {
(void) get_obj_location(obj, &x, &y, 0);
if (obj->where == OBJ_MINVENT ? cansee(x,y) : !Blind)
pline("%s %s out!", Yname2(obj), otense(obj, "go"));
end_burn(obj, TRUE);
return TRUE;
}
if (snuff_candle(obj)) return TRUE;
}
return FALSE;
}

/* Called when potentially lightable object is affected by fire_damage().
Return TRUE if object was lit and FALSE otherwise --ALI */
boolean
catch_lit(obj)
struct obj *obj;
{
xchar x, y;

if (!obj->lamplit && (obj->otyp == MAGIC_LAMP || ignitable(obj))) {
if ((obj->otyp == MAGIC_LAMP ||
obj->otyp == CANDELABRUM_OF_INVOCATION) &&
obj->spe == 0)
return FALSE;
else if (obj->otyp != MAGIC_LAMP && obj->age == 0)
return FALSE;
if (!get_obj_location(obj, &x, &y, 0))
return FALSE;
if (obj->otyp == CANDELABRUM_OF_INVOCATION && obj->cursed)
return FALSE;
if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP ||
obj->otyp == BRASS_LANTERN) && obj->cursed && !rn2(2))
return FALSE;
if (obj->where == OBJ_MINVENT ? cansee(x,y) : !Blind)
pline("%s %s light!", Yname2(obj), otense(obj, "catch"));
if (obj->otyp == POT_OIL) makeknown(obj->otyp);
if (obj->unpaid && costly_spot(u.ux, u.uy) && (obj->where == OBJ_INVENT)) {
/* if it catches while you have it, then it's your tough luck */
check_unpaid(obj);
verbalize("That's in addition to the cost of %s %s, of course.",
Yname2(obj), obj->quan == 1 ? "itself" : "themselves");
bill_dummy_object(obj);
}
begin_burn(obj, FALSE);
return TRUE;
}
return FALSE;
}

STATIC_OVL void
use_lamp(obj)
struct obj *obj;
{
char buf[BUFSZ];

if(Underwater) {
pline("This is not a diving lamp.");
return;
}
if(obj->lamplit) {
if(obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP ||
obj->otyp == BRASS_LANTERN)
pline("%s lamp is now off.", Shk_Your(buf, obj));
else
You("snuff out %s.", yname(obj));
end_burn(obj, TRUE);
return;
}
/* magic lamps with an spe == 0 (wished for) cannot be lit */
if ((!Is_candle(obj) && obj->age == 0)
|| (obj->otyp == MAGIC_LAMP && obj->spe == 0)) {
if (obj->otyp == BRASS_LANTERN)
Your("lamp has run out of power.");
else pline("This %s has no oil.", xname(obj));
return;
}
if (obj->cursed && !rn2(2)) {
pline("%s for a moment, then %s.",
Tobjnam(obj, "flicker"), otense(obj, "die"));
} else {
if(obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP ||
obj->otyp == BRASS_LANTERN) {
check_unpaid(obj);
pline("%s lamp is now on.", Shk_Your(buf, obj));
} else { /* candle(s) */
pline("%s flame%s %s%s",
s_suffix(Yname2(obj)),
plur(obj->quan), otense(obj, "burn"),
Blind ? "." : " brightly!");
if (obj->unpaid && costly_spot(u.ux, u.uy) &&
obj->age == 20L * (long)objects[obj->otyp].oc_cost) {
const char *ithem = obj->quan > 1L ? "them" : "it";
verbalize("You burn %s, you bought %s!", ithem, ithem);
bill_dummy_object(obj);
}
}
begin_burn(obj, FALSE);
}
}

STATIC_OVL void
light_cocktail(obj)
struct obj *obj; /* obj is a potion of oil */
{
char buf[BUFSZ];

if (u.uswallow) {
You(no_elbow_room);
return;
}

if (obj->lamplit) {
You("snuff the lit potion.");
end_burn(obj, TRUE);
/*
* Free & add to re-merge potion. This will average the
* age of the potions. Not exactly the best solution,
* but its easy.
*/
freeinv(obj);
(void) addinv(obj);
return;
} else if (Underwater) {
There("is not enough oxygen to sustain a fire.");
return;
}

You("light %s potion.%s", shk_your(buf, obj),
Blind ? "" : " It gives off a dim light.");
if (obj->unpaid && costly_spot(u.ux, u.uy)) {
/* Normally, we shouldn't both partially and fully charge
* for an item, but (Yendorian Fuel) Taxes are inevitable...
*/
check_unpaid(obj);
verbalize("That's in addition to the cost of the potion, of course.");
bill_dummy_object(obj);
}
makeknown(obj->otyp);

if (obj->quan > 1L) {
obj = splitobj(obj, 1L);
begin_burn(obj, FALSE); /* burn before free to get position */
obj_extract_self(obj); /* free from inv */

/* shouldn't merge */
obj = hold_another_object(obj, "You drop %s!",
doname(obj), (const char *)0);
} else
begin_burn(obj, FALSE);
}

static NEARDATA const char cuddly[] = { TOOL_CLASS, GEM_CLASS, 0 };

int
dorub()
{
struct obj *obj = getobj(cuddly, "rub");

if (obj && obj->oclass == GEM_CLASS) {
if (is_graystone(obj)) {
use_stone(obj);
return 1;
} else {
pline("Sorry, I don't know how to use that.");
return 0;
}
}

if (!obj || !wield_tool(obj, "rub")) return 0;

/* now uwep is obj */
if (uwep->otyp == MAGIC_LAMP) {
if (uwep->spe > 0 && !rn2(3)) {
check_unpaid_usage(uwep, TRUE); /* unusual item use */
djinni_from_bottle(uwep);
makeknown(MAGIC_LAMP);
uwep->otyp = OIL_LAMP;
uwep->spe = 0; /* for safety */
uwep->age = rn1(500,1000);
if (uwep->lamplit) begin_burn(uwep, TRUE);
update_inventory();
} else if (rn2(2) && !Blind)
You("see a puff of smoke.");
else pline(nothing_happens);
} else if (obj->otyp == BRASS_LANTERN) {
/* message from Adventure */
pline("Rubbing the electric lamp is not particularly rewarding.");
pline("Anyway, nothing exciting happens.");
} else pline(nothing_happens);
return 1;
}

int
dojump()
{
/* Physical jump */
return jump(0);
}

int
jump(magic)
int magic; /* 0=Physical, otherwise skill level */
{
coord cc;

if (!magic && (nolimbs(youmonst.data) || slithy(youmonst.data))) {
/* normally (nolimbs || slithy) implies !Jumping,
but that isn't necessarily the case for knights */
You_cant("jump; you have no legs!");
return 0;
} else if (!magic && !Jumping) {
You_cant("jump very far.");
return 0;
} else if (u.uswallow) {
if (magic) {
You("bounce around a little.");
return 1;
}
pline("You've got to be kidding!");
return 0;
} else if (u.uinwater) {
if (magic) {
You("swish around a little.");
return 1;
}
pline("This calls for swimming, not jumping!");
return 0;
} else if (u.ustuck) {
if (u.ustuck->mtame && !Conflict && !u.ustuck->mconf) {
You("pull free from %s.", mon_nam(u.ustuck));
u.ustuck = 0;
return 1;
}
if (magic) {
You("writhe a little in the grasp of %s!", mon_nam(u.ustuck));
return 1;
}
You("cannot escape from %s!", mon_nam(u.ustuck));
return 0;
} else if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) {
if (magic) {
You("flail around a little.");
return 1;
}
You("don't have enough traction to jump.");
return 0;
} else if (!magic && near_capacity() > UNENCUMBERED) {
You("are carrying too much to jump!");
return 0;
} else if (!magic && (u.uhunger <= 100 || ACURR(A_STR) < 6)) {
You("lack the strength to jump!");
return 0;
} else if (Wounded_legs) {
long wl = (Wounded_legs & BOTH_SIDES);
const char *bp = body_part(LEG);

if (wl == BOTH_SIDES) bp = makeplural(bp);
#ifdef STEED
if (u.usteed)
pline("%s is in no shape for jumping.", Monnam(u.usteed));
else
#endif
Your("%s%s %s in no shape for jumping.",
(wl == LEFT_SIDE) ? "left " :
(wl == RIGHT_SIDE) ? "right " : "",
bp, (wl == BOTH_SIDES) ? "are" : "is");
return 0;
}
#ifdef STEED
else if (u.usteed && u.utrap) {
pline("%s is stuck in a trap.", Monnam(u.usteed));
return (0);
}
#endif

pline("Where do you want to jump?");
cc.x = u.ux;
cc.y = u.uy;
if (getpos(&cc, TRUE, "the desired position") < 0)
return 0; /* user pressed ESC */
if (!magic && !(HJumping & ~INTRINSIC) && !EJumping &&
distu(cc.x, cc.y) != 5) {
/* The Knight jumping restriction still applies when riding a
* horse. After all, what shape is the knight piece in chess?
*/
pline("Illegal move!");
return 0;
} else if (distu(cc.x, cc.y) > (magic ? 6+magic*3 : 9)) {
pline("Too far!");
return 0;
} else if (!cansee(cc.x, cc.y)) {
You("cannot see where to land!");
return 0;
} else if (!isok(cc.x, cc.y)) {
You("cannot jump there!");
return 0;
} else {
coord uc;
int range, temp;

if(u.utrap)
switch(u.utraptype) {
case TT_BEARTRAP: {
register long side = rn2(3) ? LEFT_SIDE : RIGHT_SIDE;
You("rip yourself free of the bear trap! Ouch!");
losehp(rnd(10), "jumping out of a bear trap", KILLED_BY);
set_wounded_legs(side, rn1(1000,500));
break;
}
case TT_PIT:
You("leap from the pit!");
break;
case TT_WEB:
You("tear the web apart as you pull yourself free!");
deltrap(t_at(u.ux,u.uy));
break;
case TT_LAVA:
You("pull yourself above the lava!");
u.utrap = 0;
return 1;
case TT_INFLOOR:
You("strain your %s, but you're still stuck in the floor.",
makeplural(body_part(LEG)));
set_wounded_legs(LEFT_SIDE, rn1(10, 11));
set_wounded_legs(RIGHT_SIDE, rn1(10, 11));
return 1;
}

/*
* Check the path from uc to cc, calling hurtle_step at each
* location. The final position actually reached will be
* in cc.
*/
uc.x = u.ux;
uc.y = u.uy;
/* calculate max(abs(dx), abs(dy)) as the range */
range = cc.x - uc.x;
if (range < 0) range = -range;
temp = cc.y - uc.y;
if (temp < 0) temp = -temp;
if (range < temp)
range = temp;
(void) walk_path(&uc, &cc, hurtle_step, (genericptr_t)&range);

/* A little Sokoban guilt... */
if (In_sokoban(&u.uz))
change_luck(-1);

teleds(cc.x, cc.y, TRUE);
nomul(-1);
nomovemsg = "";
morehungry(rnd(25));
return 1;
}
}

boolean
tinnable(corpse)
struct obj *corpse;
{
if (corpse->oeaten) return 0;
if (!mons[corpse->corpsenm].cnutrit) return 0;
return 1;
}

STATIC_OVL void
use_tinning_kit(obj)
register struct obj *obj;
{
register struct obj *corpse, *can;

/* This takes only 1 move. If this is to be changed to take many
* moves, we've got to deal with decaying corpses...
*/
if (obj->spe <= 0) {
You("seem to be out of tins.");
return;
}
if (!(corpse = floorfood("tin", 2))) return;
if (corpse->oeaten) {
You("cannot tin %s which is partly eaten.",something);
return;
}
if (touch_petrifies(&mons[corpse->corpsenm])
&& !Stone_resistance && !uarmg) {
char kbuf[BUFSZ];

if (poly_when_stoned(youmonst.data))
You("tin %s without wearing gloves.",
an(mons[corpse->corpsenm].mname));
else {
pline("Tinning %s without wearing gloves is a fatal mistake...",
an(mons[corpse->corpsenm].mname));
Sprintf(kbuf, "trying to tin %s without gloves",
an(mons[corpse->corpsenm].mname));
}
instapetrify(kbuf);
}
if (is_rider(&mons[corpse->corpsenm])) {
(void) revive_corpse(corpse);
verbalize("Yes... But War does not preserve its enemies...");
return;
}
if (mons[corpse->corpsenm].cnutrit == 0) {
pline("That's too insubstantial to tin.");
return;
}
consume_obj_charge(obj, TRUE);

if ((can = mksobj(TIN, FALSE, FALSE)) != 0) {
static const char you_buy_it[] = "You tin it, you bought it!";

can->corpsenm = corpse->corpsenm;
can->cursed = obj->cursed;
can->blessed = obj->blessed;
can->owt = weight(can);
can->known = 1;
can->spe = -1; /* Mark tinned tins. No spinach allowed... */
if (carried(corpse)) {
if (corpse->unpaid)
verbalize(you_buy_it);
useup(corpse);
} else {
if (costly_spot(corpse->ox, corpse->oy) && !corpse->no_charge)
verbalize(you_buy_it);
useupf(corpse, 1L);
}
can = hold_another_object(can, "You make, but cannot pick up, %s.",
doname(can), (const char *)0);
} else impossible("Tinning failed.");
}

void
use_unicorn_horn(obj)
struct obj *obj;
{
#define PROP_COUNT 6 /* number of properties we're dealing with */
#define ATTR_COUNT (A_MAX*3) /* number of attribute points we might fix */
int idx, val, val_limit,
trouble_count, unfixable_trbl, did_prop, did_attr;
int trouble_list[PROP_COUNT + ATTR_COUNT];

if (obj && obj->cursed) {
long lcount = (long) rnd(100);

switch (rn2(6)) {
case 0: make_sick(Sick ? Sick/3L + 1L : (long)rn1(ACURR(A_CON),20),
xname(obj), TRUE, SICK_NONVOMITABLE);
break;
case 1: make_blinded(Blinded + lcount, TRUE);
break;
case 2: if (!Confusion)
You("suddenly feel %s.",
Hallucination ? "trippy" : "confused");
make_confused(HConfusion + lcount, TRUE);
break;
case 3: make_stunned(HStun + lcount, TRUE);
break;
case 4: (void) adjattrib(rn2(A_MAX), -1, FALSE);
break;
case 5: (void) make_hallucinated(HHallucination + lcount, TRUE, 0L);
break;
}
return;
}

/*
* Entries in the trouble list use a very simple encoding scheme.
*/
#define prop2trbl(X) ((X) + A_MAX)
#define attr2trbl(Y) (Y)
#define prop_trouble(X) trouble_list[trouble_count++] = prop2trbl(X)
#define attr_trouble(Y) trouble_list[trouble_count++] = attr2trbl(Y)

trouble_count = unfixable_trbl = did_prop = did_attr = 0;

/* collect property troubles */
if (Sick) prop_trouble(SICK);
if (Blinded > (long)u.ucreamed) prop_trouble(BLINDED);
if (HHallucination) prop_trouble(HALLUC);
if (Vomiting) prop_trouble(VOMITING);
if (HConfusion) prop_trouble(CONFUSION);
if (HStun) prop_trouble(STUNNED);

unfixable_trbl = unfixable_trouble_count(TRUE);

/* collect attribute troubles */
for (idx = 0; idx < A_MAX; idx++) {
val_limit = AMAX(idx);
/* don't recover strength lost from hunger */
if (idx == A_STR && u.uhs >= WEAK) val_limit--;
/* don't recover more than 3 points worth of any attribute */
if (val_limit > ABASE(idx) + 3) val_limit = ABASE(idx) + 3;

for (val = ABASE(idx); val < val_limit; val++)
attr_trouble(idx);
/* keep track of unfixed trouble, for message adjustment below */
unfixable_trbl += (AMAX(idx) - val_limit);
}

if (trouble_count == 0) {
pline(nothing_happens);
return;
} else if (trouble_count > 1) { /* shuffle */
int i, j, k;

for (i = trouble_count - 1; i > 0; i--)
if ((j = rn2(i + 1)) != i) {
k = trouble_list[j];
trouble_list[j] = trouble_list[i];
trouble_list[i] = k;
}
}

/*
* Chances for number of troubles to be fixed
* 0 1 2 3 4 5 6 7
* blessed: 22.7% 22.7% 19.5% 15.4% 10.7% 5.7% 2.6% 0.8%
* uncursed: 35.4% 35.4% 22.9% 6.3% 0 0 0 0
*/
val_limit = rn2( d(2, (obj && obj->blessed) ? 4 : 2) );
if (val_limit > trouble_count) val_limit = trouble_count;

/* fix [some of] the troubles */
for (val = 0; val < val_limit; val++) {
idx = trouble_list[val];

switch (idx) {
case prop2trbl(SICK):
make_sick(0L, (char *) 0, TRUE, SICK_ALL);
did_prop++;
break;
case prop2trbl(BLINDED):
make_blinded((long)u.ucreamed, TRUE);
did_prop++;
break;
case prop2trbl(HALLUC):
(void) make_hallucinated(0L, TRUE, 0L);
did_prop++;
break;
case prop2trbl(VOMITING):
make_vomiting(0L, TRUE);
did_prop++;
break;
case prop2trbl(CONFUSION):
make_confused(0L, TRUE);
did_prop++;
break;
case prop2trbl(STUNNED):
make_stunned(0L, TRUE);
did_prop++;
break;
default:
if (idx >= 0 && idx < A_MAX) {
ABASE(idx) += 1;
did_attr++;
} else
panic("use_unicorn_horn: bad trouble? (%d)", idx);
break;
}
}

if (did_attr)
pline("This makes you feel %s!",
(did_prop + did_attr) == (trouble_count + unfixable_trbl) ?
"great" : "better");
else if (!did_prop)
pline("Nothing seems to happen.");

flags.botl = (did_attr || did_prop);
#undef PROP_COUNT
#undef ATTR_COUNT
#undef prop2trbl
#undef attr2trbl
#undef prop_trouble
#undef attr_trouble
}

/*
* Timer callback routine: turn figurine into monster
*/
void
fig_transform(arg, timeout)
genericptr_t arg;
long timeout;
{
struct obj *figurine = (struct obj *)arg;
struct monst *mtmp;
coord cc;
boolean cansee_spot, silent, okay_spot;
boolean redraw = FALSE;
char monnambuf[BUFSZ], carriedby[BUFSZ];

if (!figurine) {
#ifdef DEBUG
pline("null figurine in fig_transform()");
#endif
return;
}
silent = (timeout != monstermoves); /* happened while away */
okay_spot = get_obj_location(figurine, &cc.x, &cc.y, 0);
if (figurine->where == OBJ_INVENT ||
figurine->where == OBJ_MINVENT)
okay_spot = enexto(&cc, cc.x, cc.y,
&mons[figurine->corpsenm]);
if (!okay_spot ||
!figurine_location_checks(figurine,&cc, TRUE)) {
/* reset the timer to try again later */
(void) start_timer((long)rnd(5000), TIMER_OBJECT,
FIG_TRANSFORM, (genericptr_t)figurine);
return;
}

cansee_spot = cansee(cc.x, cc.y);
mtmp = make_familiar(figurine, cc.x, cc.y, TRUE);
if (mtmp) {
Sprintf(monnambuf, "%s",an(m_monnam(mtmp)));
switch (figurine->where) {
case OBJ_INVENT:
if (Blind)
You_feel("%s %s from your pack!", something,
locomotion(mtmp->data,"drop"));
else
You("see %s %s out of your pack!",
monnambuf,
locomotion(mtmp->data,"drop"));
break;

case OBJ_FLOOR:
if (cansee_spot && !silent) {
You("suddenly see a figurine transform into %s!",
monnambuf);
redraw = TRUE; /* update figurine's map location */
}
break;

case OBJ_MINVENT:
if (cansee_spot && !silent) {
struct monst *mon;
mon = figurine->ocarry;
/* figurine carring monster might be invisible */
if (canseemon(figurine->ocarry)) {
Sprintf(carriedby, "%s pack",
s_suffix(a_monnam(mon)));
}
else if (is_pool(mon->mx, mon->my))
Strcpy(carriedby, "empty water");
else
Strcpy(carriedby, "thin air");
You("see %s %s out of %s!", monnambuf,
locomotion(mtmp->data, "drop"), carriedby);
}
break;
#if 0
case OBJ_MIGRATING:
break;
#endif

default:
impossible("figurine came to life where? (%d)",
(int)figurine->where);
break;
}
}
/* free figurine now */
obj_extract_self(figurine);
obfree(figurine, (struct obj *)0);
if (redraw) newsym(cc.x, cc.y);
}

STATIC_OVL boolean
figurine_location_checks(obj, cc, quietly)
struct obj *obj;
coord *cc;
boolean quietly;
{
xchar x,y;

if (carried(obj) && u.uswallow) {
if (!quietly)
You("don't have enough room in here.");
return FALSE;
}
x = cc->x; y = cc->y;
if (!isok(x,y)) {
if (!quietly)
You("cannot put the figurine there.");
return FALSE;
}
if (IS_ROCK(levl[x][y].typ) &&
!(passes_walls(&mons[obj->corpsenm]) && may_passwall(x,y))) {
if (!quietly)
You("cannot place a figurine in %s!",
IS_TREE(levl[x][y].typ) ? "a tree" : "solid rock");
return FALSE;
}
if (sobj_at(BOULDER,x,y) && !passes_walls(&mons[obj->corpsenm])
&& !throws_rocks(&mons[obj->corpsenm])) {
if (!quietly)
You("cannot fit the figurine on the boulder.");
return FALSE;
}
return TRUE;
}

STATIC_OVL void
use_figurine(optr)
struct obj **optr;
{
register struct obj *obj = *optr;
xchar x, y;
coord cc;

if (u.uswallow) {
/* can't activate a figurine while swallowed */
if (!figurine_location_checks(obj, (coord *)0, FALSE))
return;
}
if(!getdir((char *)0)) {
flags.move = multi = 0;
return;
}
x = u.ux + u.dx; y = u.uy + u.dy;
cc.x = x; cc.y = y;
/* Passing FALSE arg here will result in messages displayed */
if (!figurine_location_checks(obj, &cc, FALSE)) return;
You("%s and it transforms.",
(u.dx||u.dy) ? "set the figurine beside you" :
(Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) ||
is_pool(cc.x, cc.y)) ?
"release the figurine" :
(u.dz < 0 ?
"toss the figurine into the air" :
"set the figurine on the ground"));
(void) make_familiar(obj, cc.x, cc.y, FALSE);
(void) stop_timer(FIG_TRANSFORM, (genericptr_t)obj);
useup(obj);
*optr = 0;
}

static NEARDATA const char lubricables[] = { ALL_CLASSES, ALLOW_NONE, 0 };
static NEARDATA const char need_to_remove_outer_armor[] =
"need to remove your %s to grease your %s.";

STATIC_OVL void
use_grease(obj)
struct obj *obj;
{
struct obj *otmp;
char buf[BUFSZ];

if (Glib) {
pline("%s from your %s.", Tobjnam(obj, "slip"),
makeplural(body_part(FINGER)));
dropx(obj);
return;
}

if (obj->spe > 0) {
if ((obj->cursed || Fumbling) && !rn2(2)) {
consume_obj_charge(obj, TRUE);

pline("%s from your %s.", Tobjnam(obj, "slip"),
makeplural(body_part(FINGER)));
dropx(obj);
return;
}
otmp = getobj(lubricables, "grease");
if (!otmp) return;
if ((otmp->owornmask & WORN_ARMOR) && uarmc) {
Strcpy(buf, xname(uarmc));
You(need_to_remove_outer_armor, buf, xname(otmp));
return;
}
#ifdef TOURIST
if ((otmp->owornmask & WORN_SHIRT) && (uarmc || uarm)) {
Strcpy(buf, uarmc ? xname(uarmc) : "");
if (uarmc && uarm) Strcat(buf, " and ");
Strcat(buf, uarm ? xname(uarm) : "");
You(need_to_remove_outer_armor, buf, xname(otmp));
return;
}
#endif
consume_obj_charge(obj, TRUE);

if (otmp != &zeroobj) {
You("cover %s with a thick layer of grease.",
yname(otmp));
otmp->greased = 1;
if (obj->cursed && !nohands(youmonst.data)) {
incr_itimeout(&Glib, rnd(15));
pline("Some of the grease gets all over your %s.",
makeplural(body_part(HAND)));
}
} else {
Glib += rnd(15);
You("coat your %s with grease.",
makeplural(body_part(FINGER)));
}
} else {
if (obj->known)
pline("%s empty.", Tobjnam(obj, "are"));
else
pline("%s to be empty.", Tobjnam(obj, "seem"));
}
update_inventory();
}

static struct trapinfo {
struct obj *tobj;
xchar tx, ty;
int time_needed;
boolean force_bungle;
} trapinfo;

void
reset_trapset()
{
trapinfo.tobj = 0;
trapinfo.force_bungle = 0;
}

/* touchstones - by Ken Arnold */
STATIC_OVL void
use_stone(tstone)
struct obj *tstone;
{
    struct obj *obj;
    boolean do_scratch;
    const char *streak_color, *choices;
    char stonebuf[QBUFSZ];
    static const char scritch[] = "\"scritch, scritch\"";
    static const char allowall[3] = { COIN_CLASS, ALL_CLASSES, 0 };
    static const char justgems[3] = { ALLOW_NONE, GEM_CLASS, 0 };
#ifndef GOLDOBJ
    struct obj goldobj;
#endif

    /* in case it was acquired while blinded */
    if (!Blind) tstone->dknown = 1;
    /* when the touchstone is fully known, don't bother listing extra
junk as likely candidates for rubbing */
    choices = (tstone->otyp == TOUCHSTONE && tstone->dknown &&
objects[TOUCHSTONE].oc_name_known) ? justgems : allowall;
    Sprintf(stonebuf, "rub on the stone%s", plur(tstone->quan));
    if ((obj = getobj(choices, stonebuf)) == 0)
return;
#ifndef GOLDOBJ
    if (obj->oclass == COIN_CLASS) {
u.ugold += obj->quan; /* keep botl up to date */
goldobj = *obj;
dealloc_obj(obj);
obj = &goldobj;
    }
#endif

    if (obj == tstone && obj->quan == 1) {
You_cant("rub %s on itself.", the(xname(obj)));
return;
    }

    if (tstone->otyp == TOUCHSTONE && tstone->cursed &&
obj->oclass == GEM_CLASS && !is_graystone(obj) &&
!obj_resists(obj, 80, 100)) {
if (Blind)
pline("You feel something shatter.");
else if (Hallucination)
pline("Oh, wow, look at the pretty shards.");
else
pline("A sharp crack shatters %s%s.",
(obj->quan > 1) ? "one of " : "", the(xname(obj)));
#ifndef GOLDOBJ
     /* assert(obj != &goldobj); */
#endif
useup(obj);
return;
    }

    if (Blind) {
pline(scritch);
return;
    } else if (Hallucination) {
pline("Oh wow, man: Fractals!");
return;
    }

    do_scratch = FALSE;
    streak_color = 0;

    switch (obj->oclass) {
    case GEM_CLASS: /* these have class-specific handling below */
    case RING_CLASS:
if (tstone->otyp != TOUCHSTONE) {
do_scratch = TRUE;
} else if (obj->oclass == GEM_CLASS && (tstone->blessed ||
(!tstone->cursed &&
(Role_if(PM_ARCHEOLOGIST) || Race_if(PM_GNOME))))) {
makeknown(TOUCHSTONE);
makeknown(obj->otyp);
prinv((char *)0, obj, 0L);
return;
} else {
/* either a ring or the touchstone was not effective */
if (objects[obj->otyp].oc_material == GLASS) {
do_scratch = TRUE;
break;
}
}
streak_color = c_obj_colors[objects[obj->otyp].oc_color];
break; /* gem or ring */

    default:
switch (objects[obj->otyp].oc_material) {
case CLOTH:
pline("%s a little more polished now.", Tobjnam(tstone, "look"));
return;
case LIQUID:
if (!obj->known) /* note: not "whetstone" */
You("must think this is a wetstone, do you?");
else
pline("%s a little wetter now.", Tobjnam(tstone, "are"));
return;
case WAX:
streak_color = "waxy";
break; /* okay even if not touchstone */
case WOOD:
streak_color = "wooden";
break; /* okay even if not touchstone */
case GOLD:
do_scratch = TRUE; /* scratching and streaks */
streak_color = "golden";
break;
case SILVER:
do_scratch = TRUE; /* scratching and streaks */
streak_color = "silvery";
break;
default:
/* Objects passing the is_flimsy() test will not
scratch a stone. They will leave streaks on
non-touchstones and touchstones alike. */
if (is_flimsy(obj))
streak_color = c_obj_colors[objects[obj->otyp].oc_color];
else
do_scratch = (tstone->otyp != TOUCHSTONE);
break;
}
break; /* default oclass */
    }

    Sprintf(stonebuf, "stone%s", plur(tstone->quan));
    if (do_scratch)
pline("You make %s%sscratch marks on the %s.",
streak_color ? streak_color : (const char *)"",
streak_color ? " " : "", stonebuf);
    else if (streak_color)
pline("You see %s streaks on the %s.", streak_color, stonebuf);
    else
pline(scritch);
    return;
}

/* Place a landmine/bear trap. Helge Hafting */
STATIC_OVL void
use_trap(otmp)
struct obj *otmp;
{
int ttyp, tmp;
const char *what = (char *)0;
char buf[BUFSZ];
const char *occutext = "setting the trap";

if (nohands(youmonst.data))
what = "without hands";
else if (Stunned)
what = "while stunned";
else if (u.uswallow)
what = is_animal(u.ustuck->data) ? "while swallowed" :
"while engulfed";
else if (Underwater)
what = "underwater";
else if (Levitation)
what = "while levitating";
else if (is_pool(u.ux, u.uy))
what = "in water";
else if (is_lava(u.ux, u.uy))
what = "in lava";
else if (On_stairs(u.ux, u.uy))
what = (u.ux == xdnladder || u.ux == xupladder) ?
"on the ladder" : "on the stairs";
else if (IS_FURNITURE(levl[u.ux][u.uy].typ) ||
IS_ROCK(levl[u.ux][u.uy].typ) ||
closed_door(u.ux, u.uy) || t_at(u.ux, u.uy))
what = "here";
if (what) {
You_cant("set a trap %s!",what);
reset_trapset();
return;
}
ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP;
if (otmp == trapinfo.tobj &&
u.ux == trapinfo.tx && u.uy == trapinfo.ty) {
You("resume setting %s %s.",
shk_your(buf, otmp),
defsyms[trap_to_defsym(what_trap(ttyp))].explanation);
set_occupation(set_trap, occutext, 0);
return;
}
trapinfo.tobj = otmp;
trapinfo.tx = u.ux, trapinfo.ty = u.uy;
tmp = ACURR(A_DEX);
trapinfo.time_needed = (tmp > 17) ? 2 : (tmp > 12) ? 3 :
(tmp > 7) ? 4 : 5;
if (Blind) trapinfo.time_needed *= 2;
tmp = ACURR(A_STR);
if (ttyp == BEAR_TRAP && tmp < 18)
trapinfo.time_needed += (tmp > 12) ? 1 : (tmp > 7) ? 2 : 4;
/*[fumbling and/or confusion and/or cursed object check(s)
should be incorporated here instead of in set_trap]*/
#ifdef STEED
if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) {
boolean chance;

if (Fumbling || otmp->cursed) chance = (rnl(10) > 3);
else chance = (rnl(10) > 5);
You("aren't very skilled at reaching from %s.",
mon_nam(u.usteed));
Sprintf(buf, "Continue your attempt to set %s?",
the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation));
if(yn(buf) == 'y') {
if (chance) {
switch(ttyp) {
case LANDMINE: /* set it off */
trapinfo.time_needed = 0;
trapinfo.force_bungle = TRUE;
break;
case BEAR_TRAP: /* drop it without arming it */
reset_trapset();
You("drop %s!",
the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation));
dropx(otmp);
return;
}
}
} else {
reset_trapset();
return;
}
}
#endif
You("begin setting %s %s.",
shk_your(buf, otmp),
defsyms[trap_to_defsym(what_trap(ttyp))].explanation);
set_occupation(set_trap, occutext, 0);
return;
}

STATIC_PTR
int
set_trap()
{
struct obj *otmp = trapinfo.tobj;
struct trap *ttmp;
int ttyp;

if (!otmp || !carried(otmp) ||
u.ux != trapinfo.tx || u.uy != trapinfo.ty) {
/* ?? */
reset_trapset();
return 0;
}

if (--trapinfo.time_needed > 0) return 1; /* still busy */

ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP;
ttmp = maketrap(u.ux, u.uy, ttyp);
if (ttmp) {
ttmp->tseen = 1;
ttmp->madeby_u = 1;
newsym(u.ux, u.uy); /* if our hero happens to be invisible */
if (*in_rooms(u.ux,u.uy,SHOPBASE)) {
add_damage(u.ux, u.uy, 0L); /* schedule removal */
}
if (!trapinfo.force_bungle)
You("finish arming %s.",
the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation));
if (((otmp->cursed || Fumbling) && (rnl(10) > 5)) || trapinfo.force_bungle)
dotrap(ttmp,
(unsigned)(trapinfo.force_bungle ? FORCEBUNGLE : 0));
} else {
/* this shouldn't happen */
Your("trap setting attempt fails.");
}
useup(otmp);
reset_trapset();
return 0;
}

STATIC_OVL int
use_whip(obj)
struct obj *obj;
{
    char buf[BUFSZ];
    struct monst *mtmp;
    struct obj *otmp;
    int rx, ry, proficient, res = 0;
    const char *msg_slipsfree = "The bullwhip slips free.";
    const char *msg_snap = "Snap!";

    if (obj != uwep) {
if (!wield_tool(obj, "lash")) return 0;
else res = 1;
    }
    if (!getdir((char *)0)) return res;

    if (Stunned || (Confusion && !rn2(5))) confdir();
    rx = u.ux + u.dx;
    ry = u.uy + u.dy;
    mtmp = m_at(rx, ry);

    /* fake some proficiency checks */
    proficient = 0;
    if (Role_if(PM_ARCHEOLOGIST)) ++proficient;
    if (ACURR(A_DEX) < 6) proficient--;
    else if (ACURR(A_DEX) >= 14) proficient += (ACURR(A_DEX) - 14);
    if (Fumbling) --proficient;
    if (proficient > 3) proficient = 3;
    if (proficient < 0) proficient = 0;

    if (u.uswallow && attack(u.ustuck)) {
There("is not enough room to flick your bullwhip.");

    } else if (Underwater) {
There("is too much resistance to flick your bullwhip.");

    } else if (u.dz < 0) {
You("flick a bug off of the %s.",ceiling(u.ux,u.uy));

    } else if ((!u.dx && !u.dy) || (u.dz > 0)) {
int dam;

#ifdef STEED
/* Sometimes you hit your steed by mistake */
if (u.usteed && !rn2(proficient + 2)) {
You("whip %s!", mon_nam(u.usteed));
kick_steed();
return 1;
}
#endif
if (Levitation
#ifdef STEED
|| u.usteed
#endif
) {
/* Have a shot at snaring something on the floor */
otmp = level.objects[u.ux][u.uy];
if (otmp && otmp->otyp == CORPSE && otmp->corpsenm == PM_HORSE) {
pline("Why beat a dead horse?");
return 1;
}
if (otmp && proficient) {
You("wrap your bullwhip around %s on the %s.",
an(singular(otmp, xname)), surface(u.ux, u.uy));
if (rnl(6) || pickup_object(otmp, 1L, TRUE) < 1)
pline(msg_slipsfree);
return 1;
}
}
dam = rnd(2) + dbon() + obj->spe;
if (dam <= 0) dam = 1;
You("hit your %s with your bullwhip.", body_part(FOOT));
Sprintf(buf, "killed %sself with %s bullwhip", uhim(), uhis());
losehp(dam, buf, NO_KILLER_PREFIX);
flags.botl = 1;
return 1;

    } else if ((Fumbling || Glib) && !rn2(5)) {
pline_The("bullwhip slips out of your %s.", body_part(HAND));
dropx(obj);

    } else if (u.utrap && u.utraptype == TT_PIT) {
/*
* Assumptions:
*
* if you're in a pit
* - you are attempting to get out of the pit
* - or, if you are applying it towards a small
* monster then it is assumed that you are
* trying to hit it.
* else if the monster is wielding a weapon
* - you are attempting to disarm a monster
* else
* - you are attempting to hit the monster
*
* if you're confused (and thus off the mark)
* - you only end up hitting.
*
*/
const char *wrapped_what = (char *)0;

if (mtmp) {
if (bigmonst(mtmp->data)) {
wrapped_what = strcpy(buf, mon_nam(mtmp));
} else if (proficient) {
if (attack(mtmp)) return 1;
else pline(msg_snap);
}
}
if (!wrapped_what) {
if (IS_FURNITURE(levl[rx][ry].typ))
wrapped_what = something;
else if (sobj_at(BOULDER, rx, ry))
wrapped_what = "a boulder";
}
if (wrapped_what) {
coord cc;

cc.x = rx; cc.y = ry;
You("wrap your bullwhip around %s.", wrapped_what);
if (proficient && rn2(proficient + 2)) {
if (!mtmp || enexto(&cc, rx, ry, youmonst.data)) {
You("yank yourself out of the pit!");
teleds(cc.x, cc.y, TRUE);
u.utrap = 0;
vision_full_recalc = 1;
}
} else {
pline(msg_slipsfree);
}
if (mtmp) wakeup(mtmp);
} else pline(msg_snap);

    } else if (mtmp) {
if (!canspotmon(mtmp) &&
!glyph_is_invisible(levl[rx][ry].glyph)) {
pline("A monster is there that you couldn't see.");
map_invisible(rx, ry);
}
otmp = MON_WEP(mtmp); /* can be null */
if (otmp) {
char onambuf[BUFSZ];
const char *mon_hand;
boolean gotit = proficient && (!Fumbling || !rn2(10));

Strcpy(onambuf, cxname(otmp));
if (gotit) {
mon_hand = mbodypart(mtmp, HAND);
if (bimanual(otmp)) mon_hand = makeplural(mon_hand);
} else
mon_hand = 0; /* lint suppression */

You("wrap your bullwhip around %s %s.",
s_suffix(mon_nam(mtmp)), onambuf);
if (gotit && otmp->cursed) {
pline("%s welded to %s %s%c",
(otmp->quan == 1L) ? "It is" : "They are",
mhis(mtmp), mon_hand,
!otmp->bknown ? '!' : '.');
otmp->bknown = 1;
gotit = FALSE; /* can't pull it free */
}
if (gotit) {
obj_extract_self(otmp);
possibly_unwield(mtmp, FALSE);
setmnotwielded(mtmp,otmp);

switch (rn2(proficient + 1)) {
case 2:
/* to floor near you */
You("yank %s %s to the %s!", s_suffix(mon_nam(mtmp)),
onambuf, surface(u.ux, u.uy));
place_object(otmp, u.ux, u.uy);
stackobj(otmp);
break;
case 3:
/* right to you */
#if 0
if (!rn2(25)) {
/* proficient with whip, but maybe not
so proficient at catching weapons */
int hitu, hitvalu;

hitvalu = 8 + otmp->spe;
hitu = thitu(hitvalu,
dmgval(otmp, &youmonst),
otmp, (char *)0);
if (hitu) {
pline_The("%s hits you as you try to snatch it!",
the(onambuf));
}
place_object(otmp, u.ux, u.uy);
stackobj(otmp);
break;
}
#endif /* 0 */
/* right into your inventory */
You("snatch %s %s!", s_suffix(mon_nam(mtmp)), onambuf);
if (otmp->otyp == CORPSE &&
touch_petrifies(&mons[otmp->corpsenm]) &&
!uarmg && !Stone_resistance &&
!(poly_when_stoned(youmonst.data) &&
polymon(PM_STONE_GOLEM))) {
char kbuf[BUFSZ];

Sprintf(kbuf, "%s corpse",
an(mons[otmp->corpsenm].mname));
pline("Snatching %s is a fatal mistake.", kbuf);
instapetrify(kbuf);
}
otmp = hold_another_object(otmp, "You drop %s!",
doname(otmp), (const char *)0);
break;
default:
/* to floor beneath mon */
You("yank %s from %s %s!", the(onambuf),
s_suffix(mon_nam(mtmp)), mon_hand);
obj_no_longer_held(otmp);
place_object(otmp, mtmp->mx, mtmp->my);
stackobj(otmp);
break;
}
} else {
pline(msg_slipsfree);
}
wakeup(mtmp);
} else {
if (mtmp->m_ap_type &&
!Protection_from_shape_changers && !sensemon(mtmp))
stumble_onto_mimic(mtmp);
else You("flick your bullwhip towards %s.", mon_nam(mtmp));
if (proficient) {
if (attack(mtmp)) return 1;
else pline(msg_snap);
}
}

    } else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) {
/* it must be air -- water checked above */
You("snap your whip through thin air.");

    } else {
pline(msg_snap);

    }
    return 1;
}


static const char
not_enough_room[] = "There's not enough room here to use that.",
where_to_hit[] = "Where do you want to hit?",
cant_see_spot[] = "won't hit anything if you can't see that spot.",
cant_reach[] = "can't reach that spot from here.";

/* Distance attacks by pole-weapons */
STATIC_OVL int
use_pole (obj)
struct obj *obj;
{
int res = 0, typ, max_range = 4, min_range = 4;
coord cc;
struct monst *mtmp;


/* Are you allowed to use the pole? */
if (u.uswallow) {
pline(not_enough_room);
return (0);
}
if (obj != uwep) {
if (!wield_tool(obj, "swing")) return(0);
else res = 1;
}
     /* assert(obj == uwep); */

/* Prompt for a location */
pline(where_to_hit);
cc.x = u.ux;
cc.y = u.uy;
if (getpos(&cc, TRUE, "the spot to hit") < 0)
return 0; /* user pressed ESC */

/* Calculate range */
typ = uwep_skill_type();
if (typ == P_NONE || P_SKILL(typ) <= P_BASIC) max_range = 4;
else if (P_SKILL(typ) == P_SKILLED) max_range = 5;
else max_range = 8;
if (distu(cc.x, cc.y) > max_range) {
pline("Too far!");
return (res);
} else if (distu(cc.x, cc.y) < min_range) {
pline("Too close!");
return (res);
} else if (!cansee(cc.x, cc.y) &&
((mtmp = m_at(cc.x, cc.y)) == (struct monst *)0 ||
!canseemon(mtmp))) {
You(cant_see_spot);
return (res);
} else if (!couldsee(cc.x, cc.y)) { /* Eyes of the Overworld */
You(cant_reach);
return res;
}

/* Attack the monster there */
if ((mtmp = m_at(cc.x, cc.y)) != (struct monst *)0) {
int oldhp = mtmp->mhp;

bhitpos = cc;
check_caitiff(mtmp);
(void) thitmonst(mtmp, uwep);
/* check the monster's HP because thitmonst() doesn't return
* an indication of whether it hit. Not perfect (what if it's a
* non-silver weapon on a shade?)
*/
if (mtmp->mhp < oldhp)
u.uconduct.weaphit++;
} else
/* Now you know that nothing is there... */
pline(nothing_happens);
return (1);
}

STATIC_OVL int
use_cream_pie(obj)
struct obj *obj;
{
boolean wasblind = Blind;
boolean wascreamed = u.ucreamed;
boolean several = FALSE;

if (obj->quan > 1L) {
several = TRUE;
obj = splitobj(obj, 1L);
}
if (Hallucination)
You("give yourself a facial.");
else
pline("You immerse your %s in %s%s.", body_part(FACE),
several ? "one of " : "",
several ? makeplural(the(xname(obj))) : the(xname(obj)));
if(can_blnd((struct monst*)0, &youmonst, AT_WEAP, obj)) {
int blindinc = rnd(25);
u.ucreamed += blindinc;
make_blinded(Blinded + (long)blindinc, FALSE);
if (!Blind || (Blind && wasblind))
pline("There's %ssticky goop all over your %s.",
wascreamed ? "more " : "",
body_part(FACE));
else /* Blind && !wasblind */
You_cant("see through all the sticky goop on your %s.",
body_part(FACE));
}
if (obj->unpaid) {
verbalize("You used it, you bought it!");
bill_dummy_object(obj);
}
obj_extract_self(obj);
delobj(obj);
return(0);
}

STATIC_OVL int
use_grapple (obj)
struct obj *obj;
{
int res = 0, typ, max_range = 4, tohit;
coord cc;
struct monst *mtmp;
struct obj *otmp;

/* Are you allowed to use the hook? */
if (u.uswallow) {
pline(not_enough_room);
return (0);
}
if (obj != uwep) {
if (!wield_tool(obj, "cast")) return(0);
else res = 1;
}
     /* assert(obj == uwep); */

/* Prompt for a location */
pline(where_to_hit);
cc.x = u.ux;
cc.y = u.uy;
if (getpos(&cc, TRUE, "the spot to hit") < 0)
return 0; /* user pressed ESC */

/* Calculate range */
typ = uwep_skill_type();
if (typ == P_NONE || P_SKILL(typ) <= P_BASIC) max_range = 4;
else if (P_SKILL(typ) == P_SKILLED) max_range = 5;
else max_range = 8;
if (distu(cc.x, cc.y) > max_range) {
pline("Too far!");
return (res);
} else if (!cansee(cc.x, cc.y)) {
You(cant_see_spot);
return (res);
} else if (!couldsee(cc.x, cc.y)) { /* Eyes of the Overworld */
You(cant_reach);
return res;
}

/* What do you want to hit? */
tohit = rn2(5);
if (typ != P_NONE && P_SKILL(typ) >= P_SKILLED) {
winid tmpwin = create_nhwindow(NHW_MENU);
anything any;
char buf[BUFSZ];
menu_item *selected;

any.a_void = 0; /* set all bits to zero */
any.a_int = 1; /* use index+1 (cant use 0) as identifier */
start_menu(tmpwin);
any.a_int++;
Sprintf(buf, "an object on the %s", surface(cc.x, cc.y));
add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
buf, MENU_UNSELECTED);
any.a_int++;
add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
"a monster", MENU_UNSELECTED);
any.a_int++;
Sprintf(buf, "the %s", surface(cc.x, cc.y));
add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
buf, MENU_UNSELECTED);
end_menu(tmpwin, "Aim for what?");
tohit = rn2(4);
if (select_menu(tmpwin, PICK_ONE, &selected) > 0 &&
rn2(P_SKILL(typ) > P_SKILLED ? 20 : 2))
tohit = selected[0].item.a_int - 1;
free((genericptr_t)selected);
destroy_nhwindow(tmpwin);
}

/* What did you hit? */
switch (tohit) {
case 0: /* Trap */
/* FIXME -- untrap needs to deal with non-adjacent traps */
break;
case 1: /* Object */
if ((otmp = level.objects[cc.x][cc.y]) != 0) {
You("snag an object from the %s!", surface(cc.x, cc.y));
(void) pickup_object(otmp, 1L, FALSE);
/* If pickup fails, leave it alone */
newsym(cc.x, cc.y);
return (1);
}
break;
case 2: /* Monster */
if ((mtmp = m_at(cc.x, cc.y)) == (struct monst *)0) break;
if (verysmall(mtmp->data) && !rn2(4) &&
enexto(&cc, u.ux, u.uy, (struct permonst *)0)) {
You("pull in %s!", mon_nam(mtmp));
mtmp->mundetected = 0;
rloc_to(mtmp, cc.x, cc.y);
return (1);
} else if ((!bigmonst(mtmp->data) && !strongmonst(mtmp->data)) ||
rn2(4)) {
(void) thitmonst(mtmp, uwep);
return (1);
}
/* FALL THROUGH */
case 3: /* Surface */
if (IS_AIR(levl[cc.x][cc.y].typ) || is_pool(cc.x, cc.y))
pline_The("hook slices through the %s.", surface(cc.x, cc.y));
else {
You("are yanked toward the %s!", surface(cc.x, cc.y));
hurtle(sgn(cc.x-u.ux), sgn(cc.y-u.uy), 1, FALSE);
spoteffects(TRUE);
}
return (1);
default: /* Yourself (oops!) */
if (P_SKILL(typ) <= P_BASIC) {
You("hook yourself!");
losehp(rn1(10,10), "a grappling hook", KILLED_BY);
return (1);
}
break;
}
pline(nothing_happens);
return (1);
}


#define BY_OBJECT ((struct monst *)0)

/* return 1 if the wand is broken, hence some time elapsed */
STATIC_OVL int
do_break_wand(obj)
    struct obj *obj;
{
    static const char nothing_else_happens[] = "But nothing else happens...";
    register int i, x, y;
    register struct monst *mon;
    int dmg, damage;
    boolean affects_objects;
    boolean shop_damage = FALSE;
    int expltype = EXPL_MAGICAL;
    char confirm[QBUFSZ], the_wand[BUFSZ], buf[BUFSZ];

    Strcpy(the_wand, yname(obj));
    Sprintf(confirm, "Are you really sure you want to break %s?",
safe_qbuf("", sizeof("Are you really sure you want to break ?"),
the_wand, ysimple_name(obj), "the wand"));
    if (yn(confirm) == 'n' ) return 0;

    if (nohands(youmonst.data)) {
You_cant("break %s without hands!", the_wand);
return 0;
    } else if (ACURR(A_STR) < 10) {
You("don't have the strength to break %s!", the_wand);
return 0;
    }
    pline("Raising %s high above your %s, you break it in two!",
the_wand, body_part(HEAD));

    /* [ALI] Do this first so that wand is removed from bill. Otherwise,
* the freeinv() below also hides it from setpaid() which causes problems.
*/
    if (obj->unpaid) {
check_unpaid(obj); /* Extra charge for use */
bill_dummy_object(obj);
    }

    current_wand = obj; /* destroy_item might reset this */
    freeinv(obj); /* hide it from destroy_item instead... */
    setnotworn(obj); /* so we need to do this ourselves */

    if (obj->spe <= 0) {
pline(nothing_else_happens);
goto discard_broken_wand;
    }
    obj->ox = u.ux;
    obj->oy = u.uy;
    dmg = obj->spe * 4;
    affects_objects = FALSE;

    switch (obj->otyp) {
    case WAN_WISHING:
    case WAN_NOTHING:
    case WAN_LOCKING:
    case WAN_PROBING:
    case WAN_ENLIGHTENMENT:
    case WAN_OPENING:
    case WAN_SECRET_DOOR_DETECTION:
pline(nothing_else_happens);
goto discard_broken_wand;
    case WAN_DEATH:
    case WAN_LIGHTNING:
dmg *= 4;
goto wanexpl;
    case WAN_FIRE:
expltype = EXPL_FIERY;
    case WAN_COLD:
if (expltype == EXPL_MAGICAL) expltype = EXPL_FROSTY;
dmg *= 2;
    case WAN_MAGIC_MISSILE:
    wanexpl:
explode(u.ux, u.uy,
(obj->otyp - WAN_MAGIC_MISSILE), dmg, WAND_CLASS, expltype);
makeknown(obj->otyp); /* explode described the effect */
goto discard_broken_wand;
    case WAN_STRIKING:
/* we want this before the explosion instead of at the very end */
pline("A wall of force smashes down around you!");
dmg = d(1 + obj->spe,6); /* normally 2d12 */
    case WAN_CANCELLATION:
    case WAN_POLYMORPH:
    case WAN_TELEPORTATION:
    case WAN_UNDEAD_TURNING:
affects_objects = TRUE;
break;
    default:
break;
    }

    /* magical explosion and its visual effect occur before specific effects */
    explode(obj->ox, obj->oy, 0, rnd(dmg), WAND_CLASS, EXPL_MAGICAL);

    /* this makes it hit us last, so that we can see the action first */
    for (i = 0; i <= 8; i++) {
bhitpos.x = x = obj->ox + xdir[i];
bhitpos.y = y = obj->oy + ydir[i];
if (!isok(x,y)) continue;

if (obj->otyp == WAN_DIGGING) {
if(dig_check(BY_OBJECT, FALSE, x, y)) {
if (IS_WALL(levl[x][y].typ) || IS_DOOR(levl[x][y].typ)) {
/* normally, pits and holes don't anger guards, but they
* do if it's a wall or door that's being dug */
watch_dig((struct monst *)0, x, y, TRUE);
if (*in_rooms(x,y,SHOPBASE)) shop_damage = TRUE;
}
digactualhole(x, y, BY_OBJECT,
(rn2(obj->spe) < 3 || !Can_dig_down(&u.uz)) ?
PIT : HOLE);
}
continue;
} else if(obj->otyp == WAN_CREATE_MONSTER) {
/* u.ux,u.uy creates it near you--x,y might create it in rock */
(void) makemon((struct permonst *)0, u.ux, u.uy, NO_MM_FLAGS);
continue;
} else {
if (x == u.ux && y == u.uy) {
/* teleport objects first to avoid race with tele control and
autopickup. Other wand/object effects handled after
possible wand damage is assessed */
if (obj->otyp == WAN_TELEPORTATION &&
affects_objects && level.objects[x][y]) {
(void) bhitpile(obj, bhito, x, y);
if (flags.botl) bot(); /* potion effects */
}
damage = zapyourself(obj, FALSE);
if (damage) {
Sprintf(buf, "killed %sself by breaking a wand", uhim());
losehp(damage, buf, NO_KILLER_PREFIX);
}
if (flags.botl) bot(); /* blindness */
} else if ((mon = m_at(x, y)) != 0) {
(void) bhitm(mon, obj);
/* if (flags.botl) bot(); */
}
if (affects_objects && level.objects[x][y]) {
(void) bhitpile(obj, bhito, x, y);
if (flags.botl) bot(); /* potion effects */
}
}
    }

    /* Note: if player fell thru, this call is a no-op.
Damage is handled in digactualhole in that case */
    if (shop_damage) pay_for_damage("dig into", FALSE);

    if (obj->otyp == WAN_LIGHT)
litroom(TRUE, obj); /* only needs to be done once */

 discard_broken_wand:
    obj = current_wand; /* [see dozap() and destroy_item()] */
    current_wand = 0;
    if (obj)
delobj(obj);
    nomul(0);
    return 1;
}

STATIC_OVL boolean
uhave_graystone()
{
register struct obj *otmp;

for(otmp = invent; otmp; otmp = otmp->nobj)
if(is_graystone(otmp))
return TRUE;
return FALSE;
}

STATIC_OVL void
add_class(cl, class)
char *cl;
char class;
{
char tmp[2];
tmp[0] = class;
tmp[1] = '\0';
Strcat(cl, tmp);
}

int
doapply()
{
struct obj *obj;
register int res = 1;
char class_list[MAXOCLASSES+2];

if(check_capacity((char *)0)) return (0);

if (carrying(POT_OIL) || uhave_graystone())
Strcpy(class_list, tools_too);
else
Strcpy(class_list, tools);
if (carrying(CREAM_PIE) || carrying(EUCALYPTUS_LEAF))
add_class(class_list, FOOD_CLASS);

obj = getobj(class_list, "use or apply");
if(!obj) return 0;

if (obj->oartifact && !touch_artifact(obj, &youmonst))
return 1; /* evading your grasp costs a turn; just be
grateful that you don't drop it as well */

if (obj->oclass == WAND_CLASS)
return do_break_wand(obj);

switch(obj->otyp){
case BLINDFOLD:
case LENSES:
if (obj == ublindf) {
if (!cursed(obj)) Blindf_off(obj);
} else if (!ublindf)
Blindf_on(obj);
else You("are already %s.",
ublindf->otyp == TOWEL ? "covered by a towel" :
ublindf->otyp == BLINDFOLD ? "wearing a blindfold" :
"wearing lenses");
break;
case CREAM_PIE:
res = use_cream_pie(obj);
break;
case BULLWHIP:
res = use_whip(obj);
break;
case GRAPPLING_HOOK:
res = use_grapple(obj);
break;
case LARGE_BOX:
case CHEST:
case ICE_BOX:
case SACK:
case BAG_OF_HOLDING:
case OILSKIN_SACK:
res = use_container(obj, 1);
break;
case BAG_OF_TRICKS:
bagotricks(obj);
break;
case CAN_OF_GREASE:
use_grease(obj);
break;
case LOCK_PICK:
#ifdef TOURIST
case CREDIT_CARD:
#endif
case SKELETON_KEY:
(void) pick_lock(obj);
break;
case PICK_AXE:
case DWARVISH_MATTOCK:
res = use_pick_axe(obj);
break;
case TINNING_KIT:
use_tinning_kit(obj);
break;
case LEASH:
use_leash(obj);
break;
#ifdef STEED
case SADDLE:
res = use_saddle(obj);
break;
#endif
case MAGIC_WHISTLE:
use_magic_whistle(obj);
break;
case TIN_WHISTLE:
use_whistle(obj);
break;
case EUCALYPTUS_LEAF:
/* MRKR: Every Australian knows that a gum leaf makes an */
/* excellent whistle, especially if your pet is a */
/* tame kangaroo named Skippy. */
if (obj->blessed) {
use_magic_whistle(obj);
/* sometimes the blessing will be worn off */
if (!rn2(49)) {
if (!Blind) {
char buf[BUFSZ];

pline("%s %s %s.", Shk_Your(buf, obj),
aobjnam(obj, "glow"), hcolor("brown"));
obj->bknown = 1;
}
unbless(obj);
}
} else {
use_whistle(obj);
}
break;
case STETHOSCOPE:
res = use_stethoscope(obj);
break;
case MIRROR:
res = use_mirror(obj);
break;
case BELL:
case BELL_OF_OPENING:
use_bell(&obj);
break;
case CANDELABRUM_OF_INVOCATION:
use_candelabrum(obj);
break;
case WAX_CANDLE:
case TALLOW_CANDLE:
use_candle(&obj);
break;
case OIL_LAMP:
case MAGIC_LAMP:
case BRASS_LANTERN:
use_lamp(obj);
break;
case POT_OIL:
light_cocktail(obj);
break;
#ifdef TOURIST
case EXPENSIVE_CAMERA:
res = use_camera(obj);
break;
#endif
case TOWEL:
res = use_towel(obj);
break;
case CRYSTAL_BALL:
use_crystal_ball(obj);
break;
case MAGIC_MARKER:
res = dowrite(obj);
break;
case TIN_OPENER:
if(!carrying(TIN)) {
You("have no tin to open.");
goto xit;
}
You("cannot open a tin without eating or discarding its contents.");
if(flags.verbose)
pline("In order to eat, use the 'e' command.");
if(obj != uwep)
    pline("Opening the tin will be much easier if you wield the tin opener.");
goto xit;

case FIGURINE:
use_figurine(&obj);
break;
case UNICORN_HORN:
use_unicorn_horn(obj);
break;
case WOODEN_FLUTE:
case MAGIC_FLUTE:
case TOOLED_HORN:
case FROST_HORN:
case FIRE_HORN:
case WOODEN_HARP:
case MAGIC_HARP:
case BUGLE:
case LEATHER_DRUM:
case DRUM_OF_EARTHQUAKE:
res = do_play_instrument(obj);
break;
case HORN_OF_PLENTY: /* not a musical instrument */
if (obj->spe > 0) {
struct obj *otmp;
const char *what;

consume_obj_charge(obj, TRUE);
if (!rn2(13)) {
otmp = mkobj(POTION_CLASS, FALSE);
if (objects[otmp->otyp].oc_magic) do {
otmp->otyp = rnd_class(POT_BOOZE, POT_WATER);
} while (otmp->otyp == POT_SICKNESS);
what = "A potion";
} else {
otmp = mkobj(FOOD_CLASS, FALSE);
if (otmp->otyp == FOOD_RATION && !rn2(7))
otmp->otyp = LUMP_OF_ROYAL_JELLY;
what = "Some food";
}
pline("%s spills out.", what);
otmp->blessed = obj->blessed;
otmp->cursed = obj->cursed;
otmp->owt = weight(otmp);
otmp = hold_another_object(otmp, u.uswallow ?
"Oops! %s out of your reach!" :
(Is_airlevel(&u.uz) ||
Is_waterlevel(&u.uz) ||
levl[u.ux][u.uy].typ < IRONBARS ||
levl[u.ux][u.uy].typ >= ICE) ?
"Oops! %s away from you!" :
"Oops! %s to the floor!",
The(aobjnam(otmp, "slip")),
(const char *)0);
makeknown(HORN_OF_PLENTY);
} else
pline(nothing_happens);
break;
case LAND_MINE:
case BEARTRAP:
use_trap(obj);
break;
case FLINT:
case LUCKSTONE:
case LOADSTONE:
case TOUCHSTONE:
use_stone(obj);
break;
default:
/* Pole-weapons can strike at a distance */
if (is_pole(obj)) {
res = use_pole(obj);
break;
} else if (is_pick(obj) || is_axe(obj)) {
res = use_pick_axe(obj);
break;
}
pline("Sorry, I don't know how to use that.");
xit:
nomul(0);
return 0;
}
if (res && obj && obj->oartifact) arti_speak(obj);
nomul(0);
return res;
}

/* Keep track of unfixable troubles for purposes of messages saying you feel
* great.
*/
int
unfixable_trouble_count(is_horn)
boolean is_horn;
{
int unfixable_trbl = 0;

if (Stoned) unfixable_trbl++;
if (Strangled) unfixable_trbl++;
if (Wounded_legs
#ifdef STEED
&& !u.usteed
#endif
) unfixable_trbl++;
if (Slimed) unfixable_trbl++;
/* lycanthropy is not desirable, but it doesn't actually make you feel
bad */

/* we'll assume that intrinsic stunning from being a bat/stalker
doesn't make you feel bad */
if (!is_horn) {
if (Confusion) unfixable_trbl++;
if (Sick) unfixable_trbl++;
if (HHallucination) unfixable_trbl++;
if (Vomiting) unfixable_trbl++;
if (HStun) unfixable_trbl++;
}
return unfixable_trbl;
}

#endif /* OVLB */

/*apply.c*/
Something went wrong with that request. Please try again.