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
|
/*
* File: decks.cc
* Summary: Functions with decks of cards.
*/
#include "AppHdr.h"
#include "decks.h"
#include <iostream>
#include <algorithm>
#include "externs.h"
#include "beam.h"
#include "cio.h"
#include "coordit.h"
#include "database.h"
#include "dgn-actions.h"
#include "dungeon.h"
#include "effects.h"
#include "env.h"
#include "files.h"
#include "food.h"
#include "ghost.h"
#include "godwrath.h"
#include "invent.h"
#include "it_use2.h"
#include "item_use.h"
#include "itemprop.h"
#include "items.h"
#include "makeitem.h"
#include "maps.h"
#include "message.h"
#include "misc.h"
#include "mon-iter.h"
#include "mon-place.h"
#include "mon-util.h"
#include "mgen_data.h"
#include "coord.h"
#include "mon-stuff.h"
#include "mutation.h"
#include "options.h"
#include "ouch.h"
#include "player.h"
#include "player-stats.h"
#include "religion.h"
#include "godconduct.h"
#include "skills2.h"
#include "spells1.h"
#include "spells2.h"
#include "spells3.h"
#include "spells4.h"
#include "spl-cast.h"
#include "spl-mis.h"
#include "spl-util.h"
#include "state.h"
#include "stuff.h"
#include "terrain.h"
#include "transform.h"
#include "traps.h"
#include "view.h"
#include "xom.h"
// DECK STRUCTURE: deck.plus is the number of cards the deck *started*
// with, deck.plus2 is the number of cards drawn, deck.special is the
// deck rarity, deck.props["cards"] holds the list of cards (with the
// highest index card being the top card, and index 0 being the bottom
// card), deck.props["drawn_cards"] holds the list of drawn cards
// (with index 0 being the first drawn), deck.props["card_flags"]
// holds the flags for each card, deck.props["num_marked"] is the
// number of marked cards left in the deck, and
// deck.props["non_brownie_draws"] is the number of non-marked draws
// you have to make from that deck before earning brownie points from
// it again.
//
// The card type and per-card flags are each stored as unsigned bytes,
// for a maximum of 256 different kinds of cards and 8 bits of flags.
static void _deck_ident(item_def& deck);
struct card_with_weights
{
card_type card;
int weight[3];
};
typedef card_with_weights deck_archetype;
#define END_OF_DECK {NUM_CARDS, {0,0,0}}
const deck_archetype deck_of_transport[] = {
{ CARD_PORTAL, {5, 5, 5} },
{ CARD_WARP, {5, 5, 5} },
{ CARD_SWAP, {5, 5, 5} },
{ CARD_VELOCITY, {5, 5, 5} },
END_OF_DECK
};
const deck_archetype deck_of_emergency[] = {
{ CARD_TOMB, {5, 5, 5} },
{ CARD_BANSHEE, {5, 5, 5} },
{ CARD_DAMNATION, {0, 1, 2} },
{ CARD_SOLITUDE, {5, 5, 5} },
{ CARD_WARPWRIGHT, {5, 5, 5} },
{ CARD_FLIGHT, {5, 5, 5} },
END_OF_DECK
};
const deck_archetype deck_of_destruction[] = {
{ CARD_VITRIOL, {5, 5, 5} },
{ CARD_FLAME, {5, 5, 5} },
{ CARD_FROST, {5, 5, 5} },
{ CARD_VENOM, {5, 5, 5} },
{ CARD_HAMMER, {5, 5, 5} },
{ CARD_SPARK, {5, 5, 5} },
{ CARD_PAIN, {5, 5, 5} },
{ CARD_TORMENT, {5, 5, 5} },
END_OF_DECK
};
const deck_archetype deck_of_battle[] = {
{ CARD_ELIXIR, {5, 5, 5} },
{ CARD_BATTLELUST, {5, 5, 5} },
{ CARD_METAMORPHOSIS, {5, 5, 5} },
{ CARD_HELM, {5, 5, 5} },
{ CARD_BLADE, {5, 5, 5} },
{ CARD_SHADOW, {5, 5, 5} },
END_OF_DECK
};
const deck_archetype deck_of_enchantments[] = {
{ CARD_ELIXIR, {5, 5, 5} },
END_OF_DECK
};
const deck_archetype deck_of_summoning[] = {
{ CARD_CRUSADE, {5, 5, 5} },
{ CARD_SUMMON_ANIMAL, {5, 5, 5} },
{ CARD_SUMMON_DEMON, {5, 5, 5} },
{ CARD_SUMMON_WEAPON, {5, 5, 5} },
{ CARD_SUMMON_FLYING, {5, 5, 5} },
{ CARD_SUMMON_SKELETON, {5, 5, 5} },
{ CARD_SUMMON_UGLY, {5, 5, 5} },
END_OF_DECK
};
const deck_archetype deck_of_wonders[] = {
{ CARD_POTION, {5, 5, 5} },
{ CARD_FOCUS, {1, 1, 2} },
{ CARD_SHUFFLE, {0, 1, 2} },
{ CARD_EXPERIENCE, {5, 5, 5} },
{ CARD_WILD_MAGIC, {5, 5, 5} },
{ CARD_HELIX, {5, 5, 5} },
{ CARD_SAGE, {5, 5, 5} },
END_OF_DECK
};
const deck_archetype deck_of_dungeons[] = {
{ CARD_WATER, {5, 5, 5} },
{ CARD_GLASS, {5, 5, 5} },
{ CARD_MAP, {5, 5, 5} },
{ CARD_DOWSING, {5, 5, 5} },
{ CARD_SPADE, {5, 5, 5} },
{ CARD_TROWEL, {5, 5, 5} },
{ CARD_MINEFIELD, {5, 5, 5} },
END_OF_DECK
};
const deck_archetype deck_of_oddities[] = {
{ CARD_GENIE, {5, 5, 5} },
{ CARD_BARGAIN, {5, 5, 5} },
{ CARD_WRATH, {5, 5, 5} },
{ CARD_XOM, {5, 5, 5} },
{ CARD_FEAST, {5, 5, 5} },
{ CARD_FAMINE, {5, 5, 5} },
{ CARD_CURSE, {5, 5, 5} },
END_OF_DECK
};
const deck_archetype deck_of_punishment[] = {
{ CARD_WRAITH, {5, 5, 5} },
{ CARD_WILD_MAGIC, {5, 5, 5} },
{ CARD_WRATH, {5, 5, 5} },
{ CARD_XOM, {5, 5, 5} },
{ CARD_FAMINE, {5, 5, 5} },
{ CARD_CURSE, {5, 5, 5} },
{ CARD_TOMB, {5, 5, 5} },
{ CARD_DAMNATION, {5, 5, 5} },
{ CARD_PORTAL, {5, 5, 5} },
{ CARD_MINEFIELD, {5, 5, 5} },
{ CARD_SWINE, {5, 5, 5} },
END_OF_DECK
};
static void _check_odd_card(unsigned char flags)
{
if ((flags & CFLAG_ODDITY) && !(flags & CFLAG_SEEN))
mpr("This card doesn't seem to belong here.");
}
int cards_in_deck(const item_def &deck)
{
ASSERT(is_deck(deck));
const CrawlHashTable &props = deck.props;
ASSERT(props.exists("cards"));
return (props["cards"].get_vector().size());
}
static void _shuffle_deck(item_def &deck)
{
ASSERT(is_deck(deck));
CrawlHashTable &props = deck.props;
ASSERT(props.exists("cards"));
CrawlVector &cards = props["cards"].get_vector();
CrawlVector &flags = props["card_flags"].get_vector();
ASSERT(flags.size() == cards.size());
// Don't use std::shuffle(), since we want to apply exactly the
// same shuffling to both the cards vector and the flags vector.
std::vector<vec_size> pos;
for (unsigned long i = 0; i < cards.size(); ++i)
pos.push_back(random2(cards.size()));
for (vec_size i = 0; i < pos.size(); ++i)
{
std::swap(cards[i], cards[pos[i]]);
std::swap(flags[i], flags[pos[i]]);
}
}
card_type get_card_and_flags(const item_def& deck, int idx,
unsigned char& _flags)
{
const CrawlHashTable &props = deck.props;
const CrawlVector &cards = props["cards"].get_vector();
const CrawlVector &flags = props["card_flags"].get_vector();
// Negative idx means read from the end.
if (idx < 0)
idx += static_cast<int>(cards.size());
_flags = (unsigned char) flags[idx].get_byte();
return static_cast<card_type>(cards[idx].get_byte());
}
static void _set_card_and_flags(item_def& deck, int idx, card_type card,
unsigned char _flags)
{
CrawlHashTable &props = deck.props;
CrawlVector &cards = props["cards"].get_vector();
CrawlVector &flags = props["card_flags"].get_vector();
if (idx == -1)
idx = static_cast<int>(cards.size()) - 1;
cards[idx] = (char) card;
flags[idx] = (char) _flags;
}
const char* card_name(card_type card)
{
switch (card)
{
case CARD_PORTAL: return "the Portal";
case CARD_WARP: return "the Warp";
case CARD_SWAP: return "Swap";
case CARD_VELOCITY: return "Velocity";
case CARD_DAMNATION: return "Damnation";
case CARD_SOLITUDE: return "Solitude";
case CARD_ELIXIR: return "the Elixir";
case CARD_BATTLELUST: return "Battlelust";
case CARD_METAMORPHOSIS: return "Metamorphosis";
case CARD_HELM: return "the Helm";
case CARD_BLADE: return "the Blade";
case CARD_SHADOW: return "the Shadow";
case CARD_POTION: return "the Potion";
case CARD_FOCUS: return "Focus";
case CARD_SHUFFLE: return "Shuffle";
case CARD_EXPERIENCE: return "Experience";
case CARD_HELIX: return "the Helix";
case CARD_SAGE: return "the Sage";
case CARD_DOWSING: return "Dowsing";
case CARD_TROWEL: return "the Trowel";
case CARD_MINEFIELD: return "the Minefield";
case CARD_STAIRS: return "the Stairs";
case CARD_GENIE: return "the Genie";
case CARD_TOMB: return "the Tomb";
case CARD_WATER: return "Water";
case CARD_GLASS: return "Vitrification";
case CARD_MAP: return "the Map";
case CARD_BANSHEE: return "the Banshee";
case CARD_WILD_MAGIC: return "Wild Magic";
case CARD_CRUSADE: return "the Crusade";
case CARD_SUMMON_ANIMAL: return "the Herd";
case CARD_SUMMON_DEMON: return "the Pentagram";
case CARD_SUMMON_WEAPON: return "the Dance";
case CARD_SUMMON_FLYING: return "Foxfire";
case CARD_SUMMON_SKELETON: return "the Bones";
case CARD_SUMMON_UGLY: return "Repulsiveness";
case CARD_SUMMON_ANY: return "Summoning";
case CARD_XOM: return "Xom";
case CARD_FAMINE: return "Famine";
case CARD_FEAST: return "the Feast";
case CARD_WARPWRIGHT: return "Warpwright";
case CARD_FLIGHT: return "Flight";
case CARD_VITRIOL: return "Vitriol";
case CARD_FLAME: return "Flame";
case CARD_FROST: return "Frost";
case CARD_VENOM: return "Venom";
case CARD_SPARK: return "the Spark";
case CARD_HAMMER: return "the Hammer";
case CARD_PAIN: return "Pain";
case CARD_TORMENT: return "Torment";
case CARD_SPADE: return "the Spade";
case CARD_BARGAIN: return "the Bargain";
case CARD_WRATH: return "Wrath";
case CARD_WRAITH: return "the Wraith";
case CARD_CURSE: return "the Curse";
case CARD_SWINE: return "the Swine";
case NUM_CARDS: return "a buggy card";
}
return "a very buggy card";
}
static const deck_archetype* _random_sub_deck(unsigned char deck_type)
{
const deck_archetype *pdeck = NULL;
switch (deck_type)
{
case MISC_DECK_OF_ESCAPE:
pdeck = (coinflip() ? deck_of_transport : deck_of_emergency);
break;
case MISC_DECK_OF_DESTRUCTION: pdeck = deck_of_destruction; break;
case MISC_DECK_OF_DUNGEONS: pdeck = deck_of_dungeons; break;
case MISC_DECK_OF_SUMMONING: pdeck = deck_of_summoning; break;
case MISC_DECK_OF_WONDERS: pdeck = deck_of_wonders; break;
case MISC_DECK_OF_PUNISHMENT: pdeck = deck_of_punishment; break;
case MISC_DECK_OF_WAR:
switch (random2(6))
{
case 0: pdeck = deck_of_destruction; break;
case 1: pdeck = deck_of_enchantments; break;
case 2: pdeck = deck_of_battle; break;
case 3: pdeck = deck_of_summoning; break;
case 4: pdeck = deck_of_transport; break;
case 5: pdeck = deck_of_emergency; break;
}
break;
case MISC_DECK_OF_CHANGES:
switch (random2(3))
{
case 0: pdeck = deck_of_battle; break;
case 1: pdeck = deck_of_dungeons; break;
case 2: pdeck = deck_of_wonders; break;
}
break;
case MISC_DECK_OF_DEFENCE:
pdeck = (coinflip() ? deck_of_emergency : deck_of_battle);
break;
}
ASSERT(pdeck);
return (pdeck);
}
static card_type _choose_from_archetype(const deck_archetype* pdeck,
deck_rarity_type rarity)
{
// We assume here that common == 0, rare == 1, legendary == 2.
// FIXME: We should use one of the various choose_random_weighted
// functions here, probably with an iterator, instead of
// duplicating the implementation.
int totalweight = 0;
card_type result = NUM_CARDS;
for (int i = 0; pdeck[i].card != NUM_CARDS; ++i)
{
const card_with_weights& cww = pdeck[i];
totalweight += cww.weight[rarity];
if (x_chance_in_y(cww.weight[rarity], totalweight))
result = cww.card;
}
return result;
}
static card_type _random_card(unsigned char deck_type, deck_rarity_type rarity,
bool &was_oddity)
{
const deck_archetype *pdeck = _random_sub_deck(deck_type);
if (one_chance_in(100))
{
pdeck = deck_of_oddities;
was_oddity = true;
}
return _choose_from_archetype(pdeck, rarity);
}
static card_type _random_card(const item_def& item, bool &was_oddity)
{
return _random_card(item.sub_type, deck_rarity(item), was_oddity);
}
static card_type _draw_top_card(item_def& deck, bool message,
unsigned char &_flags)
{
CrawlHashTable &props = deck.props;
CrawlVector &cards = props["cards"].get_vector();
CrawlVector &flags = props["card_flags"].get_vector();
int num_cards = cards.size();
int idx = num_cards - 1;
ASSERT(num_cards > 0);
card_type card = get_card_and_flags(deck, idx, _flags);
cards.pop_back();
flags.pop_back();
if (message)
{
if (_flags & CFLAG_MARKED)
mprf("You draw %s.", card_name(card));
else
mprf("You draw a card... It is %s.", card_name(card));
_check_odd_card(_flags);
}
return card;
}
static void _push_top_card(item_def& deck, card_type card,
unsigned char _flags)
{
CrawlHashTable &props = deck.props;
CrawlVector &cards = props["cards"].get_vector();
CrawlVector &flags = props["card_flags"].get_vector();
cards.push_back((char) card);
flags.push_back((char) _flags);
}
static void _remember_drawn_card(item_def& deck, card_type card, bool allow_id)
{
ASSERT( is_deck(deck) );
CrawlHashTable &props = deck.props;
CrawlVector &drawn = props["drawn_cards"].get_vector();
drawn.push_back( static_cast<char>(card) );
// Once you've drawn two cards, you know the deck.
if (allow_id && (drawn.size() >= 2 || origin_is_god_gift(deck)))
_deck_ident(deck);
}
const std::vector<card_type> get_drawn_cards(const item_def& deck)
{
std::vector<card_type> result;
if (is_deck(deck))
{
const CrawlHashTable &props = deck.props;
const CrawlVector &drawn = props["drawn_cards"].get_vector();
for (unsigned int i = 0; i < drawn.size(); ++i)
{
const char tmp = drawn[i];
result.push_back(static_cast<card_type>(tmp));
}
}
return result;
}
static bool _check_buggy_deck(item_def& deck)
{
std::ostream& strm = msg::streams(MSGCH_DIAGNOSTICS);
if (!is_deck(deck))
{
crawl_state.zero_turns_taken();
strm << "This isn't a deck at all!" << std::endl;
return (true);
}
CrawlHashTable &props = deck.props;
if (!props.exists("cards")
|| props["cards"].get_type() != SV_VEC
|| props["cards"].get_vector().get_type() != SV_BYTE
|| cards_in_deck(deck) == 0)
{
crawl_state.zero_turns_taken();
if (!props.exists("cards"))
strm << "Seems this deck never had any cards in the first place!";
else if (props["cards"].get_type() != SV_VEC)
strm << "'cards' property isn't a vector.";
else
{
if (props["cards"].get_vector().get_type() != SV_BYTE)
strm << "'cards' vector doesn't contain bytes.";
if (cards_in_deck(deck) == 0)
{
strm << "Strange, this deck is already empty.";
int cards_left = 0;
if (deck.plus2 >= 0)
cards_left = deck.plus - deck.plus2;
else
cards_left = -deck.plus;
if (cards_left != 0)
{
strm << " But there should have been " << cards_left
<< " cards left.";
}
}
}
strm << std::endl
<< "A swarm of software bugs snatches the deck from you "
"and whisks it away."
<< std::endl;
if (deck.link == you.equip[EQ_WEAPON])
unwield_item();
dec_inv_item_quantity( deck.link, 1 );
did_god_conduct(DID_CARDS, 1);
return (true);
}
bool problems = false;
CrawlVector &cards = props["cards"].get_vector();
CrawlVector &flags = props["card_flags"].get_vector();
vec_size num_cards = cards.size();
vec_size num_flags = flags.size();
unsigned int num_buggy = 0;
unsigned int num_marked = 0;
for (vec_size i = 0; i < num_cards; ++i)
{
unsigned char card = cards[i].get_byte();
unsigned char _flags = flags[i].get_byte();
if (card >= NUM_CARDS)
{
cards.erase(i);
flags.erase(i);
i--;
num_cards--;
num_buggy++;
}
else
{
if (_flags & CFLAG_MARKED)
num_marked++;
}
}
if (num_buggy > 0)
{
strm << num_buggy << " buggy cards found in the deck, discarding them."
<< std::endl;
deck.plus2 += num_buggy;
num_cards = cards.size();
num_flags = cards.size();
problems = true;
}
if (num_cards == 0)
{
crawl_state.zero_turns_taken();
strm << "Oops, all of the cards seem to be gone." << std::endl
<< "A swarm of software bugs snatches the deck from you "
"and whisks it away." << std::endl;
if (deck.link == you.equip[EQ_WEAPON])
unwield_item();
dec_inv_item_quantity( deck.link, 1 );
did_god_conduct(DID_CARDS, 1);
return (true);
}
if (static_cast<long>(num_cards) > deck.plus)
{
if (deck.plus == 0)
strm << "Deck was created with zero cards???" << std::endl;
else if (deck.plus < 0)
strm << "Deck was created with *negative* cards?!" << std::endl;
else
{
strm << "Deck has more cards than it was created with?"
<< std::endl;
}
deck.plus = num_cards;
problems = true;
}
if (num_cards > num_flags)
{
#ifdef WIZARD
strm << (num_cards - num_flags) << " more cards than flags.";
#else
strm << "More cards than flags.";
#endif
strm << std::endl;
for (unsigned int i = num_flags + 1; i <= num_cards; ++i)
flags[i] = static_cast<char>(0);
problems = true;
}
else if (num_flags > num_cards)
{
#ifdef WIZARD
strm << (num_cards - num_flags) << " more cards than flags.";
#else
strm << "More cards than flags.";
#endif
strm << std::endl;
for (unsigned int i = num_flags; i > num_cards; --i)
flags.erase(i);
problems = true;
}
if (props["num_marked"].get_byte() > static_cast<char>(num_cards))
{
strm << "More cards marked than in the deck?" << std::endl;
props["num_marked"] = static_cast<char>(num_marked);
problems = true;
}
else if (props["num_marked"].get_byte() != static_cast<char>(num_marked))
{
#ifdef WIZARD
strm << "Oops, counted " << static_cast<int>(num_marked)
<< " marked cards, but num_marked is "
<< (static_cast<int>(props["num_marked"].get_byte()));
#else
strm << "Oops, book-keeping on marked cards is wrong.";
#endif
strm << std::endl;
props["num_marked"] = static_cast<char>(num_marked);
problems = true;
}
if (deck.plus2 >= 0)
{
if (deck.plus != (deck.plus2 + static_cast<long>(num_cards)))
{
#ifdef WIZARD
strm << "Have you used " << deck.plus2 << " cards, or "
<< (deck.plus - num_cards) << "? Oops.";
#else
strm << "Oops, book-keeping on used cards is wrong.";
#endif
strm << std::endl;
deck.plus2 = deck.plus - num_cards;
problems = true;
}
}
else
{
if (-deck.plus2 != static_cast<long>(num_cards))
{
#ifdef WIZARD
strm << "There are " << num_cards << " cards left, not "
<< (-deck.plus2) << ". Oops.";
#else
strm << "Oops, book-keeping on cards left is wrong.";
#endif
strm << std::endl;
deck.plus2 = -num_cards;
problems = true;
}
}
if (!problems)
return (false);
you.wield_change = true;
if (!yesno("Problems might not have been completely fixed; "
"still use deck?", true, 'n'))
{
crawl_state.zero_turns_taken();
return (true);
}
return (false);
}
// Choose a deck from inventory and return its slot (or -1).
static int _choose_inventory_deck( const char* prompt )
{
const int slot = prompt_invent_item( prompt,
MT_INVLIST, OSEL_DRAW_DECK,
true, true, true, 0, -1, NULL,
OPER_EVOKE );
if (prompt_failed(slot))
return -1;
if (!is_deck(you.inv[slot]))
{
mpr("That isn't a deck!");
return -1;
}
return slot;
}
// Select a deck from inventory and draw a card from it.
bool choose_deck_and_draw()
{
const int slot = _choose_inventory_deck( "Draw from which deck?" );
if (slot == -1)
{
crawl_state.zero_turns_taken();
return (false);
}
evoke_deck(you.inv[slot]);
return (true);
}
static void _deck_ident(item_def& deck)
{
if (in_inventory(deck) && !item_ident(deck, ISFLAG_KNOW_TYPE))
{
set_ident_flags(deck, ISFLAG_KNOW_TYPE);
mprf("This is %s.", deck.name(DESC_NOCAP_A).c_str());
you.wield_change = true;
}
}
// This also shuffles the deck.
static void _deck_lose_card(item_def& deck)
{
unsigned char flags = 0;
// Seen cards are only half as likely to fall out,
// marked cards only one-quarter as likely (note that marked
// cards are also seen.)
do
{
_shuffle_deck(deck);
get_card_and_flags(deck, -1, flags);
}
while ( (flags & CFLAG_MARKED) && coinflip()
|| (flags & CFLAG_SEEN) && coinflip() );
_draw_top_card(deck, false, flags);
deck.plus2++;
}
// Peek at two cards in a deck, then shuffle them back in.
// Return false if the operation was failed/aborted along the way.
bool deck_peek()
{
const int slot = _choose_inventory_deck( "Peek at which deck?" );
if (slot == -1)
{
crawl_state.zero_turns_taken();
return (false);
}
item_def& deck(you.inv[slot]);
if (_check_buggy_deck(deck))
return (false);
if (cards_in_deck(deck) > 2)
{
_deck_lose_card(deck);
mpr("A card falls out of the deck.");
}
CrawlVector &cards = deck.props["cards"].get_vector();
const int num_cards = cards.size();
card_type card1, card2;
unsigned char flags1, flags2;
card1 = get_card_and_flags(deck, 0, flags1);
if (num_cards == 1)
{
mpr("There's only one card in the deck!");
_set_card_and_flags(deck, 0, card1, flags1 | CFLAG_SEEN | CFLAG_MARKED);
deck.props["num_marked"]++;
deck.plus2 = -1;
you.wield_change = true;
return (true);
}
card2 = get_card_and_flags(deck, 1, flags2);
int already_seen = 0;
if (flags1 & CFLAG_SEEN)
already_seen++;
if (flags2 & CFLAG_SEEN)
already_seen++;
// Always increase if seen 2, 50% increase if seen 1.
if (already_seen && x_chance_in_y(already_seen, 2))
deck.props["non_brownie_draws"]++;
mprf("You draw two cards from the deck. They are: %s and %s.",
card_name(card1), card_name(card2));
_set_card_and_flags(deck, 0, card1, flags1 | CFLAG_SEEN);
_set_card_and_flags(deck, 1, card2, flags2 | CFLAG_SEEN);
mpr("You shuffle the cards back into the deck.");
_shuffle_deck(deck);
// Peeking identifies the deck.
_deck_ident(deck);
you.wield_change = true;
return (true);
}
// Mark a deck: look at the next four cards, mark them, and shuffle
// them back into the deck. The player won't know what order they're
// in, and if the top card is non-marked then the player won't
// know what the next card is. Return false if the operation was
// failed/aborted along the way.
bool deck_mark()
{
const int slot = _choose_inventory_deck( "Mark which deck?" );
if (slot == -1)
{
crawl_state.zero_turns_taken();
return (false);
}
item_def& deck(you.inv[slot]);
if (_check_buggy_deck(deck))
return (false);
CrawlHashTable &props = deck.props;
if (props["num_marked"].get_byte() > 0)
{
mpr("The deck is already marked.");
crawl_state.zero_turns_taken();
return (false);
}
// Lose some cards, but keep at least two.
if (cards_in_deck(deck) > 2)
{
const int num_lost = std::min(cards_in_deck(deck)-2, random2(3) + 1);
for (int i = 0; i < num_lost; ++i)
_deck_lose_card(deck);
if (num_lost == 1)
mpr("A card falls out of the deck.");
else if (num_lost > 1)
mpr("Some cards fall out of the deck.");
}
const int num_cards = cards_in_deck(deck);
const int num_to_mark = (num_cards < 4 ? num_cards : 4);
if (num_cards == 1)
mpr("There's only one card left!");
else if (num_cards < 4)
mprf("The deck only has %d cards.", num_cards);
std::vector<std::string> names;
for (int i = 0; i < num_to_mark; ++i)
{
unsigned char flags;
card_type card = get_card_and_flags(deck, i, flags);
flags |= CFLAG_SEEN | CFLAG_MARKED;
_set_card_and_flags(deck, i, card, flags);
names.push_back(card_name(card));
}
mpr_comma_separated_list("You draw and mark ", names);
props["num_marked"] = (char) num_to_mark;
if (num_cards == 1)
;
else if (num_cards < 4)
{
mprf("You shuffle the deck.");
deck.plus2 = -num_cards;
}
else
mprf("You shuffle the cards back into the deck.");
_shuffle_deck(deck);
_deck_ident(deck);
you.wield_change = true;
return (true);
}
static void _redraw_stacked_cards(const std::vector<card_type>& draws,
unsigned int selected)
{
for (unsigned int i = 0; i < draws.size(); ++i)
{
cgotoxy(1, i+2);
textcolor(selected == i ? WHITE : LIGHTGREY);
cprintf("%u - %s", i+1, card_name(draws[i]) );
clear_to_end_of_line();
}
}
static void _describe_cards(std::vector<card_type> cards)
{
ASSERT(!cards.empty());
std::ostringstream data;
for (unsigned int i = 0; i < cards.size(); ++i)
{
std::string name = card_name(cards[i]);
std::string desc = getLongDescription(name + " card");
if (desc.empty())
desc = "No description found.";
name = uppercase_first(name);
data << "<w>" << name << "</w>\n"
<< get_linebreak_string(desc, get_number_of_cols())
<< "\n";
}
formatted_string fs = formatted_string::parse_string(data.str());
clrscr();
fs.display();
wait_for_keypress();
redraw_screen();
}
// Stack a deck: look at the next five cards, put them back in any
// order, discard the rest of the deck.
// Return false if the operation was failed/aborted along the way.
bool deck_stack()
{
const int slot = _choose_inventory_deck("Stack which deck?");
if (slot == -1)
{
crawl_state.zero_turns_taken();
return (false);
}
item_def& deck(you.inv[slot]);
if (_check_buggy_deck(deck))
return (false);
CrawlHashTable &props = deck.props;
if (props["num_marked"].get_byte() > 0)
{
mpr("You can't stack a marked deck.");
crawl_state.zero_turns_taken();
return (false);
}
_deck_ident(deck);
const int num_cards = cards_in_deck(deck);
const int num_to_stack = (num_cards < 5 ? num_cards : 5);
std::vector<card_type> draws;
std::vector<unsigned char> flags;
for (int i = 0; i < num_cards; ++i)
{
unsigned char _flags;
card_type card = _draw_top_card(deck, false, _flags);
if (i < num_to_stack)
{
draws.push_back(card);
flags.push_back(_flags | CFLAG_SEEN | CFLAG_MARKED);
}
// Rest of deck is discarded.
}
if (num_cards == 1)
mpr("There's only one card left!");
else if (num_cards < 5)
mprf("The deck only has %d cards.", num_to_stack);
else if (num_cards == 5)
mpr("The deck has exactly five cards.");
else
{
mprf("You draw the first five cards out of %d and discard the rest.",
num_cards);
}
more();
if (draws.size() > 1)
{
bool need_prompt_redraw = true;
unsigned int selected = draws.size();
while (true)
{
if (need_prompt_redraw)
{
clrscr();
cgotoxy(1,1);
textcolor(WHITE);
cprintf("Press a digit to select a card, then another digit "
"to swap it.");
cgotoxy(1,10);
cprintf("Press ? for the card descriptions, or Enter to "
"accept.");
_redraw_stacked_cards(draws, selected);
need_prompt_redraw = false;
}
// Hand-hacked implementation, instead of using Menu. Oh well.
const int c = getch();
if (c == CK_ENTER)
{
cgotoxy(1,11);
textcolor(LIGHTGREY);
cprintf("Are you sure? (press y or Y to confirm)");
if (toupper(getch()) == 'Y')
break;
cgotoxy(1,11);
clear_to_end_of_line();
continue;
}
if (c == '?')
{
_describe_cards(draws);
need_prompt_redraw = true;
}
else if (c >= '1' && c <= '0' + static_cast<int>(draws.size()))
{
const unsigned int new_selected = c - '1';
if (selected < draws.size())
{
std::swap(draws[selected], draws[new_selected]);
std::swap(flags[selected], flags[new_selected]);
selected = draws.size();
}
else
selected = new_selected;
_redraw_stacked_cards(draws, selected);
}
}
redraw_screen();
}
deck.plus2 = -num_to_stack;
for (unsigned int i = 0; i < draws.size(); ++i)
{
_push_top_card(deck, draws[draws.size() - 1 - i],
flags[flags.size() - 1 - i]);
}
props["num_marked"] = static_cast<char>(num_to_stack);
you.wield_change = true;
_check_buggy_deck(deck);
return (true);
}
// Draw the next three cards, discard two and pick one.
bool deck_triple_draw()
{
const int slot = _choose_inventory_deck("Triple draw from which deck?");
if (slot == -1)
{
crawl_state.zero_turns_taken();
return (false);
}
item_def& deck(you.inv[slot]);
if (_check_buggy_deck(deck))
return (false);
const int num_cards = cards_in_deck(deck);
// We have to identify the deck before removing cards from it.
// Otherwise, _remember_drawn_card() will implicitly call
// _deck_ident() when the deck might have no cards left.
_deck_ident(deck);
if (num_cards == 1)
{
// Only one card to draw, so just draw it.
evoke_deck(deck);
return (true);
}
const int num_to_draw = (num_cards < 3 ? num_cards : 3);
std::vector<card_type> draws;
std::vector<unsigned char> flags;
for (int i = 0; i < num_to_draw; ++i)
{
unsigned char _flags;
card_type card = _draw_top_card(deck, false, _flags);
draws.push_back(card);
flags.push_back(_flags);
}
int selected = -1;
bool need_prompt_redraw = true;
while (true)
{
if (need_prompt_redraw)
{
mpr("You draw... (choose one card, ? for their descriptions)");
for (int i = 0; i < num_to_draw; ++i)
{
msg::streams(MSGCH_PROMPT) << (static_cast<char>(i + 'a')) << " - "
<< card_name(draws[i]) << std::endl;
}
need_prompt_redraw = false;
}
const int keyin = tolower(get_ch());
if (keyin == '?')
{
_describe_cards(draws);
need_prompt_redraw = true;
}
else if (keyin >= 'a' && keyin < 'a' + num_to_draw)
{
selected = keyin - 'a';
break;
}
else
canned_msg(MSG_HUH);
}
// Note how many cards were removed from the deck.
deck.plus2 += num_to_draw;
// Don't forget to update the number of marked ones, too.
// But don't reduce the number of non-brownie draws.
char num_marked_left = deck.props["num_marked"].get_byte();
for (int i = 0; i < num_to_draw; ++i)
{
_remember_drawn_card(deck, draws[i], false);
if (flags[i] & CFLAG_MARKED)
{
ASSERT(num_marked_left > 0);
--num_marked_left;
}
}
deck.props["num_marked"] = num_marked_left;
you.wield_change = true;
// Make deck disappear *before* the card effect, since we
// don't want to unwield an empty deck.
deck_rarity_type rarity = deck_rarity(deck);
if (cards_in_deck(deck) == 0)
{
mpr("The deck of cards disappears in a puff of smoke.");
if (slot == you.equip[EQ_WEAPON])
unwield_item();
dec_inv_item_quantity( slot, 1 );
}
// Note that card_effect() might cause you to unwield the deck.
card_effect(draws[selected], rarity,
flags[selected] | CFLAG_SEEN | CFLAG_MARKED, false);
return (true);
}
// This is Nemelex retribution.
void draw_from_deck_of_punishment()
{
bool oddity;
card_type card = _random_card(MISC_DECK_OF_PUNISHMENT, DECK_RARITY_COMMON,
oddity);
mpr("You draw a card...");
card_effect(card, DECK_RARITY_COMMON);
}
static int _xom_check_card(item_def &deck, card_type card,
unsigned char flags)
{
int amusement = 64;
if (!item_type_known(deck))
amusement *= 2;
// Expecting one type of card but got another, real funny.
else if (flags & CFLAG_ODDITY)
amusement = 255;
if (player_in_a_dangerous_place())
amusement *= 2;
switch (card)
{
case CARD_XOM:
// Handled elsewhere
amusement = 0;
break;
case CARD_DAMNATION:
// Nothing happened, boring.
if (you.level_type != LEVEL_DUNGEON)
amusement = 0;
break;
case CARD_MINEFIELD:
case CARD_FAMINE:
case CARD_CURSE:
case CARD_SWINE:
// Always hilarious.
amusement = 255;
default:
break;
}
return amusement;
}
void evoke_deck( item_def& deck )
{
if (_check_buggy_deck(deck))
return;
int brownie_points = 0;
bool allow_id = in_inventory(deck) && !item_ident(deck, ISFLAG_KNOW_TYPE);
const deck_rarity_type rarity = deck_rarity(deck);
CrawlHashTable &props = deck.props;
unsigned char flags = 0;
card_type card = _draw_top_card(deck, true, flags);
// Oddity cards don't give any information about the deck.
if (flags & CFLAG_ODDITY)
allow_id = false;
// Passive Nemelex retribution: sometimes a card gets swapped out.
// More likely to happen with marked decks.
if (you.penance[GOD_NEMELEX_XOBEH])
{
int c = 1;
if ((flags & (CFLAG_MARKED | CFLAG_SEEN))
|| props["num_marked"].get_byte() > 0)
{
c = 3;
}
if (x_chance_in_y(c * you.penance[GOD_NEMELEX_XOBEH], 3000))
{
card_type old_card = card;
card = _choose_from_archetype(deck_of_punishment, rarity);
if (card != old_card)
{
simple_god_message(" seems to have exchanged this card "
"behind your back!", GOD_NEMELEX_XOBEH);
mprf("It's actually %s.", card_name(card));
// You never completely appease Nemelex, but the effects
// get less frequent.
you.penance[GOD_NEMELEX_XOBEH] -=
random2( (you.penance[GOD_NEMELEX_XOBEH]+18) / 10);
}
}
}
const int amusement = _xom_check_card(deck, card, flags);
const bool no_brownie = (props["non_brownie_draws"].get_byte() > 0);
// Do these before the deck item_def object is gone.
if (flags & CFLAG_MARKED)
props["num_marked"]--;
if (no_brownie)
props["non_brownie_draws"]--;
deck.plus2++;
_remember_drawn_card(deck, card, allow_id);
// Get rid of the deck *before* the card effect because a card
// might cause a wielded deck to be swapped out for something else,
// in which case we don't want an empty deck to go through the
// swapping process.
const bool deck_gone = (cards_in_deck(deck) == 0);
if (deck_gone)
{
mpr("The deck of cards disappears in a puff of smoke.");
dec_inv_item_quantity( deck.link, 1 );
// Finishing the deck will earn a point, even if it
// was marked or stacked.
brownie_points++;
}
const bool fake_draw = !card_effect(card, rarity, flags, false);
if (fake_draw && !deck_gone)
props["non_brownie_draws"]++;
if (!(flags & CFLAG_MARKED))
{
// Could a Xom worshipper ever get a stacked deck in the first
// place?
xom_is_stimulated(amusement);
// Nemelex likes gamblers.
if (!no_brownie)
{
brownie_points++;
if (one_chance_in(3))
brownie_points++;
}
// You can't ID off a marked card
allow_id = false;
}
if (!deck_gone && allow_id
&& you.skills[SK_EVOCATIONS] > 5 + random2(35))
{
mpr("Your skill with magical items lets you identify the deck.");
set_ident_flags( deck, ISFLAG_KNOW_TYPE );
msg::streams(MSGCH_EQUIPMENT) << deck.name(DESC_INVENTORY)
<< std::endl;
}
if (!fake_draw)
did_god_conduct(DID_CARDS, brownie_points);
// Always wield change, since the number of cards used/left has
// changed.
you.wield_change = true;
}
int get_power_level(int power, deck_rarity_type rarity)
{
int power_level = 0;
switch (rarity)
{
case DECK_RARITY_COMMON:
break;
case DECK_RARITY_LEGENDARY:
if (x_chance_in_y(power, 500))
++power_level;
// deliberate fall-through
case DECK_RARITY_RARE:
if (x_chance_in_y(power, 700))
++power_level;
break;
}
return power_level;
}
// Actual card implementations follow.
static void _portal_card(int power, deck_rarity_type rarity)
{
const int control_level = get_power_level(power, rarity);
bool instant = false;
bool controlled = false;
if (control_level >= 2)
{
instant = true;
controlled = true;
}
else if (control_level == 1)
{
if (coinflip())
instant = true;
else
controlled = true;
}
int threshold = 6;
const bool was_controlled = player_control_teleport();
const bool short_control = (you.duration[DUR_CONTROL_TELEPORT] > 0
&& you.duration[DUR_CONTROL_TELEPORT]
< threshold * BASELINE_DELAY);
if (controlled && (!was_controlled || short_control))
you.set_duration(DUR_CONTROL_TELEPORT, threshold); // Long enough to kick in.
if (instant)
you_teleport_now( true );
else
you_teleport();
}
static void _warp_card(int power, deck_rarity_type rarity)
{
if (item_blocks_teleport(true, true))
{
canned_msg(MSG_STRANGE_STASIS);
return;
}
const int control_level = get_power_level(power, rarity);
if (control_level >= 2)
blink(1000, false);
else if (control_level == 1)
cast_semi_controlled_blink(power / 4);
else
random_blink(false);
}
static void _swap_monster_card(int power, deck_rarity_type rarity)
{
// Swap between you and another monster.
// Don't choose yourself unless there are no monsters nearby.
monsters *mon_to_swap = choose_random_nearby_monster(0);
if (!mon_to_swap)
mpr("You spin around.");
else
swap_with_monster(mon_to_swap);
}
static void _velocity_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
if (power_level >= 2)
potion_effect(POT_SPEED, random2(power / 4));
else if (power_level == 1)
{
cast_fly(random2(power / 4));
cast_swiftness(random2(power / 4));
}
else
cast_swiftness(random2(power / 4));
}
static void _damnation_card(int power, deck_rarity_type rarity)
{
if (you.level_type != LEVEL_DUNGEON)
{
canned_msg(MSG_NOTHING_HAPPENS);
return;
}
// Calculate how many extra banishments you get.
const int power_level = get_power_level(power, rarity);
int nemelex_bonus = 0;
if (you.religion == GOD_NEMELEX_XOBEH && !player_under_penance())
nemelex_bonus = you.piety / 20;
int extra_targets = power_level + random2(you.skills[SK_EVOCATIONS]
+ nemelex_bonus) / 12;
for (int i = 0; i < 1 + extra_targets; ++i)
{
// Pick a random monster nearby to banish (or yourself).
monsters *mon_to_banish = choose_random_nearby_monster(1);
// Bonus banishments only banish monsters.
if (i != 0 && !mon_to_banish)
continue;
if (!mon_to_banish) // Banish yourself!
{
banished(DNGN_ENTER_ABYSS, "drawing a card");
break; // Don't banish anything else.
}
else
mon_to_banish->banish();
}
}
static void _warpwright_card(int power, deck_rarity_type rarity)
{
if (you.level_type == LEVEL_ABYSS)
{
mpr("The power of the Abyss blocks your magic.");
return;
}
int count = 0;
coord_def f;
for (adjacent_iterator ai(you.pos()); ai; ++ai)
if (grd(*ai) == DNGN_FLOOR && !find_trap(*ai) && one_chance_in(++count))
f = *ai;
if (count > 0) // found a spot
{
if (place_specific_trap(f, TRAP_TELEPORT))
{
// Mark it discovered if enough power.
if (get_power_level(power, rarity) >= 1)
find_trap(f)->reveal();
}
}
}
static void _flight_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
// Assume something _will_ happen.
bool success = true;
if (power_level == 0)
{
if (!transform(random2(power/4), coinflip() ? TRAN_SPIDER : TRAN_BAT,
true))
{
// Oops, something went wrong here (either because of cursed
// equipment or the possibility of stat loss).
success = false;
}
}
else if (power_level >= 1)
{
cast_fly(random2(power/4));
cast_swiftness(random2(power/4));
}
if (power_level == 2) // Stacks with the above.
{
if (is_valid_shaft_level() && grd(you.pos()) == DNGN_FLOOR)
{
if (place_specific_trap(you.pos(), TRAP_SHAFT))
{
find_trap(you.pos())->reveal();
mpr("A shaft materialises beneath you!");
}
}
}
if (one_chance_in(4 - power_level))
potion_effect(POT_INVISIBILITY, random2(power)/4);
else if (!success)
canned_msg(MSG_NOTHING_HAPPENS);
}
static void _minefield_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
const int radius = power_level * 2 + 2;
for (radius_iterator ri(you.pos(), radius, false, false, false); ri; ++ri)
{
if (*ri == you.pos())
continue;
if (grd(*ri) == DNGN_FLOOR && !find_trap(*ri)
&& one_chance_in(4 - power_level))
{
if (you.level_type == LEVEL_ABYSS)
grd(*ri) = coinflip() ? DNGN_DEEP_WATER : DNGN_LAVA;
else
place_specific_trap(*ri, TRAP_RANDOM);
}
}
}
static int stair_draw_count = 0;
// This does not describe an actual card. Instead, it only exists to test
// the stair movement effect in wizard mode ("&c stairs").
static void _stairs_card(int power, deck_rarity_type rarity)
{
UNUSED(power);
UNUSED(rarity);
you.duration[DUR_REPEL_STAIRS_MOVE] = 0;
you.duration[DUR_REPEL_STAIRS_CLIMB] = 0;
if (feat_stair_direction(grd(you.pos())) == CMD_NO_CMD)
you.duration[DUR_REPEL_STAIRS_MOVE] = 1000;
else
you.duration[DUR_REPEL_STAIRS_CLIMB] = 500; // more annoying
std::vector<coord_def> stairs_avail;
for (radius_iterator ri(you.pos(), LOS_RADIUS, false, true, true); ri; ++ri)
{
dungeon_feature_type feat = grd(*ri);
if (feat_stair_direction(feat) != CMD_NO_CMD
&& feat != DNGN_ENTER_SHOP)
{
stairs_avail.push_back(*ri);
}
}
if (stairs_avail.size() == 0)
{
mpr("No stairs available to move.");
return;
}
std::random_shuffle(stairs_avail.begin(), stairs_avail.end());
for (unsigned int i = 0; i < stairs_avail.size(); ++i)
move_stair(stairs_avail[i], stair_draw_count % 2, false);
stair_draw_count++;
}
static int _drain_monsters(coord_def where, int pow, int, actor *)
{
if (where == you.pos())
drain_exp();
else
{
monsters* mon = monster_at(where);
if (mon == NULL)
return (0);
if (!mon->drain_exp(&you, false, pow / 50))
simple_monster_message(mon, " is unaffected.");
}
return (1);
}
static void _mass_drain(int pow)
{
apply_area_visible(_drain_monsters, pow);
}
// Return true if it was a "genuine" draw, i.e., there was a monster
// to target. This is still exploitable by finding popcorn monsters.
static bool _damaging_card(card_type card, int power, deck_rarity_type rarity)
{
bool rc = there_are_monsters_nearby(true, false);
const int power_level = get_power_level(power, rarity);
dist target;
zap_type ztype = ZAP_DEBUGGING_RAY;
const zap_type firezaps[3] = { ZAP_FLAME, ZAP_STICKY_FLAME, ZAP_FIRE };
const zap_type frostzaps[3] = { ZAP_FROST, ZAP_THROW_ICICLE, ZAP_COLD };
const zap_type hammerzaps[3] = { ZAP_STRIKING, ZAP_STONE_ARROW,
ZAP_CRYSTAL_SPEAR };
const zap_type venomzaps[3] = { ZAP_STING, ZAP_VENOM_BOLT,
ZAP_POISON_ARROW };
const zap_type sparkzaps[3] = { ZAP_ELECTRICITY, ZAP_LIGHTNING,
ZAP_ORB_OF_ELECTRICITY };
const zap_type painzaps[2] = { ZAP_AGONY, ZAP_NEGATIVE_ENERGY };
switch (card)
{
case CARD_VITRIOL:
ztype = (one_chance_in(3) ? ZAP_DEGENERATION : ZAP_BREATHE_ACID);
break;
case CARD_FLAME:
ztype = (coinflip() ? ZAP_FIREBALL : firezaps[power_level]);
break;
case CARD_FROST: ztype = frostzaps[power_level]; break;
case CARD_HAMMER: ztype = hammerzaps[power_level]; break;
case CARD_VENOM: ztype = venomzaps[power_level]; break;
case CARD_SPARK: ztype = sparkzaps[power_level]; break;
case CARD_PAIN:
if (power_level == 2)
{
mprf("You have drawn %s.", card_name(card));
_mass_drain(power);
return (true);
}
else
ztype = painzaps[power_level];
break;
default:
break;
}
std::string prompt = "You have drawn ";
prompt += card_name(card);
prompt += ".";
bolt beam;
beam.range = LOS_RADIUS;
if (spell_direction(target, beam, DIR_NONE, TARG_HOSTILE,
LOS_RADIUS, true, true, false, NULL, prompt.c_str())
&& player_tracer(ZAP_DEBUGGING_RAY, power/4, beam))
{
zapping(ztype, random2(power/4), beam);
}
else
rc = false;
return (rc);
}
static void _elixir_card(int power, deck_rarity_type rarity)
{
int power_level = get_power_level(power, rarity);
if (power_level == 1 && you.hp * 2 > you.hp_max)
power_level = 0;
if (power_level == 0)
{
if (coinflip())
potion_effect(POT_HEAL_WOUNDS, 40); // power doesn't matter
else
cast_regen(random2(power / 4));
}
else if (power_level == 1)
{
set_hp(you.hp_max, false);
you.magic_points = 0;
}
else if (power_level >= 2)
{
set_hp(you.hp_max, false);
you.magic_points = you.max_magic_points;
}
you.redraw_hit_points = true;
you.redraw_magic_points = true;
}
static void _battle_lust_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
if (power_level >= 2)
{
you.set_duration(DUR_SLAYING, random2(power/6) + 1,
0, "You feel deadly.");
}
else if (power_level == 1)
{
you.set_duration(DUR_BUILDING_RAGE, 1,
0, "You feel your rage building.");
}
else if (power_level == 0)
potion_effect(POT_MIGHT, random2(power/4));
}
static void _metamorphosis_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
transformation_type trans;
if (power_level >= 2)
trans = coinflip() ? TRAN_DRAGON : TRAN_LICH;
else if (power_level == 1)
trans = coinflip() ? TRAN_STATUE : TRAN_BLADE_HANDS;
else
{
trans = one_chance_in(3) ? TRAN_SPIDER :
coinflip() ? TRAN_ICE_BEAST
: TRAN_BAT;
}
// Might fail, e.g. because of cursed equipment or potential death by
// stat loss. Aren't we being nice? (jpeg)
if (!transform(random2(power/4), trans, true))
canned_msg(MSG_NOTHING_HAPPENS);
}
static void _helm_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
bool do_phaseshift = false;
bool do_stoneskin = false;
bool do_shield = false;
int num_resists = 0;
// Chances are cumulative.
if (power_level >= 2)
{
if (coinflip()) do_phaseshift = true;
if (coinflip()) do_stoneskin = true;
if (coinflip()) do_shield = true;
num_resists = random2(4);
}
if (power_level >= 1)
{
if (coinflip()) do_phaseshift = true;
if (coinflip()) do_stoneskin = true;
if (coinflip()) do_shield = true;
}
if (power_level >= 0)
{
if (coinflip())
do_phaseshift = true;
else
do_stoneskin = true;
}
if (do_phaseshift)
cast_phase_shift( random2(power/4) );
if (do_stoneskin)
cast_stoneskin( random2(power/4) );
if (num_resists)
{
const duration_type possible_resists[4] = {
DUR_RESIST_POISON, DUR_INSULATION,
DUR_RESIST_FIRE, DUR_RESIST_COLD
};
const char* resist_names[4] = {
"poison", "electricity", "fire", "cold"
};
for (int i = 0; i < 4 && num_resists; ++i)
{
// If there are n left, of which we need to choose
// k, we have chance k/n of selecting the next item.
if (x_chance_in_y(num_resists, 4-i))
{
// Add a temporary resistance.
you.increase_duration(possible_resists[i], random2(power/7) +1);
msg::stream << "You feel resistant to " << resist_names[i]
<< '.' << std::endl;
--num_resists;
}
}
}
if (do_shield)
{
if (you.duration[DUR_MAGIC_SHIELD] == 0)
mpr("A magical shield forms in front of you.");
you.increase_duration(DUR_MAGIC_SHIELD, random2(power/6) + 1);
}
}
static void _blade_card(int power, deck_rarity_type rarity)
{
// Pause before jumping to the list.
if (Options.auto_list)
more();
wield_weapon(false);
const int power_level = get_power_level(power, rarity);
if (power_level >= 2)
{
cast_tukimas_dance( random2(power/4) );
}
else if (power_level == 1)
{
cast_sure_blade( random2(power/4) );
}
else
{
const brand_type brands[] = {
SPWPN_FLAMING, SPWPN_FREEZING, SPWPN_VENOM, SPWPN_DRAINING,
SPWPN_VORPAL, SPWPN_DISTORTION, SPWPN_PAIN, SPWPN_DUMMY_CRUSHING
};
if (!brand_weapon(RANDOM_ELEMENT(brands), random2(power/4)))
{
item_def* wpn = you.weapon();
if (wpn)
{
mprf("%s vibrate%s crazily for a second.",
wpn->name(DESC_CAP_YOUR).c_str(),
wpn->quantity == 1 ? "s" : "");
}
else
mprf("Your %s twitch.", your_hand(true).c_str());
}
}
}
static void _shadow_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
if (power_level >= 1)
{
mpr(you.duration[DUR_STEALTH] ? "You feel more catlike."
: "You feel stealthy.");
you.increase_duration(DUR_STEALTH, random2(power/4) + 1);
}
potion_effect(POT_INVISIBILITY, random2(power/4));
}
static void _potion_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
potion_type pot_effects[] = {
POT_HEAL_WOUNDS, POT_HEAL_WOUNDS, POT_HEAL_WOUNDS,
POT_HEALING, POT_HEALING, POT_HEALING,
POT_RESTORE_ABILITIES, POT_RESTORE_ABILITIES,
POT_POISON, POT_CONFUSION, POT_DEGENERATION
};
potion_type pot = RANDOM_ELEMENT(pot_effects);
if (power_level >= 1 && coinflip())
pot = (coinflip() ? POT_CURE_MUTATION : POT_MUTATION);
if (power_level >= 2 && one_chance_in(5))
{
// +1 to a random stat.
const potion_type gain_stat_pots[] = {
POT_GAIN_STRENGTH, POT_GAIN_DEXTERITY, POT_GAIN_INTELLIGENCE
};
pot = RANDOM_ELEMENT(gain_stat_pots);
}
potion_effect(pot, random2(power/4));
}
static void _focus_card(int power, deck_rarity_type rarity)
{
stat_type best_stat = STAT_STR;
stat_type worst_stat = STAT_STR;
for (int i = 1; i < 3; ++i)
{
stat_type s = static_cast<stat_type>(i);
const int best_diff = you.max_stat(s) - you.max_stat(best_stat);
if (best_diff > 0 || best_diff == 0 && coinflip())
best_stat = s;
const int worst_diff = you.max_stat(s) - you.max_stat(worst_stat);
if (worst_diff < 0 || worst_diff == 0 && coinflip())
worst_stat = s;
}
while (best_stat == worst_stat)
{
best_stat = static_cast<stat_type>(random2(3));
worst_stat = static_cast<stat_type>(random2(3));
}
std::string cause = "the Focus card";
if (crawl_state.is_god_acting())
{
god_type which_god = crawl_state.which_god_acting();
if (crawl_state.is_god_retribution())
cause = "the wrath of " + god_name(which_god);
else
{
if (which_god == GOD_XOM)
cause = "the capriciousness of Xom";
else
cause = "the 'helpfulness' of " + god_name(which_god);
}
}
modify_stat(best_stat, 1, true, cause.c_str(), true);
modify_stat(worst_stat, -1, true, cause.c_str(), true);
}
static void _shuffle_card(int power, deck_rarity_type rarity)
{
int perm[NUM_STATS] = { 0, 1, 2 };
std::random_shuffle(perm, perm + 3);
FixedVector<char, NUM_STATS> new_base;
for (int i = 0; i < NUM_STATS; ++i)
new_base[perm[i]] = you.base_stats[i];
std::string cause = "the Shuffle card";
if (crawl_state.is_god_acting())
{
god_type which_god = crawl_state.which_god_acting();
if (crawl_state.is_god_retribution())
cause = "the wrath of " + god_name(which_god);
else
{
if (which_god == GOD_XOM)
cause = "the capriciousness of Xom";
else
cause = "the 'helpfulness' of " + god_name(which_god);
}
}
for (int i = 0; i < NUM_STATS; ++i)
{
modify_stat(static_cast<stat_type>(i),
new_base[i] - you.base_stats[i],
true, cause.c_str(), true);
}
}
static void _experience_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
if (you.experience_level < 27)
{
mpr("You feel more experienced.");
const unsigned long xp_cap = 1 + exp_needed(2 + you.experience_level);
// power_level 2 means automatic level gain.
if (power_level == 2)
you.experience = xp_cap;
else
{
// Likely to give a level gain (power of ~500 is reasonable
// at high levels even for non-Nemelexites, so 50,000 XP.)
// But not guaranteed.
// Overrides archmagi effect, like potions of experience.
you.experience += power * 100;
if (you.experience > xp_cap)
you.experience = xp_cap;
}
}
else
mpr("You feel knowledgeable.");
// Put some free XP into pool; power_level 2 means fill pool
you.exp_available += power * 50;
if (power_level >= 2 || you.exp_available > FULL_EXP_POOL)
you.exp_available = FULL_EXP_POOL;
level_change();
}
static void _remove_bad_mutation()
{
// Ensure that only bad mutations are removed.
if (!delete_mutation(RANDOM_BAD_MUTATION, false, false, false, true))
mpr("You feel transcendent for a moment.");
}
static void _helix_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
if (power_level == 0)
{
switch (how_mutated() ? random2(3) : 0)
{
case 0:
mutate(RANDOM_MUTATION);
break;
case 1:
delete_mutation(RANDOM_MUTATION);
mutate(RANDOM_MUTATION);
break;
case 2:
delete_mutation(RANDOM_MUTATION);
break;
}
}
else if (power_level == 1)
{
switch (how_mutated() ? random2(3) : 0)
{
case 0:
mutate(coinflip() ? RANDOM_GOOD_MUTATION : RANDOM_MUTATION);
break;
case 1:
if (coinflip())
_remove_bad_mutation();
else
delete_mutation(RANDOM_MUTATION);
break;
case 2:
if (coinflip())
{
if (coinflip())
{
_remove_bad_mutation();
mutate(RANDOM_MUTATION);
}
else
{
delete_mutation(RANDOM_MUTATION);
mutate(RANDOM_GOOD_MUTATION);
}
}
else
{
delete_mutation(RANDOM_MUTATION);
mutate(RANDOM_MUTATION);
}
break;
}
}
else
{
switch (random2(3))
{
case 0:
_remove_bad_mutation();
break;
case 1:
mutate(RANDOM_GOOD_MUTATION);
break;
case 2:
if (coinflip())
{
// If you get unlucky, you could get here with no bad
// mutations and simply get a mutation effect. Oh well.
_remove_bad_mutation();
mutate(RANDOM_MUTATION);
}
else
{
delete_mutation(RANDOM_MUTATION);
mutate(RANDOM_GOOD_MUTATION);
}
break;
}
}
}
static void _sage_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
int c; // how much to weight your skills
if (power_level == 0)
c = 0;
else if (power_level == 1)
c = random2(10) + 1;
else
c = 10;
// FIXME: yet another reproduction of random_choose_weighted
// Ah for Python:
// skill = random_choice([x*(40-x)*c/10 for x in skill_levels])
int totalweight = 0;
int result = -1;
for (int i = 0; i < NUM_SKILLS; ++i )
{
if (skill_name(i) == NULL)
continue;
if (you.skills[i] < MAX_SKILL_LEVEL)
{
// Choosing a skill is likelier if you are somewhat skilled in it.
const int curweight = 1 + you.skills[i] * (40 - you.skills[i]) * c;
totalweight += curweight;
if (x_chance_in_y(curweight, totalweight))
result = i;
}
}
if (result == -1)
mpr("You feel omnipotent."); // All skills maxed.
else
{
you.set_duration(DUR_SAGE, random2(1800) + 200);
you.sage_bonus_skill = static_cast<skill_type>(result);
you.sage_bonus_degree = power / 25;
mprf(MSGCH_PLAIN, "You feel studious about %s.", skill_name(result));
}
}
static void _create_pond(const coord_def& center, int radius, bool allow_deep)
{
for (radius_iterator ri(center, radius, false); ri; ++ri)
{
const coord_def p = *ri;
if (p != you.pos() && coinflip())
{
if (grd(p) == DNGN_FLOOR)
{
dungeon_feature_type feat;
if (allow_deep && coinflip())
feat = DNGN_DEEP_WATER;
else
feat = DNGN_SHALLOW_WATER;
dungeon_terrain_changed(p, feat);
}
}
}
}
static void _deepen_water(const coord_def& center, int radius)
{
for (radius_iterator ri(center, radius, false); ri; ++ri)
{
// FIXME The iteration shouldn't affect the later squares in the
// same iteration, i.e., a newly-flooded square shouldn't count
// in the decision as to whether to make the next square flooded.
const coord_def p = *ri;
if (grd(p) == DNGN_SHALLOW_WATER
&& p != you.pos()
&& x_chance_in_y(1+count_neighbours(p, DNGN_DEEP_WATER), 8))
{
dungeon_terrain_changed(p, DNGN_DEEP_WATER);
}
if (grd(p) == DNGN_FLOOR
&& random2(3) < random2(count_neighbours(p, DNGN_DEEP_WATER)
+ count_neighbours(p, DNGN_SHALLOW_WATER)))
{
dungeon_terrain_changed(p, DNGN_SHALLOW_WATER);
}
}
}
static void _water_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
if (power_level == 0)
{
mpr("You create a pond!");
_create_pond(you.pos(), 4, false);
}
else if (power_level == 1)
{
mpr("You feel the tide rushing in!");
_create_pond(you.pos(), 6, true);
for (int i = 0; i < 2; ++i)
_deepen_water(you.pos(), 6);
}
else
{
mpr("Water floods your area!");
// Flood all visible squares.
for (radius_iterator ri( you.pos(), LOS_RADIUS, false ); ri; ++ri)
{
coord_def p = *ri;
destroy_trap(p);
if (grd(p) == DNGN_FLOOR)
{
dungeon_feature_type new_feature = DNGN_SHALLOW_WATER;
if (p != you.pos() && coinflip())
new_feature = DNGN_DEEP_WATER;
dungeon_terrain_changed(p, new_feature);
}
}
}
}
static void _glass_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
const int radius = (power_level == 2) ? 1000
: random2(power/40) + 2;
vitrify_area(radius);
}
static void _dowsing_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
bool things_to_do[3] = { false, false, false };
things_to_do[random2(3)] = true;
if (power_level == 1)
things_to_do[random2(3)] = true;
if (power_level >= 2)
{
for (int i = 0; i < 3; ++i)
things_to_do[i] = true;
}
if (things_to_do[0])
cast_detect_secret_doors( random2(power/4) );
if (things_to_do[1])
detect_traps( random2(power/4) );
if (things_to_do[2])
{
you.set_duration(DUR_TELEPATHY, random2(power/4), 0,
"You feel telepathic!");
}
}
static bool _trowel_card(int power, deck_rarity_type rarity)
{
// Early exit: don't clobber important features.
if (is_critical_feature(grd(you.pos())))
{
mpr("The dungeon trembles momentarily.");
return (false);
}
const int power_level = get_power_level(power, rarity);
bool done_stuff = false;
// [ds] FIXME: Remove the LEVEL_DUNGEON restriction once Crawl
// handles stacked level_area_types correctly. We should also
// review whether Trowel being able to create infinite portal
// vaults is a Good Thing, because it looks pretty broken to me.
if (power_level >= 2 && you.level_type == LEVEL_DUNGEON)
{
// Generate a portal to something.
const map_def *map = random_map_for_tag("trowel_portal");
if (!map)
{
mpr("A buggy portal flickers into view, then vanishes.");
}
else
{
{
no_messages n;
dgn_safe_place_map(map, true, true, you.pos());
}
mpr("A mystic portal forms.");
}
done_stuff = true;
}
else if (power_level == 1)
{
if (coinflip())
{
// Create a random bad statue and a friendly, timed golem.
// This could be really bad, because they're placed adjacent
// to you...
int num_made = 0;
const monster_type statues[] = {
MONS_ORANGE_STATUE, MONS_SILVER_STATUE, MONS_ICE_STATUE
};
if (create_monster(
mgen_data::hostile_at(
RANDOM_ELEMENT(statues), "the Trowel card",
true, 0, 0, you.pos())) != -1)
{
mpr("A menacing statue appears!");
num_made++;
}
const monster_type golems[] = {
MONS_CLAY_GOLEM, MONS_WOOD_GOLEM, MONS_STONE_GOLEM,
MONS_IRON_GOLEM, MONS_CRYSTAL_GOLEM, MONS_TOENAIL_GOLEM
};
if (create_monster(
mgen_data(RANDOM_ELEMENT(golems),
BEH_FRIENDLY, &you, 5, 0,
you.pos(), MHITYOU)) != -1)
{
mpr("You construct a golem!");
num_made++;
}
if (num_made == 2)
mpr("The constructs glare at each other.");
done_stuff = (num_made > 0);
}
else
{
// Do-nothing (effectively): create a cosmetic feature
const coord_def pos = pick_adjacent_free_square(you.pos());
if (in_bounds(pos))
{
const dungeon_feature_type statfeat[] = {
DNGN_GRANITE_STATUE, DNGN_ORCISH_IDOL
};
// We leave the items on the square
grd(pos) = RANDOM_ELEMENT(statfeat);
mpr("A statue takes form beside you.");
done_stuff = true;
}
}
}
else
{
// Generate an altar.
if (grd(you.pos()) == DNGN_FLOOR)
{
// Might get GOD_NO_GOD and no altar.
god_type rgod = static_cast<god_type>(random2(NUM_GODS));
if (rgod == GOD_JIYVA && jiyva_is_dead())
rgod = GOD_NO_GOD;
grd(you.pos()) = altar_for_god(rgod);
if (grd(you.pos()) != DNGN_FLOOR)
{
done_stuff = true;
mprf("An altar to %s grows from the floor before you!",
god_name(rgod).c_str());
}
}
}
if (!done_stuff)
canned_msg(MSG_NOTHING_HAPPENS);
return (done_stuff);
}
static void _genie_card(int power, deck_rarity_type rarity)
{
if (coinflip())
{
mpr("A genie takes form and thunders: "
"\"Choose your reward, mortal!\"");
more();
acquirement( OBJ_RANDOM, AQ_CARD_GENIE );
}
else
{
mpr("A genie takes form and thunders: "
"\"You disturbed me, fool!\"");
potion_effect(coinflip() ? POT_DEGENERATION : POT_DECAY, 40);
}
}
// Special case for *your* god, maybe?
static void _godly_wrath()
{
int tries = 100;
while (tries-- > 0)
{
god_type god = static_cast<god_type>(random2(NUM_GODS - 1) + 1);
// Don't recursively make player draw from the Deck of Punishment.
if (god == GOD_NEMELEX_XOBEH)
continue;
// Stop once we find a god willing to punish the player.
if (divine_retribution(god))
break;
}
if (tries <= 0)
mpr("You somehow manage to escape divine attention...");
}
static void _curse_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
mpr("You feel a malignant aura surround you.");
if (power_level >= 2)
{
// Curse (almost) everything + chance of decay.
while (curse_an_item(one_chance_in(6), true) && !one_chance_in(1000))
;
}
else if (power_level == 1)
{
// Curse an average of four items.
do
curse_an_item(false);
while (!one_chance_in(4));
}
else
{
// Curse 1.5 items on average.
curse_an_item(false);
if (coinflip())
curse_an_item(false);
}
}
static void _crusade_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
if (power_level >= 1)
{
// A chance to convert opponents.
for (monster_iterator mi(you.get_los()); mi; ++mi)
{
if (mi->friendly()
|| mi->holiness() != MH_NATURAL
|| mons_is_unique(mi->type)
|| mons_immune_magic(*mi)
|| player_will_anger_monster(*mi))
{
continue;
}
// Note that this bypasses the magic resistance
// (though not immunity) check. Specifically,
// you can convert Killer Klowns this way.
// Might be too good.
if (mi->hit_dice * 35 < random2(power))
{
simple_monster_message(*mi, " is converted.");
if (one_chance_in(5 - power_level))
{
mi->attitude = ATT_FRIENDLY;
// If you worship a god that lets you recruit
// permanent followers, or a god allied with one,
// count this as a recruitment.
if (is_good_god(you.religion)
|| you.religion == GOD_BEOGH
&& mons_species(mi->type) == MONS_ORC
&& !mi->is_summoned()
&& !mi->is_shapeshifter())
{
// Prevent assertion if the monster was
// previously worshipping a different god,
// rather than already worshipping your god or
// being an atheist.
mi->god = GOD_NO_GOD;
mons_make_god_gift(*mi, is_good_god(you.religion) ?
GOD_SHINING_ONE : GOD_BEOGH);
}
}
else
mi->add_ench(ENCH_CHARM);
mons_att_changed(*mi);
}
}
}
abjuration(power/4);
}
static void _summon_demon_card(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
demon_class_type dct;
if (power_level >= 2)
dct = DEMON_GREATER;
else if (power_level == 1)
dct = DEMON_COMMON;
else
dct = DEMON_LESSER;
// FIXME: The manual testing for message printing is there because
// we can't rely on create_monster() to do it for us. This is
// because if you are completely surrounded by walls, create_monster()
// will never manage to give a position which isn't (-1,-1)
// and thus not print the message.
// This hack appears later in this file as well.
if (create_monster(
mgen_data(summon_any_demon(dct), BEH_FRIENDLY, &you,
std::min(power/50 + 1, 6), 0,
you.pos(), MHITYOU),
false) == -1)
{
mpr("You see a puff of smoke.");
}
}
static void _summon_any_monster(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
monster_type mon_chosen = NUM_MONSTERS;
coord_def chosen_spot;
int num_tries;
if (power_level == 0)
num_tries = 1;
else if (power_level == 1)
num_tries = 4;
else
num_tries = 18;
for (int i = 0; i < num_tries; ++i)
{
int dx, dy;
do
{
dx = random2(3) - 1;
dy = random2(3) - 1;
}
while (dx == 0 && dy == 0);
coord_def delta(dx,dy);
monster_type cur_try;
do
{
cur_try = random_monster_at_grid(you.pos() + delta);
}
while (mons_is_unique(cur_try));
if (mon_chosen == NUM_MONSTERS
|| mons_power(mon_chosen) < mons_power(cur_try))
{
mon_chosen = cur_try;
chosen_spot = you.pos();
}
}
if (mon_chosen == NUM_MONSTERS) // Should never happen.
return;
const bool friendly = (power_level > 0 || !one_chance_in(4));
if (create_monster(mgen_data(mon_chosen,
friendly ? BEH_FRIENDLY : BEH_HOSTILE, &you,
3, 0, chosen_spot, MHITYOU),
false) == -1)
{
mpr("You see a puff of smoke.");
}
}
static void _summon_dancing_weapon(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
const bool friendly = (power_level > 0 || !one_chance_in(4));
const int mon =
create_monster(
mgen_data(MONS_DANCING_WEAPON,
friendly ? BEH_FRIENDLY : BEH_HOSTILE, &you,
power_level + 3, 0, you.pos(), MHITYOU),
false);
// Given the abundance of Nemelex decks, not setting hard reset
// leaves a trail of weapons behind, most of which just get
// offered to Nemelex again, adding an unnecessary source of
// piety.
if (mon != -1)
{
// Override the weapon.
ASSERT(menv[mon].weapon() != NULL);
item_def& wpn(*menv[mon].weapon());
// FIXME: Mega-hack (breaks encapsulation too).
wpn.flags &= ~ISFLAG_RACIAL_MASK;
if (power_level == 0)
{
// Wimpy, negative-enchantment weapon.
wpn.plus = -random2(4);
wpn.plus2 = -random2(4);
wpn.sub_type = (coinflip() ? WPN_DAGGER : WPN_CLUB);
set_item_ego_type(wpn, OBJ_WEAPONS, SPWPN_NORMAL);
}
else if (power_level == 1)
{
// This is getting good.
wpn.plus = random2(4) - 1;
wpn.plus2 = random2(4) - 1;
wpn.sub_type = (coinflip() ? WPN_LONG_SWORD : WPN_HAND_AXE);
if (coinflip())
{
set_item_ego_type(wpn, OBJ_WEAPONS,
coinflip() ? SPWPN_FLAMING : SPWPN_FREEZING);
}
}
else if (power_level == 2)
{
// Rare and powerful.
wpn.plus = random2(4) + 2;
wpn.plus2 = random2(4) + 2;
wpn.sub_type = (coinflip() ? WPN_KATANA : WPN_EXECUTIONERS_AXE);
set_item_ego_type(wpn, OBJ_WEAPONS,
coinflip() ? SPWPN_SPEED : SPWPN_ELECTROCUTION);
}
item_colour(wpn);
menv[mon].flags |= MF_HARD_RESET;
ghost_demon newstats;
newstats.init_dancing_weapon(wpn, power / 4);
menv[mon].set_ghost(newstats);
menv[mon].dancing_weapon_init();
}
else
mpr("You see a puff of smoke.");
}
static void _summon_flying(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
const bool friendly = (power_level > 0 || !one_chance_in(4));
const monster_type flytypes[] = {
MONS_BUTTERFLY, MONS_BUMBLEBEE, MONS_INSUBSTANTIAL_WISP,
MONS_VAPOUR, MONS_YELLOW_WASP, MONS_RED_WASP
};
// Choose what kind of monster.
// Be nice and don't summon friendly invisibles.
monster_type result = MONS_PROGRAM_BUG;
do
result = flytypes[random2(4) + power_level];
while (friendly && mons_class_flag(result, M_INVIS)
&& !you.can_see_invisible());
for (int i = 0; i < power_level * 5 + 2; ++i)
{
create_monster(
mgen_data(result,
friendly ? BEH_FRIENDLY : BEH_HOSTILE, &you,
std::min(power/50 + 1, 6), 0,
you.pos(), MHITYOU));
}
if (mons_class_flag(result, M_INVIS) && !you.can_see_invisible()
&& !friendly)
{
mpr("Whatever you just summoned cannot be friendly.");
}
}
static void _summon_skeleton(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
const bool friendly = (power_level > 0 || !one_chance_in(4));
const monster_type skeltypes[] = {
MONS_SKELETON_LARGE, MONS_SKELETAL_WARRIOR, MONS_BONE_DRAGON
};
if (create_monster(mgen_data(skeltypes[power_level],
friendly ? BEH_FRIENDLY : BEH_HOSTILE, &you,
std::min(power/50 + 1, 6), 0,
you.pos(), MHITYOU),
false) == -1)
{
mpr("You see a puff of smoke.");
}
}
static void _summon_ugly(int power, deck_rarity_type rarity)
{
const int power_level = get_power_level(power, rarity);
const bool friendly = (power_level > 0 || !one_chance_in(4));
monster_type ugly;
if (power_level >= 2)
ugly = MONS_VERY_UGLY_THING;
else if (power_level == 1)
ugly = coinflip() ? MONS_VERY_UGLY_THING : MONS_UGLY_THING;
else
ugly = MONS_UGLY_THING;
if (create_monster(mgen_data(ugly,
friendly ? BEH_FRIENDLY : BEH_HOSTILE,
&you,
std::min(power/50 + 1, 6), 0,
you.pos(), MHITYOU),
false) == -1)
{
mpr("You see a puff of smoke.");
}
}
static int _card_power(deck_rarity_type rarity)
{
int result = 0;
if (you.penance[GOD_NEMELEX_XOBEH])
{
result -= you.penance[GOD_NEMELEX_XOBEH];
}
else if (you.religion == GOD_NEMELEX_XOBEH)
{
result = you.piety;
result *= (you.skills[SK_EVOCATIONS] + 25);
result /= 27;
}
result += you.skills[SK_EVOCATIONS] * 9;
if (rarity == DECK_RARITY_RARE)
result += 150;
else if (rarity == DECK_RARITY_LEGENDARY)
result += 300;
return (result);
}
bool card_effect(card_type which_card, deck_rarity_type rarity,
unsigned char flags, bool tell_card)
{
bool rc = true;
const int power = _card_power(rarity);
const god_type god =
(crawl_state.is_god_acting()) ? crawl_state.which_god_acting()
: GOD_NO_GOD;
#ifdef DEBUG_DIAGNOSTICS
msg::streams(MSGCH_DIAGNOSTICS) << "Card power: " << power
<< ", rarity: " << static_cast<int>(rarity)
<< std::endl;
#endif
if (tell_card)
{
// These card types will usually give this message in the targeting
// prompt, and the cases where they don't are handled specially.
if (which_card != CARD_VITRIOL && which_card != CARD_FLAME
&& which_card != CARD_FROST && which_card != CARD_HAMMER
&& which_card != CARD_SPARK && which_card != CARD_PAIN
&& which_card != CARD_VENOM)
{
mprf("You have drawn %s.", card_name(which_card));
}
}
if (which_card == CARD_XOM && !crawl_state.is_god_acting())
{
if (you.religion == GOD_XOM)
{
// Being a self-centered deity, Xom *always* finds this
// maximally hilarious.
god_speaks(GOD_XOM, "Xom roars with laughter!");
you.gift_timeout = 255;
}
else if (you.penance[GOD_XOM])
god_speaks(GOD_XOM, "Xom laughs nastily.");
}
switch (which_card)
{
case CARD_PORTAL: _portal_card(power, rarity); break;
case CARD_WARP: _warp_card(power, rarity); break;
case CARD_SWAP: _swap_monster_card(power, rarity); break;
case CARD_VELOCITY: _velocity_card(power, rarity); break;
case CARD_DAMNATION: _damnation_card(power, rarity); break;
case CARD_SOLITUDE: cast_dispersal(power/4); break;
case CARD_ELIXIR: _elixir_card(power, rarity); break;
case CARD_BATTLELUST: _battle_lust_card(power, rarity); break;
case CARD_METAMORPHOSIS: _metamorphosis_card(power, rarity); break;
case CARD_HELM: _helm_card(power, rarity); break;
case CARD_BLADE: _blade_card(power, rarity); break;
case CARD_SHADOW: _shadow_card(power, rarity); break;
case CARD_POTION: _potion_card(power, rarity); break;
case CARD_FOCUS: _focus_card(power, rarity); break;
case CARD_SHUFFLE: _shuffle_card(power, rarity); break;
case CARD_EXPERIENCE: _experience_card(power, rarity); break;
case CARD_HELIX: _helix_card(power, rarity); break;
case CARD_SAGE: _sage_card(power, rarity); break;
case CARD_WATER: _water_card(power, rarity); break;
case CARD_GLASS: _glass_card(power, rarity); break;
case CARD_DOWSING: _dowsing_card(power, rarity); break;
case CARD_MINEFIELD: _minefield_card(power, rarity); break;
case CARD_STAIRS: _stairs_card(power, rarity); break;
case CARD_GENIE: _genie_card(power, rarity); break;
case CARD_CURSE: _curse_card(power, rarity); break;
case CARD_WARPWRIGHT: _warpwright_card(power, rarity); break;
case CARD_FLIGHT: _flight_card(power, rarity); break;
case CARD_TOMB: entomb(power); break;
case CARD_WRAITH: drain_exp(false); lose_level(); break;
case CARD_WRATH: _godly_wrath(); break;
case CARD_CRUSADE: _crusade_card(power, rarity); break;
case CARD_SUMMON_DEMON: _summon_demon_card(power, rarity); break;
case CARD_SUMMON_ANIMAL: summon_animals(random2(power/3)); break;
case CARD_SUMMON_ANY: _summon_any_monster(power, rarity); break;
case CARD_SUMMON_WEAPON: _summon_dancing_weapon(power, rarity); break;
case CARD_SUMMON_FLYING: _summon_flying(power, rarity); break;
case CARD_SUMMON_SKELETON: _summon_skeleton(power, rarity); break;
case CARD_SUMMON_UGLY: _summon_ugly(power, rarity); break;
case CARD_XOM: xom_acts(5 + random2(power/10)); break;
case CARD_TROWEL: rc = _trowel_card(power, rarity); break;
case CARD_SPADE: your_spells(SPELL_DIG, random2(power/4), false); break;
case CARD_BANSHEE: mass_enchantment(ENCH_FEAR, power, MHITYOU); break;
case CARD_TORMENT: torment(TORMENT_CARDS, you.pos()); break;
case CARD_VENOM:
if (coinflip())
{
mprf("You have drawn %s.", card_name(which_card));
your_spells(SPELL_OLGREBS_TOXIC_RADIANCE, random2(power/4), false);
}
else
rc = _damaging_card(which_card, power, rarity);
break;
case CARD_VITRIOL:
case CARD_FLAME:
case CARD_FROST:
case CARD_HAMMER:
case CARD_SPARK:
case CARD_PAIN:
rc = _damaging_card(which_card, power, rarity);
break;
case CARD_BARGAIN:
you.increase_duration(DUR_BARGAIN,
random2(power) + random2(power) + 2);
break;
case CARD_MAP:
if (!magic_mapping( random2(power/10) + 15, random2(power), true))
mpr("The map is blank.");
break;
case CARD_WILD_MAGIC:
// Yes, high power is bad here.
MiscastEffect( &you, god == GOD_NO_GOD ? NON_MONSTER : -god,
SPTYP_RANDOM, random2(power/15) + 5, random2(power),
"a card of wild magic" );
break;
case CARD_FAMINE:
if (you.is_undead == US_UNDEAD)
mpr("You feel rather smug.");
else
set_hunger(500, true);
break;
case CARD_FEAST:
if (you.is_undead == US_UNDEAD)
mpr("You feel a horrible emptiness.");
else
set_hunger(12000, true);
break;
case CARD_SWINE:
if (!transform(1 + power/2 + random2(power/2), TRAN_PIG, true))
{
mpr("You feel like a pig.");
break;
}
break;
case NUM_CARDS:
// The compiler will complain if any card remains unhandled.
mpr("You have drawn a buggy card!");
break;
}
if (you.religion == GOD_XOM && !rc)
{
god_speaks(GOD_XOM, "\"How boring, let's spice things up a little.\"");
xom_acts(abs(you.piety - HALF_MAX_PIETY));
}
if (you.religion == GOD_NEMELEX_XOBEH && !rc)
simple_god_message(" seems disappointed in you.");
return rc;
}
bool top_card_is_known(const item_def &deck)
{
if (!is_deck(deck))
return (false);
unsigned char flags;
get_card_and_flags(deck, -1, flags);
return (flags & CFLAG_MARKED);
}
card_type top_card(const item_def &deck)
{
if (!is_deck(deck))
return (NUM_CARDS);
unsigned char flags;
card_type card = get_card_and_flags(deck, -1, flags);
UNUSED(flags);
return (card);
}
bool is_deck(const item_def &item)
{
return (item.base_type == OBJ_MISCELLANY
&& item.sub_type >= MISC_DECK_OF_ESCAPE
&& item.sub_type <= MISC_DECK_OF_DEFENCE);
}
bool bad_deck(const item_def &item)
{
if (!is_deck(item))
return (false);
return (!item.props.exists("cards")
|| item.props["cards"].get_type() != SV_VEC
|| item.props["cards"].get_vector().get_type() != SV_BYTE
|| cards_in_deck(item) == 0);
}
deck_rarity_type deck_rarity(const item_def &item)
{
ASSERT( is_deck(item) );
return static_cast<deck_rarity_type>(item.special);
}
unsigned char deck_rarity_to_color(deck_rarity_type rarity)
{
switch (rarity)
{
case DECK_RARITY_COMMON:
{
const unsigned char colours[] = {LIGHTBLUE, GREEN, CYAN, RED};
return RANDOM_ELEMENT(colours);
}
case DECK_RARITY_RARE:
return (coinflip() ? MAGENTA : BROWN);
case DECK_RARITY_LEGENDARY:
return LIGHTMAGENTA;
}
return (WHITE);
}
void init_deck(item_def &item)
{
CrawlHashTable &props = item.props;
ASSERT(is_deck(item));
ASSERT(!props.exists("cards"));
ASSERT(item.plus > 0);
ASSERT(item.plus <= 127);
ASSERT(item.special >= DECK_RARITY_COMMON
&& item.special <= DECK_RARITY_LEGENDARY);
const store_flags fl = SFLAG_CONST_TYPE;
props["cards"].new_vector(SV_BYTE, fl).resize((vec_size)item.plus);
props["card_flags"].new_vector(SV_BYTE, fl).resize((vec_size)item.plus);
props["drawn_cards"].new_vector(SV_BYTE, fl);
for (int i = 0; i < item.plus; ++i)
{
bool was_odd = false;
card_type card = _random_card(item, was_odd);
unsigned char flags = 0;
if (was_odd)
flags = CFLAG_ODDITY;
_set_card_and_flags(item, i, card, flags);
}
ASSERT(cards_in_deck(item) == item.plus);
props["num_marked"] = (char) 0;
props["non_brownie_draws"] = (char) 0;
props.assert_validity();
item.plus2 = 0;
item.colour = deck_rarity_to_color((deck_rarity_type) item.special);
}
static void _unmark_deck(item_def& deck)
{
if (!is_deck(deck))
return;
CrawlHashTable &props = deck.props;
if (!props.exists("card_flags"))
return;
CrawlVector &flags = props["card_flags"].get_vector();
for (unsigned int i = 0; i < flags.size(); ++i)
{
flags[i] =
static_cast<char>((static_cast<char>(flags[i]) & ~CFLAG_MARKED));
}
// We'll be mean and leave non_brownie_draws as-is.
props["num_marked"] = static_cast<char>(0);
}
static void _unmark_and_shuffle_deck(item_def& deck)
{
if (is_deck(deck))
{
_unmark_deck(deck);
_shuffle_deck(deck);
}
}
void shuffle_all_decks_on_level()
{
for (int i = 0; i < MAX_ITEMS; ++i)
{
item_def& item(mitm[i]);
if (item.defined() && is_deck(item))
{
#ifdef DEBUG_DIAGNOSTICS
mprf(MSGCH_DIAGNOSTICS, "Shuffling: %s on level %d, branch %d",
item.name(DESC_PLAIN).c_str(),
static_cast<int>(you.absdepth0),
static_cast<int>(you.where_are_you));
#endif
_unmark_and_shuffle_deck(item);
}
}
}
static bool _shuffle_inventory_decks()
{
bool success = false;
for (int i = 0; i < ENDOFPACK; ++i)
{
item_def& item(you.inv[i]);
if (item.defined() && is_deck(item))
{
#ifdef DEBUG_DIAGNOSTICS
mprf(MSGCH_DIAGNOSTICS, "Shuffling in inventory: %s",
item.name(DESC_PLAIN).c_str());
#endif
_unmark_and_shuffle_deck(item);
success = true;
}
}
return success;
}
void nemelex_shuffle_decks()
{
add_daction(DACT_SHUFFLE_DECKS);
_shuffle_inventory_decks();
// Wildly inaccurate, but of similar quality as the old code which
// was triggered by the presence of any deck anywhere.
if (you.num_gifts[GOD_NEMELEX_XOBEH])
god_speaks(GOD_NEMELEX_XOBEH, "You hear Nemelex Xobeh chuckle.");
}
|