1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288
|
/* File: loadsave.c */
/* Purpose: interact with savefiles. This file was made by
unifying load2.c and save.c from the old codebase. Doing it
this way makes maintenance easier and lets us share code. */
#include "angband.h"
static void do_byte(byte *, int);
static void do_u16b(u16b *, int);
static void do_s16b(s16b *, int);
static void do_u32b(u32b *, int);
static void do_s32b(s32b *, int);
static void do_string(char *, int, int);
static void do_lore(int, int);
static void do_monster(monster_type *, int);
static void do_randomizer(int flag);
static void do_spells(int, int);
static void note(cptr);
static void do_fate(int, int);
static void do_item(object_type *, int);
static void do_options(int);
static bool_ do_store(store_type *, int);
static void do_messages(int flag);
static void do_xtra(int, int);
static bool_ do_savefile_aux(int);
static void junkinit(void);
static void morejunk(void);
static bool_ do_inventory(int);
static bool_ do_dungeon(int, bool_);
static void do_grid(int);
static void my_sentinel(char *, u16b, int);
static void do_ver_s16b(s16b *, u32b, s16b, int);
static void skip_ver_byte(u32b, int);
errr rd_savefile(void);
static FILE *fff; /* Local savefile ptr */
/*
* Basic byte-level reading from savefile. This provides a single point
* of interface to the pseudoencryption that ToME (and Angband)
* uses. I'm thinking about if it might be faster/better to modify all
* the do_* functions to directly do this stuff -- it'd make the code
* somewhat uglier to maintain, but concievably might be much faster. Or
* is it better maybe to scrap the pseudoencryption entirely and adopt
* some other means of obfuscation, should it still prove useful in any
* way? -- Improv
*
* What's the point of encryption on savefiles anyway? If I wanted to
* make a cheater savefile, I'd activate debug mode, and hack the game
* not to save it. There's no point. -- takkaria
*/
static byte sf_get(void)
{
byte c;
/* Get a character, decode the value */
c = getc(fff) & 0xFF;
/* Return the value */
return (c);
}
static void sf_put(byte v)
{
(void)putc((int)v, fff);
}
/*
* Do object memory and similar stuff
*/
static void do_xtra(int k_idx, int flag)
{
byte tmp8u = 0;
object_kind *k_ptr = &k_info[k_idx];
if (flag == LS_SAVE)
{
if (k_ptr->aware) tmp8u |= 0x01;
if (k_ptr->tried) tmp8u |= 0x02;
if (k_ptr->know) tmp8u |= 0x04;
if (k_ptr->artifact) tmp8u |= 0x80;
do_byte(&tmp8u, flag);
}
if (flag == LS_LOAD)
{
do_byte(&tmp8u, flag);
k_ptr->aware = ((tmp8u & 0x01) ? TRUE : FALSE);
k_ptr->tried = ((tmp8u & 0x02) ? TRUE : FALSE);
k_ptr->know = ((tmp8u & 0x04) ? TRUE : FALSE);
k_ptr->artifact = ((tmp8u & 0x80) ? TRUE : FALSE);
}
}
/*
* Load/Save quick start data
*/
void do_quick_start(int flag)
{
int i;
do_s16b(&previous_char.sex, flag);
do_s16b(&previous_char.race, flag);
do_s16b(&previous_char.rmod, flag);
do_s16b(&previous_char.pclass, flag);
do_s16b(&previous_char.spec, flag);
do_byte(&previous_char.quests, flag);
do_byte(&previous_char.god, flag);
do_s32b(&previous_char.grace, flag);
do_s16b(&previous_char.age, flag);
do_s16b(&previous_char.wt, flag);
do_s16b(&previous_char.ht, flag);
do_s16b(&previous_char.sc, flag);
do_s32b(&previous_char.au, flag);
for (i = 0; i < 6; i++) do_s16b(&(previous_char.stat[i]), flag);
do_s16b(&previous_char.luck, flag);
do_s16b(&previous_char.chaos_patron, flag);
do_u32b(&previous_char.weapon, flag);
do_byte((byte*)&previous_char.quick_ok, flag);
for (i = 0; i < 4; i++) do_string(previous_char.history[i], 60, flag);
}
/*
* The special saved subrace
*/
static void do_subrace(int flag)
{
player_race_mod *sr_ptr = &race_mod_info[SUBRACE_SAVE];
int i;
char buf[81];
if (flag == LS_SAVE)
strncpy(buf, sr_ptr->title + rmp_name, 80);
do_string(buf, 80, flag);
if (flag == LS_LOAD)
strncpy(sr_ptr->title + rmp_name, buf, 80);
if (flag == LS_SAVE)
strncpy(buf, sr_ptr->desc + rmp_text, 80);
do_string(buf, 80, flag);
if (flag == LS_LOAD)
strncpy(sr_ptr->desc + rmp_text, buf, 80);
do_byte((byte*)&sr_ptr->place, flag);
for (i = 0; i < 6; i++)
do_s16b(&sr_ptr->r_adj[i], flag);
do_byte((byte*)&sr_ptr->luck, flag);
do_s16b(&sr_ptr->mana, flag);
do_s16b(&sr_ptr->r_dis, flag);
do_s16b(&sr_ptr->r_dev, flag);
do_s16b(&sr_ptr->r_sav, flag);
do_s16b(&sr_ptr->r_stl, flag);
do_s16b(&sr_ptr->r_srh, flag);
do_s16b(&sr_ptr->r_fos, flag);
do_s16b(&sr_ptr->r_thn, flag);
do_s16b(&sr_ptr->r_thb, flag);
do_byte((byte*)&sr_ptr->r_mhp, flag);
do_s16b(&sr_ptr->r_exp, flag);
do_byte((byte*)&sr_ptr->b_age, flag);
do_byte((byte*)&sr_ptr->m_age, flag);
do_byte((byte*)&sr_ptr->m_b_ht, flag);
do_byte((byte*)&sr_ptr->m_m_ht, flag);
do_byte((byte*)&sr_ptr->f_b_ht, flag);
do_byte((byte*)&sr_ptr->f_m_ht, flag);
do_byte((byte*)&sr_ptr->m_b_wt, flag);
do_byte((byte*)&sr_ptr->m_m_wt, flag);
do_byte((byte*)&sr_ptr->f_b_wt, flag);
do_byte((byte*)&sr_ptr->f_m_wt, flag);
do_byte((byte*)&sr_ptr->infra, flag);
for (i = 0; i < 4; i++)
do_s16b(&sr_ptr->powers[i], flag);
for (i = 0; i < BODY_MAX; i++)
do_byte((byte*)&sr_ptr->body_parts[i], flag);
do_u32b(&sr_ptr->flags1, flag);
do_u32b(&sr_ptr->flags2, flag);
for (i = 0; i < PY_MAX_LEVEL + 1; i++)
{
do_u32b(&sr_ptr->oflags1[i], flag);
do_u32b(&sr_ptr->oflags2[i], flag);
do_u32b(&sr_ptr->oflags3[i], flag);
do_u32b(&sr_ptr->oflags4[i], flag);
do_u32b(&sr_ptr->oflags5[i], flag);
do_u32b(&sr_ptr->oesp[i], flag);
do_s16b(&sr_ptr->opval[i], flag);
}
do_byte(&sr_ptr->g_attr, flag);
do_byte((byte*)&sr_ptr->g_char, flag);
for (i = 0; i < MAX_SKILLS; i++)
{
do_byte((byte*)&sr_ptr->skill_basem[i], flag);
do_u32b(&sr_ptr->skill_base[i], flag);
do_byte((byte*)&sr_ptr->skill_modm[i], flag);
do_s16b(&sr_ptr->skill_mod[i], flag);
}
}
/*
* Misc. other data
*/
static char loaded_game_module[80];
static bool_ do_extra(int flag)
{
int i, j;
byte tmp8u;
s16b tmp16s;
u32b tmp32u;
u16b tmp16b;
u32b dummy32u = 0;
do_string(player_name, 32, flag);
do_string(died_from, 80, flag);
for (i = 0; i < 4; i++)
{
do_string(history[i], 60, flag);
}
/* Handle the special levels info */
if (flag == LS_SAVE)
{
tmp8u = max_d_idx;
tmp16s = MAX_DUNGEON_DEPTH;
}
do_byte(&tmp8u, flag);
if (flag == LS_LOAD)
{
if (tmp8u > max_d_idx)
{
note(format("Too many (%d) dungeon types!", tmp8u));
}
}
do_s16b(&tmp16s, flag);
if (flag == LS_LOAD)
{
if (tmp16s > MAX_DUNGEON_DEPTH)
{
note(format("Too many (%d) max level by dungeon type!", tmp16s));
}
}
/* Load the special levels history */
for (i = 0; i < tmp8u; i++)
{
for (j = 0; j < tmp16s; j++)
{
do_byte((byte*)&special_lvl[j][i], flag);
}
}
do_byte((byte*)&generate_special_feeling, flag);
/* Load the quick start data */
do_quick_start(flag);
/* Load/save the special subrace */
do_subrace(flag);
/* Race/Class/Gender/Spells */
do_s32b(&p_ptr->lives, flag);
do_byte(&p_ptr->prace, flag);
do_byte(&p_ptr->pracem, flag);
do_byte(&p_ptr->pclass, flag);
do_byte(&p_ptr->pspec, flag);
do_byte(&p_ptr->psex, flag);
do_u16b(&tmp16b, flag);
do_u16b(&tmp16b, flag);
do_byte(&p_ptr->mimic_form, flag);
do_s16b(&p_ptr->mimic_level, flag);
if (flag == LS_SAVE) tmp8u = 0;
do_byte(&p_ptr->hitdie, flag);
do_u16b(&p_ptr->expfact, flag);
do_s16b(&p_ptr->age, flag);
do_s16b(&p_ptr->ht, flag);
do_s16b(&p_ptr->wt, flag);
/* Dump the stats (maximum and current) */
for (i = 0; i < 6; ++i) do_s16b(&p_ptr->stat_max[i], flag);
for (i = 0; i < 6; ++i) do_s16b(&p_ptr->stat_cur[i], flag);
for (i = 0; i < 6; ++i) do_s16b(&p_ptr->stat_cnt[i], flag);
for (i = 0; i < 6; ++i) do_s16b(&p_ptr->stat_los[i], flag);
/* Dump the skills */
do_s16b(&p_ptr->skill_points, flag);
do_s16b(&p_ptr->skill_last_level, flag);
do_s16b(&p_ptr->melee_style, flag);
do_s16b(&p_ptr->use_piercing_shots, flag);
tmp16s = MAX_SKILLS;
do_s16b(&tmp16s, flag);
if ((flag == LS_LOAD) && (tmp16s > MAX_SKILLS))
{
quit("Too many skills");
}
if (flag == LS_SAVE) old_max_s_idx = max_s_idx;
do_u16b(&old_max_s_idx, flag);
for (i = 0; i < tmp16s; ++i)
{
if (i < old_max_s_idx)
{
do_s32b(&s_info[i].value, flag);
do_s32b(&s_info[i].mod, flag);
do_byte((byte*)&s_info[i].dev, flag);
do_byte((byte*)&s_info[i].hidden, flag);
do_u32b(&s_info[i].uses, flag);
}
else
{
do_u32b(&tmp32u, flag);
do_s16b(&tmp16s, flag);
do_byte(&tmp8u, flag);
do_byte(&tmp8u, flag);
do_u32b(&tmp32u, flag);
}
}
tmp16s = max_ab_idx;
do_s16b(&tmp16s, flag);
if ((flag == LS_LOAD) && (tmp16s > max_ab_idx))
{
quit("Too many abilities");
}
for (i = 0; i < tmp16s; ++i)
{
do_byte((byte*)&ab_info[i].acquired, flag);
}
do_s16b(&p_ptr->luck_base, flag);
do_s16b(&p_ptr->luck_max, flag);
/* Found 24 unused bytes here...
Converted it to be the alchemist's
known artifact flags.
Note that the ego flags and the gained levels
record are recorded here too, but we use the
_ver_ format to protect save file compatablity.
Note that the other alchemist knowledge (item types known)
is stored in do_aux, and is a bit flag in a previously
unused bit.
*/
for (i = 0; i < 6 ; ++i)
do_u32b(&alchemist_known_artifacts[i], flag);
for (i = 0; i < 32 ; ++i)
do_u32b(&alchemist_known_egos[i], flag);
do_u32b(&alchemist_gained, flag);
do_s32b(&p_ptr->au, flag);
do_s32b(&p_ptr->max_exp, flag);
do_s32b(&p_ptr->exp, flag);
do_u16b(&p_ptr->exp_frac, flag);
do_s16b(&p_ptr->lev, flag);
do_s16b(&p_ptr->town_num, flag); /* -KMW- */
/* Write arena and rewards information -KMW- */
do_s16b(&p_ptr->arena_number, flag);
do_s16b(&p_ptr->inside_arena, flag);
do_s16b(&p_ptr->inside_quest, flag);
do_byte((byte*)&p_ptr->exit_bldg, flag);
/* Save/load spellbinder */
do_byte(&p_ptr->spellbinder_num, flag);
do_byte(&p_ptr->spellbinder_trigger, flag);
for (i = 0; i < 4; i++)
do_u32b(&p_ptr->spellbinder[i], flag);
do_byte(&tmp8u, flag); /* tmp8u should be 0 at this point */
if (flag == LS_SAVE) tmp8u = MAX_PLOTS;
do_byte(&tmp8u, flag);
if ((flag == LS_LOAD) && (tmp8u > MAX_PLOTS))
{
quit(format("Too many plots, %d %d", tmp8u, MAX_PLOTS));
}
for (i = 0; i < tmp8u; i++)
{
do_s16b(&plots[i], flag);
}
if (flag == LS_SAVE)
{
tmp8u = MAX_RANDOM_QUEST;
}
do_byte(&tmp8u, flag);
if ((flag == LS_LOAD) &&
(tmp8u > MAX_RANDOM_QUEST)) quit("Too many random quests");
for (i = 0; i < tmp8u; i++)
{
do_byte(&random_quests[i].type, flag);
do_s16b(&random_quests[i].r_idx, flag);
do_byte((byte*)&random_quests[i].done, flag);
}
do_s16b(&p_ptr->oldpx, flag);
do_s16b(&p_ptr->oldpy, flag);
do_s16b(&p_ptr->mhp, flag);
do_s16b(&p_ptr->chp, flag);
do_u16b(&p_ptr->chp_frac, flag);
do_s16b(&p_ptr->hp_mod, flag);
do_s16b(&p_ptr->msane, flag);
do_s16b(&p_ptr->csane, flag);
do_u16b(&p_ptr->csane_frac, flag);
do_s16b(&p_ptr->msp, flag);
do_s16b(&p_ptr->csp, flag);
do_u16b(&p_ptr->csp_frac, flag);
/* XXX
Here's where tank points were.
Those who run the estate of you-know-who is really stupid.
I'll never even consider reading her books now. -- neil */
do_s16b(&tmp16s, flag);
do_s16b(&tmp16s, flag);
do_s16b(&tmp16s, flag);
do_s16b(&tmp16s, flag);
/* Gods */
do_s32b(&p_ptr->grace, flag);
do_byte((byte*)&p_ptr->praying, flag);
do_s16b(&p_ptr->melkor_sacrifice, flag);
do_byte(&p_ptr->pgod, flag);
/* Max Player and Dungeon Levels */
do_s16b(&p_ptr->max_plv, flag);
if (flag == LS_SAVE)
tmp8u = max_d_idx;
do_byte(&tmp8u, flag);
for (i = 0; i < tmp8u; i++)
{
if (flag == LS_SAVE)
tmp16s = max_dlv[i];
do_s16b(&tmp16s, flag);
if ((flag == LS_LOAD) && (i <= max_d_idx))
max_dlv[i] = tmp16s;
}
/* Repair max player level??? */
if ((flag == LS_LOAD) && (p_ptr->max_plv < p_ptr->lev))
p_ptr->max_plv = p_ptr->lev;
do_byte((byte*)&(p_ptr->help.enabled), flag);
do_u32b(&(p_ptr->help.help1), flag);
/* More info */
tmp16s = 0;
do_s16b(&p_ptr->sc, flag);
do_s16b(&p_ptr->blind, flag);
do_s16b(&p_ptr->paralyzed, flag);
do_s16b(&p_ptr->confused, flag);
do_s16b(&p_ptr->food, flag);
do_s32b(&p_ptr->energy, flag);
do_s16b(&p_ptr->fast, flag);
do_s16b(&p_ptr->speed_factor, flag);
do_s16b(&p_ptr->slow, flag);
do_s16b(&p_ptr->afraid, flag);
do_s16b(&p_ptr->cut, flag);
do_s16b(&p_ptr->stun, flag);
do_s16b(&p_ptr->poisoned, flag);
do_s16b(&p_ptr->image, flag);
do_s16b(&p_ptr->protevil, flag);
do_s16b(&p_ptr->protundead, flag);
do_s16b(&p_ptr->invuln, flag);
do_s16b(&p_ptr->hero, flag);
do_s16b(&p_ptr->shero, flag);
do_s16b(&p_ptr->shield, flag);
do_s16b(&p_ptr->shield_power, flag);
do_s16b(&p_ptr->shield_power_opt, flag);
do_s16b(&p_ptr->shield_power_opt2, flag);
do_s16b(&p_ptr->shield_opt, flag);
do_s16b(&p_ptr->blessed, flag);
do_s16b(&p_ptr->control, flag);
do_byte(&p_ptr->control_dir, flag);
do_s16b(&p_ptr->tim_thunder, flag);
do_s16b(&p_ptr->tim_thunder_p1, flag);
do_s16b(&p_ptr->tim_thunder_p2, flag);
do_s16b(&p_ptr->tim_project, flag);
do_s16b(&p_ptr->tim_project_dam, flag);
do_s16b(&p_ptr->tim_project_gf, flag);
do_s16b(&p_ptr->tim_project_rad, flag);
do_s16b(&p_ptr->tim_project_flag, flag);
do_s16b(&p_ptr->tim_magic_breath, flag);
do_s16b(&p_ptr->tim_water_breath, flag);
do_s16b(&p_ptr->tim_roots, flag);
do_s16b(&p_ptr->tim_roots_ac, flag);
do_s16b(&p_ptr->tim_roots_dam, flag);
do_s16b(&p_ptr->tim_invis, flag);
do_s16b(&p_ptr->word_recall, flag);
do_s16b(&p_ptr->recall_dungeon, flag);
do_s16b(&p_ptr->see_infra, flag);
do_s16b(&p_ptr->tim_infra, flag);
do_s16b(&p_ptr->oppose_fire, flag);
do_s16b(&p_ptr->oppose_cold, flag);
do_s16b(&p_ptr->oppose_acid, flag);
do_s16b(&p_ptr->oppose_elec, flag);
do_s16b(&p_ptr->oppose_pois, flag);
do_s16b(&p_ptr->oppose_ld, flag);
do_s16b(&p_ptr->oppose_cc, flag);
do_s16b(&p_ptr->oppose_ss, flag);
do_s16b(&p_ptr->oppose_nex, flag);
do_s16b(&p_ptr->tim_esp, flag);
do_s16b(&p_ptr->tim_wraith, flag);
do_s16b(&p_ptr->tim_ffall, flag);
do_ver_s16b(&p_ptr->tim_fly, SAVEFILE_VERSION, 0, flag);
do_s16b(&p_ptr->tim_fire_aura, flag);
do_ver_s16b(&p_ptr->tim_poison, SAVEFILE_VERSION, 0, flag);
do_s16b(&p_ptr->resist_magic, flag);
do_s16b(&p_ptr->tim_invisible, flag);
do_s16b(&p_ptr->tim_inv_pow, flag);
do_s16b(&p_ptr->tim_mimic, flag);
do_s16b(&p_ptr->lightspeed, flag);
do_s16b(&p_ptr->tim_lite, flag);
do_ver_s16b(&p_ptr->tim_regen, SAVEFILE_VERSION, 0, flag);
do_ver_s16b(&p_ptr->tim_regen_pow, SAVEFILE_VERSION, 0, flag);
do_s16b(&p_ptr->holy, flag);
do_s16b(&p_ptr->walk_water, flag);
do_s16b(&p_ptr->tim_mental_barrier, flag);
do_s16b(&p_ptr->immov_cntr, flag);
do_s16b(&p_ptr->strike, flag);
do_s16b(&p_ptr->meditation, flag);
do_s16b(&p_ptr->tim_reflect, flag);
do_s16b(&p_ptr->tim_res_time, flag);
do_s16b(&p_ptr->tim_deadly, flag);
do_s16b(&p_ptr->prob_travel, flag);
do_s16b(&p_ptr->disrupt_shield, flag);
do_s16b(&p_ptr->parasite, flag);
do_s16b(&p_ptr->parasite_r_idx, flag);
do_s32b(&p_ptr->loan, flag);
do_s32b(&p_ptr->loan_time, flag);
do_s16b(&p_ptr->absorb_soul, flag);
do_s16b(&p_ptr->chaos_patron, flag);
if (flag == LS_SAVE) tmp16s = max_corruptions;
do_s16b(&tmp16s, flag);
for (i = 0; i < tmp16s; i++)
{
if ((flag == LS_SAVE) && (i < max_corruptions))
tmp8u = p_ptr->corruptions[i];
do_byte(&tmp8u, flag);
if ((flag == LS_LOAD) && (i < max_corruptions))
p_ptr->corruptions[i] = tmp8u;
}
do_byte(&p_ptr->confusing, flag);
do_byte((byte*)&p_ptr->black_breath, flag);
do_byte((byte*)&fate_flag, flag);
do_byte(&p_ptr->searching, flag);
do_byte(&p_ptr->maximize, flag);
do_byte(&p_ptr->preserve, flag);
do_byte(&p_ptr->special, flag);
do_byte((byte*)&ambush_flag, flag);
do_byte(&p_ptr->allow_one_death, flag);
do_s16b(&p_ptr->xtra_spells, flag);
do_byte(&tmp8u, flag);
do_s16b(&no_breeds, flag);
do_s16b(&p_ptr->protgood, flag);
/* Auxilliary variables */
do_u32b(&p_ptr->mimic_extra, flag);
do_u32b(&p_ptr->antimagic_extra, flag);
do_u32b(&p_ptr->druid_extra, flag);
do_u32b(&p_ptr->druid_extra2, flag);
do_u32b(&p_ptr->druid_extra3, flag);
do_u32b(&p_ptr->music_extra, flag);
do_u32b(&p_ptr->music_extra2, flag);
do_u32b(&p_ptr->necro_extra, flag);
do_u32b(&p_ptr->necro_extra2, flag);
do_u32b(&p_ptr->race_extra1, flag);
do_u32b(&p_ptr->race_extra2, flag);
do_u32b(&p_ptr->race_extra3, flag);
do_u32b(&p_ptr->race_extra4, flag);
do_u32b(&p_ptr->race_extra5, flag);
do_u32b(&p_ptr->race_extra6, flag);
do_u32b(&p_ptr->race_extra7, flag);
do_u16b(&p_ptr->body_monster, flag);
do_byte((byte*)&p_ptr->disembodied, flag);
/* Are we in astral mode? */
do_byte((byte*)&p_ptr->astral, flag);
if (flag == LS_SAVE) tmp16s = POWER_MAX_INIT;
do_s16b(&tmp16s, flag);
if ((flag == LS_LOAD) && (tmp16s > POWER_MAX_INIT))
note(format("Too many (%u) powers!", tmp16s));
if (flag == LS_SAVE) tmp16s = POWER_MAX_INIT;
for (i = 0; i < tmp16s; i++)
do_byte((byte*)&p_ptr->powers_mod[i], flag);
skip_ver_byte(100, flag);
/* The tactic */
do_byte((byte*)&p_ptr->tactic, flag);
/* The movement */
do_byte((byte*)&p_ptr->movement, flag);
/* The comapnions killed */
do_s16b(&p_ptr->companion_killed, flag);
/* The fate */
do_byte((byte*)&p_ptr->no_mortal, flag);
/* The bounties */
for (i = 0; i < MAX_BOUNTIES; i++)
{
do_s16b(&bounties[i][0], flag);
do_s16b(&bounties[i][1], flag);
}
do_u32b(&total_bounties, flag);
do_s16b(&spell_num, flag);
for (i = 0; i < MAX_SPELLS; i++)
do_spells(i, flag);
do_s16b(&rune_num, flag);
for (i = 0; i < MAX_RUNES; i++)
{
do_string(rune_spells[i].name, 30, flag);
do_s16b(&rune_spells[i].type, flag);
do_s16b(&rune_spells[i].rune2, flag);
do_s16b(&rune_spells[i].mana, flag);
}
/* Load random seeds */
do_u32b(&dummy32u, flag); /* Load-compatibility with old savefiles. */
do_u32b(&seed_flavor, flag); /* For consistent object flavors. */
do_u32b(&dummy32u, flag); /* Load-compatibility with old savefiles. */
/* Special stuff */
do_u16b(&tmp16b, flag); /* Dummy */
do_u16b(&total_winner, flag);
do_u16b(&has_won, flag);
do_u16b(&noscore, flag);
/* Write death */
if (flag == LS_SAVE) tmp8u = death;
do_byte(&tmp8u, flag);
if (flag == LS_LOAD) death = tmp8u;
/* Incompatible module? */
if (flag == LS_LOAD)
{
s32b ok;
call_lua("module_savefile_loadable", "(s,d)", "d", loaded_game_module, death, &ok);
/* Argh bad game module! */
if (!ok)
{
note(format("Bad game module. Savefile was saved with module '%s' but game is '%s'.", loaded_game_module, game_module));
return (FALSE);
}
}
/* Write feeling */
if (flag == LS_SAVE) tmp8u = feeling;
do_byte(&tmp8u, flag);
if (flag == LS_LOAD) feeling = tmp8u;
/* Turn of last "feeling" */
do_s32b(&old_turn, flag);
/* Current turn */
do_s32b(&turn, flag);
return TRUE;
}
/* Save the current persistent dungeon -SC- */
void save_dungeon(void)
{
char tmp[16];
char name[1024], buf[5];
/* Save only persistent dungeons */
if (!get_dungeon_save(buf) || (!dun_level)) return;
/* Construct filename */
sprintf(tmp, "%s.%s", player_base, buf);
path_build(name, 1024, ANGBAND_DIR_SAVE, tmp);
/* Open the file */
fff = my_fopen(name, "wb");
/* Save the dungeon */
do_dungeon(LS_SAVE, TRUE);
my_fclose(fff);
}
/*
* Medium level player saver
*/
static bool_ save_player_aux(char *name)
{
bool_ ok = FALSE;
int fd = -1;
int mode = 0644;
/* No file yet */
fff = NULL;
/* File type is "SAVE" */
FILE_TYPE(FILE_TYPE_SAVE);
/* Create the savefile */
fd = fd_make(name, mode);
/* File is okay */
if (fd >= 0)
{
/* Close the "fd" */
(void)fd_close(fd);
/* Open the savefile */
fff = my_fopen(name, "wb");
/* Successful open */
if (fff)
{
/* Write the savefile */
if (do_savefile_aux(LS_SAVE)) ok = TRUE;
/* Attempt to close it */
if (my_fclose(fff)) ok = FALSE;
}
/* "broken" savefile */
if (!ok)
{
/* Remove "broken" files */
(void)fd_kill(name);
}
}
/* Failure */
if (!ok) return (FALSE);
/* Successful save */
character_saved = TRUE;
/* Success */
return (TRUE);
}
/*
* Attempt to save the player in a savefile
*/
bool_ save_player(void)
{
int result = FALSE;
char safe[1024];
/* New savefile */
strcpy(safe, savefile);
strcat(safe, ".new");
/* Remove it */
fd_kill(safe);
/* Attempt to save the player */
if (save_player_aux(safe))
{
char temp[1024];
/* Old savefile */
strcpy(temp, savefile);
strcat(temp, ".old");
/* Remove it */
fd_kill(temp);
/* Preserve old savefile */
fd_move(savefile, temp);
/* Activate new savefile */
fd_move(safe, savefile);
/* Remove preserved savefile */
fd_kill(temp);
/* Hack -- Pretend the character was loaded */
character_loaded = TRUE;
/* Success */
result = TRUE;
}
save_savefile_names();
/* Return the result */
return (result);
}
bool_ file_exist(char *buf)
{
int fd;
bool_ result;
/* Open savefile */
fd = fd_open(buf, O_RDONLY);
/* File exists */
if (fd >= 0)
{
fd_close(fd);
result = TRUE;
}
else
result = FALSE;
return result;
}
/*
* Attempt to Load a "savefile"
*
* On multi-user systems, you may only "read" a savefile if you will be
* allowed to "write" it later, this prevents painful situations in which
* the player loads a savefile belonging to someone else, and then is not
* allowed to save his game when he quits.
*
* We return "TRUE" if the savefile was usable, and we set the global
* flag "character_loaded" if a real, living, character was loaded.
*
* Note that we always try to load the "current" savefile, even if
* there is no such file, so we must check for "empty" savefile names.
*/
bool_ load_player(void)
{
int fd = -1;
errr err = 0;
cptr what = "generic";
/* Paranoia */
turn = 0;
/* Paranoia */
death = FALSE;
/* Allow empty savefile name */
if (!savefile[0]) return (TRUE);
/* XXX XXX XXX Fix this */
/* Verify the existance of the savefile */
if (!file_exist(savefile))
{
/* Give a message */
msg_format("Savefile does not exist: %s", savefile);
msg_print(NULL);
/* Allow this */
return (TRUE);
}
/* Okay */
if (!err)
{
/* Open the savefile */
fd = fd_open(savefile, O_RDONLY);
/* No file */
if (fd < 0) err = -1;
/* Message (below) */
if (err) what = "Cannot open savefile";
}
/* Process file */
if (!err)
{
/* Open the file XXX XXX XXX XXX Should use Angband file interface */
fff = my_fopen(savefile, "rb");
/* fff = fdopen(fd, "r"); */
/* Read the first four bytes */
do_u32b(&vernum, LS_LOAD);
do_byte(&sf_extra, LS_LOAD);
/* XXX XXX XXX XXX Should use Angband file interface */
my_fclose(fff);
/* fclose(fff) */
/* Close the file */
fd_close(fd);
}
/* Process file */
if (!err)
{
/* Extract version */
sf_major = VERSION_MAJOR;
sf_minor = VERSION_MINOR;
sf_patch = VERSION_PATCH;
sf_extra = VERSION_EXTRA;
/* Clear screen */
Term_clear();
/* Attempt to load */
err = rd_savefile();
/* Message (below) */
if (err) what = "Cannot parse savefile";
}
/* Paranoia */
if (!err)
{
/* Invalid turn */
if (!turn) err = -1;
/* Message (below) */
if (err) what = "Broken savefile";
}
/* Okay */
if (!err)
{
/* Maybe the scripts want to resurrect char */
if (process_hooks_ret(HOOK_LOAD_END, "d", "(d)", death))
{
character_loaded = process_hooks_return[0].num;
death = process_hooks_return[1].num;
return TRUE;
}
/* Player is dead */
if (death)
{
/* Player is no longer "dead" */
death = FALSE;
/* Cheat death (unless the character retired) */
if (arg_wizard && !total_winner)
{
/* A character was loaded */
character_loaded = TRUE;
/* Done */
return (TRUE);
}
/* Count lives */
sf_lives++;
/* Forget turns */
turn = old_turn = 0;
/* Done */
return (TRUE);
}
/* A character was loaded */
character_loaded = TRUE;
/* Still alive */
if (p_ptr->chp >= 0)
{
/* Reset cause of death */
(void)strcpy(died_from, "(alive and well)");
}
/* Success */
return (TRUE);
}
/* Message */
msg_format("Error (%s) reading %d.%d.%d savefile.",
what, sf_major, sf_minor, sf_patch);
msg_print(NULL);
/* Oops */
return (FALSE);
}
/*
* Size-aware read/write routines for the savefile, do all their
* work through sf_get and sf_put.
*/
static void do_byte(byte *v, int flag)
{
if (flag == LS_LOAD)
{
*v = sf_get();
return;
}
if (flag == LS_SAVE)
{
byte val = *v;
sf_put(val);
return;
}
/* We should never reach here, so bail out */
printf("FATAL: do_byte passed %d\n", flag);
exit(0);
}
static void do_u16b(u16b *v, int flag)
{
if (flag == LS_LOAD)
{
(*v) = sf_get();
(*v) |= ((u16b)(sf_get()) << 8);
return;
}
if (flag == LS_SAVE)
{
u16b val;
val = *v;
sf_put((byte)(val & 0xFF));
sf_put((byte)((val >> 8) & 0xFF));
return;
}
/* Never should reach here, bail out */
printf("FATAL: do_u16b passed %d\n", flag);
exit(0);
}
static void do_s16b(s16b *ip, int flag)
{
if (flag == LS_LOAD)
{
do_u16b((u16b *)ip, flag);
return;
}
if (flag == LS_SAVE)
{
do_u16b((u16b *)ip, flag);
return;
}
/* Blah blah, never should reach here, die */
printf("FATAL: do_s16b passed %d\n", flag);
exit(0);
}
static void do_u32b(u32b *ip, int flag)
{
if (flag == LS_LOAD)
{
(*ip) = sf_get();
(*ip) |= ((u32b)(sf_get()) << 8);
(*ip) |= ((u32b)(sf_get()) << 16);
(*ip) |= ((u32b)(sf_get()) << 24);
return;
}
if (flag == LS_SAVE)
{
u32b val = *ip;
sf_put((byte)(val & 0xFF));
sf_put((byte)((val >> 8) & 0xFF));
sf_put((byte)((val >> 16) & 0xFF));
sf_put((byte)((val >> 24) & 0xFF));
return;
}
/* Bad news if you're here, because you're going down */
printf("FATAL: do_u32b passed %d\n", flag);
exit(0);
}
static void do_s32b(s32b *ip, int flag)
{
if (flag == LS_LOAD)
{
do_u32b((u32b *)ip, flag);
return;
}
if (flag == LS_SAVE)
{
do_u32b((u32b *)ip, flag);
return;
}
/* Raus! Schnell! */
printf("FATAL: do_s32b passed %d\n", flag);
exit(0);
}
static void do_string(char *str, int max, int flag)
/* Max is ignored for writing */
{
if (flag == LS_LOAD)
{
int i;
/* Read the string */
for (i = 0; TRUE; i++)
{
byte tmp8u;
/* Read a byte */
do_byte(&tmp8u, LS_LOAD);
/* Collect string while legal */
if (i < max) str[i] = tmp8u;
/* End of string */
if (!tmp8u) break;
}
/* Terminate */
str[max - 1] = '\0';
return;
}
if (flag == LS_SAVE)
{
while (*str)
{
do_byte((byte*)str, flag);
str++;
}
do_byte((byte*)str, flag); /* Output a terminator */
return;
}
printf("FATAL: do_string passed flag %d\n", flag);
exit(0);
}
static void skip_ver_byte(u32b version, int flag)
/* Reads and discards a byte if the savefile is as old as/older than version */
{
if ((flag == LS_LOAD) && (vernum <= version))
{
byte forget;
do_byte(&forget, flag);
}
return;
}
static void do_ver_s16b(s16b *v, u32b version, s16b defval, int flag)
{
if ((flag == LS_LOAD) && (vernum < version))
{
*v = defval;
return;
}
do_s16b(v, flag);
}
/*
* Show information on the screen, one line at a time.
*
* Avoid the top two lines, to avoid interference with "msg_print()".
*/
static void note(cptr msg)
{
static int y = 2;
/* Draw the message */
prt(msg, y, 0);
/* Advance one line (wrap if needed) */
if (++y >= 24) y = 2;
/* Flush it */
Term_fresh();
}
/*
* Determine if an item can be wielded/worn (e.g. helmet, sword, bow, arrow)
*/
static bool_ wearable_p(object_type *o_ptr)
{
/* Valid "tval" codes */
switch (o_ptr->tval)
{
case TV_WAND:
case TV_STAFF:
case TV_ROD:
case TV_ROD_MAIN:
case TV_SHOT:
case TV_ARROW:
case TV_BOLT:
case TV_BOOMERANG:
case TV_BOW:
case TV_DIGGING:
case TV_HAFTED:
case TV_POLEARM:
case TV_MSTAFF:
case TV_SWORD:
case TV_AXE:
case TV_BOOTS:
case TV_GLOVES:
case TV_HELM:
case TV_CROWN:
case TV_SHIELD:
case TV_CLOAK:
case TV_SOFT_ARMOR:
case TV_HARD_ARMOR:
case TV_DRAG_ARMOR:
case TV_SCROLL:
case TV_LITE:
case TV_POTION:
case TV_POTION2:
case TV_AMULET:
case TV_RING:
case TV_HYPNOS:
case TV_INSTRUMENT:
case TV_DAEMON_BOOK:
case TV_TRAPKIT:
case TV_TOOL:
{
return (TRUE);
}
}
/* Nope */
return (FALSE);
}
/*
* rd/wr an object
*
* FIXME! This code probably has a lot of cruft from the old Z/V codebase.
*
*/
static void do_item(object_type *o_ptr, int flag)
{
byte old_dd;
byte old_ds;
u32b f1, f2, f3, f4, f5, esp;
object_kind *k_ptr;
/* Kind */
do_s16b(&o_ptr->k_idx, flag);
/* Location */
do_byte(&o_ptr->iy, flag);
do_byte(&o_ptr->ix, flag);
/* Type/Subtype */
do_byte(&o_ptr->tval, flag);
do_byte(&o_ptr->sval, flag);
/* Special pval */
do_s32b(&o_ptr->pval, flag);
/* Special pval */
do_s16b(&o_ptr->pval2, flag);
/* Special pval */
do_s32b(&o_ptr->pval3, flag);
do_byte(&o_ptr->discount, flag);
do_byte(&o_ptr->number, flag);
do_s32b(&o_ptr->weight, flag);
do_byte(&o_ptr->name1, flag);
do_s16b(&o_ptr->name2, flag);
do_s16b(&o_ptr->name2b, flag);
do_s16b(&o_ptr->timeout, flag);
do_s16b(&o_ptr->to_h, flag);
do_s16b(&o_ptr->to_d, flag);
do_s16b(&o_ptr->to_a, flag);
do_s16b(&o_ptr->ac, flag);
/* We do special processing of this flag when reading */
if (flag == LS_LOAD)
{
do_byte(&old_dd, LS_LOAD);
do_byte(&old_ds, LS_LOAD);
}
if (flag == LS_SAVE)
{
do_byte(&o_ptr->dd, LS_SAVE);
do_byte(&o_ptr->ds, LS_SAVE);
}
do_byte(&o_ptr->ident, flag);
do_byte(&o_ptr->marked, flag);
/* flags */
do_u32b(&o_ptr->art_flags1, flag);
do_u32b(&o_ptr->art_flags2, flag);
do_u32b(&o_ptr->art_flags3, flag);
do_u32b(&o_ptr->art_flags4, flag);
do_u32b(&o_ptr->art_flags5, flag);
do_u32b(&o_ptr->art_esp, flag);
/* obvious flags */
do_u32b(&o_ptr->art_oflags1, flag);
do_u32b(&o_ptr->art_oflags2, flag);
do_u32b(&o_ptr->art_oflags3, flag);
do_u32b(&o_ptr->art_oflags4, flag);
do_u32b(&o_ptr->art_oflags5, flag);
do_u32b(&o_ptr->art_oesp, flag);
/* Monster holding object */
do_s16b(&o_ptr->held_m_idx, flag);
/* Special powers */
do_byte(&o_ptr->xtra1, flag);
do_s16b(&o_ptr->xtra2, flag);
do_byte(&o_ptr->elevel, flag);
do_s32b(&o_ptr->exp, flag);
/* Read the pseudo-id */
do_byte(&o_ptr->sense, flag);
/* Read the found info */
do_byte(&o_ptr->found, flag);
do_s16b(&o_ptr->found_aux1, flag);
do_s16b(&o_ptr->found_aux2, flag);
do_s16b(&o_ptr->found_aux3, flag);
do_s16b(&o_ptr->found_aux4, flag);
if (flag == LS_LOAD)
{
char buf[128];
/* Inscription */
do_string(buf, 128, LS_LOAD);
/* Save the inscription */
if (buf[0]) o_ptr->note = quark_add(buf);
do_string(buf, 128, LS_LOAD);
if (buf[0]) o_ptr->art_name = quark_add(buf);
}
if (flag == LS_SAVE)
{
/* Save the inscription (if any) */
if (o_ptr->note)
{
do_string((char *)quark_str(o_ptr->note), 0, LS_SAVE);
}
else
{
do_string("", 0, LS_SAVE);
}
if (o_ptr->art_name)
{
do_string((char *)quark_str(o_ptr->art_name), 0, LS_SAVE);
}
else
{
do_string("", 0, LS_SAVE);
}
}
if (flag == LS_SAVE) return ; /* Stick any more shared code before this. The rest
of this function is reserved for LS_LOAD's
cleanup functions */
/*********** END OF LS_SAVE ***************/
/* Obtain the "kind" template */
k_ptr = &k_info[o_ptr->k_idx];
/* Obtain tval/sval from k_info */
o_ptr->tval = k_ptr->tval;
if (o_ptr->tval != TV_RANDART) o_ptr->sval = k_ptr->sval;
/* Repair non "wearable" items */
if (!wearable_p(o_ptr))
{
/* Acquire correct fields */
o_ptr->to_h = k_ptr->to_h;
o_ptr->to_d = k_ptr->to_d;
o_ptr->to_a = k_ptr->to_a;
/* Acquire correct fields */
o_ptr->ac = k_ptr->ac;
o_ptr->dd = k_ptr->dd;
o_ptr->ds = k_ptr->ds;
/* All done */
return;
}
/* Extract the flags */
object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp);
/* Paranoia */
if (o_ptr->name1)
{
artifact_type *a_ptr;
/* Obtain the artifact info */
a_ptr = &a_info[o_ptr->name1];
/* Verify that artifact */
if (!a_ptr->name) o_ptr->name1 = 0;
}
/* Paranoia */
if (o_ptr->name2)
{
ego_item_type *e_ptr;
/* Obtain the ego-item info */
e_ptr = &e_info[o_ptr->name2];
/* Verify that ego-item */
if (!e_ptr->name) o_ptr->name2 = 0;
}
/* Acquire standard fields */
o_ptr->ac = k_ptr->ac;
o_ptr->dd = k_ptr->dd;
o_ptr->ds = k_ptr->ds;
/* Artifacts */
if (o_ptr->name1)
{
artifact_type *a_ptr;
/* Obtain the artifact info */
a_ptr = &a_info[o_ptr->name1];
/* Acquire new artifact fields */
o_ptr->ac = a_ptr->ac;
o_ptr->dd = a_ptr->dd;
o_ptr->ds = a_ptr->ds;
/* Acquire new artifact weight */
o_ptr->weight = a_ptr->weight;
}
/* Ego items */
if (o_ptr->name2)
{
o_ptr->dd = old_dd;
o_ptr->ds = old_ds;
}
if (o_ptr->art_name) /* A random artifact */
{
o_ptr->dd = old_dd;
o_ptr->ds = old_ds;
}
}
/*
* Read a monster
*/
static void do_monster(monster_type *m_ptr, int flag)
{
int i;
bool_ tmp;
/* Read the monster race */
do_s16b(&m_ptr->r_idx, flag);
do_u16b(&m_ptr->ego, flag);
/* Read the other information */
do_byte(&m_ptr->fy, flag);
do_byte(&m_ptr->fx, flag);
do_s32b(&m_ptr->hp, flag);
do_s32b(&m_ptr->maxhp, flag);
do_s16b(&m_ptr->csleep, flag);
do_byte(&m_ptr->mspeed, flag);
do_byte(&m_ptr->energy, flag);
do_byte(&m_ptr->stunned, flag);
do_byte(&m_ptr->confused, flag);
do_byte(&m_ptr->monfear, flag);
do_u32b(&m_ptr->smart, flag);
do_s16b(&m_ptr->status, flag);
do_s16b(&m_ptr->possessor, flag);
do_byte(&m_ptr->speed, flag);
do_byte(&m_ptr->level, flag);
do_s16b(&m_ptr->ac, flag);
do_u32b(&m_ptr->exp, flag);
do_s16b(&m_ptr->target, flag);
do_s16b(&m_ptr->bleeding, flag);
do_s16b(&m_ptr->poisoned, flag);
do_s32b(&m_ptr->mflag, flag);
if (flag == LS_LOAD) m_ptr->mflag &= PERM_MFLAG_MASK;
/* Attacks */
for (i = 0; i < 4; i++)
{
do_byte(&m_ptr->blow[i].method, flag);
do_byte(&m_ptr->blow[i].effect, flag);
do_byte(&m_ptr->blow[i].d_dice, flag);
do_byte(&m_ptr->blow[i].d_side, flag);
}
/* Mind */
tmp = (m_ptr->mind) ? TRUE : FALSE;
do_byte((byte*)&tmp, flag);
if (tmp)
{
if (flag == LS_LOAD)
{
MAKE(m_ptr->mind, monster_mind);
}
}
/* Special race */
tmp = (m_ptr->sr_ptr) ? TRUE : FALSE;
do_byte((byte*)&tmp, flag);
if (tmp)
{
if (flag == LS_LOAD)
{
MAKE(m_ptr->sr_ptr, monster_race);
}
do_u32b(&m_ptr->sr_ptr->name, flag);
do_u32b(&m_ptr->sr_ptr->text, flag);
do_u16b(&m_ptr->sr_ptr->hdice, flag);
do_u16b(&m_ptr->sr_ptr->hside, flag);
do_s16b(&m_ptr->sr_ptr->ac, flag);
do_s16b(&m_ptr->sr_ptr->sleep, flag);
do_byte(&m_ptr->sr_ptr->aaf, flag);
do_byte(&m_ptr->sr_ptr->speed, flag);
do_s32b(&m_ptr->sr_ptr->mexp, flag);
do_s32b(&m_ptr->sr_ptr->weight, flag);
do_byte(&m_ptr->sr_ptr->freq_inate, flag);
do_byte(&m_ptr->sr_ptr->freq_spell, flag);
do_u32b(&m_ptr->sr_ptr->flags1, flag);
do_u32b(&m_ptr->sr_ptr->flags2, flag);
do_u32b(&m_ptr->sr_ptr->flags3, flag);
do_u32b(&m_ptr->sr_ptr->flags4, flag);
do_u32b(&m_ptr->sr_ptr->flags5, flag);
do_u32b(&m_ptr->sr_ptr->flags6, flag);
do_u32b(&m_ptr->sr_ptr->flags7, flag);
do_u32b(&m_ptr->sr_ptr->flags8, flag);
do_u32b(&m_ptr->sr_ptr->flags9, flag);
/* Attacks */
for (i = 0; i < 4; i++)
{
do_byte(&m_ptr->sr_ptr->blow[i].method, flag);
do_byte(&m_ptr->sr_ptr->blow[i].effect, flag);
do_byte(&m_ptr->sr_ptr->blow[i].d_dice, flag);
do_byte(&m_ptr->sr_ptr->blow[i].d_side, flag);
}
for (i = 0; i < BODY_MAX; i++)
do_byte(&m_ptr->sr_ptr->body_parts[i], flag);
do_byte(&m_ptr->sr_ptr->level, flag);
do_byte(&m_ptr->sr_ptr->rarity, flag);
do_byte((byte*)&m_ptr->sr_ptr->d_char, flag);
do_byte(&m_ptr->sr_ptr->d_attr, flag);
do_byte((byte*)&m_ptr->sr_ptr->x_char, flag);
do_byte(&m_ptr->sr_ptr->x_attr, flag);
do_s16b(&m_ptr->sr_ptr->max_num, flag);
do_byte(&m_ptr->sr_ptr->cur_num, flag);
}
}
/*
* Handle monster lore
*/
static void do_lore(int r_idx, int flag)
{
monster_race *r_ptr = &r_info[r_idx];
/* Count sights/deaths/kills */
do_s16b(&r_ptr->r_sights, flag);
do_s16b(&r_ptr->r_deaths, flag);
do_s16b(&r_ptr->r_pkills, flag);
do_s16b(&r_ptr->r_tkills, flag);
/* Count wakes and ignores */
do_byte(&r_ptr->r_wake, flag);
do_byte(&r_ptr->r_ignore, flag);
/* Extra stuff */
do_byte(&r_ptr->r_xtra1, flag);
do_byte(&r_ptr->r_xtra2, flag);
/* Count drops */
do_byte(&r_ptr->r_drop_gold, flag);
do_byte(&r_ptr->r_drop_item, flag);
/* Count spells */
do_byte(&r_ptr->r_cast_inate, flag);
do_byte(&r_ptr->r_cast_spell, flag);
/* Count blows of each type */
do_byte(&r_ptr->r_blows[0], flag);
do_byte(&r_ptr->r_blows[1], flag);
do_byte(&r_ptr->r_blows[2], flag);
do_byte(&r_ptr->r_blows[3], flag);
/* Memorize flags */
do_u32b(&r_ptr->r_flags1, flag); /* Just to remind you */
do_u32b(&r_ptr->r_flags2, flag); /* flag is unrelated to */
do_u32b(&r_ptr->r_flags3, flag); /* the other argument */
do_u32b(&r_ptr->r_flags4, flag);
do_u32b(&r_ptr->r_flags5, flag);
do_u32b(&r_ptr->r_flags6, flag);
do_u32b(&r_ptr->r_flags7, flag);
do_u32b(&r_ptr->r_flags8, flag);
do_u32b(&r_ptr->r_flags9, flag);
/* Read the "Racial" monster tmp16b per level */
do_s16b(&r_ptr->max_num, flag);
do_byte((byte*)&r_ptr->on_saved, flag);
if (flag == LS_LOAD)
{
/* Lore flag repair? */
r_ptr->r_flags1 &= r_ptr->flags1;
r_ptr->r_flags2 &= r_ptr->flags2;
r_ptr->r_flags3 &= r_ptr->flags3;
r_ptr->r_flags4 &= r_ptr->flags4;
r_ptr->r_flags5 &= r_ptr->flags5;
r_ptr->r_flags6 &= r_ptr->flags6;
}
}
/*
* Read a store
*/
static bool_ do_store(store_type *str, int flag)
/* FIXME! Why does this return anything when
it always returns the same thing? */
{
int j;
byte num;
byte store_inven_max = STORE_INVEN_MAX;
/* Some basic info */
do_s32b(&str->store_open, flag);
do_s16b(&str->insult_cur, flag);
do_u16b(&str->owner, flag);
if (flag == LS_SAVE) num = str->stock_num;
/* Could be cleaner, done this way for benefit of the for loop later on */
do_byte(&num, flag);
do_s16b(&str->good_buy, flag);
do_s16b(&str->bad_buy, flag);
/* Last visit */
do_s32b(&str->last_visit, flag);
/* Items */
for (j = 0; j < num; j++)
{
if (flag == LS_LOAD)
/* Can't this be cleaner? */
{
object_type forge;
/* Wipe the object */
object_wipe(&forge);
/* Read the item */
do_item(&forge, LS_LOAD);
/* Acquire valid items */
if ((str->stock_num < store_inven_max) && (str->stock_num < str->stock_size))
{
int k = str->stock_num++;
/* Acquire the item */
object_copy(&str->stock[k], &forge);
}
}
if (flag == LS_SAVE) do_item(&str->stock[j], flag);
}
/* Success */
return (TRUE);
}
/*
* RNG state
*/
static void do_randomizer(int flag)
{
int i;
u16b tmp16u = 0;
/* Tmp */
do_u16b(&tmp16u, flag);
/* Place */
do_u16b(&Rand_place, flag);
/* State */
for (i = 0; i < RAND_DEG; i++)
{
do_u32b(&Rand_state[i], flag);
}
/* Accept */
if (flag == LS_LOAD)
{
Rand_quick = FALSE;
}
}
/*
* Handle options
*
* Normal options are stored as a set of 256 bit flags,
* plus a set of 256 bit masks to indicate which bit flags were defined
* at the time the savefile was created. This will allow new options
* to be added, and old options to be removed, at any time, without
* hurting old savefiles.
*
* The window options are stored in the same way, but note that each
* window gets 32 options, and their order is fixed by certain defines.
*/
static void do_options(int flag)
{
int i, n;
u32b oflag[8];
u32b mask[8];
/*** Special info */
/* Read "delay_factor" */
do_byte(&delay_factor, flag);
/* Read "hitpoint_warn" */
do_byte(&hitpoint_warn, flag);
/*** Cheating options ***/
if (flag == LS_LOAD) /* There *MUST* be some nice way to unify this! */
{
u16b c;
do_u16b(&c, LS_LOAD);
if (c & 0x0002) wizard = TRUE;
cheat_peek = (c & 0x0100) ? TRUE : FALSE;
cheat_hear = (c & 0x0200) ? TRUE : FALSE;
cheat_room = (c & 0x0400) ? TRUE : FALSE;
cheat_xtra = (c & 0x0800) ? TRUE : FALSE;
cheat_know = (c & 0x1000) ? TRUE : FALSE;
cheat_live = (c & 0x2000) ? TRUE : FALSE;
}
if (flag == LS_SAVE)
{
u16b c = 0;
if (wizard) c |= 0x0002;
if (cheat_peek) c |= 0x0100;
if (cheat_hear) c |= 0x0200;
if (cheat_room) c |= 0x0400;
if (cheat_xtra) c |= 0x0800;
if (cheat_know) c |= 0x1000;
if (cheat_live) c |= 0x2000;
do_u16b(&c, LS_SAVE);
}
do_byte((byte*)&autosave_l, flag);
do_byte((byte*)&autosave_t, flag);
do_s16b(&autosave_freq, flag);
if (flag == LS_LOAD)
{
/* Read the option flags */
for (n = 0; n < 8; n++) do_u32b(&oflag[n], flag);
/* Read the option masks */
for (n = 0; n < 8; n++) do_u32b(&mask[n], flag);
/* Analyze the options */
for (n = 0; n < 8; n++)
{
/* Analyze the options */
for (i = 0; i < 32; i++)
{
/* Process valid flags */
if (mask[n] & (1L << i))
{
/* Process valid flags */
if (option_mask[n] & (1L << i))
{
/* Set */
if (oflag[n] & (1L << i))
{
/* Set */
option_flag[n] |= (1L << i);
}
/* Clear */
else
{
/* Clear */
option_flag[n] &= ~(1L << i);
}
}
}
}
}
/*** Window Options ***/
/* Read the window flags */
for (n = 0; n < 8; n++) do_u32b(&oflag[n], flag);
/* Read the window masks */
for (n = 0; n < 8; n++) do_u32b(&mask[n], flag);
/* Analyze the options */
for (n = 0; n < 8; n++)
{
/* Analyze the options */
for (i = 0; i < 32; i++)
{
/* Process valid flags */
if (mask[n] & (1L << i))
{
/* Process valid flags */
if (window_mask[n] & (1L << i))
{
/* Set */
if (oflag[n] & (1L << i))
{
/* Set */
window_flag[n] |= (1L << i);
}
/* Clear */
else
{
/* Clear */
window_flag[n] &= ~(1L << i);
}
}
}
}
}
}
if (flag == LS_SAVE)
{
/* Analyze the options */
for (i = 0; option_info[i].o_desc; i++)
{
int os = option_info[i].o_page;
int ob = option_info[i].o_bit;
/* Process real entries */
if (option_info[i].o_var)
{
/* Set */
if (*option_info[i].o_var)
{
/* Set */
option_flag[os] |= (1L << ob);
}
/* Clear */
else
{
/* Clear */
option_flag[os] &= ~(1L << ob);
}
}
}
/*** Normal options ***/
/* Dump the flags */
for (i = 0; i < 8; i++) do_u32b(&option_flag[i], flag);
/* Dump the masks */
for (i = 0; i < 8; i++) do_u32b(&option_mask[i], flag);
/*** Window options ***/
/* Dump the flags */
for (i = 0; i < 8; i++) do_u32b(&window_flag[i], flag);
/* Dump the masks */
for (i = 0; i < 8; i++) do_u32b(&window_mask[i], flag);
}
}
/* Load/Save the random spells info */
static void do_spells(int i, int flag)
{
random_spell *s_ptr = &random_spells[i];
do_string(s_ptr->name, 30, flag);
do_string(s_ptr->desc, 30, flag);
do_s16b(&s_ptr->mana, flag);
do_s16b(&s_ptr->fail, flag);
do_u32b(&s_ptr->proj_flags, flag);
do_byte(&s_ptr->GF, flag);
do_byte(&s_ptr->radius, flag);
do_byte(&s_ptr->dam_sides, flag);
do_byte(&s_ptr->dam_dice, flag);
do_byte(&s_ptr->level, flag);
do_byte((byte*)&s_ptr->untried, flag);
}
/*
* Handle player inventory
*
* FIXME! This function probably could be unified better
* Note that the inventory is "re-sorted" later by "dungeon()".
*/
static bool_ do_inventory(int flag)
{
if (flag == LS_LOAD)
{
int slot = 0;
object_type forge;
object_type *q_ptr;
/* No items */
inven_cnt = 0;
equip_cnt = 0;
/* Read until done */
while (1)
{
u16b n;
/* Get the next item index */
do_u16b(&n, LS_LOAD);
/* Nope, we reached the end */
if (n == 0xFFFF) break;
/* Get local object */
q_ptr = &forge;
/* Wipe the object */
object_wipe(q_ptr);
/* Read the item */
do_item(q_ptr, LS_LOAD);
/* Hack -- verify item */
if (!q_ptr->k_idx) return (FALSE);
/* Wield equipment */
if (n >= INVEN_WIELD)
{
/* Copy object */
object_copy(&p_ptr->inventory[n], q_ptr);
/* Take care of item sets */
if (q_ptr->name1)
{
wield_set(q_ptr->name1, a_info[q_ptr->name1].set, TRUE);
}
/* One more item */
equip_cnt++;
}
/* Warning -- backpack is full */
else if (inven_cnt == INVEN_PACK)
{
/* Oops */
note("Too many items in the inventory!");
/* Fail */
return (FALSE);
}
/* Carry inventory */
else
{
/* Get a slot */
n = slot++;
/* Copy object */
object_copy(&p_ptr->inventory[n], q_ptr);
/* One more item */
inven_cnt++;
}
}
}
if (flag == LS_SAVE)
{
u16b i;
u16b sent = 0xFFFF;
for (i = 0; i < INVEN_TOTAL; i++)
{
object_type *o_ptr = &p_ptr->inventory[i];
if (!o_ptr->k_idx) continue;
do_u16b(&i, flag);
do_item(o_ptr, flag);
}
do_u16b(&sent, LS_SAVE); /* Sentinel */
}
/* Success */
return (TRUE);
}
/*
* Read the saved messages
*/
static void do_messages(int flag) /* FIXME! We should be able to unify this better */
{
int i;
char buf[128];
byte color, type;
s16b num;
if (flag == LS_SAVE) num = message_num();
/* Total */
do_s16b(&num, flag);
/* Read the messages */
if (flag == LS_LOAD)
{
for (i = 0; i < num; i++)
{
/* Read the message */
do_string(buf, 128, LS_LOAD);
do_byte(&color, flag);
do_byte(&type, flag);
/* Save the message */
message_add(type, buf, color);
}
}
if (flag == LS_SAVE)
{
byte holder;
for (i = num - 1; i >= 0; i--)
{
do_string((char *)message_str((s16b)i), 0, LS_SAVE);
holder = message_color((s16b)i);
do_byte(&holder, flag);
holder = message_type((s16b)i);
do_byte(&holder, flag);
}
}
}
/*
* Handle dungeon
*
* The monsters/objects must be loaded in the same order
* that they were stored, since the actual indexes matter.
*/
static bool_ do_dungeon(int flag, bool_ no_companions)
{
int i;
cave_type *c_ptr;
/* Read specific */
u16b tmp16b = 0;
my_sentinel("Before do_dungeon", 324, flag);
/* Header info */
do_s16b(&dun_level, flag);
do_byte(&dungeon_type, flag);
do_s16b(&num_repro, flag);
do_s16b(&p_ptr->py, flag);
do_s16b(&p_ptr->px, flag);
do_s16b(&cur_hgt, flag);
do_s16b(&cur_wid, flag);
do_s16b(&max_panel_rows, flag);
do_s16b(&max_panel_cols, flag);
do_u32b(&dungeon_flags1, flag);
do_u32b(&dungeon_flags2, flag);
/* Last teleportation */
do_s16b(&last_teleportation_y, flag);
do_s16b(&last_teleportation_y, flag);
/* Spell effects */
tmp16b = MAX_EFFECTS;
do_u16b(&tmp16b, flag);
if ((flag == LS_LOAD) && (tmp16b > MAX_EFFECTS))
{
quit("Too many spell effects");
}
for (i = 0; i < tmp16b; ++i)
{
do_s16b(&effects[i].type, flag);
do_s16b(&effects[i].dam, flag);
do_s16b(&effects[i].time, flag);
do_u32b(&effects[i].flags, flag);
do_s16b(&effects[i].cx, flag);
do_s16b(&effects[i].cy, flag);
do_s16b(&effects[i].rad, flag);
}
/* TO prevent bugs with evolving dungeons */
for (i = 0; i < 100; i++)
{
do_s16b(&floor_type[i], flag);
do_s16b(&fill_type[i], flag);
}
if ((flag == LS_LOAD) && (!dun_level && !p_ptr->inside_quest))
{
int xstart = 0;
int ystart = 0;
/* Init the wilderness */
process_dungeon_file("w_info.txt", &ystart, &xstart, cur_hgt, cur_wid,
TRUE, FALSE);
/* Init the town */
xstart = 0;
ystart = 0;
init_flags = 0;
process_dungeon_file("t_info.txt", &ystart, &xstart, cur_hgt, cur_wid,
TRUE, FALSE);
}
do_grid(flag);
/*** Objects ***/
if (flag == LS_SAVE) compact_objects(0);
if (flag == LS_SAVE) compact_monsters(0);
if (flag == LS_SAVE)
{
tmp16b = o_max;
if (no_companions)
{
for (i = 1; i < o_max; i++)
{
object_type *o_ptr = &o_list[i];
if (o_ptr->held_m_idx && (m_list[o_ptr->held_m_idx].status == MSTATUS_COMPANION)) tmp16b--;
}
}
/* Item count */
do_u16b(&tmp16b, flag);
tmp16b = o_max;
}
else
/* Read item count */
do_u16b(&tmp16b, flag);
/* Verify maximum */
if ((flag == LS_LOAD) && (tmp16b > max_o_idx))
{
note(format("Too many (%d) object entries!", tmp16b));
return (FALSE);
}
/* Dungeon items */
for (i = 1; i < tmp16b; i++)
{
int o_idx;
object_type *o_ptr;
if (flag == LS_SAVE)
{
o_ptr = &o_list[i];
/* Don't save objects held by companions when no_companions is set */
if (no_companions && o_ptr->held_m_idx && (m_list[o_ptr->held_m_idx].status == MSTATUS_COMPANION)) continue;
do_item(o_ptr, LS_SAVE);
continue; /* Saving is easy */
}
/* Until the end of the loop, this is all LS_LOAD */
/* Get a new record */
o_idx = o_pop();
/* Oops */
if (i != o_idx)
{
note(format("Object allocation error (%d <> %d)", i, o_idx));
return (FALSE);
}
/* Acquire place */
o_ptr = &o_list[o_idx];
/* Read the item */
do_item(o_ptr, LS_LOAD);
/* Monster */
if (o_ptr->held_m_idx)
{
monster_type *m_ptr;
/* Monster */
m_ptr = &m_list[o_ptr->held_m_idx];
/* Build a stack */
o_ptr->next_o_idx = m_ptr->hold_o_idx;
/* Place the object */
m_ptr->hold_o_idx = o_idx;
}
/* Dungeon */
else
{
/* Access the item location */
c_ptr = &cave[o_ptr->iy][o_ptr->ix];
/* Build a stack */
o_ptr->next_o_idx = c_ptr->o_idx;
/* Place the object */
c_ptr->o_idx = o_idx;
}
}
/*** Monsters ***/
if (flag == LS_SAVE)
{
tmp16b = m_max;
if (no_companions)
{
for (i = 1; i < m_max; i++)
{
monster_type *m_ptr = &m_list[i];
if (m_ptr->status == MSTATUS_COMPANION) tmp16b--;
}
}
/* Write the monster count */
do_u16b(&tmp16b, flag);
tmp16b = m_max;
}
else
/* Read the monster count */
do_u16b(&tmp16b, flag);
/* Validate */
if ((flag == LS_LOAD) && (tmp16b > max_m_idx))
{
note(format("Too many (%d) monster entries!", tmp16b));
return (FALSE);
}
/* Read the monsters */
for (i = 1; i < tmp16b; i++)
{
int m_idx;
monster_type *m_ptr;
monster_race *r_ptr;
if (flag == LS_SAVE)
{
m_ptr = &m_list[i];
/* Don't save companions when no_companions is set */
if (no_companions && m_ptr->status == MSTATUS_COMPANION) continue;
do_monster(m_ptr, LS_SAVE);
continue; /* Easy to save a monster */
}
/* From here on, it's all LS_LOAD */
/* Get a new record */
m_idx = m_pop();
/* Oops */
if (i != m_idx)
{
note(format("Monster allocation error (%d <> %d)", i, m_idx));
return (FALSE);
}
/* Acquire monster */
m_ptr = &m_list[m_idx];
/* Read the monster */
do_monster(m_ptr, LS_LOAD);
/* Access grid */
c_ptr = &cave[m_ptr->fy][m_ptr->fx];
/* Mark the location */
c_ptr->m_idx = m_idx;
/* Controlled ? */
if (m_ptr->mflag & MFLAG_CONTROL)
p_ptr->control = m_idx;
/* Access race */
r_ptr = &r_info[m_ptr->r_idx];
/* Count XXX XXX XXX */
r_ptr->cur_num++;
}
/* Read the kept monsters */
tmp16b = (flag == LS_SAVE && !no_companions) ? max_m_idx : 0;
/* Read the monster count */
do_u16b(&tmp16b, flag);
/* Hack -- verify */
if ((flag == LS_LOAD) && (tmp16b > max_m_idx))
{
note(format("Too many (%d) monster entries!", tmp16b));
return (FALSE);
}
for (i = 1; i < tmp16b; i++)
{
monster_type *m_ptr;
/* Acquire monster */
m_ptr = &km_list[i];
/* Read the monster */
do_monster(m_ptr, flag);
}
/*** Success ***/
/* The dungeon is ready */
if (flag == LS_LOAD) character_dungeon = TRUE;
/* Success */
return (TRUE);
}
/* Returns TRUE if we successfully load the dungeon */
bool_ load_dungeon(char *ext)
{
char tmp[16];
char name[1024];
byte old_dungeon_type = dungeon_type;
s16b old_dun = dun_level;
/* Construct name */
sprintf(tmp, "%s.%s", player_base, ext);
path_build(name, 1024, ANGBAND_DIR_SAVE, tmp);
/* Open the file */
fff = my_fopen(name, "rb");
if (fff == NULL)
{
dun_level = old_dun;
dungeon_type = old_dungeon_type;
my_fclose(fff);
return (FALSE);
}
/* Read the dungeon */
if (!do_dungeon(LS_LOAD, FALSE))
{
dun_level = old_dun;
dungeon_type = old_dungeon_type;
my_fclose(fff);
return (FALSE);
}
dun_level = old_dun;
dungeon_type = old_dungeon_type;
/* Done */
my_fclose(fff);
return (TRUE);
}
void do_blocks(int flag)
/* Handle blocked-allocation stuff for quests and lua stuff
This depends on a dyn_tosave array of s32b's. Adjust as needed
if other data structures are desirable. This also is not hooked
in yet. Ideally, plug it near the end of the savefile.
*/
{
s16b numblks, n_iter = 0; /* How many blocks do we have? */
do_s16b(&numblks, flag);
while (n_iter < numblks)
{
/* do_s32b(dyn_tosave[n_iter], flag); */
n_iter++;
}
my_sentinel("In blocked-allocation area", 37, flag);
}
void do_fate(int i, int flag)
{
if ((flag == LS_LOAD) && (i >= MAX_FATES)) i = MAX_FATES - 1;
do_byte(&fates[i].fate, flag);
do_byte(&fates[i].level, flag);
do_byte(&fates[i].serious, flag);
do_s16b(&fates[i].o_idx, flag);
do_s16b(&fates[i].e_idx, flag);
do_s16b(&fates[i].a_idx, flag);
do_s16b(&fates[i].v_idx, flag);
do_s16b(&fates[i].r_idx, flag);
do_s16b(&fates[i].count, flag);
do_s16b(&fates[i].time, flag);
do_byte((byte*)&fates[i].know, flag);
}
/*
* Actually read the savefile
*/
static bool_ do_savefile_aux(int flag)
{
int i, j;
byte tmp8u;
u16b tmp16u;
u32b tmp32u;
bool_ *reals;
u16b real_max = 0;
/* Mention the savefile version */
if (flag == LS_LOAD)
{
if (vernum < 100)
{
note(format("Savefile version %lu too old! ", vernum));
return FALSE;
}
else
{
note(format("Loading version %lu savefile... ", vernum));
}
}
if (flag == LS_SAVE)
{
sf_when = time((time_t *) 0); /* Note when file was saved */
sf_xtra = 0L; /* What the hell is this? */
sf_saves++; /* Increment the saves ctr */
}
/* Handle version bytes. FIXME! DG wants me to change this all around */
if (flag == LS_LOAD)
{
u32b mt32b;
byte mtbyte;
/* Discard all this, we've already read it */
do_u32b(&mt32b, flag);
do_byte(&mtbyte, flag);
}
if (flag == LS_SAVE)
{
u32b saver;
saver = SAVEFILE_VERSION;
do_u32b(&saver, flag);
tmp8u = (byte)rand_int(256);
do_byte(&tmp8u, flag); /* 'encryption' */
}
/* Operating system info? Not really. This is just set to 0L */
do_u32b(&sf_xtra, flag);
/* Time of last save */
do_u32b(&sf_when, flag);
/* Number of past lives */
do_u16b(&sf_lives, flag);
/* Number of times saved */
do_u16b(&sf_saves, flag);
/* Game module */
if (flag == LS_SAVE)
strcpy(loaded_game_module, game_module);
do_string(loaded_game_module, 80, flag);
/* Read RNG state */
do_randomizer(flag);
if ((flag == LS_LOAD) && (arg_fiddle)) note("Loaded Randomizer Info");
/* Automatizer state */
do_byte((byte*)&automatizer_enabled, flag);
/* Then the options */
do_options(flag);
if ((flag == LS_LOAD) && (arg_fiddle)) note("Loaded Option Flags");
/* Then the "messages" */
do_messages(flag);
if ((flag == LS_LOAD) && (arg_fiddle)) note("Loaded Messages");
/* Monster Memory */
if (flag == LS_SAVE) tmp16u = max_r_idx;
do_u16b(&tmp16u, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (tmp16u > max_r_idx))
{
note(format("Too many (%u) monster races!", tmp16u));
return (FALSE);
}
/* Read the available records */
for (i = 0; i < tmp16u; i++)
{
/* Read the lore */
do_lore(i, flag);
}
if ((flag == LS_LOAD) && (arg_fiddle)) note("Loaded Monster Memory");
/* Object Memory */
if (flag == LS_SAVE) tmp16u = max_k_idx;
do_u16b(&tmp16u, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (tmp16u > max_k_idx))
{
note(format("Too many (%u) object kinds!", tmp16u));
return (FALSE);
}
/* Read the object memory */
for (i = 0; i < tmp16u; i++) do_xtra(i, flag);
if ((flag == LS_LOAD) && (arg_fiddle)) note("Loaded Object Memory");
if (flag == LS_LOAD) junkinit();
{
u16b max_towns_ldsv;
u16b max_quests_ldsv;
if (flag == LS_SAVE) max_towns_ldsv = max_towns;
/* Number of towns */
do_u16b(&max_towns_ldsv, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (max_towns_ldsv > max_towns))
{
note(format("Too many (%u) towns!", max_towns_ldsv));
return (FALSE);
}
/* Min of random towns */
if (flag == LS_SAVE) max_towns_ldsv = TOWN_RANDOM;
do_u16b(&max_towns_ldsv, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (max_towns_ldsv != TOWN_RANDOM))
{
note(format("Different random towns base (%u)!", max_towns_ldsv));
return (FALSE);
}
for (i = 0; i < max_towns; i++)
{
do_byte((byte*)&town_info[i].destroyed, flag);
if (i >= TOWN_RANDOM)
{
do_u32b(&town_info[i].seed, flag);
do_byte(&town_info[i].numstores, flag);
do_byte(&town_info[i].flags, flag);
/* If the town is realy used create a sock */
if ((town_info[i].flags & (TOWN_REAL)) && (flag == LS_LOAD))
{
create_stores_stock(i);
}
}
}
/* Number of dungeon */
if (flag == LS_SAVE) max_towns_ldsv = max_d_idx;
do_u16b(&max_towns_ldsv, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (max_towns_ldsv > max_d_idx))
{
note(format("Too many dungeon types (%u)!", max_towns_ldsv));
return (FALSE);
}
/* Number of towns per dungeon */
if (flag == LS_SAVE) max_quests_ldsv = TOWN_DUNGEON;
do_u16b(&max_quests_ldsv, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (max_quests_ldsv > TOWN_DUNGEON))
{
note(format("Too many town per dungeons (%u)!", max_quests_ldsv));
return (FALSE);
}
for (i = 0; i < max_towns_ldsv; i++)
{
for (j = 0; j < max_quests_ldsv; j++)
{
do_s16b(&(d_info[i].t_idx[j]), flag);
do_s16b(&(d_info[i].t_level[j]), flag);
}
do_s16b(&(d_info[i].t_num), flag);
}
if (flag == LS_SAVE) max_quests_ldsv = MAX_Q_IDX_INIT;
/* Number of quests */
do_u16b(&max_quests_ldsv, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (max_quests_ldsv > MAX_Q_IDX_INIT))
{
note(format("Too many (%u) quests!", max_quests_ldsv));
return (FALSE);
}
for (i = 0; i < max_quests_ldsv; i++)
{
do_s16b(&quest[i].status, flag);
for (j = 0; j < 4; j++)
{
do_s32b(&(quest[i].data[j]), flag);
}
/* Init the hooks */
if ((flag == LS_LOAD) && (quest[i].type == HOOK_TYPE_C)) quest[i].init(i);
}
/* Position in the wilderness */
do_s32b(&p_ptr->wilderness_x, flag);
do_s32b(&p_ptr->wilderness_y, flag);
do_byte((byte*)&p_ptr->wild_mode, flag);
do_byte((byte*)&p_ptr->old_wild_mode, flag);
{
s32b wild_x_size, wild_y_size;
if (flag == LS_SAVE)
{
wild_x_size = max_wild_x;
wild_y_size = max_wild_y;
}
/* Size of the wilderness */
do_s32b(&wild_x_size, flag);
do_s32b(&wild_y_size, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) &&
((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y)))
{
note(format("Wilderness is too big (%u/%u)!",
wild_x_size, wild_y_size));
return (FALSE);
}
/* Wilderness seeds */
for (i = 0; i < wild_x_size; i++)
{
for (j = 0; j < wild_y_size; j++)
{
do_u32b(&wild_map[j][i].seed, flag);
do_u16b(&wild_map[j][i].entrance, flag);
do_byte((byte*)&wild_map[j][i].known, flag);
}
}
}
}
if ((flag == LS_LOAD) && (arg_fiddle)) note("Loaded Quests");
/* Load the random artifacts. */
if (flag == LS_SAVE) tmp16u = MAX_RANDARTS;
do_u16b(&tmp16u, flag);
if ((flag == LS_LOAD) && (tmp16u > MAX_RANDARTS))
{
note(format("Too many (%u) random artifacts!", tmp16u));
return (FALSE);
}
for (i = 0; i < tmp16u; i++)
{
random_artifact *ra_ptr = &random_artifacts[i];
do_string(ra_ptr->name_full, 80, flag);
do_string(ra_ptr->name_short, 80, flag);
do_byte(&ra_ptr->level, flag);
do_byte(&ra_ptr->attr, flag);
do_u32b(&ra_ptr->cost, flag);
do_byte(&ra_ptr->activation, flag);
do_byte(&ra_ptr->generated, flag);
}
/* Load the Artifacts */
if (flag == LS_SAVE) tmp16u = max_a_idx;
do_u16b(&tmp16u, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (tmp16u > max_a_idx))
{
note(format("Too many (%u) artifacts!", tmp16u));
return (FALSE);
}
/* Read the artifact flags */
for (i = 0; i < tmp16u; i++)
{
do_byte(&(&a_info[i])->cur_num, flag);
}
if ((flag == LS_LOAD) && arg_fiddle) note("Loaded Artifacts");
/* Fates */
if (flag == LS_SAVE) tmp16u = MAX_FATES;
do_u16b(&tmp16u, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (tmp16u > MAX_FATES))
{
note(format("Too many (%u) fates!", tmp16u));
return (FALSE);
}
/* Read the fate flags */
for (i = 0; i < tmp16u; i++)
{
do_fate(i, flag);
}
if ((flag == LS_LOAD) && arg_fiddle) note("Loaded Fates");
/* Load the Traps */
if (flag == LS_SAVE) tmp16u = max_t_idx;
do_u16b(&tmp16u, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (tmp16u > max_t_idx))
{
note(format("Too many (%u) traps!", tmp16u));
return (FALSE);
}
/* fate flags */
for (i = 0; i < tmp16u; i++)
{
do_byte((byte*)&t_info[i].ident, flag);
}
if ((flag == LS_LOAD) && (arg_fiddle)) note("Loaded Traps");
/* inscription knowledge */
if (flag == LS_SAVE) tmp16u = MAX_INSCRIPTIONS;
do_u16b(&tmp16u, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (tmp16u > MAX_INSCRIPTIONS))
{
note(format("Too many (%u) inscriptions!", tmp16u));
return (FALSE);
}
/* Read the inscription flag */
for (i = 0; i < tmp16u; i++)
do_byte((byte*)&inscription_info[i].know, flag);
if ((flag == LS_LOAD) && arg_fiddle) note("Loaded Inscriptions");
/* Read the extra stuff */
if (!do_extra(flag))
return FALSE;
if ((flag == LS_LOAD) && arg_fiddle) note("Loaded extra information");
/* player_hp array */
if (flag == LS_SAVE) tmp16u = PY_MAX_LEVEL;
do_u16b(&tmp16u, flag);
/* Incompatible save files */
if ((flag == LS_LOAD) && (tmp16u > PY_MAX_LEVEL))
{
note(format("Too many (%u) hitpoint entries!", tmp16u));
return (FALSE);
}
/* Read the player_hp array */
for (i = 0; i < tmp16u; i++)
{
do_s16b(&player_hp[i], flag);
}
if (flag == LS_LOAD) morejunk();
/* Read the pet command settings */
do_byte(&p_ptr->pet_follow_distance, flag);
do_byte(&p_ptr->pet_open_doors, flag);
do_byte(&p_ptr->pet_pickup_items, flag);
/* Read the inventory */
if (!do_inventory(flag) && (flag == LS_LOAD)) /* do NOT reverse this ordering */
{
note("Unable to read inventory");
return (FALSE);
}
/* Note that this forbids max_towns from shrinking, but that is fine */
C_MAKE(reals, max_towns, bool_);
/* Find the real towns */
if (flag == LS_SAVE)
{
for (i = 1; i < max_towns; i++)
{
if (!(town_info[i].flags & (TOWN_REAL))) continue;
reals[real_max++] = i;
}
}
do_u16b(&real_max, flag);
for (i = 0; i < real_max; i++)
{
do_byte((byte*)&reals[i], flag);
}
/* Read the stores */
if (flag == LS_SAVE) tmp16u = max_st_idx;
do_u16b(&tmp16u, flag);
/* Ok now read the real towns */
for (i = 0; i < real_max; i++)
{
int z = reals[i];
/* Ultra paranoia */
if (!town_info[z].stocked) create_stores_stock(z);
for (j = 0; j < tmp16u; j++)
do_store(&town_info[z].store[j], flag);
}
C_FREE(reals, max_towns, bool_);
if (flag == LS_SAVE) tmp32u = extra_savefile_parts;
do_u32b(&tmp32u, flag);
if (flag == LS_SAVE)
{
/* Save the stuff */
process_hooks(HOOK_SAVE_GAME, "()");
}
if (flag == LS_LOAD)
{
u32b len = tmp32u;
while (len)
{
char key_buf[100];
/* Load a key */
load_number_key(key_buf, &tmp32u);
/* Process it -- the hooks can use it or ignore it */
process_hooks(HOOK_LOAD_GAME, "(s,l)", key_buf, tmp32u);
len--;
}
}
/* I'm not dead yet... */
if (!death)
{
/* Dead players have no dungeon */
if (flag == LS_LOAD) note("Restoring Dungeon...");
if ((flag == LS_LOAD) && (!do_dungeon(LS_LOAD, FALSE)))
{
note("Error reading dungeon data");
return (FALSE);
}
if (flag == LS_SAVE) do_dungeon(LS_SAVE, FALSE);
my_sentinel("Before ghost data", 435, flag);
my_sentinel("After ghost data", 320, flag);
}
{
byte foo = 0;
if (flag == LS_SAVE)
{
/*
* Safety Padding. It's there
* for a good reason. Trust me on
* this. Keep this at the *END*
* of the file, and do *NOT* try to
* read it. Insert any new stuff before
* this position.
*/
do_byte(&foo, LS_SAVE);
}
}
/* Success */
return (TRUE);
}
/*
* Actually read the savefile
*/
errr rd_savefile(void)
{
errr err = 0;
/* The savefile is a binary file */
fff = my_fopen(savefile, "rb");
/* Paranoia */
if (!fff) return ( -1);
/* Call the sub-function */
err = !do_savefile_aux(LS_LOAD);
/* Check for errors */
if (ferror(fff)) err = -1;
/* Close the file */
my_fclose(fff);
/* Result */
return (err);
}
/*
* Note that this function may not be needed at all.
* It was taken out of load_player_aux(). Do we need it?
*/
static void junkinit(void)
{
int i, j;
p_ptr->arena_number = 0;
p_ptr->inside_arena = 0;
p_ptr->inside_quest = 0;
p_ptr->exit_bldg = TRUE;
p_ptr->exit_bldg = TRUE;
p_ptr->town_num = 1;
p_ptr->wilderness_x = 4;
p_ptr->wilderness_y = 4;
for (i = 0; i < max_wild_x; i++)
{
for (j = 0; j < max_wild_y; j++)
{
wild_map[j][i].seed = rand_int(0x10000000);
}
}
}
static void morejunk(void)
{
sp_ptr = &sex_info[p_ptr->psex]; /* Sex */
rp_ptr = &race_info[p_ptr->prace]; /* Raceclass */
rmp_ptr = &race_mod_info[p_ptr->pracem];
cp_ptr = &class_info[p_ptr->pclass];
spp_ptr = &class_info[p_ptr->pclass].spec[p_ptr->pspec];
}
static void do_grid(int flag)
/* Does the grid, RLE, blahblah. RLE sucks. I hate it. */
{
int i = 0, y = 0, x = 0;
byte count = 0;
byte tmp8u = 0;
s16b tmp16s = 0;
cave_type *c_ptr;
byte prev_char = 0;
s16b prev_s16b = 0;
int ymax = cur_hgt, xmax = cur_wid;
int part; /* Which section of the grid we're on */
for (part = 0; part < 9; part++) /* There are 8 fields to the grid, each stored
in a seperate RLE data structure */
{
if (flag == LS_SAVE)
{
count = 0;
prev_s16b = 0;
prev_char = 0; /* Clear, prepare for RLE */
for (y = 0; y < cur_hgt; y++)
{
for (x = 0; x < cur_wid; x++)
{
c_ptr = &cave[y][x];
switch (part)
{
case 0:
tmp16s = c_ptr->info;
break;
case 1:
tmp8u = c_ptr->feat;
break;
case 2:
tmp8u = c_ptr->mimic;
break;
case 3:
tmp16s = c_ptr->special;
break;
case 4:
tmp16s = c_ptr->special2;
break;
case 5:
tmp16s = c_ptr->t_idx;
break;
case 6:
tmp16s = c_ptr->inscription;
break;
case 7:
tmp8u = c_ptr->mana;
break;
case 8:
tmp16s = c_ptr->effect;
break;
}
/* Flush a full run */
if ((((part != 1) && (part != 2) && (part != 7)) &&
(tmp16s != prev_s16b)) || (((part == 1) || (part == 2)
|| (part == 7)) &&
(tmp8u != prev_char)) ||
(count == MAX_UCHAR))
{
do_byte(&count, LS_SAVE);
switch (part)
{
case 0:
case 3:
case 4:
case 5:
case 6:
case 8:
do_s16b(&prev_s16b, LS_SAVE);
prev_s16b = tmp16s;
break;
case 1:
case 2:
case 7:
do_byte(&prev_char, LS_SAVE);
prev_char = tmp8u;
break;
}
count = 1; /* Reset RLE */
}
else
count++; /* Otherwise, keep going */
}
}
/* Fallen off the end of the world, flush anything left */
if (count)
{
do_byte(&count, LS_SAVE);
switch (part)
{
case 0:
case 3:
case 4:
case 5:
case 6:
case 8:
do_s16b(&prev_s16b, LS_SAVE);
break;
case 1:
case 2:
case 7:
do_byte(&prev_char, LS_SAVE);
break;
}
}
}
if (flag == LS_LOAD)
{
x = 0;
for (y = 0; y < ymax; )
{
do_byte(&count, LS_LOAD);
switch (part)
{
case 0:
case 3:
case 4:
case 5:
case 6:
case 8:
do_s16b(&tmp16s, LS_LOAD);
break;
case 1:
case 2:
case 7:
do_byte(&tmp8u, LS_LOAD);
break;
}
for (i = count; i > 0; i--) /* RLE */
{
c_ptr = &cave[y][x];
switch (part)
{
case 0:
c_ptr->info = tmp16s;
break;
case 1:
c_ptr->feat = tmp8u;
break;
case 2:
c_ptr->mimic = tmp8u;
break;
case 3:
c_ptr->special = tmp16s;
break;
case 4:
c_ptr->special2 = tmp16s;
break;
case 5:
c_ptr->t_idx = tmp16s;
break;
case 6:
c_ptr->inscription = tmp16s;
break;
case 7:
c_ptr->mana = tmp8u;
break;
case 8:
c_ptr->effect = tmp16s;
break;
}
if (++x >= xmax)
{
/* Wrap */
x = 0;
if ((++y) >= ymax) break;
}
}
}
}
}
}
static void my_sentinel(char *place, u16b value, int flag)
/* This function lets us know exactly where a savefile is
broken by reading/writing conveniently a sentinel at this
spot */
{
if (flag == LS_SAVE)
{
do_u16b(&value, flag);
return;
}
if (flag == LS_LOAD)
{
u16b found;
do_u16b(&found, flag);
if (found == value) /* All is good */
return;
/* All is bad */
note(format("Savefile broken %s", place));
return;
}
note(format("Impossible has occurred")); /* Programmer error */
exit(0);
}
/********** Variable savefile stuff **************/
/*
* Add num slots to the savefile
*/
void register_savefile(int num)
{
extra_savefile_parts += (num > 0) ? num : 0;
}
void save_number_key(char *key, u32b val)
{
byte len = strlen(key);
do_byte(&len, LS_SAVE);
while (*key)
{
do_byte((byte*)key, LS_SAVE);
key++;
}
do_u32b(&val, LS_SAVE);
}
void load_number_key(char *key, u32b *val)
{
byte len, i = 0;
do_byte(&len, LS_LOAD);
while (i < len)
{
do_byte((byte*)&key[i], LS_LOAD);
i++;
}
key[i] = '\0';
do_u32b(val, LS_LOAD);
}
|