1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280
|
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "stdafx.h"
#include "freespace2/freespace.h"
#include "MissionSave.h"
#include "mission/missiongoals.h"
#include "mission/missionmessage.h"
#include "mission/missionparse.h"
#include "FredRender.h"
#include "ai/aigoals.h"
#include "starfield/starfield.h"
#include "lighting/lighting.h"
#include "globalincs/linklist.h"
#include "weapon/weapon.h"
#include "mission/missioncampaign.h"
#include "CampaignTreeWnd.h"
#include "CampaignTreeView.h"
#include "CampaignEditorDlg.h"
#include "parse/sexp.h"
#include "mission/missionbriefcommon.h"
#include "Management.h"
#include "gamesnd/eventmusic.h"
#include "starfield/nebula.h"
#include "asteroid/asteroid.h"
#include "missionui/missioncmdbrief.h"
#include "jumpnode/jumpnode.h"
#include "MainFrm.h"
#include "localization/fhash.h"
#include "nebula/neb.h"
#include "osapi/osapi.h"
#include "FredView.h"
#include "cfile/cfile.h"
#include "object/objectdock.h"
#include "object/objectshield.h"
#include "iff_defs/iff_defs.h"
#include "missionui/fictionviewer.h"
#include "globalincs/version.h"
#include "sound/sound.h"
#include "sound/ds.h"
#include "math/vecmat.h"
void CFred_mission_save::convert_special_tags_to_retail(char *text, int max_len)
{
replace_all(text, "$quote", "''", max_len);
replace_all(text, "$semicolon", ",", max_len);
}
void CFred_mission_save::convert_special_tags_to_retail(SCP_string &text)
{
replace_all(text, "$quote", "''");
replace_all(text, "$semicolon", ",");
}
// Goober5000 - convert $quote and $semicolon to '' and ,
void CFred_mission_save::convert_special_tags_to_retail()
{
int i, team, stage;
if ( Format_fs2_open != FSO_FORMAT_RETAIL)
return;
for (team = 0; team < Num_teams; team++)
{
// command briefing
for (stage = 0; stage < Cmd_briefs[team].num_stages; stage++)
{
convert_special_tags_to_retail(Cmd_briefs[team].stage[stage].text);
}
// briefing
for (stage = 0; stage < Briefings[team].num_stages; stage++)
{
convert_special_tags_to_retail(Briefings[team].stages[stage].text);
}
// debriefing
for (stage = 0; stage < Debriefings[team].num_stages; stage++)
{
convert_special_tags_to_retail(Debriefings[team].stages[stage].text);
}
}
for (i = Num_builtin_messages; i < Num_messages; i++)
{
convert_special_tags_to_retail(Messages[i].message, MESSAGE_LENGTH);
}
}
void CFred_mission_save::save_mission_internal(const char *pathname)
{
CTime t;
t = CTime::GetCurrentTime();
strcpy_s(The_mission.modified, t.Format("%x at %X"));
reset_parse();
fred_parse_flag = 0;
fp = cfopen(pathname, "wt", CFILE_NORMAL, CF_TYPE_MISSIONS);
if (!fp) {
nprintf(("Error", "Can't open mission file to save.\n"));
err = -1;
return;
}
// Goober5000
convert_special_tags_to_retail();
if (save_mission_info())
err = -2;
else if (save_plot_info())
err = -3;
else if (save_variables())
err = -3;
// else if (save_briefing_info())
// err = -4;
else if (save_cutscenes())
err = -4;
else if (save_fiction())
err = -3;
else if (save_cmd_briefs())
err = -4;
else if (save_briefing())
err = -4;
else if (save_debriefing())
err = -5;
else if (save_players())
err = -6;
else if (save_objects())
err = -7;
else if (save_wings())
err = -8;
else if (save_events())
err = -9;
else if (save_goals())
err = -10;
else if (save_waypoints())
err = -11;
else if (save_messages())
err = -12;
else if (save_reinforcements())
err = -13;
else if (save_bitmaps())
err = -14;
else if (save_asteroid_fields())
err = -15;
else if (save_music())
err = -16;
else {
required_string_fred("#End");
parse_comments(2);
token_found = NULL;
parse_comments();
fout("\n");
}
cfclose(fp);
if (err)
mprintf(("Mission saving error code #%d\n", err));
}
int CFred_mission_save::save_mission_file(char *pathname)
{
char backup_name[256], savepath[MAX_PATH_LEN], *p;
strcpy_s(savepath, "");
p = strrchr(pathname, '\\');
if ( p ) {
*p = '\0';
strcpy_s(savepath, pathname);
*p = '\\';
strcat_s(savepath, "\\");
}
strcat_s(savepath, "saving.xxx");
save_mission_internal(savepath);
if (!err) {
strcpy_s(backup_name, pathname);
if (backup_name[strlen(backup_name) - 4] == '.')
backup_name[strlen(backup_name) - 4] = 0;
strcat_s(backup_name, ".bak");
cf_attrib(pathname, 0, FILE_ATTRIBUTE_READONLY, CF_TYPE_MISSIONS);
cf_delete(backup_name, CF_TYPE_MISSIONS);
cf_rename(pathname, backup_name, CF_TYPE_MISSIONS);
cf_rename(savepath, pathname, CF_TYPE_MISSIONS);
}
return err;
}
int CFred_mission_save::autosave_mission_file(char *pathname)
{
char backup_name[256], name2[256];
int i, len;
len = strlen(pathname);
strcpy_s(backup_name, pathname);
strcpy_s(name2, pathname);
sprintf(backup_name + len, ".%.3d", BACKUP_DEPTH);
cf_delete(backup_name, CF_TYPE_MISSIONS);
for (i=BACKUP_DEPTH; i>1; i--) {
sprintf(backup_name + len, ".%.3d", i - 1);
sprintf(name2 + len, ".%.3d", i);
cf_rename(backup_name, name2, CF_TYPE_MISSIONS);
}
strcpy(backup_name + len, ".001");
save_mission_internal(backup_name);
return err;
}
int CFred_mission_save::save_mission_info()
{
required_string_fred("#Mission Info");
parse_comments(0);
required_string_fred("$Version:");
parse_comments(2);
fout(" %.2f", FRED_MISSION_VERSION);
// XSTR
required_string_fred("$Name:");
parse_comments();
fout_ext(" ", "%s", The_mission.name);
required_string_fred("$Author:");
parse_comments();
fout(" %s", The_mission.author);
required_string_fred("$Created:");
parse_comments();
fout(" %s", The_mission.created);
required_string_fred("$Modified:");
parse_comments();
fout(" %s", The_mission.modified);
required_string_fred("$Notes:");
parse_comments();
fout("\n%s", The_mission.notes);
required_string_fred("$End Notes:");
parse_comments(0);
// XSTR
required_string_fred("$Mission Desc:");
parse_comments(2);
fout_ext("\n", "%s", The_mission.mission_desc);
fout("\n");
required_string_fred("$end_multi_text");
parse_comments(0);
#if 0
if (optional_string_fred("+Game Type:"))
parse_comments(2);
else
fout("\n\n+Game Type:");
fout("\n%s", Game_types[The_mission.game_type]);
#endif
if ( optional_string_fred("+Game Type Flags:")){
parse_comments(1);
} else {
fout("\n+Game Type Flags:");
}
fout(" %d", The_mission.game_type);
if (optional_string_fred("+Flags:")){
parse_comments(1);
} else {
fout("\n+Flags:");
}
fout(" %d", The_mission.flags);
// maybe write out Nebula intensity
if(The_mission.flags & MISSION_FLAG_FULLNEB){
Assert(Neb2_awacs > 0.0f);
fout("\n+NebAwacs: %f\n", Neb2_awacs);
// storm name
fout("\n+Storm: %s\n", Mission_parse_storm_name);
}
// Goober5000
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
// write out the nebula clipping multipliers
fout("\n+Fog Near Mult: %f\n", Neb2_fog_near_mult);
fout("\n+Fog Far Mult: %f\n", Neb2_fog_far_mult);
if (The_mission.contrail_threshold != CONTRAIL_THRESHOLD_DEFAULT)
{
fout("\n$Contrail Speed Threshold: %d\n", The_mission.contrail_threshold);
}
}
// For multiplayer missions -- write out the number of player starts and number of respawns
if (The_mission.game_type & MISSION_TYPE_MULTI) {
if (optional_string_fred("+Num Players:"))
parse_comments(2);
else
fout("\n+Num Players:");
fout(" %d", Player_starts);
if (optional_string_fred("+Num Respawns:"))
parse_comments(2);
else
fout("\n+Num Respawns:");
fout(" %d", The_mission.num_respawns);
if ( Format_fs2_open != FSO_FORMAT_RETAIL ) {
fso_comment_push(";;FSO 3.6.11;;");
if (optional_string_fred("+Max Respawn Time:"))
parse_comments(2);
else {
fout_version("\n+Max Respawn Time:");
}
fso_comment_pop();
fout(" %d", The_mission.max_respawn_delay);
}
else {
bypass_comment(";;FSO 3.6.11;; +Max Respawn Time:");
}
}
if ( Format_fs2_open == FSO_FORMAT_RETAIL )
{
if ( optional_string_fred("+Red Alert:"))
parse_comments(2);
else
fout("\n+Red Alert:");
fout(" %d", (The_mission.flags & MISSION_FLAG_RED_ALERT) ? 1 : 0);
}
if ( Format_fs2_open == FSO_FORMAT_RETAIL ) //-V581
{
if ( optional_string_fred("+Scramble:"))
parse_comments(2);
else
fout("\n+Scramble:");
fout(" %d", (The_mission.flags & MISSION_FLAG_SCRAMBLE) ? 1 : 0);
}
if ( optional_string_fred("+Disallow Support:")){
parse_comments(1);
} else {
fout("\n+Disallow Support:");
}
// this is compatible with non-SCP variants - Goober5000
fout(" %d", (The_mission.support_ships.max_support_ships == 0)?1:0 );
// here be WMCoolmon's hull and subsys repair stuff
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if ( optional_string_fred("+Hull Repair Ceiling:")) {
parse_comments(1);
} else {
fout("\n+Hull Repair Ceiling:");
}
fout(" %f", The_mission.support_ships.max_hull_repair_val);
if ( optional_string_fred("+Subsystem Repair Ceiling:")) {
parse_comments(1);
} else {
fout("\n+Subsystem Repair Ceiling:");
}
fout(" %f", The_mission.support_ships.max_subsys_repair_val);
}
if (Mission_all_attack) {
if (optional_string_fred("+All Teams Attack")){
parse_comments();
} else {
fout("\n+All Teams Attack");
}
}
if (Entry_delay_time) {
if (optional_string_fred("+Player Entry Delay:"))
parse_comments(2);
else
fout("\n\n+Player Entry Delay:");
fout("\n%f", f2fl(Entry_delay_time));
}
if (optional_string_fred("+Viewer pos:")){
parse_comments(2);
} else {
fout("\n\n+Viewer pos:");
}
save_vector(view_pos);
if (optional_string_fred("+Viewer orient:")){
parse_comments();
} else {
fout("\n+Viewer orient:");
}
save_matrix(view_orient);
// squadron info
if(!(The_mission.game_type & MISSION_TYPE_MULTI) && (strlen(The_mission.squad_name) > 0)){ //-V805
// squad name
fout("\n+SquadReassignName: %s", The_mission.squad_name);
// maybe squad logo
if(strlen(The_mission.squad_filename) > 0){ //-V805
fout("\n+SquadReassignLogo: %s", The_mission.squad_filename);
}
}
// Goober5000 - special wing info
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
int i;
fout("\n");
// starting wings
if (strcmp(Starting_wing_names[0], "Alpha") || strcmp(Starting_wing_names[1], "Beta") || strcmp(Starting_wing_names[2], "Gamma"))
{
fout("\n$Starting wing names: ( ");
for (i=0; i<MAX_STARTING_WINGS; i++)
{
fout ("\"%s\" ", Starting_wing_names[i]);
}
fout (")");
}
// squadron wings
if (strcmp(Squadron_wing_names[0], "Alpha") || strcmp(Squadron_wing_names[1], "Beta") || strcmp(Squadron_wing_names[2], "Gamma") || strcmp(Squadron_wing_names[3], "Delta") || strcmp(Squadron_wing_names[4], "Epsilon"))
{
fout("\n$Squadron wing names: ( ");
for (i=0; i<MAX_SQUADRON_WINGS; i++)
{
fout("\"%s\" ", Squadron_wing_names[i]);
}
fout(")");
}
// tvt wings
if (strcmp(TVT_wing_names[0], "Alpha") || strcmp(TVT_wing_names[1], "Zeta"))
{
fout("\n$Team-versus-team wing names: ( ");
for (i=0; i<MAX_TVT_WINGS; i++)
{
fout("\"%s\" ", TVT_wing_names[i]);
}
fout(")");
}
}
save_custom_bitmap("$Load Screen 640:", "$Load Screen 1024:", The_mission.loading_screen[GR_640], The_mission.loading_screen[GR_1024], 1);
// Phreak's skybox stuff
if (strlen(The_mission.skybox_model) > 0) //-V805
{
char out_str[NAME_LENGTH];
char *period;
// kill off any extension, we will add one here
strcpy_s(out_str, The_mission.skybox_model);
period = strrchr(out_str, '.');
if (period != NULL)
*period = 0;
fso_comment_push(";;FSO 3.6.0;;");
if (optional_string_fred("$Skybox Model:")) {
parse_comments(2);
fout(" %s.pof", out_str);
} else {
fout_version("\n\n$Skybox Model: %s.pof", out_str);
}
fso_comment_pop();
} else {
bypass_comment(";;FSO 3.6.0;; $Skybox Model:");
}
// orientation?
if ((strlen(The_mission.skybox_model) > 0) && !vm_matrix_same(&vmd_identity_matrix, &The_mission.skybox_orientation)) {
fso_comment_push(";;FSO 3.6.14;;");
if (optional_string_fred("+Skybox Orientation:")) {
parse_comments(1);
save_matrix(The_mission.skybox_orientation);
} else {
fout_version("\n+Skybox Orientation:");
save_matrix(The_mission.skybox_orientation);
}
fso_comment_pop();
} else {
bypass_comment(";;FSO 3.6.14;; +Skybox Orientation:");
}
// are skybox flags in use?
if (The_mission.skybox_flags != DEFAULT_NMODEL_FLAGS) {
//char out_str[4096];
fso_comment_push(";;FSO 3.6.11;;");
if (optional_string_fred("+Skybox Flags:")) {
parse_comments(1);
fout( " %d", The_mission.skybox_flags);
} else {
fout_version("\n+Skybox Flags: %d", The_mission.skybox_flags);
}
fso_comment_pop();
} else {
bypass_comment(";;FSO 3.6.11;; +Skybox Flags:");
}
// Goober5000's AI profile stuff
int profile_index = (The_mission.ai_profile - Ai_profiles);
Assert(profile_index >= 0 && profile_index < MAX_AI_PROFILES);
fso_comment_push(";;FSO 3.6.9;;");
if (optional_string_fred("$AI Profile:")) {
parse_comments(2);
fout(" %s", The_mission.ai_profile->profile_name);
} else {
fout_version("\n\n$AI Profile: %s", The_mission.ai_profile->profile_name);
}
fso_comment_pop();
// sound environment (EFX/EAX) - taylor
sound_env *m_env = &The_mission.sound_environment;
if ( (m_env->id >= 0) && (m_env->id < (int)EFX_presets.size()) ) {
EFXREVERBPROPERTIES *prop = &EFX_presets[m_env->id];
fso_comment_push(";;FSO 3.6.12;;");
fout_version("\n\n$Sound Environment: %s", prop->name.c_str());
if (m_env->volume != prop->flGain) {
fout_version("\n+Volume: %f", m_env->volume);
}
if (m_env->damping != prop->flDecayHFRatio) {
fout_version("\n+Damping: %f", m_env->damping);
}
if (m_env->decay != prop->flDecayTime) {
fout_version("\n+Decay Time: %f", m_env->decay);
}
fso_comment_pop();
}
return err;
}
int CFred_mission_save::save_plot_info()
{
if ( Format_fs2_open == FSO_FORMAT_RETAIL )
{
if (optional_string_fred("#Plot Info"))
{
parse_comments(2);
// XSTR
required_string_fred("$Tour:");
parse_comments(2);
fout_ext(" ", "Blah");
required_string_fred("$Pre-Briefing Cutscene:");
parse_comments();
fout(" Blah");
required_string_fred("$Pre-Mission Cutscene:");
parse_comments();
fout(" Blah");
required_string_fred("$Next Mission Success:");
parse_comments();
fout(" Blah");
required_string_fred("$Next Mission Partial:");
parse_comments();
fout(" Blah");
required_string_fred("$Next Mission Failure:");
parse_comments();
fout(" Blah");
}
else
{
fout("\n\n#Plot Info\n\n");
fout("$Tour: ");
fout_ext(NULL, "Blah");
fout("\n");
fout("$Pre-Briefing Cutscene: Blah\n");
fout("$Pre-Mission Cutscene: Blah\n");
fout("$Next Mission Success: Blah\n");
fout("$Next Mission Partial: Blah\n");
fout("$Next Mission Failure: Blah\n");
fout("\n");
}
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_cutscenes()
{
char type[NAME_LENGTH];
SCP_string sexp_out;
// Let's just assume it has them for now -
if (!(The_mission.cutscenes.empty()) ) {
if (Format_fs2_open != FSO_FORMAT_RETAIL) {
if (optional_string_fred("#Cutscenes")) {
parse_comments(2);
}
else {
fout_version("\n\n#Cutscenes\n\n");
}
for (uint i = 0; i < The_mission.cutscenes.size(); i++) {
if ( strlen(The_mission.cutscenes[i].filename) ) {
// determine the name of this cutscene type
switch (The_mission.cutscenes[i].type) {
case MOVIE_PRE_FICTION:
strcpy_s(type, "$Fiction Viewer Cutscene:");
break;
case MOVIE_PRE_CMD_BRIEF:
strcpy_s(type, "$Command Brief Cutscene:");
break;
case MOVIE_PRE_BRIEF:
strcpy_s(type, "$Briefing Cutscene:");
break;
case MOVIE_PRE_GAME:
strcpy_s(type, "$Pre-game Cutscene:");
break;
case MOVIE_PRE_DEBRIEF:
strcpy_s(type, "$Debriefing Cutscene:");
break;
case MOVIE_END_CAMPAIGN:
strcpy_s(type, "$Campaign End Cutscene:");
break;
default:
Int3();
continue;
}
if (optional_string_fred(type)) {
parse_comments();
fout(" %s", The_mission.cutscenes[i].filename);
}
else {
fout_version("%s %s\n", type, The_mission.cutscenes[i].filename);
}
required_string_fred("+formula:");
parse_comments();
convert_sexp_to_string(sexp_out, The_mission.cutscenes[i].formula, SEXP_SAVE_MODE);
fout(" %s", sexp_out.c_str());
}
}
required_string_fred("#end");
parse_comments();
}
else {
MessageBox(NULL, "Warning: This mission contains cutscene data, but you are saving in the retail mission format. This information will be lost", "Incompatibility with retail mission format", MB_OK);
}
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_fiction()
{
if (mission_has_fiction())
{
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if (optional_string_fred("#Fiction Viewer"))
parse_comments(2);
else
fout("\n\n#Fiction Viewer");
// we have multiple stages now, so save them all
for (SCP_vector<fiction_viewer_stage>::iterator stage = Fiction_viewer_stages.begin(); stage != Fiction_viewer_stages.end(); ++stage)
{
fout("\n");
// save file
required_string_fred("$File:");
parse_comments();
fout(" %s", stage->story_filename);
// save font
if (strlen(stage->font_filename) > 0) //-V805
{
if (optional_string_fred("$Font:"))
parse_comments();
else
fout("\n$Font:");
fout(" %s", stage->font_filename);
}
else
optional_string_fred("$Font:");
// save voice
if (strlen(stage->voice_filename) > 0) //-V805
{
if (optional_string_fred("$Voice:"))
parse_comments();
else
fout("\n$Voice:");
fout(" %s", stage->voice_filename);
}
else
optional_string_fred("$Voice:");
// save UI
if (strlen(stage->ui_name) > 0)
{
if (optional_string_fred("$UI:"))
parse_comments();
else
fout("\n$UI:");
fout(" %s", stage->ui_name);
}
else
optional_string_fred("$UI:");
// save background
save_custom_bitmap("$Background 640:", "$Background 1024:", stage->background[GR_640], stage->background[GR_1024]);
// save sexp formula if we have one
if (stage->formula >= 0 && stage->formula != Locked_sexp_true)
{
SCP_string sexp_out;
convert_sexp_to_string(sexp_out, stage->formula, SEXP_SAVE_MODE);
if (optional_string_fred("$Formula:"))
parse_comments();
else
fout("\n$Formula:");
fout(" %s", sexp_out.c_str());
}
else
optional_string_fred("$Formula:");
}
}
else
{
MessageBox(NULL, "Warning: This mission contains fiction viewer data, but you are saving in the retail mission format.", "Incompatibility with retail mission format", MB_OK);
}
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_cmd_brief()
{
int stage;
stage = 0;
required_string_fred("#Command Briefing");
parse_comments(2);
if (The_mission.game_type & MISSION_TYPE_MULTI)
return err; // no command briefings allowed in multiplayer missions.
save_custom_bitmap("$Background 640:", "$Background 1024:", Cur_cmd_brief->background[GR_640], Cur_cmd_brief->background[GR_1024], 1);
for (stage=0; stage<Cur_cmd_brief->num_stages; stage++) {
required_string_fred("$Stage Text:");
parse_comments(2);
// XSTR
fout_ext("\n", "%s", Cur_cmd_brief->stage[stage].text.c_str());
required_string_fred("$end_multi_text", "$Stage Text:");
parse_comments();
required_string_fred("$Ani Filename:");
parse_comments();
fout(" %s", Cur_cmd_brief->stage[stage].ani_filename);
required_string_fred("+Wave Filename:", "$Ani Filename:");
parse_comments();
fout(" %s", Cur_cmd_brief->stage[stage].wave_filename);
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_cmd_briefs()
{
int i;
for (i=0; i<Num_teams; i++) {
Cur_cmd_brief = &Cmd_briefs[i];
save_cmd_brief();
}
return err;
}
int CFred_mission_save::save_briefing()
{
int i,j,k, nb;
SCP_string sexp_out;
brief_stage *bs;
brief_icon *bi;
for ( nb = 0; nb < Num_teams; nb++ ) {
required_string_fred("#Briefing");
parse_comments(2);
required_string_fred("$start_briefing");
parse_comments();
save_custom_bitmap("$briefing_background_640:", "$briefing_background_1024:", Briefings[nb].background[GR_640], Briefings[nb].background[GR_1024]);
save_custom_bitmap("$ship_select_background_640:", "$ship_select_background_1024:", Briefings[nb].ship_select_background[GR_640], Briefings[nb].ship_select_background[GR_1024]);
save_custom_bitmap("$weapon_select_background_640:", "$weapon_select_background_1024:", Briefings[nb].weapon_select_background[GR_640], Briefings[nb].weapon_select_background[GR_1024]);
Assert(Briefings[nb].num_stages <= MAX_BRIEF_STAGES);
required_string_fred("$num_stages:");
parse_comments();
fout(" %d", Briefings[nb].num_stages);
for (i=0; i<Briefings[nb].num_stages; i++) {
bs = &Briefings[nb].stages[i];
required_string_fred("$start_stage");
parse_comments();
required_string_fred("$multi_text");
parse_comments();
// XSTR
fout_ext("\n", "%s", bs->text.c_str());
required_string_fred("$end_multi_text", "$start_stage");
parse_comments();
if (!drop_white_space(bs->voice)[0]){
strcpy_s(bs->voice, "None");
}
required_string_fred("$voice:");
parse_comments();
fout(" %s", bs->voice);
required_string_fred("$camera_pos:");
parse_comments();
save_vector(bs->camera_pos);
required_string_fred("$camera_orient:");
parse_comments();
save_matrix(bs->camera_orient);
required_string_fred("$camera_time:");
parse_comments();
fout(" %d", bs->camera_time);
required_string_fred("$num_lines:");
parse_comments();
fout(" %d", bs->num_lines);
for (k=0; k<bs->num_lines; k++) {
required_string_fred("$line_start:");
parse_comments();
fout(" %d", bs->lines[k].start_icon);
required_string_fred("$line_end:");
parse_comments();
fout(" %d", bs->lines[k].end_icon);
fso_comment_pop();
}
required_string_fred("$num_icons:");
parse_comments();
Assert(bs->num_icons <= MAX_STAGE_ICONS );
fout(" %d", bs->num_icons);
required_string_fred("$Flags:");
parse_comments();
fout(" %d", bs->flags);
required_string_fred("$Formula:");
parse_comments();
convert_sexp_to_string(sexp_out, bs->formula, SEXP_SAVE_MODE);
fout(" %s", sexp_out.c_str());
for ( j = 0; j < bs->num_icons; j++ ) {
bi = &bs->icons[j];
required_string_fred("$start_icon");
parse_comments();
required_string_fred("$type:");
parse_comments();
fout(" %d", bi->type);
required_string_fred("$team:");
parse_comments();
fout(" %s", Iff_info[bi->team].iff_name);
required_string_fred("$class:");
parse_comments();
if (bi->ship_class < 0)
bi->ship_class = 0;
fout(" %s", Ship_info[bi->ship_class].name);
required_string_fred("$pos:");
parse_comments();
save_vector(bi->pos);
if (drop_white_space(bi->label)[0]) {
if (optional_string_fred("$label:"))
parse_comments();
else
fout("\n$label:");
fout(" %s", bi->label);
}
if (optional_string_fred("+id:"))
parse_comments();
else
fout("\n+id:");
fout(" %d", bi->id);
required_string_fred("$hlight:");
parse_comments();
fout(" %d", (bi->flags & BI_HIGHLIGHT)?1:0 );
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
required_string_fred("$mirror:");
parse_comments();
fout(" %d", (bi->flags & BI_MIRROR_ICON)?1:0 );
}
if ((Format_fs2_open != FSO_FORMAT_RETAIL) && (bi->flags & BI_USE_WING_ICON))
{
required_string_fred("$use wing icon:");
parse_comments();
fout(" %d", (bi->flags & BI_USE_WING_ICON)?1:0 );
}
required_string_fred("$multi_text");
parse_comments();
// sprintf(out,"\n%s", bi->text);
// fout(out);
required_string_fred("$end_multi_text");
parse_comments();
required_string_fred("$end_icon");
parse_comments();
fso_comment_pop();
}
required_string_fred("$end_stage");
parse_comments();
fso_comment_pop();
}
required_string_fred("$end_briefing");
parse_comments();
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_debriefing()
{
int j, i;
SCP_string sexp_out;
for ( j = 0; j < Num_teams; j++ ) {
Debriefing = &Debriefings[j];
required_string_fred("#Debriefing_info");
parse_comments(2);
save_custom_bitmap("$Background 640:", "$Background 1024:", Debriefing->background[GR_640], Debriefing->background[GR_1024], 1);
required_string_fred("$Num stages:");
parse_comments(2);
fout(" %d", Debriefing->num_stages);
for (i=0; i<Debriefing->num_stages; i++) {
required_string_fred("$Formula:");
parse_comments(2);
convert_sexp_to_string(sexp_out, Debriefing->stages[i].formula, SEXP_SAVE_MODE);
fout(" %s", sexp_out.c_str());
// XSTR
required_string_fred("$Multi text");
parse_comments();
fout_ext("\n ", "%s", Debriefing->stages[i].text.c_str());
required_string_fred("$end_multi_text");
parse_comments();
if (!drop_white_space(Debriefing->stages[i].voice)[0]){
strcpy_s(Debriefing->stages[i].voice, "None");
}
required_string_fred("$Voice:");
parse_comments();
fout(" %s", Debriefing->stages[i].voice);
// XSTR
required_string_fred("$Recommendation text:");
parse_comments();
fout_ext("\n ", "%s", Debriefing->stages[i].recommendation_text.c_str());
required_string_fred("$end_multi_text");
parse_comments();
fso_comment_pop();
}
}
fso_comment_pop(true);
return err;
}
int sexp_variable_block_count();
// save variables
int CFred_mission_save::save_variables()
{
char *type;
char number[] = "number";
char string[] = "string";
char block[] = "block";
int i;
int num_block_vars = 0;
// sort sexp_variables
sexp_variable_sort();
// get count
int num_variables = sexp_variable_count();
if (Format_fs2_open == FSO_FORMAT_RETAIL) {
generate_special_explosion_block_variables();
num_block_vars = num_block_variables();
}
int total_variables = num_variables + num_block_vars;
if (total_variables > 0) {
// write 'em out
required_string_fred("#Sexp_variables");
parse_comments(2);
required_string_fred("$Variables:");
parse_comments(2);
fout("\n(");
// parse_comments();
for (i=0; i<num_variables; i++) {
if (Sexp_variables[i].type & SEXP_VARIABLE_NUMBER) {
type = number;
} else {
type = string;
}
// index "var name" "default" "type"
fout("\n\t\t%d\t\t\"%s\"\t\t\"%s\"\t\t\"%s\"", i, Sexp_variables[i].variable_name, Sexp_variables[i].text, type);
// persistent and network variables
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
// Network variable - Karajorma
if (Sexp_variables[i].type & SEXP_VARIABLE_NETWORK) {
fout("\t\t\"%s\"", "network-variable");
}
// player-persistent - Goober5000
if (Sexp_variables[i].type & SEXP_VARIABLE_PLAYER_PERSISTENT) {
fout("\t\t\"%s\"", "player-persistent");
// campaign-persistent - Goober5000
} else if (Sexp_variables[i].type & SEXP_VARIABLE_CAMPAIGN_PERSISTENT) {
fout("\t\t\"%s\"", "campaign-persistent");
}
}
// parse_comments();
}
for (i=MAX_SEXP_VARIABLES-num_block_vars; i<MAX_SEXP_VARIABLES; i++) {
type = block;
fout("\n\t\t%d\t\t\"%s\"\t\t\"%s\"\t\t\"%s\"", i, Block_variables[i].variable_name, Block_variables[i].text, type);
}
fout("\n)");
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_players()
{
int i, j;
int var_idx;
int used_pool[MAX_WEAPON_TYPES];
if (optional_string_fred("#Alternate Types:")) { // Make sure the parser doesn't get out of sync
required_string_fred("#end");
}
if (optional_string_fred("#Callsigns:")) {
required_string_fred("#end");
}
// write out alternate name list
if(Mission_alt_type_count > 0){
fout("\n\n#Alternate Types:\n");
// write them all out
for(i=0; i<Mission_alt_type_count; i++){
fout("$Alt: %s\n", Mission_alt_types[i]);
}
// end
fout("\n#end\n");
}
// write out callsign list
if(Mission_callsign_count > 0){
fout("\n\n#Callsigns:\n");
// write them all out
for(i=0; i<Mission_callsign_count; i++){
fout("$Callsign: %s\n", Mission_callsigns[i]);
}
// end
fout("\n#end\n");
}
required_string_fred("#Players");
parse_comments(2);
fout("\t\t;! %d total\n", Player_starts);
for (i=0; i<Num_teams; i++) {
required_string_fred("$Starting Shipname:");
parse_comments();
Assert(Player_start_shipnum >= 0);
fout(" %s", Ships[Player_start_shipnum].ship_name);
required_string_fred("$Ship Choices:");
parse_comments();
fout(" (\n");
for (j=0; j<Team_data[i].num_ship_choices; j++) {
// Check to see if a variable name should be written for the class rather than a number
if (strlen(Team_data[i].ship_list_variables[j])) {
var_idx = get_index_sexp_variable_name(Team_data[i].ship_list_variables[j]);
Assert (var_idx > -1 && var_idx < MAX_SEXP_VARIABLES);
fout("\t@%s\t", Sexp_variables[var_idx].variable_name);
}
else {
fout("\t\"%s\"\t", Ship_info[Team_data[i].ship_list[j]].name);
}
// Now check if we should write a variable or a number for the amount of ships available
if (strlen(Team_data[i].ship_count_variables[j])) {
var_idx = get_index_sexp_variable_name(Team_data[i].ship_count_variables[j]);
Assert (var_idx > -1 && var_idx < MAX_SEXP_VARIABLES);
fout("@%s\n", Sexp_variables[var_idx].variable_name);
}
else {
fout("%d\n", Team_data[i].ship_count[j]);
}
}
fout(")");
if (optional_string_fred("+Weaponry Pool:", "$Starting Shipname:")){
parse_comments(2);
} else {
fout("\n\n+Weaponry Pool:");
}
fout(" (\n");
generate_weaponry_usage_list(i, used_pool);
for (j=0; j<Team_data[i].num_weapon_choices; j++) {
// first output the weapon name or a variable that sets it
if (strlen(Team_data[i].weaponry_pool_variable[j])) {
var_idx = get_index_sexp_variable_name(Team_data[i].weaponry_pool_variable[j]);
Assert (var_idx > -1 && var_idx < MAX_SEXP_VARIABLES);
fout("\t@%s\t", Sexp_variables[var_idx].variable_name);
}
else {
fout("\t\"%s\"\t", Weapon_info[Team_data[i].weaponry_pool[j]].name);
}
// now output the amount of this weapon or a variable that sets it. If this weapon is in the used pool and isn't
// set by a variable we should add the amount of weapons used by the wings to it and zero the entry so we know
// that we have dealt with it
if (strlen(Team_data[i].weaponry_amount_variable[j])) {
var_idx = get_index_sexp_variable_name(Team_data[i].weaponry_amount_variable[j]);
Assert (var_idx > -1 && var_idx < MAX_SEXP_VARIABLES);
fout ("@%s\n", Sexp_variables[var_idx].variable_name);
}
else {
if (strlen(Team_data[i].weaponry_pool_variable[j])) {
fout ("%d\n", Team_data[i].weaponry_count[j]);
}
else {
fout ("%d\n", Team_data[i].weaponry_count[j] + used_pool[Team_data[i].weaponry_pool[j]]);
used_pool[Team_data[i].weaponry_pool[j]] = 0;
}
}
}
// now we add anything left in the used pool as a static entry
for (j=0; j<Num_weapon_types; j++){
if (used_pool[j] > 0){
fout("\t\"%s\"\t%d\n", Weapon_info[j].name, used_pool[j]);
}
}
fout(")");
// Goober5000 - mjn.mixael's required weapon feature
bool uses_required_weapon = false;
for (j=0; j<MAX_WEAPON_TYPES; j++)
{
if (Team_data[i].weapon_required[j])
{
uses_required_weapon = true;
break;
}
}
if (uses_required_weapon)
{
if (optional_string_fred("+Required for mission:", "$Starting Shipname:"))
parse_comments(2);
else
fout("\n+Required for mission:");
fout(" (");
for (j=0; j<MAX_WEAPON_TYPES; j++)
{
if (Team_data[i].weapon_required[j])
fout(" \"%s\"", Weapon_info[j].name);
}
fout(" )");
}
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
// Goober5000
void CFred_mission_save::save_single_dock_instance(ship *shipp, dock_instance *dock_ptr)
{
Assert(shipp && dock_ptr);
Assert(dock_ptr->docked_objp->type == OBJ_SHIP || dock_ptr->docked_objp->type == OBJ_START);
// get ships and objects
object *objp = &Objects[shipp->objnum];
object *other_objp = dock_ptr->docked_objp;
ship *other_shipp = &Ships[other_objp->instance];
// write other ship
if (optional_string_fred("+Docked With:", "$Name:"))
parse_comments();
else
fout("\n+Docked With:");
fout(" %s", other_shipp->ship_name);
// Goober5000 - hm, Volition seems to have reversed docker and dockee here
// write docker (actually dockee) point
required_string_fred("$Docker Point:", "$Name:");
parse_comments();
fout(" %s", model_get_dock_name(Ship_info[other_shipp->ship_info_index].model_num, dock_find_dockpoint_used_by_object(other_objp, objp)));
// write dockee (actually docker) point
required_string_fred("$Dockee Point:", "$Name:");
parse_comments();
fout(" %s", model_get_dock_name(Ship_info[shipp->ship_info_index].model_num, dock_find_dockpoint_used_by_object(objp, other_objp)));
fso_comment_pop(true);
}
int CFred_mission_save::save_objects()
{
SCP_string sexp_out;
int i, j, z;
ai_info *aip;
object *objp;
ship *shipp;
ship_info *sip;
required_string_fred("#Objects");
parse_comments(2);
fout("\t\t;! %d total\n", ship_get_num_ships() );
for (i=z=0; i<MAX_SHIPS; i++) {
if (Ships[i].objnum < 0){
continue;
}
j = Objects[Ships[i].objnum].type;
if ((j != OBJ_SHIP) && (j != OBJ_START)){
continue;
}
shipp = &Ships[i];
objp = &Objects[shipp->objnum];
sip = &Ship_info[shipp->ship_info_index];
required_string_either_fred("$Name:", "#Wings");
required_string_fred("$Name:");
parse_comments(z ? 2 : 1);
fout(" %s\t\t;! Object #%d\n", shipp->ship_name, i);
required_string_fred("$Class:");
parse_comments(0);
fout(" %s", Ship_info[shipp->ship_info_index].name);
//alt classes stuff
if (Format_fs2_open != FSO_FORMAT_RETAIL) {
for (SCP_vector<alt_class>::iterator ii = shipp->s_alt_classes.begin(); ii != shipp->s_alt_classes.end(); ++ii) {
// is this a variable?
if (ii->variable_index != -1) {
fout("\n$Alt Ship Class: @%s", Sexp_variables[ii->variable_index].variable_name);
}
else {
fout("\n$Alt Ship Class: \"%s\"", Ship_info[ii->ship_class].name);
}
// default class?
if (ii->default_to_this_class) {
fout("\n+Default Class:");
}
}
}
// optional alternate type name
if(strlen(Fred_alt_names[i])){
fout("\n$Alt: %s\n", Fred_alt_names[i]);
}
// optional callsign
if(strlen(Fred_callsigns[i])){
fout("\n$Callsign: %s\n", Fred_callsigns[i]);
}
required_string_fred("$Team:");
parse_comments();
fout(" %s", Iff_info[shipp->team].iff_name);
if (Ship_info[shipp->ship_info_index].uses_team_colors) {
required_string_fred("$Team Color Setting:");
parse_comments();
fout(" %s", shipp->team_name.c_str());
}
required_string_fred("$Location:");
parse_comments();
save_vector(Objects[shipp->objnum].pos);
required_string_fred("$Orientation:");
parse_comments();
save_matrix(Objects[shipp->objnum].orient);
if (Format_fs2_retail)
{
required_string_fred("$IFF:");
parse_comments();
fout(" %s", "IFF 1");
}
Assert(shipp->ai_index >= 0);
aip = &Ai_info[shipp->ai_index];
required_string_fred("$AI Behavior:");
parse_comments();
fout(" %s", Ai_behavior_names[aip->behavior]);
if (shipp->weapons.ai_class != Ship_info[shipp->ship_info_index].ai_class) {
if (optional_string_fred("+AI Class:", "$Name:"))
parse_comments();
else
fout("\n+AI Class:");
fout(" %s", Ai_class_names[shipp->weapons.ai_class]);
}
save_ai_goals(Ai_info[shipp->ai_index].goals, i);
// XSTR
required_string_fred("$Cargo 1:");
parse_comments();
fout_ext(" ", "%s", Cargo_names[shipp->cargo1]);
save_common_object_data(&Objects[shipp->objnum], &Ships[i]);
if (shipp->wingnum >= 0){
shipp->arrival_location = ARRIVE_AT_LOCATION;
}
required_string_fred("$Arrival Location:");
parse_comments();
fout(" %s", Arrival_location_names[shipp->arrival_location]);
if (shipp->arrival_location != ARRIVE_AT_LOCATION)
{
if (optional_string_fred("+Arrival Distance:", "$Name:")){
parse_comments();
} else {
fout("\n+Arrival Distance:");
}
fout(" %d", shipp->arrival_distance);
if (optional_string_fred("$Arrival Anchor:", "$Name:")){
parse_comments();
} else {
fout("\n$Arrival Anchor:");
}
z = shipp->arrival_anchor;
if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG)
{
// get name
char tmp[NAME_LENGTH + 15];
stuff_special_arrival_anchor_name(tmp, z, Format_fs2_retail);
// save it
fout(" %s", tmp);
}
else if (z >= 0)
{
fout(" %s", Ships[z].ship_name);
}
else
{
fout(" <error>");
}
}
// Goober5000
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if ((shipp->arrival_location == ARRIVE_FROM_DOCK_BAY) && (shipp->arrival_path_mask > 0))
{
int j, anchor_shipnum;
polymodel *pm;
anchor_shipnum = shipp->arrival_anchor;
Assert(anchor_shipnum >= 0 && anchor_shipnum < MAX_SHIPS);
fout("\n+Arrival Paths: ( ");
pm = model_get(Ship_info[Ships[anchor_shipnum].ship_info_index].model_num);
for (j = 0; j < pm->ship_bay->num_paths; j++)
{
if (shipp->arrival_path_mask & (1 << j))
{
fout("\"%s\" ", pm->paths[pm->ship_bay->path_indexes[j]].name);
}
}
fout(")");
}
}
if (shipp->arrival_delay)
{
if (optional_string_fred("+Arrival Delay:", "$Name:"))
parse_comments();
else
fout("\n+Arrival Delay:");
fout(" %d", shipp->arrival_delay);
}
required_string_fred("$Arrival Cue:");
parse_comments();
convert_sexp_to_string(sexp_out, shipp->arrival_cue, SEXP_SAVE_MODE);
fout(" %s", sexp_out.c_str());
required_string_fred("$Departure Location:");
parse_comments();
fout(" %s", Departure_location_names[shipp->departure_location]);
if ( shipp->departure_location != DEPART_AT_LOCATION )
{
required_string_fred("$Departure Anchor:");
parse_comments();
if ( shipp->departure_anchor >= 0 )
fout(" %s", Ships[shipp->departure_anchor].ship_name );
else
fout(" <error>");
}
// Goober5000
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if ((shipp->departure_location == DEPART_AT_DOCK_BAY) && (shipp->departure_path_mask > 0))
{
int j, anchor_shipnum;
polymodel *pm;
anchor_shipnum = shipp->departure_anchor;
Assert(anchor_shipnum >= 0 && anchor_shipnum < MAX_SHIPS);
fout("\n+Departure Paths: ( ");
pm = model_get(Ship_info[Ships[anchor_shipnum].ship_info_index].model_num);
for (j = 0; j < pm->ship_bay->num_paths; j++)
{
if (shipp->departure_path_mask & (1 << j))
{
fout("\"%s\" ", pm->paths[pm->ship_bay->path_indexes[j]].name);
}
}
fout(")");
}
}
if (shipp->departure_delay)
{
if (optional_string_fred("+Departure delay:", "$Name:"))
parse_comments();
else
fout("\n+Departure delay:");
fout(" %d", shipp->departure_delay);
}
required_string_fred("$Departure Cue:");
parse_comments();
convert_sexp_to_string(sexp_out, shipp->departure_cue, SEXP_SAVE_MODE);
fout(" %s", sexp_out.c_str());
required_string_fred("$Determination:");
parse_comments();
fout(" 10"); // dummy value for backwards compatibility
if (optional_string_fred("+Flags:", "$Name:")) {
parse_comments();
fout (" (");
} else
fout("\n+Flags: (");
if (shipp->flags & SF_CARGO_REVEALED)
fout(" \"cargo-known\"");
if (shipp->flags & SF_IGNORE_COUNT)
fout(" \"ignore-count\"");
if (objp->flags & OF_PROTECTED)
fout(" \"protect-ship\"");
if (shipp->flags & SF_REINFORCEMENT)
fout(" \"reinforcement\"");
if (objp->flags & OF_NO_SHIELDS)
fout(" \"no-shields\"");
if (shipp->flags & SF_ESCORT)
fout(" \"escort\"");
if (objp->type == OBJ_START)
fout(" \"player-start\"");
if (shipp->flags & SF_NO_ARRIVAL_MUSIC)
fout(" \"no-arrival-music\"");
if (shipp->flags & SF_NO_ARRIVAL_WARP)
fout(" \"no-arrival-warp\"");
if (shipp->flags & SF_NO_DEPARTURE_WARP)
fout(" \"no-departure-warp\"");
if (Objects[shipp->objnum].flags & OF_INVULNERABLE)
fout(" \"invulnerable\"");
if (shipp->flags & SF_HIDDEN_FROM_SENSORS)
fout(" \"hidden-from-sensors\"");
if (shipp->flags & SF_SCANNABLE)
fout(" \"scannable\"");
if (Ai_info[shipp->ai_index].ai_flags & AIF_KAMIKAZE)
fout(" \"kamikaze\"");
if (Ai_info[shipp->ai_index].ai_flags & AIF_NO_DYNAMIC)
fout(" \"no-dynamic\"");
if (shipp->flags & SF_RED_ALERT_STORE_STATUS)
fout(" \"red-alert-carry\"");
if (objp->flags & OF_BEAM_PROTECTED)
fout(" \"beam-protect-ship\"");
if (objp->flags & OF_FLAK_PROTECTED)
fout(" \"flak-protect-ship\"");
if (objp->flags & OF_LASER_PROTECTED)
fout(" \"laser-protect-ship\"");
if (objp->flags & OF_MISSILE_PROTECTED)
fout(" \"missile-protect-ship\"");
if (shipp->ship_guardian_threshold != 0)
fout(" \"guardian\"");
if (objp->flags & OF_SPECIAL_WARPIN)
fout(" \"special-warp\"");
if (shipp->flags & SF_VAPORIZE)
fout(" \"vaporize\"");
if (shipp->flags2 & SF2_STEALTH)
fout(" \"stealth\"");
if (shipp->flags2 & SF2_FRIENDLY_STEALTH_INVIS)
fout(" \"friendly-stealth-invisible\"");
if (shipp->flags2 & SF2_DONT_COLLIDE_INVIS)
fout(" \"don't-collide-invisible\"");
//for compatibility reasons ship locked or weapons locked are saved as both locked in retail mode
if ((Format_fs2_open == FSO_FORMAT_RETAIL) && ((shipp->flags2 & SF2_SHIP_LOCKED) || (shipp->flags2 & SF2_WEAPONS_LOCKED)))
fout(" \"locked\"");
fout(" )");
// flags2 added by Goober5000 --------------------------------
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if (optional_string_fred("+Flags2:", "$Name:")) {
parse_comments();
fout (" (");
} else
fout("\n+Flags2: (");
if (shipp->flags2 & SF2_PRIMITIVE_SENSORS)
fout(" \"primitive-sensors\"");
if (shipp->flags2 & SF2_NO_SUBSPACE_DRIVE)
fout(" \"no-subspace-drive\"");
if (shipp->flags2 & SF2_NAVPOINT_CARRY)
fout(" \"nav-carry-status\"");
if (shipp->flags2 & SF2_AFFECTED_BY_GRAVITY)
fout(" \"affected-by-gravity\"");
if (shipp->flags2 & SF2_TOGGLE_SUBSYSTEM_SCANNING)
fout(" \"toggle-subsystem-scanning\"");
if (objp->flags & OF_TARGETABLE_AS_BOMB)
fout(" \"targetable-as-bomb\"");
if (shipp->flags2 & SF2_NO_BUILTIN_MESSAGES)
fout(" \"no-builtin-messages\"");
if (shipp->flags2 & SF2_PRIMARIES_LOCKED)
fout(" \"primaries-locked\"");
if (shipp->flags2 & SF2_SECONDARIES_LOCKED)
fout(" \"secondaries-locked\"");
if (shipp->flags2 & SF2_NO_DEATH_SCREAM)
fout(" \"no-death-scream\"");
if (shipp->flags2 & SF2_ALWAYS_DEATH_SCREAM)
fout(" \"always-death-scream\"");
if (shipp->flags2 & SF2_NAVPOINT_NEEDSLINK)
fout(" \"nav-needslink\"");
if (shipp->flags2 & SF2_HIDE_SHIP_NAME)
fout(" \"hide-ship-name\"");
if (shipp->flags2 & SF2_SET_CLASS_DYNAMICALLY)
fout(" \"set-class-dynamically\"");
if (shipp->flags2 & SF2_LOCK_ALL_TURRETS_INITIALLY)
fout(" \"lock-all-turrets\"");
if (shipp->flags2 & SF2_AFTERBURNER_LOCKED)
fout(" \"afterburners-locked\"");
if (shipp->flags2 & SF2_FORCE_SHIELDS_ON)
fout(" \"force-shields-on\"");
if (objp->flags & OF_IMMOBILE)
fout(" \"immobile\"");
if (shipp->flags2 & SF2_NO_ETS)
fout(" \"no-ets\"");
if (shipp->flags2 & SF2_CLOAKED)
fout(" \"cloaked\"");
if (shipp->flags2 & SF2_SHIP_LOCKED)
fout(" \"ship-locked\"");
if (shipp->flags2 & SF2_WEAPONS_LOCKED)
fout(" \"weapons-locked\"");
if (shipp->flags2 & SF2_SCRAMBLE_MESSAGES)
fout(" \"scramble-messages\"");
if (!(objp->flags & OF_COLLIDES))
fout(" \"no-collide\"");
if (shipp->flags2 & SF2_NO_DISABLED_SELF_DESTRUCT)
fout(" \"no-disabled-self-destruct\"");
fout(" )");
}
// -----------------------------------------------------------
fout("\n+Respawn priority: %d", shipp->respawn_priority); // HA! Newline added by Goober5000
if (shipp->flags & SF_ESCORT) {
if (optional_string_fred("+Escort priority:", "$Name:")) {
parse_comments();
} else {
fout("\n+Escort priority:");
}
fout(" %d", shipp->escort_priority);
}
// special explosions
if (Format_fs2_open != FSO_FORMAT_RETAIL) {
if (shipp->use_special_explosion) {
fso_comment_push(";;FSO 3.6.13;;");
if (optional_string_fred("$Special Explosion:", "$Name:")) {
parse_comments();
required_string_fred("+Special Exp Damage:");
parse_comments();
fout(" %d", shipp->special_exp_damage);
required_string_fred("+Special Exp Blast:");
parse_comments();
fout(" %d", shipp->special_exp_blast);
required_string_fred("+Special Exp Inner Radius:");
parse_comments();
fout(" %d", shipp->special_exp_inner);
required_string_fred("+Special Exp Outer Radius:");
parse_comments();
fout(" %d", shipp->special_exp_outer);
if (shipp->use_shockwave && (shipp->special_exp_shockwave_speed > 0)) {
optional_string_fred("+Special Exp Shockwave Speed:");
parse_comments();
fout(" %d", shipp->special_exp_shockwave_speed);
}
else {
bypass_comment(";;FSO 3.6.13;; +Special Exp Shockwave Speed:", "$Name:");
}
if (shipp->special_exp_deathroll_time > 0) {
optional_string_fred("+Special Exp Death Roll Time:");
parse_comments();
fout(" %d", shipp->special_exp_deathroll_time);
}
else {
bypass_comment(";;FSO 3.6.13;; +Special Exp Death Roll Time:", "$Name:");
}
}
else {
fout_version("\n$Special Explosion:");
fout_version("\n+Special Exp Damage:");
fout(" %d", shipp->special_exp_damage);
fout_version("\n+Special Exp Blast:");
fout(" %d", shipp->special_exp_blast);
fout_version("\n+Special Exp Inner Radius:");
fout(" %d", shipp->special_exp_inner);
fout_version("\n+Special Exp Outer Radius:");
fout(" %d", shipp->special_exp_outer);
if (shipp->use_shockwave && (shipp->special_exp_shockwave_speed > 0)) {
fout_version("\n+Special Exp Shockwave Speed:");
fout(" %d", shipp->special_exp_shockwave_speed);
}
if (shipp->special_exp_deathroll_time > 0) {
fout_version("\n+Special Exp Death Roll Time:");
fout(" %d", shipp->special_exp_deathroll_time);
}
}
fso_comment_pop();
}
else {
bypass_comment(";;FSO 3.6.13;; +Special Exp Shockwave Speed:", "$Name:");
bypass_comment(";;FSO 3.6.13;; +Special Exp Death Roll Time:", "$Name:");
}
}
// retail format special explosions
else {
if (shipp->use_special_explosion) {
int special_exp_index;
if (has_special_explosion_block_index(&Ships[i], &special_exp_index)) {
fout("\n+Special Exp index:");
fout(" %d", special_exp_index);
}
else {
CString text = "You are saving in the retail mission format, but ";
text += "the mission has too many special explosions defined. \"";
text += shipp->ship_name;
text += "\" has therefore lost any special explosion data that was defined for it. ";
text += "\" Either remove special explosions or SEXP variables if you need it to have one ";
MessageBox(NULL, text, "Too many variables!", MB_OK);
}
}
}
// Goober5000 ------------------------------------------------
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if (shipp->special_hitpoints) {
fso_comment_push(";;FSO 3.6.13;;");
if (optional_string_fred("+Special Hitpoints:", "$Name:")) {
parse_comments();
} else {
fout_version("\n+Special Hitpoints:");
}
fso_comment_pop();
fout(" %d", shipp->special_hitpoints);
}
else {
bypass_comment(";;FSO 3.6.13;; +Special Hitpoints:", "$Name:");
}
if (shipp->special_shield >= 0) {
fso_comment_push(";;FSO 3.6.13;;");
if (optional_string_fred("+Special Shield Points:", "$Name:")) {
parse_comments();
} else {
fout_version("\n+Special Shield Points:");
}
fso_comment_pop();
fout(" %d", shipp->special_shield);
}
else {
bypass_comment(";;FSO 3.6.13;; +Special Shield Points:", "$Name:");
}
}
// -----------------------------------------------------------
if ( Ai_info[shipp->ai_index].ai_flags & AIF_KAMIKAZE ) {
if ( optional_string_fred("+Kamikaze Damage:", "$Name:")){
parse_comments();
} else {
fout("\n+Kamikaze Damage:");
}
fout(" %d", Ai_info[shipp->ai_index].kamikaze_damage);
}
if (shipp->hotkey != -1) {
if (optional_string_fred("+Hotkey:", "$Name:")){
parse_comments();
} else {
fout("\n+Hotkey:");
}
fout(" %d", shipp->hotkey);
}
// mwa -- new code to save off information about initially docked ships.
// Goober5000 - newer code to save off information about initially docked ships. ;)
if (object_is_docked(&Objects[shipp->objnum]))
{
// possible incompatibility
if ( Format_fs2_open == FSO_FORMAT_RETAIL && !dock_check_docked_one_on_one(&Objects[shipp->objnum]))
{
static bool warned = false;
if (!warned)
{
CString text = "You are saving in the retail mission format, but \"";
text += shipp->ship_name;
text += "\" is docked to more than one ship. If you wish to run this mission in retail, ";
text += "you should remove the additional ships and save the mission again.";
MessageBox(NULL, text, "Incompatibility with retail mission format", MB_OK);
warned = true; // to avoid zillions of boxes
}
}
// save one-on-one groups as if they were retail
if (dock_check_docked_one_on_one(&Objects[shipp->objnum]))
{
// retail format only saved information for non-leaders
if (!(shipp->flags & SF_DOCK_LEADER))
{
save_single_dock_instance(&Ships[i], Objects[shipp->objnum].dock_list);
}
}
// multiply docked
else
{
// save all instances for all ships
for (dock_instance *dock_ptr = Objects[shipp->objnum].dock_list; dock_ptr != NULL; dock_ptr = dock_ptr->next)
{
save_single_dock_instance(&Ships[i], dock_ptr);
}
}
}
// check the ship flag about killing off the ship before a missino starts. Write out the appropriate
// variable if necessary
if ( shipp->flags & SF_KILL_BEFORE_MISSION ) {
if ( optional_string_fred("+Destroy At:", "$Name:"))
parse_comments();
else
fout("\n+Destroy At: ");
fout(" %d", shipp->final_death_time );
}
// possibly write out the orders that this ship will accept. We'll only do it if the orders
// are not the default set of orders
if ( shipp->orders_accepted != ship_get_default_orders_accepted( &Ship_info[shipp->ship_info_index]) ) {
if ( optional_string_fred("+Orders Accepted:", "$Name:") )
parse_comments();
else
fout("\n+Orders Accepted:");
fout(" %d\t\t;! note that this is a bitfield!!!", shipp->orders_accepted);
}
if (shipp->group >= 0) {
if (optional_string_fred("+Group:", "$Name:"))
parse_comments();
else
fout("\n+Group:");
fout(" %d", shipp->group);
}
// always write out the score to ensure backwards compatibility. If the score is the same as the value
// in the table write out a flag to tell the game to simply use whatever is in the table instead
if (Ship_info[shipp->ship_info_index].score == shipp->score ) {
fso_comment_push(";;FSO 3.6.10;;");
if ( optional_string_fred("+Use Table Score:", "$Name:") ) {
parse_comments();
} else {
fout_version("\n+Use Table Score:");
}
fso_comment_pop();
}
else {
bypass_comment(";;FSO 3.6.10;; +Use Table Score:", "$Name:");
}
if (optional_string_fred("+Score:", "$Name:"))
parse_comments();
else
fout("\n+Score:");
fout(" %d", shipp->score);
if (Format_fs2_open != FSO_FORMAT_RETAIL && shipp->assist_score_pct != 0) {
fso_comment_push(";;FSO 3.6.10;;");
if ( optional_string_fred("+Assist Score Percentage:") ) {
parse_comments();
} else {
fout_version("\n+Assist Score Percentage:");
}
fso_comment_pop();
fout(" %f", shipp->assist_score_pct);
}
else {
bypass_comment(";;FSO 3.6.10;; +Assist Score Percentage:", "$Name:");
}
// deal with the persona for this ship as well.
if ( shipp->persona_index != -1 ) {
if (optional_string_fred("+Persona Index:", "$Name:"))
parse_comments();
else
fout("\n+Persona Index:");
fout(" %d", shipp->persona_index);
}
// Goober5000 - deal with texture replacement ----------------
if (!Fred_texture_replacements.empty()) {
bool needs_header = true;
fso_comment_push(";;FSO 3.6.8;;");
for (SCP_vector<texture_replace>::iterator ii = Fred_texture_replacements.begin(); ii != Fred_texture_replacements.end(); ++ii) {
if ( !stricmp(shipp->ship_name, ii->ship_name) ) {
if (needs_header) {
if (optional_string_fred("$Texture Replace:")) {
parse_comments(1);
} else {
fout_version("\n$Texture Replace:");
}
needs_header = false;
}
// write out this entry
if (optional_string_fred("+old:")) {
parse_comments(1);
fout(" %s", ii->old_texture);
} else {
fout_version("\n+old: %s", ii->old_texture);
}
if (optional_string_fred("+new:")) {
parse_comments(1);
fout(" %s", ii->new_texture);
} else {
fout_version("\n+new: %s", ii->new_texture);
}
}
}
fso_comment_pop();
} else {
bypass_comment(";;FSO 3.6.8;; $Texture Replace:", "$Name:");
}
// end of texture replacement -------------------------------
z++;
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_common_object_data(object *objp, ship *shipp)
{
int j, z;
ship_subsys *ptr = NULL;
ship_info *sip = NULL;
ship_weapon *wp = NULL;
float temp_max_hull_strength;
sip = &Ship_info[shipp->ship_info_index];
if ((int) objp->phys_info.speed) {
if (optional_string_fred("+Initial Velocity:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+Initial Velocity:");
fout(" %d", (int) objp->phys_info.speed);
}
// Goober5000
if (Format_fs2_open != FSO_FORMAT_RETAIL && (shipp->special_hitpoints))
{
temp_max_hull_strength = (float)shipp->special_hitpoints;
}
else
{
temp_max_hull_strength = sip->max_hull_strength;
}
if ((int) objp->hull_strength != temp_max_hull_strength) {
if (optional_string_fred("+Initial Hull:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+Initial Hull:");
fout(" %d", (int) objp->hull_strength);
}
if ((int) shield_get_strength(objp) != 100) {
if (optional_string_fred("+Initial Shields:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+Initial Shields:");
fout(" %d", (int) objp->shield_quadrant[0]);
}
// save normal ship weapons info
required_string_fred("+Subsystem:", "$Name:");
parse_comments();
fout(" Pilot");
wp = &shipp->weapons;
z = 0;
j = wp->num_primary_banks;
while (j-- && (j >= 0))
if (wp->primary_bank_weapons[j] != sip->primary_bank_weapons[j])
z = 1;
if (z) {
if (optional_string_fred("+Primary Banks:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+Primary Banks:");
fout(" ( ");
for (j=0; j<wp->num_primary_banks; j++) {
if (wp->primary_bank_weapons[j] != -1) { // Just in case someone has set a weapon bank to empty
fout("\"%s\" ", Weapon_info[wp->primary_bank_weapons[j]].name);
} else {
fout("\"\" ");
}
}
fout(")");
}
z = 0;
j = wp->num_secondary_banks;
while (j-- && (j >= 0))
if (wp->secondary_bank_weapons[j] != sip->secondary_bank_weapons[j])
z = 1;
if (z) {
if (optional_string_fred("+Secondary Banks:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+Secondary Banks:");
fout(" ( ");
for (j=0; j<wp->num_secondary_banks; j++) {
if (wp->secondary_bank_weapons[j] != -1) {
fout("\"%s\" ", Weapon_info[wp->secondary_bank_weapons[j]].name);
} else {
fout("\"\" ");
}
}
fout(")");
}
z = 0;
j = wp->num_secondary_banks;
while (j-- && (j >= 0))
if (wp->secondary_bank_ammo[j] != 100)
z = 1;
if (z) {
if (optional_string_fred("+Sbank Ammo:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+Sbank Ammo:");
fout(" ( ");
for (j=0; j<wp->num_secondary_banks; j++)
fout("%d ", wp->secondary_bank_ammo[j]);
fout(")");
}
ptr = GET_FIRST(&shipp->subsys_list);
Assert(ptr);
while (ptr != END_OF_LIST(&shipp->subsys_list) && ptr) {
// Crashing here!
if ( (ptr->current_hits) || (ptr->system_info && ptr->system_info->type == SUBSYSTEM_TURRET) || (ptr->subsys_cargo_name > 0)) {
if (optional_string_fred("+Subsystem:", "$Name:"))
parse_comments();
else
fout("\n+Subsystem:");
fout(" %s", ptr->system_info->subobj_name);
}
if (ptr->current_hits) {
if (optional_string_fred("$Damage:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n$Damage:");
fout(" %d", (int) ptr->current_hits);
}
if (ptr->subsys_cargo_name > 0) {
if (optional_string_fred("+Cargo Name:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+Cargo Name:");
fout_ext(NULL, "%s", Cargo_names[ptr->subsys_cargo_name]);
}
if (ptr->system_info->type == SUBSYSTEM_TURRET)
save_turret_info(ptr, shipp - Ships);
ptr = GET_NEXT(ptr);
fso_comment_pop();
}
/* for (j=0; j<shipp->status_count; j++) {
required_string_fred("$Status Description:");
parse_comments(-1);
fout(" %s", Status_desc_names[shipp->status_type[j]]);
required_string_fred("$Status:");
parse_comments(-1);
fout(" %s", Status_type_names[shipp->status[j]]);
required_string_fred("$Target:");
parse_comments(-1);
fout(" %s", Status_target_names[shipp->target[j]]);
}*/
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_wings()
{
SCP_string sexp_out;
int i, j, z, ship, count = 0;
fred_parse_flag = 0;
required_string_fred("#Wings");
parse_comments(2);
fout("\t\t;! %d total", Num_wings);
for (i=0; i<MAX_WINGS; i++) {
if (!Wings[i].wave_count)
continue;
count++;
required_string_either_fred("$Name:", "#Events");
required_string_fred("$Name:");
parse_comments(2);
fout(" %s", Wings[i].name);
// squad logo - Goober5000
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if (strlen(Wings[i].wing_squad_filename) > 0) //-V805
{
if (optional_string_fred("+Squad Logo:", "$Name:"))
parse_comments();
else
fout("\n+Squad Logo:");
fout(" %s", Wings[i].wing_squad_filename);
}
}
required_string_fred("$Waves:");
parse_comments();
fout(" %d", Wings[i].num_waves);
required_string_fred("$Wave Threshold:");
parse_comments();
fout(" %d", Wings[i].threshold);
required_string_fred("$Special Ship:");
parse_comments();
fout(" %d\t\t;! %s\n", Wings[i].special_ship,
Ships[Wings[i].ship_index[Wings[i].special_ship]].ship_name);
required_string_fred("$Arrival Location:");
parse_comments();
fout(" %s", Arrival_location_names[Wings[i].arrival_location]);
if (Wings[i].arrival_location != ARRIVE_AT_LOCATION)
{
if (optional_string_fred("+Arrival Distance:", "$Name:"))
parse_comments();
else
fout("\n+Arrival Distance:");
fout(" %d", Wings[i].arrival_distance);
if (optional_string_fred("$Arrival Anchor:", "$Name:"))
parse_comments();
else
fout("\n$Arrival Anchor:");
z = Wings[i].arrival_anchor;
if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG)
{
// get name
char tmp[NAME_LENGTH + 15];
stuff_special_arrival_anchor_name(tmp, z, Format_fs2_retail);
// save it
fout(" %s", tmp);
}
else if (z >= 0)
{
fout(" %s", Ships[z].ship_name);
}
else
{
fout(" <error>");
}
}
// Goober5000
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if ((Wings[i].arrival_location == ARRIVE_FROM_DOCK_BAY) && (Wings[i].arrival_path_mask > 0))
{
int j, anchor_shipnum;
polymodel *pm;
anchor_shipnum = Wings[i].arrival_anchor;
Assert(anchor_shipnum >= 0 && anchor_shipnum < MAX_SHIPS);
fout("\n+Arrival Paths: ( ");
pm = model_get(Ship_info[Ships[anchor_shipnum].ship_info_index].model_num);
for (j = 0; j < pm->ship_bay->num_paths; j++)
{
if (Wings[i].arrival_path_mask & (1 << j))
{
fout("\"%s\" ", pm->paths[pm->ship_bay->path_indexes[j]].name);
}
}
fout(")");
}
}
if (Wings[i].arrival_delay)
{
if (optional_string_fred("+Arrival delay:", "$Name:"))
parse_comments();
else
fout("\n+Arrival delay:");
fout(" %d", Wings[i].arrival_delay);
}
required_string_fred("$Arrival Cue:");
parse_comments();
convert_sexp_to_string(sexp_out, Wings[i].arrival_cue, SEXP_SAVE_MODE);
fout(" %s", sexp_out.c_str());
required_string_fred("$Departure Location:");
parse_comments();
fout(" %s", Departure_location_names[Wings[i].departure_location]);
if ( Wings[i].departure_location != DEPART_AT_LOCATION )
{
required_string_fred("$Departure Anchor:");
parse_comments();
if ( Wings[i].departure_anchor >= 0 )
fout(" %s", Ships[Wings[i].departure_anchor].ship_name );
else
fout(" <error>");
}
// Goober5000
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if ((Wings[i].departure_location == DEPART_AT_DOCK_BAY) && (Wings[i].departure_path_mask > 0))
{
int j, anchor_shipnum;
polymodel *pm;
anchor_shipnum = Wings[i].departure_anchor;
Assert(anchor_shipnum >= 0 && anchor_shipnum < MAX_SHIPS);
fout("\n+Departure Paths: ( ");
pm = model_get(Ship_info[Ships[anchor_shipnum].ship_info_index].model_num);
for (j = 0; j < pm->ship_bay->num_paths; j++)
{
if (Wings[i].departure_path_mask & (1 << j))
{
fout("\"%s\" ", pm->paths[pm->ship_bay->path_indexes[j]].name);
}
}
fout(")");
}
}
if (Wings[i].departure_delay)
{
if (optional_string_fred("+Departure delay:", "$Name:"))
parse_comments();
else
fout("\n+Departure delay:");
fout(" %d", Wings[i].departure_delay);
}
required_string_fred("$Departure Cue:");
parse_comments();
convert_sexp_to_string(sexp_out, Wings[i].departure_cue, SEXP_SAVE_MODE);
fout(" %s", sexp_out.c_str());
required_string_fred("$Ships:");
parse_comments();
fout(" (\t\t;! %d total\n", Wings[i].wave_count);
for (j=0; j<Wings[i].wave_count; j++) {
ship = Wings[i].ship_index[j];
// if (Objects[Ships[ship].objnum].type == OBJ_START)
// fout("\t\"Player 1\"\n");
// else
fout("\t\"%s\"\n", Ships[Wings[i].ship_index[j]].ship_name);
}
fout(")");
save_ai_goals(Wings[i].ai_goals, -1);
if (Wings[i].hotkey != -1) {
if (optional_string_fred("+Hotkey:", "$Name:"))
parse_comments();
else
fout("\n+Hotkey:");
fout(" %d", Wings[i].hotkey);
}
if ( optional_string_fred("+Flags:", "$Name:")) {
parse_comments();
fout( " (" );
} else
fout("\n+Flags: (");
if ( Wings[i].flags & WF_IGNORE_COUNT )
fout(" \"ignore-count\"");
if ( Wings[i].flags & WF_REINFORCEMENT )
fout(" \"reinforcement\"");
if ( Wings[i].flags & WF_NO_ARRIVAL_MUSIC )
fout(" \"no-arrival-music\"");
if ( Wings[i].flags & WF_NO_ARRIVAL_MESSAGE )
fout(" \"no-arrival-message\"");
if ( Wings[i].flags & WF_NO_ARRIVAL_WARP )
fout(" \"no-arrival-warp\"");
if ( Wings[i].flags & WF_NO_DEPARTURE_WARP )
fout(" \"no-departure-warp\"");
if ( Wings[i].flags & WF_NO_DYNAMIC )
fout( " \"no-dynamic\"" );
fout(" )");
if (Wings[i].wave_delay_min) {
if (optional_string_fred("+Wave Delay Min:", "$Name:"))
parse_comments();
else
fout("\n+Wave Delay Min:");
fout(" %d", Wings[i].wave_delay_min);
}
if (Wings[i].wave_delay_max) {
if (optional_string_fred("+Wave Delay Max:", "$Name:"))
parse_comments();
else
fout("\n+Wave Delay Max:");
fout(" %d", Wings[i].wave_delay_max);
}
fso_comment_pop();
}
fso_comment_pop(true);
Assert(count == Num_wings);
return err;
}
int CFred_mission_save::save_goals()
{
SCP_string sexp_out;
int i;
fred_parse_flag = 0;
required_string_fred("#Goals");
parse_comments(2);
fout("\t\t;! %d total\n", Num_goals);
for (i=0; i<Num_goals; i++) {
int type;
required_string_either_fred("$Type:", "#Waypoints");
required_string_fred("$Type:");
parse_comments(i ? 2 : 1);
type = Mission_goals[i].type & GOAL_TYPE_MASK;
fout(" %s", Goal_type_names[type]);
if (*Mission_goals[i].name) {
if (optional_string_fred("+Name:", "$Type:"))
parse_comments();
else
fout("\n+Name:");
fout(" %s", Mission_goals[i].name);
}
// XSTR
required_string_fred("$MessageNew:");
parse_comments();
fout_ext(" ", "%s", Mission_goals[i].message);
fout("\n");
required_string_fred("$end_multi_text");
parse_comments(0);
required_string_fred("$Formula:");
parse_comments();
convert_sexp_to_string(sexp_out, Mission_goals[i].formula, SEXP_SAVE_MODE);
fout(" %s", sexp_out.c_str());
if ( Mission_goals[i].type & INVALID_GOAL ) {
if (optional_string_fred("+Invalid", "$Type:"))
parse_comments();
else
fout("\n+Invalid");
}
if ( Mission_goals[i].flags & MGF_NO_MUSIC ) {
if (optional_string_fred("+No music", "$Type:"))
parse_comments();
else
fout("\n+No music");
}
if ( Mission_goals[i].score != 0 ) {
if ( optional_string_fred("+Score:", "$Type:"))
parse_comments();
else
fout("\n+Score:");
fout(" %d", Mission_goals[i].score );
}
if ( The_mission.game_type & MISSION_TYPE_MULTI_TEAMS ) {
if ( optional_string_fred("+Team:", "$Type:"))
parse_comments();
else
fout("\n+Team:");
fout(" %d", Mission_goals[i].team );
}
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_waypoints()
{
//object *ptr;
fred_parse_flag = 0;
required_string_fred("#Waypoints");
parse_comments(2);
fout("\t\t;! %d lists total\n", Waypoint_lists.size());
SCP_list<CJumpNode>::iterator jnp;
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp)
{
required_string_fred("$Jump Node:", "$Jump Node Name:");
parse_comments(2);
save_vector(jnp->GetSCPObject()->pos);
required_string_fred("$Jump Node Name:", "$Jump Node:");
parse_comments();
fout(" %s", jnp->GetName());
if(jnp->IsSpecialModel())
{
if ( optional_string_fred("+Model File:", "$Jump Node:"))
parse_comments();
else
fout("\n+Model File:");
int model = jnp->GetModelNumber();
polymodel *pm = model_get(model);
fout(" %s", pm->filename );
}
if(jnp->IsColored())
{
if ( optional_string_fred("+Alphacolor:", "$Jump Node:"))
parse_comments();
else
fout("\n+Alphacolor:");
color jn_color = jnp->GetColor();
fout(" %u %u %u %u", jn_color.red, jn_color.green, jn_color.blue, jn_color.alpha );
}
int hidden_is_there = optional_string_fred("+Hidden:", "$Jump Node:");
if(hidden_is_there)
parse_comments();
if(hidden_is_there || jnp->IsHidden())
{
if(!hidden_is_there)
fout("\n+Hidden:");
if(jnp->IsHidden())
fout(" %s", "true");
else
fout(" %s", "false");
}
fso_comment_pop();
}
SCP_list<waypoint_list>::iterator ii;
for (ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++ii)
{
required_string_either_fred("$Name:", "#Messages");
required_string_fred("$Name:");
parse_comments((ii == Waypoint_lists.begin()) ? 1 : 2);
fout(" %s", ii->get_name());
required_string_fred("$List:");
parse_comments();
fout(" (\t\t;! %d points in list\n", ii->get_waypoints().size());
save_waypoint_list(&(*ii));
fout(")");
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_waypoint_list(waypoint_list *wp_list)
{
Assert(wp_list != NULL);
SCP_vector<waypoint>::iterator ii;
for (ii = wp_list->get_waypoints().begin(); ii != wp_list->get_waypoints().end(); ++ii)
{
vec3d *pos = ii->get_pos();
fout("\t( %f, %f, %f )\n", pos->xyz.x, pos->xyz.y, pos->xyz.z);
}
return 0;
}
int CFred_mission_save::save_messages()
{
int i;
fred_parse_flag = 0;
required_string_fred("#Messages");
parse_comments(2);
fout("\t\t;! %d total\n", Num_messages-Num_builtin_messages);
// Goober5000 - special Command info
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if (stricmp(The_mission.command_sender, DEFAULT_COMMAND))
fout("\n$Command Sender: %s", The_mission.command_sender);
if (The_mission.command_persona != Default_command_persona)
fout("\n$Command Persona: %s", Personas[The_mission.command_persona].name);
}
for (i=Num_builtin_messages; i<Num_messages; i++) {
required_string_either_fred("$Name:", "#Reinforcements");
required_string_fred("$Name:");
parse_comments(2);
fout(" %s", Messages[i].name);
// team
required_string_fred("$Team:");
parse_comments(1);
if((Messages[i].multi_team < 0) || (Messages[i].multi_team >= 2)){
fout(" %d", -1);
} else {
fout(" %d", Messages[i].multi_team);
}
// XSTR
required_string_fred("$MessageNew:");
parse_comments();
fout_ext(" ", "%s", Messages[i].message);
fout("\n");
required_string_fred("$end_multi_text");
parse_comments(0);
if ( Messages[i].persona_index != -1 ) {
if ( optional_string_fred("+Persona:", "$Name:"))
parse_comments();
else
fout("\n+Persona:");
fout(" %s", Personas[Messages[i].persona_index].name );
}
if (Messages[i].avi_info.name) {
if (optional_string_fred("+AVI Name:", "$Name:"))
parse_comments();
else
fout("\n+AVI Name:");
fout(" %s", Messages[i].avi_info.name);
}
if (Messages[i].wave_info.name) {
if (optional_string_fred("+Wave Name:", "$Name:"))
parse_comments();
else
fout("\n+Wave Name:");
fout(" %s", Messages[i].wave_info.name);
}
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_vector(vec3d &v)
{
fout(" %f, %f, %f", v.xyz.x, v.xyz.y, v.xyz.z);
return 0;
}
int CFred_mission_save::save_matrix(matrix &m)
{
fout("\n\t%f, %f, %f,\n", m.vec.rvec.xyz.x, m.vec.rvec.xyz.y, m.vec.rvec.xyz.z);
fout("\t%f, %f, %f,\n", m.vec.uvec.xyz.x, m.vec.uvec.xyz.y, m.vec.uvec.xyz.z);
fout("\t%f, %f, %f", m.vec.fvec.xyz.x, m.vec.fvec.xyz.y, m.vec.fvec.xyz.z);
return 0;
}
// Goober5000 - move past the comment without copying it to the output file
// (used for special FSO comment tags)
void CFred_mission_save::bypass_comment(const char *comment, const char *end)
{
char *ch = strstr(raw_ptr, comment);
if (ch != NULL)
{
if (end != NULL) {
char *ep = strstr(raw_ptr, end);
if (ep != NULL && ep < ch)
return;
}
char *writep = ch;
char *readp = strchr(writep, '\n');
// copy all characters past it
while (*readp != '\0')
{
*writep = *readp;
writep++;
readp++;
}
*writep = '\0';
}
}
// saves comments from previous campaign/mission file
void CFred_mission_save::parse_comments(int newlines)
{
char *comment_start = NULL;
int state = 0, same_line = 0, first_comment = 1, tab = 0, flag = 0;
bool version_added = false;
if (newlines < 0) {
newlines = -newlines;
tab = 1;
}
if (newlines)
same_line = 1;
if (fred_parse_flag || !Token_found_flag || !token_found || (token_found && (*Mission_text_raw == EOF_CHAR))) {
while (newlines-- > 0)
fout("\n");
if (tab && token_found)
fout_version("\t%s", token_found);
else if (token_found)
fout_version("%s", token_found);
else if (tab)
fout("\t");
return;
}
while (*raw_ptr != EOF_CHAR) {
// state values (as far as I could figure out):
// 0 - raw_ptr not inside comment
// 1 - raw_ptr inside /**/ comment
// 2 - raw_ptr inside ; (newline-delimited) comment
// 3,4 - raw_ptr inside ;; (FSO version) comment
if (!state) {
if (token_found && (*raw_ptr == *token_found))
if (!strnicmp(raw_ptr, token_found, strlen(token_found))) {
same_line = newlines - 1 + same_line;
while (same_line-- > 0)
fout("\n");
if (tab) {
fout_version("\t");
fout("%s", token_found);
} else {
fout_version("%s", token_found);
}
// If you have a bunch of lines that all start with the same token (like, say, "+Subsystem:"),
// this makes it so it won't just repeatedly match the first one. -MageKing17
raw_ptr++;
if (version_added)
fso_comment_pop();
return;
}
if ((*raw_ptr == '/') && (raw_ptr[1] == '*')) {
comment_start = raw_ptr;
state = 1;
}
if ((*raw_ptr == ';') && (raw_ptr[1] != '!')) {
comment_start = raw_ptr;
state = 2;
// check for a FSO version comment, but if we can't understand it then
// just handle it as a regular comment
if ( (raw_ptr[1] == ';') && (raw_ptr[2] == 'F') && (raw_ptr[3] == 'S') && (raw_ptr[4] == 'O') ) {
int major, minor, build, revis;
int s_num = scan_fso_version_string(raw_ptr, &major, &minor, &build, &revis);
// hack for releases
if (FS_VERSION_REVIS < 1000) {
s_num = 3;
}
if ( (s_num == 3) && ((major < FS_VERSION_MAJOR) || ((major == FS_VERSION_MAJOR) && ((minor < FS_VERSION_MINOR) || ((minor == FS_VERSION_MINOR) && (build <= FS_VERSION_BUILD))))) ) {
state = 3;
} else if ( (s_num == 4) && ((major < FS_VERSION_MAJOR) || ((major == FS_VERSION_MAJOR) && ((minor < FS_VERSION_MINOR) || ((minor == FS_VERSION_MINOR) && ((build < FS_VERSION_BUILD) || ((build == FS_VERSION_BUILD) && (revis <= FS_VERSION_REVIS))))))) ) {
state = 3;
} else {
state = 4;
}
}
}
if (*raw_ptr == '\n')
flag = 1;
if (flag && state && !(state == 3) )
fout("\n");
} else {
if (*raw_ptr == '\n') {
if (state == 2) {
if (first_comment && !flag)
fout("\t\t");
*raw_ptr = 0;
fout("%s\n", comment_start);
*raw_ptr = '\n';
state = first_comment = same_line = flag = 0;
} else if (state == 4) {
same_line = newlines - 2 + same_line;
while (same_line-- > 0)
fout("\n");
if (*(raw_ptr-1) == '\r') {
*(raw_ptr-1) = '\0';
} else {
*raw_ptr = 0;
}
fout("%s\n", comment_start);
if (*(raw_ptr-1) == '\0') {
*(raw_ptr-1) = '\r';
} else {
*raw_ptr = '\n';
}
state = first_comment = same_line = flag = 0;
}
}
if ((*raw_ptr == '*') && (raw_ptr[1] == '/') && (state == 1)) {
if (first_comment && !flag)
fout("\t\t");
const char tmp = raw_ptr[2];
raw_ptr[2] = 0;
fout("%s", comment_start);
raw_ptr[2] = tmp;
state = first_comment = flag = 0;
}
if ( (*raw_ptr == ';') && (raw_ptr[1] == ';') && (state == 3) ) {
const char tmp = raw_ptr[2];
raw_ptr[2] = 0;
if (version_added)
fso_comment_pop();
else
version_added = true;
fso_comment_push(comment_start);
raw_ptr[2] = tmp;
state = first_comment = flag = 0;
raw_ptr++;
}
}
raw_ptr++;
}
if (version_added)
fso_comment_pop();
return;
}
int CFred_mission_save::fout_version(char *format, ...)
{
SCP_string str_scp;
char *ch = NULL;
va_list args;
if (err) {
return err;
}
// output the version first thing, but skip the special case where we use
// fout_version() for multiline value strings (typically indicated by an initial space)
if ( (Format_fs2_open == FSO_FORMAT_COMPATIBILITY_MODE) && (*format != ' ') && !fso_ver_comment.empty() ) {
while (*format == '\n') {
str_scp.append(1, *format);
format++;
}
str_scp.append(fso_ver_comment.back().c_str());
str_scp.append(" ");
cfputs(str_scp.c_str(), fp);
str_scp = "";
}
va_start(args, format);
vsprintf(str_scp, format, args);
va_end(args);
char *str_c = vm_strdup(str_scp.c_str());
// this could be a multi-line string, so we've got to handle it all properly
if ( (Format_fs2_open == FSO_FORMAT_COMPATIBILITY_MODE) && !fso_ver_comment.empty() ) {
bool first_line = true;
char *str_p = str_c;
ch = strchr(str_c, '\n');
// if we have something, and it's not just at the end, then process it specially
if ( (ch != NULL) && (*(ch+1) != '\0') ) {
do {
if ( *(ch+1) != '\0' ) {
*ch = '\0';
if (first_line) {
first_line = false;
} else {
cfputs(fso_ver_comment.back().c_str(), fp);
cfputs(" ", fp);
}
cfputs(str_p, fp);
cfputc('\n', fp);
str_p = ch+1;
} else {
if (first_line) {
first_line = false;
} else {
cfputs(fso_ver_comment.back().c_str(), fp);
cfputs(" ", fp);
}
cfputs(str_p, fp);
str_p = ch+1;
break;
}
} while ( (ch = strchr(str_p, '\n')) != NULL );
// be sure to account for any ending elements too
if ( strlen(str_p) ) {
cfputs(fso_ver_comment.back().c_str(), fp);
cfputs(" ", fp);
cfputs(str_p, fp);
}
vm_free(str_c);
return 0;
}
}
cfputs(str_c, fp);
vm_free(str_c);
return 0;
}
int CFred_mission_save::fout(char *format, ...)
{
SCP_string str;
va_list args;
if (err) {
return err;
}
va_start(args, format);
vsprintf(str, format, args);
va_end(args);
cfputs(str.c_str(), fp);
return 0;
}
int CFred_mission_save::fout_ext(char *pre_str, char *format, ...)
{
SCP_string str_scp;
SCP_string str_out_scp;
va_list args;
int str_id;
if (err){
return err;
}
va_start(args, format);
vsprintf(str_scp, format, args);
va_end(args);
if (pre_str) {
str_out_scp = pre_str;
}
// lookup the string in the hash table
str_id = fhash_string_exists(str_scp.c_str());
// doesn't exist, so assign it an ID of -1 and stick it in the table
if (str_id <= -2) {
str_out_scp += " XSTR(\"";
str_out_scp += str_scp;
str_out_scp += "\", -1)";
// add the string to the table
fhash_add_str(str_scp.c_str(), -1);
}
// _does_ exist, so just write it out as it is
else {
char buf[10];
sprintf(buf, "%d", str_id);
str_out_scp += " XSTR(\"";
str_out_scp += str_scp;
str_out_scp += "\", ";
str_out_scp += buf;
str_out_scp += ")";
}
char *str_out_c = vm_strdup(str_out_scp.c_str());
// this could be a multi-line string, so we've got to handle it all properly
if ( !fso_ver_comment.empty() ) {
bool first_line = true;
char *str_p = str_out_c;
char *ch = strchr(str_out_c, '\n');
// if we have something, and it's not just at the end, then process it specially
if ( (ch != NULL) && (*(ch+1) != '\0') ) {
do {
if ( *(ch+1) != '\0' ) {
*ch = '\0';
if (first_line) {
first_line = false;
} else {
cfputs(fso_ver_comment.back().c_str(), fp);
cfputs(" ", fp);
}
cfputs(str_p, fp);
cfputc('\n', fp);
str_p = ch+1;
} else {
if (first_line) {
first_line = false;
} else {
cfputs(fso_ver_comment.back().c_str(), fp);
cfputs(" ", fp);
}
cfputs(str_p, fp);
str_p = ch+1;
break;
}
} while ( (ch = strchr(str_p, '\n')) != NULL );
// be sure to account for any ending elements too
if ( strlen(str_p) ) {
cfputs(fso_ver_comment.back().c_str(), fp);
cfputs(" ", fp);
cfputs(str_p, fp);
}
vm_free(str_out_c);
return 0;
}
}
cfputs(str_out_c, fp);
vm_free(str_out_c);
return 0;
}
void CFred_mission_save::save_ai_goals(ai_goal *goalp, int ship)
{
char *str = NULL, buf[80];
int i, valid, flag = 1;
for (i=0; i<MAX_AI_GOALS; i++) {
if (goalp[i].ai_mode == AI_GOAL_NONE)
continue;
if (flag) {
if (optional_string_fred("$AI Goals:", "$Name:"))
parse_comments();
else
fout("\n$AI Goals:");
fout(" ( goals ");
flag = 0;
}
if (goalp[i].ai_mode == AI_GOAL_CHASE_ANY) {
fout("( ai-chase-any %d ) ", goalp[i].priority);
} else if (goalp[i].ai_mode == AI_GOAL_UNDOCK) {
fout("( ai-undock %d ) ", goalp[i].priority);
} else if (goalp[i].ai_mode == AI_GOAL_KEEP_SAFE_DISTANCE) {
fout("( ai-keep-safe-distance %d ) ", goalp[i].priority);
} else if (goalp[i].ai_mode == AI_GOAL_PLAY_DEAD) {
fout("( ai-play-dead %d ) ", goalp[i].priority);
} else if (goalp[i].ai_mode == AI_GOAL_WARP) {
fout("( ai-warp-out %d ) ", goalp[i].priority);
} else {
valid = 1;
if (!goalp[i].target_name) {
Warning(LOCATION, "Ai goal has no target where one is required");
} else {
sprintf(buf, "\"%s\"", goalp[i].target_name);
switch (goalp[i].ai_mode) {
case AI_GOAL_WAYPOINTS:
str = "ai-waypoints";
break;
case AI_GOAL_WAYPOINTS_ONCE:
str = "ai-waypoints-once";
break;
case AI_GOAL_DESTROY_SUBSYSTEM:
if (goalp[i].docker.index == -1 || !goalp[i].docker.index) {
valid = 0;
Warning(LOCATION, "AI destroy subsystem goal invalid subsystem name\n");
} else {
sprintf(buf, "\"%s\" \"%s\"", goalp[i].target_name, goalp[i].docker.name);
str = "ai-destroy-subsystem";
}
break;
case AI_GOAL_DOCK:
if (ship < 0) {
valid = 0;
Warning(LOCATION, "Wings aren't allowed to have a docking goal\n");
} else if (goalp[i].docker.index == -1 || !goalp[i].docker.index) {
valid = 0;
Warning(LOCATION, "AI dock goal for \"%s\" has invalid docker point "
"(docking with \"%s\")\n", Ships[ship].ship_name, goalp[i].target_name);
} else if (goalp[i].dockee.index == -1 || !goalp[i].dockee.index) {
valid = 0;
Warning(LOCATION, "AI dock goal for \"%s\" has invalid dockee point "
"(docking with \"%s\")\n", Ships[ship].ship_name, goalp[i].target_name);
} else {
sprintf(buf, "\"%s\" \"%s\" \"%s\"", goalp[i].target_name,
goalp[i].docker.name, goalp[i].dockee.name);
str = "ai-dock";
}
break;
case AI_GOAL_CHASE:
str = "ai-chase";
break;
case AI_GOAL_CHASE_WING:
str = "ai-chase-wing";
break;
case AI_GOAL_GUARD:
str = "ai-guard";
break;
case AI_GOAL_GUARD_WING:
str = "ai-guard-wing";
break;
case AI_GOAL_DISABLE_SHIP:
str = "ai-disable-ship";
break;
case AI_GOAL_DISARM_SHIP:
str = "ai-disarm-ship";
break;
case AI_GOAL_IGNORE:
str = "ai-ignore";
break;
case AI_GOAL_IGNORE_NEW:
str = "ai-ignore-new";
break;
case AI_GOAL_EVADE_SHIP:
str = "ai-evade-ship";
break;
case AI_GOAL_STAY_NEAR_SHIP:
str = "ai-stay-near-ship";
break;
case AI_GOAL_STAY_STILL:
str = "ai-stay-still";
break;
default:
Assert(0);
}
if (valid)
fout("( %s %s %d ) ", str, buf, goalp[i].priority);
}
}
fso_comment_pop();
}
if (!flag)
fout(")");
fso_comment_pop(true);
}
int CFred_mission_save::save_events()
{
SCP_string sexp_out;
int i, j, add_flag;
fred_parse_flag = 0;
required_string_fred("#Events");
parse_comments(2);
fout("\t\t;! %d total\n", Num_mission_events);
for (i=0; i<Num_mission_events; i++) {
required_string_either_fred("$Formula:", "#Goals");
required_string_fred("$Formula:");
parse_comments(i ? 2 : 1);
convert_sexp_to_string(sexp_out, Mission_events[i].formula, SEXP_SAVE_MODE);
fout(" %s", sexp_out.c_str());
if (*Mission_events[i].name) {
if (optional_string_fred("+Name:", "$Formula:")){
parse_comments();
} else {
fout("\n+Name:");
}
fout(" %s", Mission_events[i].name);
}
if ( optional_string_fred("+Repeat Count:", "$Formula:")){
parse_comments();
} else {
fout("\n+Repeat Count:");
}
// if we have a trigger count but no repeat count, we want the event to loop until it has triggered enough times
if ( Mission_events[i].repeat_count == 1 && Mission_events[i].trigger_count != 1) {
fout(" -1");
}
else {
fout(" %d", Mission_events[i].repeat_count);
}
if (Format_fs2_open != FSO_FORMAT_RETAIL && Mission_events[i].trigger_count != 1 ) {
fso_comment_push(";;FSO 3.6.11;;");
if ( optional_string_fred("+Trigger Count:", "$Formula:")){
parse_comments();
} else {
fout_version("\n+Trigger Count:");
}
fso_comment_pop();
fout(" %d", Mission_events[i].trigger_count);
}
if ( optional_string_fred("+Interval:", "$Formula:")){
parse_comments();
} else {
fout("\n+Interval:");
}
fout(" %d", Mission_events[i].interval);
if ( Mission_events[i].score != 0 ) {
if ( optional_string_fred("+Score:", "$Formula:")){
parse_comments();
} else {
fout("\n+Score:");
}
fout(" %d", Mission_events[i].score);
}
if ( Mission_events[i].chain_delay >= 0 ) {
if ( optional_string_fred("+Chained:", "$Formula:")){
parse_comments();
} else {
fout("\n+Chained:");
}
fout(" %d", Mission_events[i].chain_delay);
}
//XSTR
if (Mission_events[i].objective_text) {
if (optional_string_fred("+Objective:", "$Formula:")){
parse_comments();
} else {
fout("\n+Objective:");
}
fout_ext(" ", "%s", Mission_events[i].objective_text);
}
//XSTR
if (Mission_events[i].objective_key_text) {
if (optional_string_fred("+Objective key:", "$Formula:")){
parse_comments();
} else {
fout("\n+Objective key:");
}
fout_ext(" ", "%s", Mission_events[i].objective_key_text);
}
// save team
if (Mission_events[i].team >= 0){
if (optional_string_fred("+Team:")){
parse_comments();
} else {
fout("\n+Team:");
}
fout(" %d", Mission_events[i].team);
}
if (Format_fs2_open != FSO_FORMAT_RETAIL && Mission_events[i].mission_log_flags != 0 ) {
fso_comment_push(";;FSO 3.6.11;;");
if ( optional_string_fred("+Event Log Flags: (", "$Formula:")){
parse_comments();
} else {
fout_version("\n+Event Log Flags: (");
}
fso_comment_pop();
for (j = 0; j < MAX_MISSION_EVENT_LOG_FLAGS ; j++) {
add_flag = 1 << j;
if (Mission_events[i].mission_log_flags & add_flag ) {
fout(" \"%s\"", Mission_event_log_flags[j]);
}
}
fout(" )");
}
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_reinforcements()
{
int i, j, type;
fred_parse_flag = 0;
required_string_fred("#Reinforcements");
parse_comments(2);
fout("\t\t;! %d total\n", Num_reinforcements);
for (i=0; i<Num_reinforcements; i++) {
required_string_either_fred("$Name:", "#Background bitmaps");
required_string_fred("$Name:");
parse_comments(i ? 2 : 1);
fout(" %s", Reinforcements[i].name);
type = TYPE_ATTACK_PROTECT;
for (j=0; j<MAX_SHIPS; j++)
if ((Ships[j].objnum != -1) && !stricmp(Ships[j].ship_name, Reinforcements[i].name)) {
if (Ship_info[Ships[j].ship_info_index].flags & SIF_SUPPORT)
type = TYPE_REPAIR_REARM;
break;
}
required_string_fred("$Type:");
parse_comments();
fout(" %s", Reinforcement_type_names[type]);
required_string_fred("$Num times:");
parse_comments();
fout(" %d", Reinforcements[i].uses);
if ( optional_string_fred("+Arrival Delay:", "$Name:"))
parse_comments();
else
fout("\n+Arrival Delay:");
fout(" %d", Reinforcements[i].arrival_delay );
if (optional_string_fred("+No Messages:", "$Name:"))
parse_comments();
else
fout("\n+No Messages:");
fout(" (");
for (j = 0; j < MAX_REINFORCEMENT_MESSAGES; j++) {
if ( strlen(Reinforcements[i].no_messages[j]) )
fout(" \"%s\"", Reinforcements[i].no_messages[j]);
}
fout(" )");
if (optional_string_fred("+Yes Messages:", "$Name:"))
parse_comments();
else
fout("\n+Yes Messages:");
fout(" (");
for (j = 0; j < MAX_REINFORCEMENT_MESSAGES; j++) {
if ( strlen(Reinforcements[i].yes_messages[j]) )
fout(" \"%s\"", Reinforcements[i].yes_messages[j]);
}
fout(" )");
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_bitmaps()
{
int i;
uint j;
fred_parse_flag = 0;
required_string_fred("#Background bitmaps");
parse_comments(2);
fout("\t\t;! %d total\n", stars_get_num_bitmaps());
required_string_fred("$Num stars:");
parse_comments();
fout(" %d", Num_stars);
required_string_fred("$Ambient light level:");
parse_comments();
fout(" %d", The_mission.ambient_light_level);
// neb2 stuff
if(The_mission.flags & MISSION_FLAG_FULLNEB){
required_string_fred("+Neb2:");
parse_comments();
fout(" %s\n", Neb2_texture_name);
required_string_fred("+Neb2Flags:");
parse_comments();
fout(" %d\n", Neb2_poof_flags);
}
// neb 1 stuff
else {
if (Nebula_index >= 0) {
if (optional_string_fred("+Nebula:")){
parse_comments();
} else {
fout("\n+Nebula:");
}
fout(" %s", Nebula_filenames[Nebula_index]);
required_string_fred("+Color:");
parse_comments();
fout(" %s", Nebula_colors[Mission_palette]);
required_string_fred("+Pitch:");
parse_comments();
fout(" %d", Nebula_pitch);
required_string_fred("+Bank:");
parse_comments();
fout(" %d", Nebula_bank);
required_string_fred("+Heading:");
parse_comments();
fout(" %d", Nebula_heading);
}
}
fso_comment_pop();
// Goober5000 - save all but the lowest priority using the special comment tag
for (i = 0; i < Num_backgrounds; i++)
{
bool tag = (i < Num_backgrounds - 1);
background_t *background = &Backgrounds[i];
fso_comment_push(";;FSO 3.6.9;;");
if (optional_string_fred("$Bitmap List:")) {
parse_comments(2);
} else {
fout_version("\n\n$Bitmap List:");
}
if ( !tag ) {
fso_comment_pop(true);
}
// save suns by filename
for (j = 0; j < background->suns.size(); j++)
{
starfield_list_entry *sle = &background->suns[j];
// filename
required_string_fred("$Sun:");
parse_comments();
fout(" %s", sle->filename);
// angles
required_string_fred("+Angles:");
parse_comments();
fout(" %f %f %f", sle->ang.p, sle->ang.b, sle->ang.h);
// scale
required_string_fred("+Scale:");
parse_comments();
fout(" %f", sle->scale_x);
}
// save background bitmaps by filename
for (j = 0; j < background->bitmaps.size(); j++)
{
starfield_list_entry *sle = &background->bitmaps[j];
// filename
required_string_fred("$Starbitmap:");
parse_comments();
fout(" %s", sle->filename);
// angles
required_string_fred("+Angles:");
parse_comments();
fout(" %f %f %f", sle->ang.p, sle->ang.b, sle->ang.h);
// scale
required_string_fred("+ScaleX:");
parse_comments();
fout(" %f", sle->scale_x);
required_string_fred("+ScaleY:");
parse_comments();
fout(" %f", sle->scale_y);
// div
required_string_fred("+DivX:");
parse_comments();
fout(" %d", sle->div_x);
required_string_fred("+DivY:");
parse_comments();
fout(" %d", sle->div_y);
}
fso_comment_pop();
}
// taylor's environment map thingy
if (strlen(The_mission.envmap_name) > 0) { //-V805
fso_comment_push(";;FSO 3.6.9;;");
if (optional_string_fred("$Environment Map:")) {
parse_comments(2);
fout(" %s", The_mission.envmap_name);
} else {
fout_version("\n\n$Environment Map: %s", The_mission.envmap_name);
}
fso_comment_pop();
} else {
bypass_comment(";;FSO 3.6.9;; $Environment Map:");
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_asteroid_fields()
{
int i, idx;
fred_parse_flag = 0;
required_string_fred("#Asteroid Fields");
parse_comments(2);
for (i=0; i<1 /*MAX_ASTEROID_FIELDS*/; i++) {
if (!Asteroid_field.num_initial_asteroids)
continue;
required_string_fred("$Density:");
parse_comments(2);
fout(" %d", Asteroid_field.num_initial_asteroids);
// field type
if (optional_string_fred("+Field Type:")){
parse_comments();
} else {
fout("\n+Field Type:");
}
fout(" %d", Asteroid_field.field_type);
// debris type
if (optional_string_fred("+Debris Genre:")){
parse_comments();
} else {
fout("\n+Debris Genre:");
}
fout(" %d", Asteroid_field.debris_genre);
// field_debris_type (only if ship genre)
if (Asteroid_field.debris_genre == DG_SHIP) {
for (int idx=0; idx<3; idx++) {
if (Asteroid_field.field_debris_type[idx] != -1) {
if (optional_string_fred("+Field Debris Type:")){
parse_comments();
} else {
fout("\n+Field Debris Type:");
}
fout(" %d", Asteroid_field.field_debris_type[idx]);
}
}
} else {
// asteroid subtypes stored in field_debris_type as -1 or 1
for (idx=0; idx<3; idx++) {
if (Asteroid_field.field_debris_type[idx] != -1) {
if (optional_string_fred("+Field Debris Type:")){
parse_comments();
} else {
fout("\n+Field Debris Type:");
}
fout(" %d", idx);
}
}
}
required_string_fred("$Average Speed:");
parse_comments();
fout(" %f", vm_vec_mag(&Asteroid_field.vel));
required_string_fred("$Minimum:");
parse_comments();
save_vector(Asteroid_field.min_bound);
required_string_fred("$Maximum:");
parse_comments();
save_vector(Asteroid_field.max_bound);
if (Asteroid_field.has_inner_bound == 1) {
if (optional_string_fred("+Inner Bound:")){
parse_comments();
} else {
fout("\n+Inner Bound:");
}
required_string_fred("$Minimum:");
parse_comments();
save_vector(Asteroid_field.inner_min_bound);
required_string_fred("$Maximum:");
parse_comments();
save_vector(Asteroid_field.inner_max_bound);
}
fso_comment_pop();
}
fso_comment_pop(true);
return err;
}
int CFred_mission_save::save_music()
{
required_string_fred("#Music");
parse_comments(2);
required_string_fred("$Event Music:");
parse_comments(2);
if (Current_soundtrack_num < 0)
fout(" None");
else
fout(" %s", Soundtracks[Current_soundtrack_num].name);
// Goober5000 - save using the special comment prefix
if (stricmp(The_mission.substitute_event_music_name, "None")) {
fso_comment_push(";;FSO 3.6.9;;");
if (optional_string_fred("$Substitute Event Music:")) {
parse_comments(1);
fout(" %s", The_mission.substitute_event_music_name);
} else {
fout_version("\n$Substitute Event Music: %s", The_mission.substitute_event_music_name);
}
fso_comment_pop();
} else {
bypass_comment(";;FSO 3.6.9;; $Substitute Event Music:");
}
required_string_fred("$Briefing Music:");
parse_comments();
if (Mission_music[SCORE_BRIEFING] < 0)
fout(" None");
else
fout(" %s", Spooled_music[Mission_music[SCORE_BRIEFING]].name);
// Goober5000 - save using the special comment prefix
if (stricmp(The_mission.substitute_briefing_music_name, "None")) {
fso_comment_push(";;FSO 3.6.9;;");
if (optional_string_fred("$Substitute Briefing Music:")) {
parse_comments(1);
fout(" %s", The_mission.substitute_briefing_music_name);
} else {
fout_version("\n$Substitute Briefing Music: %s", The_mission.substitute_briefing_music_name);
}
fso_comment_pop();
} else {
bypass_comment(";;FSO 3.6.9;; $Substitute Briefing Music:");
}
// avoid keeping the old one around
bypass_comment(";;FSO 3.6.8;; $Substitute Music:");
// old stuff
if (Mission_music[SCORE_DEBRIEF_SUCCESS] != event_music_get_spooled_music_index("Success")) {
if (optional_string_fred("$Debriefing Success Music:")) {
parse_comments(1);
} else {
fout("\n$Debriefing Success Music:");
}
fout(" %s", Mission_music[SCORE_DEBRIEF_SUCCESS] < 0 ? "None" : Spooled_music[Mission_music[SCORE_DEBRIEF_SUCCESS]].name);
}
if (Mission_music[SCORE_DEBRIEF_AVERAGE] != event_music_get_spooled_music_index("Average")) {
if (optional_string_fred("$Debriefing Average Music:")) {
parse_comments(1);
} else {
fout("\n$Debriefing Average Music:");
}
fout(" %s", Mission_music[SCORE_DEBRIEF_AVERAGE] < 0 ? "None" : Spooled_music[Mission_music[SCORE_DEBRIEF_AVERAGE]].name);
}
if (Mission_music[SCORE_DEBRIEF_FAIL] != event_music_get_spooled_music_index("Failure")) {
if (optional_string_fred("$Debriefing Fail Music:")) {
parse_comments(1);
} else {
fout("\n$Debriefing Fail Music:");
}
fout(" %s", Mission_music[SCORE_DEBRIEF_FAIL] < 0 ? "None" : Spooled_music[Mission_music[SCORE_DEBRIEF_FAIL]].name);
}
// Goober5000 - save using the special comment prefix
if (mission_has_fiction() && Mission_music[SCORE_FICTION_VIEWER] >= 0) {
fso_comment_push(";;FSO 3.6.11;;");
if (optional_string_fred("$Fiction Viewer Music:")) {
parse_comments(1);
fout(" %s", Spooled_music[Mission_music[SCORE_FICTION_VIEWER]].name);
} else {
fout_version("\n$Fiction Viewer Music: %s", Spooled_music[Mission_music[SCORE_FICTION_VIEWER]].name);
}
fso_comment_pop();
} else {
bypass_comment(";;FSO 3.6.11;; $Fiction Viewer Music:");
}
fso_comment_pop(true);
return err;
}
void CFred_mission_save::save_custom_bitmap(const char *expected_string_640, const char *expected_string_1024, const char *string_field_640, const char *string_field_1024, int blank_lines)
{
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
if ((*string_field_640 != '\0') || (*string_field_1024 != '\0'))
{
while (blank_lines-- > 0)
fout("\n");
}
if (*string_field_640 != '\0')
{
fout("\n%s %s", expected_string_640, string_field_640);
}
if (*string_field_1024 != '\0')
{
fout("\n%s %s", expected_string_1024, string_field_1024);
}
}
}
void CFred_mission_save::save_turret_info(ship_subsys *ptr, int ship)
{
int i, z;
ship_weapon *wp = &ptr->weapons;
if (wp->ai_class != Ship_info[Ships[ship].ship_info_index].ai_class) {
if (optional_string_fred("+AI Class:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+AI Class:");
fout(" %s", Ai_class_names[wp->ai_class]);
}
z = 0;
i = wp->num_primary_banks;
while (i--)
if (wp->primary_bank_weapons[i] != ptr->system_info->primary_banks[i])
z = 1;
if (z) {
if (optional_string_fred("+Primary Banks:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+Primary Banks:");
fout(" ( ");
for (i=0; i<wp->num_primary_banks; i++) {
if (wp->primary_bank_weapons[i] != -1) { // Just in case someone has set a weapon bank to empty
fout("\"%s\" ", Weapon_info[wp->primary_bank_weapons[i]].name);
} else {
fout("\"\" ");
}
}
fout(")");
}
z = 0;
i = wp->num_secondary_banks;
while (i--)
if (wp->secondary_bank_weapons[i] != ptr->system_info->secondary_banks[i])
z = 1;
if (z) {
if (optional_string_fred("+Secondary Banks:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+Secondary Banks:");
fout(" ( ");
for (i=0; i<wp->num_secondary_banks; i++) {
if (wp->secondary_bank_weapons[i] != -1) {
fout("\"%s\" ", Weapon_info[wp->secondary_bank_weapons[i]].name);
} else {
fout("\"\" ");
}
}
fout(")");
}
z = 0;
i = wp->num_secondary_banks;
while (i--)
if (wp->secondary_bank_ammo[i] != 100)
z = 1;
if (z) {
if (optional_string_fred("+Sbank Ammo:", "$Name:", "+Subsystem:"))
parse_comments();
else
fout("\n+Sbank Ammo:");
fout(" ( ");
for (i=0; i<wp->num_secondary_banks; i++)
fout("%d ", wp->secondary_bank_ammo[i]);
fout(")");
}
fso_comment_pop(true);
}
int CFred_mission_save::save_campaign_file(char *pathname)
{
int i, j, m, flag;
Campaign_tree_formp->save_tree(); // flush all changes so they get saved.
Campaign_tree_viewp->sort_elements();
reset_parse();
fred_parse_flag = 0;
pathname = cf_add_ext(pathname, FS_CAMPAIGN_FILE_EXT);
fp = cfopen(pathname, "wt", CFILE_NORMAL, CF_TYPE_MISSIONS);
if (!fp) {
nprintf(("Error", "Can't open campaign file to save.\n"));
return -1;
}
required_string_fred("$Name:");
parse_comments(0);
fout(" %s", Campaign.name);
Assert((Campaign.type >= 0) && (Campaign.type < MAX_CAMPAIGN_TYPES));
required_string_fred("$Type:");
parse_comments();
fout(" %s", campaign_types[Campaign.type]);
// XSTR
if (Campaign.desc) {
required_string_fred("+Description:");
parse_comments();
fout_ext("\n", "%s", Campaign.desc);
fout("\n$end_multi_text");
}
if ( Campaign.type != CAMPAIGN_TYPE_SINGLE ) {
required_string_fred("+Num Players:");
parse_comments();
fout(" %d", Campaign.num_players);
}
// campaign flags - Goober5000
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
optional_string_fred("$Flags:");
parse_comments();
fout(" %d\n", Campaign.flags);
}
// write out the ships and weapons which the player can start the campaign with
optional_string_fred("+Starting Ships: (");
parse_comments(2);
for (i = 0; i < MAX_SHIP_CLASSES; i++ ) {
if ( Campaign.ships_allowed[i] )
fout(" \"%s\" ", Ship_info[i].name );
}
fout( ")\n" );
optional_string_fred("+Starting Weapons: (");
parse_comments();
for (i = 0; i < MAX_WEAPON_TYPES; i++ ) {
if ( Campaign.weapons_allowed[i] )
fout(" \"%s\" ", Weapon_info[i].name );
}
fout( ")\n" );
fred_parse_flag = 0;
for (i=0; i<Campaign.num_missions; i++) {
m = Sorted[i];
required_string_either_fred("$Mission:", "#End");
required_string_fred("$Mission:");
parse_comments(2);
fout(" %s", Campaign.missions[m].name);
if ( strlen(Campaign.missions[i].briefing_cutscene) ) {
if (optional_string_fred("+Briefing Cutscene:", "$Mission"))
parse_comments();
else
fout("\n+Briefing Cutscene:");
fout( " %s", Campaign.missions[i].briefing_cutscene );
}
required_string_fred("+Flags:", "$Mission:");
parse_comments();
// Goober5000
if (Format_fs2_open != FSO_FORMAT_RETAIL)
{
// don't save Bastion flag
fout(" %d", Campaign.missions[m].flags & ~CMISSION_FLAG_BASTION);
// new main hall stuff
if (optional_string_fred("+Main Hall:", "$Mission:"))
parse_comments();
else
fout("\n+Main Hall:");
fout(" %s", Campaign.missions[m].main_hall.c_str());
}
else
{
// save Bastion flag properly
fout(" %d", Campaign.missions[m].flags | ((Campaign.missions[m].main_hall != "") ? CMISSION_FLAG_BASTION : 0));
}
if ( Campaign.missions[m].debrief_persona_index > 0 ) {
fso_comment_push(";;FSO 3.6.8;;");
if (optional_string_fred("+Debriefing Persona Index:")) {
parse_comments(1);
fout(" %d", Campaign.missions[m].debrief_persona_index);
} else {
fout_version("\n+Debriefing Persona Index: %d", Campaign.missions[m].debrief_persona_index);
}
fso_comment_pop();
} else {
bypass_comment(";;FSO 3.6.8;; +Debriefing Persona Index:");
}
// save campaign link sexp
bool mission_loop = false;
bool mission_fork = false;
flag = 0;
for (j=0; j<Total_links; j++) {
if (Links[j].from == m) {
if (!flag) {
if (optional_string_fred("+Formula:", "$Mission:"))
parse_comments();
else
fout("\n+Formula:");
fout(" ( cond\n");
flag = 1;
}
//save_campaign_sexp(Links[j].sexp, Campaign.missions[Links[j].to].name);
if (Links[j].is_mission_loop) {
mission_loop = true;
} else if (Links[j].is_mission_fork) {
mission_fork = true;
} else {
save_campaign_sexp(Links[j].sexp, Links[j].to);
}
}
}
if (flag) {
fout(")");
}
// now save campaign loop sexp
if (mission_loop || mission_fork) {
if (mission_loop)
required_string_fred("\n+Mission Loop:");
else
required_string_fred("\n+Mission Fork:");
parse_comments();
int num_mission_special = 0;
for (j=0; j<Total_links; j++) {
if ( (Links[j].from == m) && (Links[j].is_mission_loop || Links[j].is_mission_fork) ) {
num_mission_special++;
if ((num_mission_special == 1) && Links[j].mission_branch_txt) {
if (mission_loop)
required_string_fred("+Mission Loop Text:");
else
required_string_fred("+Mission Fork Text:");
parse_comments();
fout_ext("\n", "%s", Links[j].mission_branch_txt);
fout("\n$end_multi_text");
}
if ((num_mission_special == 1) && Links[j].mission_branch_brief_anim) {
if (mission_loop)
required_string_fred("+Mission Loop Brief Anim:");
else
required_string_fred("+Mission Fork Brief Anim:");
parse_comments();
fout_ext("\n", "%s", Links[j].mission_branch_brief_anim);
fout("\n$end_multi_text");
}
if ((num_mission_special == 1) && Links[j].mission_branch_brief_sound) {
if (mission_loop)
required_string_fred("+Mission Loop Brief Sound:");
else
required_string_fred("+Mission Fork Brief Sound:");
parse_comments();
fout_ext("\n", "%s", Links[j].mission_branch_brief_sound);
fout("\n$end_multi_text");
}
if (num_mission_special == 1) {
// write out mission loop formula
fout("\n+Formula:");
fout(" ( cond\n");
save_campaign_sexp(Links[j].sexp, Links[j].to);
fout(")");
}
if (mission_fork) {
fout("Option: ", Campaign.missions[Links[j].to].name);
}
}
}
if (mission_loop && num_mission_special > 1) {
char buffer[1024];
sprintf(buffer, "Multiple branching loop error from mission %s\nEdit campaign for *at most* 1 loop from each mission.", Campaign.missions[m].name);
MessageBox((HWND)os_get_window(), buffer, "Error", MB_OK);
}
}
if (optional_string_fred("+Level:", "$Mission:")){
parse_comments();
} else {
fout("\n\n+Level:");
}
fout(" %d", Campaign.missions[m].level);
if (optional_string_fred("+Position:", "$Mission:")){
parse_comments();
} else {
fout("\n+Position:");
}
fout(" %d", Campaign.missions[m].pos);
fso_comment_pop();
}
required_string_fred("#End");
parse_comments(2);
token_found = NULL;
parse_comments();
fout("\n");
cfclose(fp);
if (err)
mprintf(("Campaign saving error code #%d\n", err));
else
Campaign_wnd->error_checker();
fso_comment_pop(true);
return err;
}
void CFred_mission_save::save_campaign_sexp(int node, int link_num)
{
SCP_string sexp_out;
Assert(node >= 0);
// if the link num is -1, then this is a end-of-campaign location
if ( link_num != -1 ) {
if (build_sexp_string(sexp_out, node, 2, SEXP_SAVE_MODE)) {
fout(" (\n %s\n ( next-mission \"%s\" )\n )\n", sexp_out.c_str(), Campaign.missions[link_num].name);
} else {
fout(" ( %s( next-mission \"%s\" ) )\n", sexp_out.c_str(), Campaign.missions[link_num].name);
}
} else {
if (build_sexp_string(sexp_out, node, 2, SEXP_SAVE_MODE)) {
fout(" (\n %s\n ( end-of-campaign )\n )\n", sexp_out.c_str());
} else {
fout(" ( %s( end-of-campaign ) )\n", sexp_out.c_str());
}
}
}
void CFred_mission_save::fso_comment_push(char *ver)
{
if ( fso_ver_comment.empty() ) {
fso_ver_comment.push_back( SCP_string(ver) );
return;
}
SCP_string before = fso_ver_comment.back();
int major, minor, build, revis;
int in_major, in_minor, in_build, in_revis;
int elem1, elem2;
elem1 = scan_fso_version_string( fso_ver_comment.back().c_str(), &major, &minor, &build, &revis );
elem2 = scan_fso_version_string( ver, &in_major, &in_minor, &in_build, &in_revis );
// check consistency
if (elem1 == 3 && elem2 == 4 || elem1 == 4 && elem2 == 3) {
elem1 = elem2 = 3;
} else if ((elem1 >= 3 && elem2 >= 3) && (revis < 1000 || in_revis < 1000)) {
elem1 = elem2 = 3;
}
if ( (elem1 == 3) && ((major > in_major) || ((major == in_major) && ((minor > in_minor) || ((minor == in_minor) && (build > in_build))))) ) {
// the push'd version is older than our current version, so just push a copy of the previous version
fso_ver_comment.push_back( before );
} else if ( (elem1 == 4) && ((major > in_major) || ((major == in_major) && ((minor > in_minor) || ((minor == in_minor) && ((build > in_build) || ((build == in_build) || (revis > in_revis))))))) ) {
// the push'd version is older than our current version, so just push a copy of the previous version
fso_ver_comment.push_back( before );
} else {
fso_ver_comment.push_back( SCP_string(ver) );
}
}
void CFred_mission_save::fso_comment_pop(bool pop_all)
{
if ( fso_ver_comment.empty() ) {
return;
}
if (pop_all) {
fso_ver_comment.clear();
return;
}
fso_ver_comment.pop_back();
}
|