1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785
|
/***********************************************************************
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
#ifdef HAVE_CONFIG_H
#include <fc_config.h>
#endif
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* utility */
#include "bitvector.h"
#include "deprecations.h"
#include "fcintl.h"
#include "log.h"
#include "mem.h"
#include "registry.h"
#include "shared.h"
#include "string_vector.h"
#include "support.h"
/* common */
#include "achievements.h"
#include "actions.h"
#include "ai.h"
#include "base.h"
#include "capability.h"
#include "city.h"
#include "counters.h"
#include "effects.h"
#include "extras.h"
#include "fc_types.h"
#include "featured_text.h"
#include "game.h"
#include "government.h"
#include "map.h"
#include "movement.h"
#include "multipliers.h"
#include "name_translation.h"
#include "nation.h"
#include "packets.h"
#include "player.h"
#include "requirements.h"
#include "rgbcolor.h"
#include "road.h"
#include "sex.h"
#include "specialist.h"
#include "style.h"
#include "tech.h"
#include "traderoutes.h"
#include "unit.h"
#include "unittype.h"
/* server */
#include "citytools.h"
#include "notify.h"
#include "plrhand.h"
#include "rscompat.h"
#include "rssanity.h"
#include "settings.h"
#include "srv_main.h"
/* server/advisors */
#include "advruleset.h"
/* server/scripting */
#include "script_server.h"
#include "ruleset.h"
/* RULESET_SUFFIX already used, no leading dot here */
#define RULES_SUFFIX "ruleset"
#define SCRIPT_SUFFIX "lua"
#define ADVANCE_SECTION_PREFIX "advance_"
#define TECH_CLASS_SECTION_PREFIX "techclass_"
#define BUILDING_SECTION_PREFIX "building_"
#define CITYSTYLE_SECTION_PREFIX "citystyle_"
#define MUSICSTYLE_SECTION_PREFIX "musicstyle_"
#define UEFF_SECTION_PREFIX "ueff_"
#define EFFECT_SECTION_PREFIX "effect_"
#define GOVERNMENT_SECTION_PREFIX "government_"
#define NATION_SET_SECTION_PREFIX "nset" /* without underscore? */
#define NATION_GROUP_SECTION_PREFIX "ngroup" /* without underscore? */
#define NATION_SECTION_PREFIX "nation" /* without underscore? */
#define STYLE_SECTION_PREFIX "style_"
#define CLAUSE_SECTION_PREFIX "clause_"
#define EXTRA_SECTION_PREFIX "extra_"
#define BASE_SECTION_PREFIX "base_"
#define ROAD_SECTION_PREFIX "road_"
#define RESOURCE_SECTION_PREFIX "resource_"
#define GOODS_SECTION_PREFIX "goods_"
#define SPECIALIST_SECTION_PREFIX "specialist_"
#define TERRAIN_SECTION_PREFIX "terrain_"
#define UNIT_CLASS_SECTION_PREFIX "unitclass_"
#define UNIT_SECTION_PREFIX "unit_"
#define DISASTER_SECTION_PREFIX "disaster_"
#define ACHIEVEMENT_SECTION_PREFIX "achievement_"
#define ACTION_ENABLER_SECTION_PREFIX "actionenabler_"
#define MULTIPLIER_SECTION_PREFIX "multiplier_"
#define COUNTER_SECTION_PREFIX "counter_"
#define check_name(name) (check_strlen(name, MAX_LEN_NAME, NULL))
#define check_cityname(name) (check_strlen(name, MAX_LEN_CITYNAME, NULL))
/* avoid re-reading files */
static const char name_too_long[] = "Name \"%s\" too long; truncating.";
#define MAX_SECTION_LABEL 64
#define section_strlcpy(dst, src) \
(void) loud_strlcpy(dst, src, MAX_SECTION_LABEL, name_too_long)
static char *resource_sections = NULL;
static char *terrain_sections = NULL;
static char *extra_sections = NULL;
static char *base_sections = NULL;
static char *road_sections = NULL;
static struct requirement_vector reqs_list;
static bool load_rulesetdir(const char *rsdir, bool compat_mode,
rs_conversion_logger logger,
bool act, bool buffer_script, bool load_luadata);
static struct section_file *openload_ruleset_file(const char *whichset,
const char *rsdir);
static bool load_game_names(struct section_file *file,
struct rscompat_info *compat);
static bool load_action_names(struct section_file *file,
struct rscompat_info *compat);
static bool load_tech_names(struct section_file *file,
struct rscompat_info *compat);
static bool load_unit_names(struct section_file *file,
struct rscompat_info *compat);
static bool load_building_names(struct section_file *file,
struct rscompat_info *compat);
static bool load_government_names(struct section_file *file,
struct rscompat_info *compat);
static bool load_terrain_names(struct section_file *file,
struct rscompat_info *compat);
static bool load_style_names(struct section_file *file,
struct rscompat_info *compat);
static bool load_nation_names(struct section_file *file,
struct rscompat_info *compat);
static bool load_city_name_list(struct section_file *file,
struct nation_type *pnation,
const char *secfile_str1,
const char *secfile_str2,
const char **allowed_terrains,
size_t atcount);
static bool load_ruleset_techs(struct section_file *file,
struct rscompat_info *compat);
static bool load_ruleset_units(struct section_file *file,
struct rscompat_info *compat);
static bool load_ruleset_buildings(struct section_file *file,
struct rscompat_info *compat);
static bool load_ruleset_governments(struct section_file *file,
struct rscompat_info *compat);
static bool load_ruleset_terrain(struct section_file *file,
struct rscompat_info *compat);
static bool load_ruleset_styles(struct section_file *file,
struct rscompat_info *compat);
static bool load_ruleset_cities(struct section_file *file,
struct rscompat_info *compat);
static bool load_ruleset_effects(struct section_file *file,
struct rscompat_info *compat);
static bool load_ruleset_game(struct section_file *file, bool act,
struct rscompat_info *compat);
static bool load_ruleset_actions(struct section_file *file,
struct section_file *gamefile,
struct rscompat_info *compat);
static void send_ruleset_tech_classes(struct conn_list *dest);
static void send_ruleset_techs(struct conn_list *dest);
static void send_ruleset_unit_classes(struct conn_list *dest);
static void send_ruleset_units(struct conn_list *dest);
static void send_ruleset_buildings(struct conn_list *dest);
static void send_ruleset_terrain(struct conn_list *dest);
static void send_ruleset_resources(struct conn_list *dest);
static void send_ruleset_extras(struct conn_list *dest);
static void send_ruleset_bases(struct conn_list *dest);
static void send_ruleset_roads(struct conn_list *dest);
static void send_ruleset_goods(struct conn_list *dest);
static void send_ruleset_governments(struct conn_list *dest);
static void send_ruleset_styles(struct conn_list *dest);
static void send_ruleset_clauses(struct conn_list *dest);
static void send_ruleset_musics(struct conn_list *dest);
static void send_ruleset_cities(struct conn_list *dest);
static void send_ruleset_game(struct conn_list *dest);
static void send_ruleset_team_names(struct conn_list *dest);
static bool load_ruleset_veteran(struct section_file *file,
const char *path,
struct veteran_system **vsystem, char *err,
size_t err_len);
static int secfile_lookup_int_default_min_max(struct section_file *file,
int def, int min, int max,
const char *path, ...)
fc__attribute((__format__ (__printf__, 5, 6)));
char *script_buffer = NULL;
char *parser_buffer = NULL;
/**********************************************************************//**
Notifications about ruleset errors to clients. Especially important in
case of internal server crashing.
**************************************************************************/
void ruleset_error_real(rs_conversion_logger logger,
const char *file, const char *function,
int line, enum log_level level,
const char *format, ...)
{
va_list args;
char buf[MAX_LEN_LOG_LINE];
if (logger == NULL && !log_do_output_for_level(level)) {
return;
}
va_start(args, format);
if (logger != NULL) {
fc_vsnprintf(buf, sizeof(buf), format, args);
logger(buf);
} else {
vdo_log(file, function, line, FALSE, level, buf, sizeof(buf), format, args);
}
va_end(args);
if (LOG_FATAL >= level) {
exit(EXIT_FAILURE);
}
}
/**********************************************************************//**
Purge unused action enablers from the ruleset.
**************************************************************************/
static int ruleset_purge_unused_enablers(void)
{
int purged = 0;
action_iterate(act_id) {
struct action *paction = action_by_number(act_id);
if (action_enabler_list_size(action_enablers_for_action(paction->id))
== 0) {
/* Not relevant. */
continue;
}
/* Impossible hard requirement. */
if (!action_is_in_use(paction)) {
/* Make sure that all action enablers are disabled. */
action_enabler_list_iterate(action_enablers_for_action(paction->id),
ae) {
ae->ruledit_disabled = TRUE;
purged++;
} action_enabler_list_iterate_end;
log_normal("Purged all action enablers for %s",
action_rule_name(paction));
}
/* Impossible requirement vector requirement. */
action_enabler_list_iterate(action_enablers_for_action(paction->id),
ae) {
if (!ae->ruledit_disabled
&& (!action_enabler_possible_actor(ae)
|| req_vec_is_impossible_to_fulfill(&ae->target_reqs))) {
ae->ruledit_disabled = TRUE;
purged++;
log_normal("Purged unused action enabler for %s",
action_rule_name(paction));
}
} action_enabler_list_iterate_end;
} action_iterate_end;
return purged;
}
/**********************************************************************//**
Purge unused effects from the ruleset.
**************************************************************************/
static int ruleset_purge_unused_effects(void)
{
int purged = 0;
enum effect_type type;
for (type = effect_type_begin(); type != effect_type_end();
type = effect_type_next(type)) {
effect_list_iterate(get_effects(type), eft) {
if (req_vec_is_impossible_to_fulfill(&eft->reqs)) {
eft->rulesave.do_not_save = TRUE;
purged++;
log_normal("Purged unused effect for %s",
effect_type_name(eft->type));
}
} effect_list_iterate_end;
}
return purged;
}
/**********************************************************************//**
Purge unused entities from the ruleset.
**************************************************************************/
int ruleset_purge_unused_entities(void)
{
int purged = 0;
purged += ruleset_purge_unused_enablers();
purged += ruleset_purge_unused_effects();
return purged;
}
/**********************************************************************//**
Purge the first unused requirement in a requirement vector.
@return TRUE if a requirement was purged.
**************************************************************************/
static bool purge_unused_req_vec(const struct requirement_vector *reqs,
const char *msg)
{
struct req_vec_problem *problem;
bool result;
problem = req_vec_get_first_missing_univ(reqs, req_vec_vector_number,
reqs);
if (problem == NULL) {
/* No problem. */
return FALSE;
}
if (problem->num_suggested_solutions == 0) {
/* No solution. */
req_vec_problem_free(problem);
return FALSE;
}
if (problem->num_suggested_solutions == 1
&& problem->suggested_solutions[0].operation == RVCO_REMOVE) {
/* Remove !present req that never is there. */
log_normal("%s", msg);
result = req_vec_change_apply(&problem->suggested_solutions[0],
req_vec_by_number, reqs);
req_vec_problem_free(problem);
return result;
}
/* Not handled. Don't know what this is. */
fc_assert(problem->num_suggested_solutions == 1);
req_vec_problem_free(problem);
return FALSE;
}
/**********************************************************************//**
Purge the first duplicate requirement in a requirement vector.
@return TRUE if a requirement was purged.
**************************************************************************/
static bool purge_duplicate_req_vec(const struct requirement_vector *reqs,
const char *msg)
{
struct req_vec_problem *problem;
bool result;
problem = req_vec_get_first_redundant_req(reqs, req_vec_vector_number,
reqs);
if (problem == NULL) {
/* No problem. */
return FALSE;
}
if (problem->num_suggested_solutions == 0) {
/* No solution. */
req_vec_problem_free(problem);
return FALSE;
}
if (problem->num_suggested_solutions == 2
&& problem->suggested_solutions[0].operation == RVCO_REMOVE
&& problem->suggested_solutions[1].operation == RVCO_REMOVE
&& are_requirements_equal(&problem->suggested_solutions[0].req,
&problem->suggested_solutions[1].req)) {
/* Simple duplication is handled. */
log_normal("%s", msg);
result = req_vec_change_apply(&problem->suggested_solutions[1],
req_vec_by_number, reqs);
req_vec_problem_free(problem);
return result;
}
/* Requirements of different kinds making each other redundant isn't
* supported yet. It could be done by always removing the most general
* requirement. So unit type is kept when redundant with unit flag, unit
* class and unit class flag etc. */
req_vec_problem_free(problem);
return FALSE;
}
/**********************************************************************//**
Purge the first redundant requirement in a requirement vector.
@return TRUE if a requirement was purged.
**************************************************************************/
static bool purge_redundant_req_vec(const struct requirement_vector *reqs,
const char *msg)
{
return (purge_unused_req_vec(reqs, msg)
|| purge_duplicate_req_vec(reqs, msg));
}
/**********************************************************************//**
Purge redundant requirements from action enablers.
@return the number of purged requirements.
**************************************************************************/
static int ruleset_purge_redundant_reqs_enablers(void)
{
int purged = 0;
action_iterate(act_id) {
struct action *paction = action_by_number(act_id);
char actor_reqs[MAX_LEN_NAME * 2];
char target_reqs[MAX_LEN_NAME * 2];
/* Error log text */
fc_snprintf(actor_reqs, sizeof(actor_reqs),
"Purged redundant requirement in"
" %s in action enabler for %s",
"actor_reqs", action_rule_name(paction));
fc_snprintf(target_reqs, sizeof(target_reqs),
"Purged redundant requirement in"
" %s in action enabler for %s",
"target_reqs", action_rule_name(paction));
/* Do the purging. */
action_enabler_list_iterate(action_enablers_for_action(paction->id),
ae) {
while (!ae->ruledit_disabled
&& (purge_redundant_req_vec(&ae->actor_reqs, actor_reqs)
|| purge_redundant_req_vec(&ae->target_reqs,
target_reqs))) {
purged++;
}
} action_enabler_list_iterate_end;
} action_iterate_end;
return purged;
}
/**********************************************************************//**
Purge redundant requirements from effects.
@return the number of purged requirements.
**************************************************************************/
static int ruleset_purge_redundant_reqs_effects(void)
{
int purged = 0;
enum effect_type type;
for (type = effect_type_begin(); type != effect_type_end();
type = effect_type_next(type)) {
char msg[MAX_LEN_NAME * 2];
/* Error log text */
fc_snprintf(msg, sizeof(msg),
"Purged redundant requirement in effect of type %s",
effect_type_name(type));
/* Do the purging. */
effect_list_iterate(get_effects(type), eft) {
while (purge_redundant_req_vec(&eft->reqs, msg)) {
purged++;
}
} effect_list_iterate_end;
}
return purged;
}
/**********************************************************************//**
Purge redundant requirement in requirement vectors.
@return the number of purged requirements.
**************************************************************************/
int ruleset_purge_redundant_reqs(void)
{
int purged = 0;
purged += ruleset_purge_redundant_reqs_enablers();
purged += ruleset_purge_redundant_reqs_effects();
if (purged > 0) {
/* An unused requirement may be an obligatory hard requirement. */
rscompat_enablers_add_obligatory_hard_reqs();
}
return purged;
}
/**********************************************************************//**
datafilename() wrapper: tries to match in two ways.
Returns NULL on failure, the (statically allocated) filename on success.
**************************************************************************/
static const char *valid_ruleset_filename(const char *subdir,
const char *name,
const char *extension,
bool optional)
{
char filename[512];
const char *dfilename;
fc_assert_ret_val(subdir && name && extension, NULL);
fc_snprintf(filename, sizeof(filename), "%s" DIR_SEPARATOR "%s.%s",
subdir, name, extension);
log_verbose("Trying \"%s\".", filename);
dfilename = fileinfoname(get_data_dirs(), filename);
if (dfilename) {
return dfilename;
}
fc_snprintf(filename, sizeof(filename), "default" DIR_SEPARATOR "%s.%s", name, extension);
log_verbose("Trying \"%s\": default ruleset directory.", filename);
dfilename = fileinfoname(get_data_dirs(), filename);
if (dfilename) {
return dfilename;
}
fc_snprintf(filename, sizeof(filename), "%s_%s.%s",
subdir, name, extension);
log_verbose("Trying \"%s\": alternative ruleset filename syntax.",
filename);
dfilename = fileinfoname(get_data_dirs(), filename);
if (dfilename) {
return dfilename;
} else if (!optional) {
ruleset_error(NULL, LOG_ERROR,
/* TRANS: message about an installation error. */
_("Could not find a readable \"%s.%s\" ruleset file."),
name, extension);
}
return NULL;
}
/**********************************************************************//**
Return current script.lua buffer.
**************************************************************************/
char *get_script_buffer(void)
{
return script_buffer;
}
/**********************************************************************//**
Return current parser.lua buffer.
**************************************************************************/
char *get_parser_buffer(void)
{
return parser_buffer;
}
/**********************************************************************//**
Do initial section_file_load on a ruleset file.
"whichset" = "techs", "units", "buildings", "terrain", ...
**************************************************************************/
static struct section_file *openload_ruleset_file(const char *whichset,
const char *rsdir)
{
char sfilename[512];
const char *dfilename = valid_ruleset_filename(rsdir, whichset,
RULES_SUFFIX, FALSE);
struct section_file *secfile;
if (dfilename == NULL) {
return NULL;
}
/* Need to save a copy of the filename for following message, since
section_file_load() may call datafilename() for includes. */
sz_strlcpy(sfilename, dfilename);
secfile = secfile_load(sfilename, FALSE);
if (secfile == NULL) {
ruleset_error(NULL, LOG_ERROR, "Could not load ruleset '%s':\n%s",
sfilename, secfile_error());
}
return secfile;
}
/**********************************************************************//**
Parse script file.
**************************************************************************/
static enum fc_tristate openload_script_file(const char *whichset, const char *rsdir,
char **buffer, bool optional)
{
const char *dfilename = valid_ruleset_filename(rsdir, whichset,
SCRIPT_SUFFIX, optional);
if (dfilename == NULL) {
return optional ? TRI_MAYBE : TRI_NO;
}
if (buffer == NULL) {
if (!script_server_do_file(NULL, dfilename)) {
ruleset_error(NULL, LOG_ERROR, "\"%s\": could not load ruleset script.",
dfilename);
return TRI_NO;
}
} else {
script_server_load_file(dfilename, buffer);
}
return TRI_YES;
}
/**********************************************************************//**
Load optional luadata.txt
**************************************************************************/
static struct section_file *openload_luadata_file(const char *rsdir)
{
struct section_file *secfile;
char sfilename[512];
const char *dfilename = valid_ruleset_filename(rsdir, "luadata",
"txt", TRUE);
if (dfilename == NULL) {
return NULL;
}
/* Need to save a copy of the filename for following message, since
section_file_load() may call datafilename() for includes. */
sz_strlcpy(sfilename, dfilename);
secfile = secfile_load(sfilename, FALSE);
if (secfile == NULL) {
ruleset_error(NULL, LOG_ERROR, "Could not load luadata '%s':\n%s",
sfilename, secfile_error());
}
return secfile;
}
/**********************************************************************//**
Load a requirement list. The list is returned as a static vector
(callers need not worry about freeing anything).
**************************************************************************/
struct requirement_vector *lookup_req_list(struct section_file *file,
struct rscompat_info *compat,
const char *sec,
const char *sub,
const char *rfor)
{
const char *type, *name;
int j;
const char *filename;
filename = secfile_name(file);
requirement_vector_reserve(&reqs_list, 0);
for (j = 0; (type = secfile_lookup_str_default(file, NULL, "%s.%s%d.type",
sec, sub, j)); j++) {
char buf[MAX_LEN_NAME];
const char *range;
bool survives, present, quiet;
struct entry *pentry;
struct requirement req;
if (!(pentry = secfile_entry_lookup(file, "%s.%s%d.name",
sec, sub, j))) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
return NULL;
}
name = NULL;
switch (entry_type_get(pentry)) {
case ENTRY_BOOL:
{
bool val;
if (entry_bool_get(pentry, &val)) {
fc_snprintf(buf, sizeof(buf), "%d", val);
name = buf;
}
}
break;
case ENTRY_INT:
{
int val;
if (entry_int_get(pentry, &val)) {
fc_snprintf(buf, sizeof(buf), "%d", val);
name = buf;
}
}
break;
case ENTRY_STR:
(void) entry_str_get(pentry, &name);
break;
case ENTRY_FLOAT:
fc_assert(entry_type_get(pentry) != ENTRY_FLOAT);
ruleset_error(NULL, LOG_ERROR,
"\"%s\": trying to have an floating point entry as a requirement name in '%s.%s%d'.",
filename, sec, sub, j);
break;
case ENTRY_FILEREFERENCE:
fc_assert(entry_type_get(pentry) != ENTRY_FILEREFERENCE);
break;
case ENTRY_LONG_COMMENT:
fc_assert(entry_type_get(pentry) != ENTRY_LONG_COMMENT);
break;
case ENTRY_ILLEGAL:
fc_assert(entry_type_get(pentry) != ENTRY_ILLEGAL);
break;
}
if (NULL == name) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": error in handling requirement name for '%s.%s%d'.",
filename, sec, sub, j);
return NULL;
}
if (!(range = secfile_lookup_str(file, "%s.%s%d.range", sec, sub, j))) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
return NULL;
}
if (compat->compat_mode) {
range = rscompat_req_range_3_2(compat, type, range);
}
survives = FALSE;
if ((pentry = secfile_entry_lookup(file, "%s.%s%d.survives",
sec, sub, j))
&& !entry_bool_get(pentry, &survives)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": invalid boolean value for survives for "
"'%s.%s%d'.", filename, sec, sub, j);
}
present = TRUE;
if ((pentry = secfile_entry_lookup(file, "%s.%s%d.present",
sec, sub, j))
&& !entry_bool_get(pentry, &present)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": invalid boolean value for present for "
"'%s.%s%d'.", filename, sec, sub, j);
}
quiet = FALSE;
if ((pentry = secfile_entry_lookup(file, "%s.%s%d.quiet",
sec, sub, j))
&& !entry_bool_get(pentry, &quiet)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": invalid boolean value for quiet for "
"'%s.%s%d'.", filename, sec, sub, j);
}
if (compat->compat_mode) {
rscompat_req_adjust_3_2(compat, &type, &name, &present, sec);
}
req = req_from_str(type, range, survives, present, quiet, name);
if (req.source.kind == universals_n_invalid()) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] has invalid or unknown req: "
"\"%s\" \"%s\".",
filename, sec, type, name);
return NULL;
}
requirement_vector_append(&reqs_list, req);
}
if (j > MAX_NUM_REQS) {
ruleset_error(NULL, LOG_ERROR,
"Too many (%d) requirements for %s. Max is %d",
j, rfor, MAX_NUM_REQS);
return NULL;
}
return &reqs_list;
}
/**********************************************************************//**
Load combat bonus list
**************************************************************************/
static bool lookup_cbonus_list(struct combat_bonus_list *list,
struct section_file *file,
const char *sec,
const char *sub)
{
const char *flag;
int j;
const char *filename;
bool success = TRUE;
filename = secfile_name(file);
for (j = 0; (flag = secfile_lookup_str_default(file, NULL, "%s.%s%d.flag",
sec, sub, j)); j++) {
struct combat_bonus *bonus = fc_malloc(sizeof(*bonus));
const char *type;
bonus->flag = unit_type_flag_id_by_name(flag, fc_strcasecmp);
if (!unit_type_flag_id_is_valid(bonus->flag)) {
log_error("\"%s\": unknown flag name \"%s\" in '%s.%s'.",
filename, flag, sec, sub);
FC_FREE(bonus);
success = FALSE;
continue;
}
type = secfile_lookup_str(file, "%s.%s%d.type", sec, sub, j);
bonus->type = combat_bonus_type_by_name(type, fc_strcasecmp);
if (!combat_bonus_type_is_valid(bonus->type)) {
log_error("\"%s\": unknown bonus type \"%s\" in '%s.%s'.",
filename, type, sec, sub);
FC_FREE(bonus);
success = FALSE;
continue;
}
if (!secfile_lookup_int(file, &bonus->value, "%s.%s%d.value",
sec, sub, j)) {
log_error("\"%s\": failed to get value from '%s.%s%d'.",
filename, sec, sub, j);
FC_FREE(bonus);
success = FALSE;
continue;
}
bonus->quiet = secfile_lookup_bool_default(file, FALSE,
"%s.%s%d.quiet",
sec, sub, j);
combat_bonus_list_append(list, bonus);
}
return success;
}
/**********************************************************************//**
Lookup a string prefix.entry in the file and return the corresponding
advances pointer. If (!required), return A_NEVER for match "Never" or
can't match. If (required), die when can't match. Note the first tech
should have name "None" so that will always match.
If description is not NULL, it is used in the warning message
instead of prefix (eg pass unit->name instead of prefix="units2.u27")
**************************************************************************/
static bool lookup_tech(struct section_file *file,
struct advance **result,
const char *prefix, const char *entry,
const char *filename,
const char *description)
{
const char *sval;
sval = secfile_lookup_str_default(file, NULL, "%s.%s", prefix, entry);
if (!sval || !strcmp(sval, "Never")) {
*result = A_NEVER;
} else {
*result = advance_by_rule_name(sval);
if (A_NEVER == *result) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" %s %s: couldn't match \"%s\".",
filename, (description ? description : prefix), entry, sval);
return FALSE;
}
}
return TRUE;
}
/**********************************************************************//**
Lookup a string prefix.entry in the file and return the corresponding
improvement pointer. Return B_NEVER for match "None" or
can't match.
If description is not NULL, it is used in the warning message
instead of prefix (eg pass unit->name instead of prefix="units2.u27")
**************************************************************************/
static bool lookup_building(struct section_file *file,
const char *prefix, const char *entry,
struct impr_type **result,
const char *filename,
const char *description)
{
const char *sval;
bool ok = TRUE;
sval = secfile_lookup_str_default(file, NULL, "%s.%s", prefix, entry);
if (!sval || strcmp(sval, "None") == 0) {
*result = B_NEVER;
} else {
*result = improvement_by_rule_name(sval);
if (B_NEVER == *result) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" %s %s: couldn't match \"%s\".",
filename, (description ? description : prefix), entry, sval);
ok = FALSE;
}
}
return ok;
}
/**********************************************************************//**
Lookup a prefix.entry string vector in the file and fill in the
array, which should hold MAX_NUM_UNIT_LIST items. The output array is
either NULL terminated or full (contains MAX_NUM_UNIT_LIST
items). If the vector is not found and the required parameter is set,
we report it as an error, otherwise we just punt.
**************************************************************************/
static bool lookup_unit_list(struct section_file *file, const char *prefix,
const char *entry,
struct unit_type **output,
const char *filename)
{
const char **slist;
size_t nval;
int i;
bool ok = TRUE;
/* pre-fill with NULL: */
for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
output[i] = NULL;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
if (nval == 0) {
/* 'No vector' is considered same as empty vector */
if (slist != NULL) {
free(slist);
}
return TRUE;
}
if (nval > MAX_NUM_UNIT_LIST) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": string vector %s.%s too long (%d, max %d)",
filename, prefix, entry, (int) nval, MAX_NUM_UNIT_LIST);
ok = FALSE;
} else if (nval == 1 && strcmp(slist[0], "") == 0) {
free(slist);
return TRUE;
}
if (ok) {
for (i = 0; i < nval; i++) {
const char *sval = slist[i];
struct unit_type *punittype = unit_type_by_rule_name(sval);
if (!punittype) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" %s.%s (%d): couldn't match \"%s\".",
filename, prefix, entry, i, sval);
ok = FALSE;
break;
}
output[i] = punittype;
log_debug("\"%s\" %s.%s (%d): %s (%d)", filename, prefix, entry, i, sval,
utype_number(punittype));
}
}
free(slist);
return ok;
}
/**********************************************************************//**
Lookup a prefix.entry string vector in the file and fill in the
array, which should hold MAX_NUM_TECH_LIST items. The output array is
either A_LAST terminated or full (contains MAX_NUM_TECH_LIST
items). All valid entries of the output array are guaranteed to
exist.
**************************************************************************/
static bool lookup_tech_list(struct section_file *file, const char *prefix,
const char *entry, int *output,
const char *filename)
{
const char **slist;
size_t nval;
int i;
bool ok = TRUE;
/* pre-fill with A_LAST: */
for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
output[i] = A_LAST;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
if (slist == NULL || nval == 0) {
return TRUE;
} else if (nval > MAX_NUM_TECH_LIST) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": string vector %s.%s too long (%d, max %d)",
filename, prefix, entry, (int) nval, MAX_NUM_TECH_LIST);
ok = FALSE;
}
if (ok) {
if (nval == 1 && strcmp(slist[0], "") == 0) {
FC_FREE(slist);
return TRUE;
}
for (i = 0; i < nval && ok; i++) {
const char *sval = slist[i];
struct advance *padvance = advance_by_rule_name(sval);
if (NULL == padvance) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" %s.%s (%d): couldn't match \"%s\".",
filename, prefix, entry, i, sval);
ok = FALSE;
}
if (!valid_advance(padvance)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" %s.%s (%d): \"%s\" is removed.",
filename, prefix, entry, i, sval);
ok = FALSE;
}
if (ok) {
output[i] = advance_number(padvance);
log_debug("\"%s\" %s.%s (%d): %s (%d)", filename, prefix, entry, i, sval,
advance_number(padvance));
}
}
}
FC_FREE(slist);
return ok;
}
/**********************************************************************//**
Lookup a prefix.entry string vector in the file and fill in the
array, which should hold MAX_NUM_BUILDING_LIST items. The output array is
either B_LAST terminated or full (contains MAX_NUM_BUILDING_LIST
items). [All valid entries of the output array are guaranteed to pass
improvement_exist()?]
**************************************************************************/
static bool lookup_building_list(struct section_file *file,
const char *prefix, const char *entry,
int *output, const char *filename)
{
const char **slist;
size_t nval;
int i;
bool ok = TRUE;
/* pre-fill with B_LAST: */
for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
output[i] = B_LAST;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
if (nval > MAX_NUM_BUILDING_LIST) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": string vector %s.%s too long (%d, max %d)",
filename, prefix, entry, (int) nval, MAX_NUM_BUILDING_LIST);
ok = FALSE;
} else if (nval == 0 || (nval == 1 && strcmp(slist[0], "") == 0)) {
if (slist != NULL) {
FC_FREE(slist);
}
return TRUE;
}
if (ok) {
for (i = 0; i < nval; i++) {
const char *sval = slist[i];
struct impr_type *pimprove = improvement_by_rule_name(sval);
if (NULL == pimprove) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" %s.%s (%d): couldn't match \"%s\".",
filename, prefix, entry, i, sval);
ok = FALSE;
break;
}
output[i] = improvement_number(pimprove);
log_debug("%s.%s,%d %s %d", prefix, entry, i, sval, output[i]);
}
}
free(slist);
return ok;
}
/**********************************************************************//**
Lookup a string prefix.entry in the file and set result to the
corresponding unit_type.
If description is not NULL, it is used in the warning message
instead of prefix (eg pass unit->name instead of prefix="units2.u27")
**************************************************************************/
static bool lookup_unit_type(struct section_file *file,
const char *prefix,
const char *entry,
const struct unit_type **result,
const char *filename,
const char *description)
{
const char *sval;
sval = secfile_lookup_str_default(file, "None", "%s.%s", prefix, entry);
if (strcmp(sval, "None") == 0) {
*result = NULL;
} else {
*result = unit_type_by_rule_name(sval);
if (*result == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" %s %s: couldn't match \"%s\".",
filename, (description ? description : prefix), entry, sval);
return FALSE;
}
}
return TRUE;
}
/**********************************************************************//**
Lookup entry in the file and return the corresponding government index.
filename is for error message.
**************************************************************************/
static struct government *lookup_government(struct section_file *file,
const char *entry,
const char *filename,
struct government *fallback)
{
const char *sval;
struct government *gov;
sval = secfile_lookup_str_default(file, NULL, "%s", entry);
if (!sval) {
gov = fallback;
} else {
gov = government_by_rule_name(sval);
}
if (!gov) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" %s: couldn't match \"%s\".",
filename, entry, sval);
}
return gov;
}
/**********************************************************************//**
Lookup optional string, returning allocated memory or NULL.
**************************************************************************/
static char *lookup_string(struct section_file *file, const char *prefix,
const char *suffix)
{
const char *sval = secfile_lookup_str(file, "%s.%s", prefix, suffix);
if (NULL != sval) {
char copy[strlen(sval) + 1];
strcpy(copy, sval);
remove_leading_trailing_spaces(copy);
if (strlen(copy) > 0) {
return fc_strdup(copy);
}
}
return NULL;
}
/**********************************************************************//**
Lookup optional string vector, returning allocated memory or NULL.
**************************************************************************/
static struct strvec *lookup_strvec(struct section_file *file,
const char *prefix, const char *suffix)
{
size_t dim;
const char **vec = secfile_lookup_str_vec(file, &dim,
"%s.%s", prefix, suffix);
if (NULL != vec) {
struct strvec *dest = strvec_new();
strvec_store(dest, vec, dim);
free(vec);
return dest;
}
return NULL;
}
/**********************************************************************//**
Look up the resource section name and return its pointer.
**************************************************************************/
static struct extra_type *lookup_resource(const char *filename,
const char *name,
const char *jsection)
{
struct extra_type *pres;
pres = extra_type_by_rule_name(name);
if (pres == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] has unknown \"%s\".",
filename, jsection, name);
}
return pres;
}
/**********************************************************************//**
Look up the terrain by name and return its pointer.
filename is for error message.
**************************************************************************/
static bool lookup_terrain(struct section_file *file,
const char *entry,
const char *filename,
struct terrain *pthis,
struct terrain **result,
bool null_acceptable)
{
const int j = terrain_index(pthis);
const char *jsection = &terrain_sections[j * MAX_SECTION_LABEL];
const char *name = secfile_lookup_str(file, "%s.%s", jsection, entry);
struct terrain *pterr;
if (NULL == name && !null_acceptable) {
return FALSE;
}
if (NULL == name
|| *name == '\0'
|| (0 == strcmp(name, "none"))
|| (0 == strcmp(name, "no"))) {
*result = T_NONE;
return TRUE;
}
if (0 == strcmp(name, "yes")) {
*result = pthis;
return TRUE;
}
pterr = terrain_by_rule_name(name);
*result = pterr;
if (pterr == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] has unknown \"%s\".",
secfile_name(file), jsection, name);
return FALSE;
}
return TRUE;
}
/**********************************************************************//**
Look up a value comparable to activity_count (road_time, etc).
item_name describes the thing which has the time property, if non-NULL,
for any error message.
Returns FALSE if not found in secfile, but TRUE even if validation failed.
Sets *ok to FALSE if validation failed, leaves it alone otherwise.
**************************************************************************/
bool lookup_time(const struct section_file *secfile, int *turns,
const char *sec_name, const char *property_name,
const char *filename, const char *item_name,
bool *ok)
{
/* Assumes that PACKET_UNIT_INFO.activity_count in packets.def is UINT16 */
const int max_turns = 65535 / ACTIVITY_FACTOR;
if (!secfile_lookup_int(secfile, turns, "%s.%s", sec_name, property_name)) {
return FALSE;
}
if (*turns > max_turns) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": \"%s\": \"%s\" value %d too large (max %d)",
filename, item_name ? item_name : sec_name,
property_name, *turns, max_turns);
*ok = FALSE;
}
return TRUE; /* we found _something */
}
/**********************************************************************//**
Load "name" and (optionally) "rule_name" into a struct name_translation.
**************************************************************************/
static bool ruleset_load_names(struct name_translation *pname,
const char *domain,
struct section_file *file,
const char *sec_name)
{
const char *name = secfile_lookup_str(file, "%s.name", sec_name);
const char *rule_name = secfile_lookup_str(file, "%s.rule_name", sec_name);
if (!name) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s]: no \"name\" specified.",
secfile_name(file), sec_name);
return FALSE;
}
names_set(pname, domain, name, rule_name);
return TRUE;
}
/**********************************************************************//**
Load trait values to array.
**************************************************************************/
static void ruleset_load_traits(struct trait_limits *out,
struct section_file *file,
const char *secname, const char *field_prefix)
{
enum trait tr;
/* FIXME: Use specenum trait names without duplicating them here.
* Just needs to take care of case.
* This list is also duplicated in rulesave.c:save_traits() */
const char *trait_names[] = {
"expansionist",
"trader",
"aggressive",
"builder",
NULL
};
for (tr = trait_begin(); tr != trait_end() && trait_names[tr] != NULL; tr = trait_next(tr)) {
out[tr].min = secfile_lookup_int_default(file, -1, "%s.%s%s_min",
secname,
field_prefix,
trait_names[tr]);
out[tr].max = secfile_lookup_int_default(file, -1, "%s.%s%s_max",
secname,
field_prefix,
trait_names[tr]);
out[tr].fixed = secfile_lookup_int_default(file, -1, "%s.%s%s_default",
secname,
field_prefix,
trait_names[tr]);
}
fc_assert(tr == trait_end()); /* number of trait_names correct */
}
/**********************************************************************//**
Load names from game.ruleset so other rulesets can refer to objects
with their name.
**************************************************************************/
static bool load_game_names(struct section_file *file,
struct rscompat_info *compat)
{
struct section_list *sec;
int nval;
const char *filename = secfile_name(file);
bool ok = TRUE;
/* section: datafile */
compat->version = rscompat_check_capabilities(file, filename, compat);
if (compat->version <= 0) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
sec = secfile_sections_by_name_prefix(file, ACHIEVEMENT_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
if (nval > MAX_ACHIEVEMENT_TYPES) {
int num = nval; /* No "size_t" to printf */
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many achievement types (%d, max %d)",
filename, num, MAX_ACHIEVEMENT_TYPES);
ok = FALSE;
} else {
game.control.num_achievement_types = nval;
}
if (ok) {
achievements_iterate(pach) {
const char *sec_name = section_name(section_list_get(sec, achievement_index(pach)));
if (!ruleset_load_names(&pach->name, NULL, file, sec_name)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Cannot load achievement names",
filename);
ok = FALSE;
break;
}
} achievements_iterate_end;
}
section_list_destroy(sec);
if (ok) {
sec = secfile_sections_by_name_prefix(file, GOODS_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
if (nval > MAX_GOODS_TYPES) {
int num = nval; /* No "size_t" to printf */
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many goods types (%d, max %d)",
filename, num, MAX_GOODS_TYPES);
section_list_destroy(sec);
ok = FALSE;
} else if (nval < 1) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": At least one goods type needed",
filename);
section_list_destroy(sec);
ok = FALSE;
} else {
game.control.num_goods_types = nval;
}
if (ok) {
goods_type_iterate(pgood) {
const char *sec_name
= section_name(section_list_get(sec, goods_index(pgood)));
if (!ruleset_load_names(&pgood->name, NULL, file, sec_name)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Cannot load goods names",
filename);
ok = FALSE;
break;
}
} goods_type_iterate_end;
}
section_list_destroy(sec);
}
if (ok) {
sec = secfile_sections_by_name_prefix(file, COUNTER_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
if (nval > MAX_COUNTERS) {
size_t num = nval;
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many counters (" SIZE_T_PRINTF ", max %d)",
filename, num, MAX_COUNTERS);
ok = FALSE;
}
if (ok) {
int count_idx;
game.control.num_counters = nval;
for (count_idx = 0; count_idx < nval; count_idx++) {
struct counter *pcount = counter_by_id(count_idx);
const char *sec_name
= section_name(section_list_get(sec, count_idx));
if (!ruleset_load_names(&pcount->name, NULL, file, sec_name)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Cannot load counters names",
filename);
ok = FALSE;
break;
}
}
}
section_list_destroy(sec);
}
return ok;
}
/**********************************************************************//**
Load names from actions.ruleset so other rulesets can refer to objects
with their name.
**************************************************************************/
static bool load_action_names(struct section_file *file,
struct rscompat_info *compat)
{
const char *filename = secfile_name(file);
bool ok = TRUE;
if (!rscompat_check_cap_and_version(file, filename, compat)) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* Unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* Unused */
return ok;
}
/**********************************************************************//**
Load names of technologies so other rulesets can refer to techs with
their name.
**************************************************************************/
static bool load_tech_names(struct section_file *file,
struct rscompat_info *compat)
{
struct section_list *sec = NULL;
/* Number of techs in the ruleset (means without A_NONE). */
int num_techs = 0;
int i;
const char *filename = secfile_name(file);
bool ok = TRUE;
const char *flag;
if (!rscompat_check_cap_and_version(file, filename, compat)) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
/* User tech flag names */
for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
i++) {
const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
i);
if (tech_flag_id_by_name(flag, fc_strcasecmp) != tech_flag_id_invalid()) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Duplicate tech flag name '%s'",
filename, flag);
ok = FALSE;
break;
}
if (i > MAX_NUM_USER_TECH_FLAGS) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many user tech flags!",
filename);
ok = FALSE;
break;
}
set_user_tech_flag_name(TECH_USER_1 + i, flag, helptxt);
}
if (ok) {
size_t nval;
for (; i < MAX_NUM_USER_TECH_FLAGS; i++) {
set_user_tech_flag_name(TECH_USER_1 + i, NULL, NULL);
}
/* Tech classes */
sec = secfile_sections_by_name_prefix(file, TECH_CLASS_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
if (nval > MAX_NUM_TECH_CLASSES) {
int num = nval; /* No "size_t" to printf */
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many tech classes (%d, max %d)",
filename, num, MAX_NUM_TECH_CLASSES);
section_list_destroy(sec);
ok = FALSE;
} else {
game.control.num_tech_classes = nval;
}
if (ok) {
tech_class_iterate(ptclass) {
const char *sec_name
= section_name(section_list_get(sec, tech_class_index(ptclass)));
if (!ruleset_load_names(&ptclass->name, NULL, file, sec_name)) {
ruleset_error(NULL, LOG_ERROR, "\"%s\": Cannot load tech class names",
filename);
ok = FALSE;
break;
}
} tech_class_iterate_end;
}
}
if (ok) {
/* The techs: */
sec = secfile_sections_by_name_prefix(file, ADVANCE_SECTION_PREFIX);
if (NULL == sec || 0 == (num_techs = section_list_size(sec))) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": No Advances?!?", filename);
ok = FALSE;
} else {
log_verbose("%d advances (including possibly unused)", num_techs);
if (num_techs + A_FIRST > A_LAST) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many advances (%d, max %d)",
filename, num_techs, A_LAST - A_FIRST);
ok = FALSE;
}
}
}
if (ok) {
game.control.num_tech_types = num_techs + A_FIRST; /* includes A_NONE */
i = 0;
advance_iterate(adv) {
if (!ruleset_load_names(&adv->name, NULL, file,
section_name(section_list_get(sec, i)))) {
ok = FALSE;
break;
}
i++;
} advance_iterate_end;
}
section_list_destroy(sec);
return ok;
}
/**********************************************************************//**
Load technologies related ruleset data
**************************************************************************/
static bool load_ruleset_techs(struct section_file *file,
struct rscompat_info *compat)
{
struct section_list *sec;
const char **slist;
int i;
size_t nval;
struct advance *a_none = advance_by_number(A_NONE);
const char *filename = secfile_name(file);
bool ok = TRUE;
sec = secfile_sections_by_name_prefix(file, TECH_CLASS_SECTION_PREFIX);
i = 0;
tech_class_iterate(ptclass) {
const char *sec_name = section_name(section_list_get(sec, i));
ptclass->cost_pct = secfile_lookup_int_default(file, 100, "%s.%s",
sec_name, "cost_pct");
i++;
} tech_class_iterate_end;
sec = secfile_sections_by_name_prefix(file, ADVANCE_SECTION_PREFIX);
i = 0;
advance_iterate(a) {
const char *sec_name = section_name(section_list_get(sec, i));
const char *sval;
int j, ival;
struct requirement_vector *research_reqs;
if (!lookup_tech(file, &a->require[AR_ONE], sec_name, "req1",
filename, rule_name_get(&a->name))
|| !lookup_tech(file, &a->require[AR_TWO], sec_name, "req2",
filename, rule_name_get(&a->name))
|| !lookup_tech(file, &a->require[AR_ROOT], sec_name, "root_req",
filename, rule_name_get(&a->name))) {
ok = FALSE;
break;
}
if ((A_NEVER == a->require[AR_ONE] && A_NEVER != a->require[AR_TWO])
|| (A_NEVER != a->require[AR_ONE] && A_NEVER == a->require[AR_TWO])) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] \"%s\": \"Never\" with non-\"Never\".",
filename, sec_name, rule_name_get(&a->name));
ok = FALSE;
break;
}
if (a_none == a->require[AR_ONE] && a_none != a->require[AR_TWO]) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] \"%s\": should have \"None\" second.",
filename, sec_name, rule_name_get(&a->name));
ok = FALSE;
break;
}
if (game.control.num_tech_classes == 0) {
a->tclass = NULL;
} else {
const char *classname;
classname = lookup_string(file, sec_name, "class");
if (classname != NULL) {
classname = Q_(classname);
a->tclass = tech_class_by_rule_name(classname);
if (a->tclass == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] \"%s\": Unknown tech class \"%s\".",
filename, sec_name, rule_name_get(&a->name), classname);
ok = FALSE;
break;
}
} else {
a->tclass = NULL; /* Default */
}
}
research_reqs = lookup_req_list(file, compat, sec_name, "research_reqs",
rule_name_get(&a->name));
if (research_reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&a->research_reqs, research_reqs);
BV_CLR_ALL(a->flags);
slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
for (j = 0; j < nval; j++) {
sval = slist[j];
if (strcmp(sval, "") == 0) {
continue;
}
ival = tech_flag_id_by_name(sval, fc_strcasecmp);
if (!tech_flag_id_is_valid(ival)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] \"%s\": bad flag name \"%s\".",
filename, sec_name, rule_name_get(&a->name), sval);
ok = FALSE;
break;
} else {
BV_SET(a->flags, ival);
}
}
free(slist);
if (!ok) {
break;
}
sz_strlcpy(a->graphic_str,
secfile_lookup_str_default(file, "-", "%s.graphic", sec_name));
sz_strlcpy(a->graphic_alt,
secfile_lookup_str_default(file, "-",
"%s.graphic_alt", sec_name));
a->helptext = lookup_strvec(file, sec_name, "helptext");
a->bonus_message = lookup_string(file, sec_name, "bonus_message");
a->cost = secfile_lookup_int_default(file, -1, "%s.%s",
sec_name, "cost");
a->num_reqs = 0;
i++;
} advance_iterate_end;
/* Propagate a root tech up into the tech tree. If a technology
* X has Y has a root tech, then any technology requiring X (in the
* normal way or as a root tech) also has Y as a root tech.
* Later techs may gain a whole set of root techs in this way. The one
* we store in AR_ROOT is a more or less arbitrary one of these,
* also signalling that the set is non-empty; after this, you'll still
* have to walk the tech tree to find them all. */
restart:
if (ok) {
advance_iterate(a) {
if (valid_advance(a)
&& A_NEVER != a->require[AR_ROOT]) {
bool out_of_order = FALSE;
/* Now find any tech depending on this technology and update its
* root_req. */
advance_iterate(b) {
if (valid_advance(b)
&& A_NEVER == b->require[AR_ROOT]
&& (a == b->require[AR_ONE] || a == b->require[AR_TWO])) {
b->require[AR_ROOT] = a->require[AR_ROOT];
b->inherited_root_req = TRUE;
if (b < a) {
out_of_order = TRUE;
}
}
} advance_iterate_end;
if (out_of_order) {
/* HACK: If we just changed the root_tech of a lower-numbered
* technology, we need to go back so that we can propagate the
* root_tech up to that technology's parents... */
goto restart;
}
}
} advance_iterate_end;
/* Now rename A_NEVER to A_NONE for consistency */
advance_iterate_all(a) {
if (A_NEVER == a->require[AR_ROOT]) {
a->require[AR_ROOT] = a_none;
}
} advance_iterate_all_end;
/* Some more consistency checking:
Non-removed techs depending on removed techs is too
broken to fix by default, so die.
*/
advance_iterate(a) {
if (valid_advance(a)) {
/* We check for recursive tech loops later,
* in build_required_techs_helper. */
if (!valid_advance(a->require[AR_ONE])) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" tech \"%s\": req1 leads to removed tech.",
filename, advance_rule_name(a));
ok = FALSE;
break;
}
if (!valid_advance(a->require[AR_TWO])) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" tech \"%s\": req2 leads to removed tech.",
filename, advance_rule_name(a));
ok = FALSE;
break;
}
}
} advance_iterate_end;
}
section_list_destroy(sec);
if (ok) {
secfile_check_unused(file);
}
return ok;
}
/**********************************************************************//**
Load names of units so other rulesets can refer to units with
their name.
**************************************************************************/
static bool load_unit_names(struct section_file *file,
struct rscompat_info *compat)
{
struct section_list *sec = NULL;
int nval = 0;
int i;
const char *filename = secfile_name(file);
const char *flag;
bool ok = TRUE;
if (!rscompat_check_cap_and_version(file, filename, compat)) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
/* User unit flag names */
for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
i++) {
const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
i);
if (unit_type_flag_id_by_name(flag, fc_strcasecmp)
!= unit_type_flag_id_invalid()) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Duplicate unit flag name '%s'",
filename, flag);
ok = FALSE;
break;
}
if (i > MAX_NUM_USER_UNIT_FLAGS) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many user unit type flags!",
filename);
ok = FALSE;
break;
}
set_user_unit_type_flag_name(UTYF_USER_FLAG_1 + i, flag, helptxt);
}
if (ok) {
/* Blank the remaining unit type user flags. */
for (; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
set_user_unit_type_flag_name(UTYF_USER_FLAG_1 + i, NULL, NULL);
}
}
if (ok) {
/* User unit class flag names */
for (i = 0;
(flag = secfile_lookup_str_default(file, NULL,
"control.class_flags%d.name",
i));
i++) {
const char *helptxt = secfile_lookup_str_default(file, NULL,
"control.class_flags%d.helptxt", i);
if (unit_class_flag_id_by_name(flag, fc_strcasecmp)
!= unit_class_flag_id_invalid()) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Duplicate unit class flag name '%s'",
filename, flag);
ok = FALSE;
break;
}
if (i > MAX_NUM_USER_UCLASS_FLAGS) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many user unit class flags!",
filename);
ok = FALSE;
break;
}
set_user_unit_class_flag_name(UCF_USER_FLAG_1 + i, flag, helptxt);
}
}
if (ok) {
/* Blank the remaining unit class user flags. */
for (; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
set_user_unit_class_flag_name(UCF_USER_FLAG_1 + i, NULL, NULL);
}
}
if (ok) {
/* Unit classes */
sec = secfile_sections_by_name_prefix(file, UNIT_CLASS_SECTION_PREFIX);
if (NULL == sec || 0 == (nval = section_list_size(sec))) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": No unit classes?!?", filename);
ok = FALSE;
} else {
log_verbose("%d unit classes", nval);
if (nval > UCL_LAST) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many unit classes (%d, max %d)",
filename, nval, UCL_LAST);
ok = FALSE;
}
}
}
if (ok) {
game.control.num_unit_classes = nval;
unit_class_iterate(punitclass) {
const int pci = uclass_index(punitclass);
if (!ruleset_load_names(&punitclass->name, NULL, file,
section_name(section_list_get(sec, pci)))) {
ok = FALSE;
break;
}
} unit_class_iterate_end;
}
section_list_destroy(sec);
sec = NULL;
/* The names: */
if (ok) {
sec = secfile_sections_by_name_prefix(file, UNIT_SECTION_PREFIX);
if (NULL == sec || 0 == (nval = section_list_size(sec))) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": No unit types?!?", filename);
ok = FALSE;
} else {
log_verbose("%d unit types (including possibly unused)", nval);
if (nval > U_LAST) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many unit types (%d, max %d)",
filename, nval, U_LAST);
ok = FALSE;
}
}
}
if (ok) {
game.control.num_unit_types = nval;
unit_type_iterate(punittype) {
const int utypei = utype_index(punittype);
if (!ruleset_load_names(&punittype->name, NULL, file,
section_name(section_list_get(sec, utypei)))) {
ok = FALSE;
break;
}
} unit_type_iterate_end;
}
section_list_destroy(sec);
return ok;
}
/**********************************************************************//**
Load veteran levels.
**************************************************************************/
static bool load_ruleset_veteran(struct section_file *file,
const char *path,
struct veteran_system **vsystem, char *err,
size_t err_len)
{
const char **vlist_name;
int *vlist_power, *vlist_raise, *vlist_wraise, *vlist_move;
size_t count_name, count_power, count_raise, count_wraise, count_move;
int i;
bool ret = TRUE;
/* The pointer should be uninitialised. */
if (*vsystem != NULL) {
fc_snprintf(err, err_len, "Veteran system is defined?!");
return FALSE;
}
/* Load data. */
vlist_name = secfile_lookup_str_vec(file, &count_name,
"%s.veteran_names", path);
vlist_power = secfile_lookup_int_vec(file, &count_power,
"%s.veteran_power_fact", path);
vlist_raise = secfile_lookup_int_vec(file, &count_raise,
"%s.veteran_base_raise_chance", path);
vlist_wraise = secfile_lookup_int_vec(file, &count_wraise,
"%s.veteran_work_raise_chance",
path);
vlist_move = secfile_lookup_int_vec(file, &count_move,
"%s.veteran_move_bonus", path);
if (count_name > MAX_VET_LEVELS) {
ret = FALSE;
fc_snprintf(err, err_len, "\"%s\": Too many veteran levels (section "
"'%s': %lu, max %d)", secfile_name(file), path,
(long unsigned)count_name, MAX_VET_LEVELS);
} else if (count_name != count_power
|| count_name != count_raise
|| count_name != count_wraise
|| count_name != count_move) {
ret = FALSE;
fc_snprintf(err, err_len, "\"%s\": Different lengths for the veteran "
"settings in section '%s'", secfile_name(file),
path);
} else if (count_name == 0) {
/* Nothing defined. */
*vsystem = NULL;
} else {
/* Generate the veteran system. */
*vsystem = veteran_system_new((int)count_name);
#define rs_sanity_veteran(_path, _entry, _i, _condition, _action) \
if (_condition) { \
log_error("Invalid veteran definition '%s.%s[%d]'!", \
_path, _entry, _i); \
log_debug("Failed check: '%s'. Update value: '%s'.", \
#_condition, #_action); \
_action; \
}
for (i = 0; i < count_name; i++) {
/* Some sanity checks. */
rs_sanity_veteran(path, "veteran_power_fact", i,
(vlist_power[i] < 0), vlist_power[i] = 0);
rs_sanity_veteran(path, "veteran_base_raise_chance", i,
(vlist_raise[i] < 0), vlist_raise[i] = 0);
rs_sanity_veteran(path, "veteran_work_raise_chance", i,
(vlist_wraise[i] < 0), vlist_wraise[i] = 0);
rs_sanity_veteran(path, "veteran_move_bonus", i,
(vlist_move[i] < 0), vlist_move[i] = 0);
if (i == 0) {
/* First element.*/
rs_sanity_veteran(path, "veteran_power_fact", i,
(vlist_power[i] != 100), vlist_power[i] = 100);
} else if (i == count_name - 1) {
/* Last element. */
rs_sanity_veteran(path, "veteran_power_fact", i,
(vlist_power[i] < vlist_power[i - 1]),
vlist_power[i] = vlist_power[i - 1]);
rs_sanity_veteran(path, "veteran_base_raise_chance", i,
(vlist_raise[i] != 0), vlist_raise[i] = 0);
rs_sanity_veteran(path, "veteran_work_raise_chance", i,
(vlist_wraise[i] != 0), vlist_wraise[i] = 0);
} else {
/* All elements in between. */
rs_sanity_veteran(path, "veteran_power_fact", i,
(vlist_power[i] < vlist_power[i - 1]),
vlist_power[i] = vlist_power[i - 1]);
rs_sanity_veteran(path, "veteran_base_raise_chance", i,
(vlist_raise[i] > 100), vlist_raise[i] = 100);
rs_sanity_veteran(path, "veteran_work_raise_chance", i,
(vlist_wraise[i] > 100), vlist_wraise[i] = 100);
}
veteran_system_definition(*vsystem, i, vlist_name[i], vlist_power[i],
vlist_move[i], vlist_raise[i],
vlist_wraise[i]);
}
#undef rs_sanity_veteran
}
if (vlist_name) {
free(vlist_name);
}
if (vlist_power) {
free(vlist_power);
}
if (vlist_raise) {
free(vlist_raise);
}
if (vlist_wraise) {
free(vlist_wraise);
}
if (vlist_move) {
free(vlist_move);
}
return ret;
}
/**********************************************************************//**
Load units related ruleset data.
**************************************************************************/
static bool load_ruleset_units(struct section_file *file,
struct rscompat_info *compat)
{
int j, ival;
size_t nval;
struct section_list *sec, *csec;
const char *sval, **slist;
const char *filename = secfile_name(file);
char msg[MAX_LEN_MSG];
bool ok = TRUE;
if (!load_ruleset_veteran(file, "veteran_system", &game.veteran, msg,
sizeof(msg))
|| game.veteran == NULL) {
ruleset_error(NULL, LOG_ERROR,
"Error loading the default veteran system: %s",
msg);
ok = FALSE;
}
sec = secfile_sections_by_name_prefix(file, UNIT_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
csec = secfile_sections_by_name_prefix(file, UNIT_CLASS_SECTION_PREFIX);
nval = (NULL != csec ? section_list_size(csec) : 0);
if (ok) {
unit_class_iterate(uc) {
int i = uclass_index(uc);
const char *sec_name = section_name(section_list_get(csec, i));
if (secfile_lookup_int(file, &uc->min_speed, "%s.min_speed", sec_name)) {
uc->min_speed *= SINGLE_MOVE;
} else {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
if (!secfile_lookup_int(file, &uc->hp_loss_pct,
"%s.hp_loss_pct", sec_name)) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
uc->non_native_def_pct = secfile_lookup_int_default(file, 100,
"%s.non_native_def_pct",
sec_name);
BV_CLR_ALL(uc->flags);
slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
for (j = 0; j < nval; j++) {
sval = slist[j];
if (strcmp(sval, "") == 0) {
continue;
}
ival = unit_class_flag_id_by_name(sval, fc_strcasecmp);
if (!unit_class_flag_id_is_valid(ival)) {
ok = FALSE;
ival = unit_type_flag_id_by_name(sval, fc_strcasecmp);
if (unit_type_flag_id_is_valid(ival)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_class \"%s\": unit_type flag \"%s\"!",
filename, uclass_rule_name(uc), sval);
} else {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_class \"%s\": bad flag name \"%s\".",
filename, uclass_rule_name(uc), sval);
}
break;
} else {
BV_SET(uc->flags, ival);
}
}
free(slist);
uc->helptext = lookup_strvec(file, sec_name, "helptext");
if (!ok) {
break;
}
} unit_class_iterate_end;
}
if (ok) {
/* Tech and Gov requirements; per unit veteran system */
unit_type_iterate(u) {
const int i = utype_index(u);
const struct section *psection = section_list_get(sec, i);
const char *sec_name = section_name(psection);
if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
struct advance *adv_req;
struct impr_type *impr_req = NULL;
if (!lookup_tech(file, &adv_req, sec_name,
"tech_req", filename,
rule_name_get(&u->name))) {
ok = FALSE;
break;
}
if (adv_req == A_NEVER) {
ruleset_error(NULL, LOG_ERROR, "%s lacks valid tech_req.",
rule_name_get(&u->name));
ok = FALSE;
break;
} else if (adv_req != advance_by_number(A_NONE)) {
requirement_vector_append(&u->build_reqs,
req_from_values(VUT_ADVANCE, REQ_RANGE_PLAYER,
FALSE, TRUE, FALSE,
advance_number(adv_req)));
}
/* Read the government build requirement from the old ruleset format
* and put it in unit_type's build_reqs requirement vector.
* The build_reqs requirement vector isn't ready to be exposed in the
* ruleset yet.
* Barbarians can build certain units as long as anyone in the world
* has the required tech. Regular players must have the required tech
* them self to build the same unit. One way to solve this is to make
* unit building an action enabler controlled action with a city (not
* unit) actor.
* Putting a requirement vector on unit types in the ruleset will
* force ruleset authors to change all their unit type build
* requirements to a requirement vector. Forcing them to convert their
* unit type requirements again in the next version (should building be
* switched to an action enabler with a city actor) is not good. */
if (NULL != section_entry_by_name(psection, "gov_req")) {
char tmp[200] = "\0";
struct government *need_government;
fc_strlcat(tmp, section_name(psection), sizeof(tmp));
fc_strlcat(tmp, ".gov_req", sizeof(tmp));
need_government = lookup_government(file, tmp, filename, NULL);
if (need_government == NULL) {
ok = FALSE;
break;
}
requirement_vector_append(&u->build_reqs, req_from_values(
VUT_GOVERNMENT, REQ_RANGE_PLAYER,
FALSE, TRUE, FALSE,
government_number(need_government)));
}
/* Read the building build requirement from the old ruleset format
* and put it in unit_type's build_reqs requirement vector.
* The build_reqs requirement vector isn't ready to be exposed in the
* ruleset yet.
* See the comment for gov_req above for why. */
if (!lookup_building(file, sec_name, "impr_req",
&impr_req, filename,
rule_name_get(&u->name))) {
ok = FALSE;
break;
}
if (impr_req) {
requirement_vector_append(&u->build_reqs, req_from_values(
VUT_IMPROVEMENT, REQ_RANGE_CITY,
FALSE, TRUE, FALSE,
improvement_number(impr_req)));
}
} else {
/* Freeciv-3.2 format */
struct requirement_vector *reqs;
reqs = lookup_req_list(file, compat, sec_name, "reqs",
utype_rule_name(u));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&u->build_reqs, reqs);
}
if (!load_ruleset_veteran(file, sec_name, &u->veteran,
msg, sizeof(msg))) {
ruleset_error(NULL, LOG_ERROR,
"Error loading the veteran system: %s",
msg);
ok = FALSE;
break;
}
if (!lookup_unit_type(file, sec_name, "obsolete_by",
&u->obsoleted_by, filename,
rule_name_get(&u->name))
|| !lookup_unit_type(file, sec_name, "convert_to",
&u->converted_to, filename,
rule_name_get(&u->name))) {
ok = FALSE;
break;
}
u->convert_time = 1; /* default */
lookup_time(file, &u->convert_time, sec_name, "convert_time",
filename, rule_name_get(&u->name), &ok);
} unit_type_iterate_end;
}
if (ok) {
/* main stats: */
unit_type_iterate(u) {
const int i = utype_index(u);
struct unit_class *pclass;
const char *sec_name = section_name(section_list_get(sec, i));
const char *str;
sval = secfile_lookup_str(file, "%s.class", sec_name);
pclass = unit_class_by_rule_name(sval);
if (!pclass) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\": bad class \"%s\".",
filename, utype_rule_name(u), sval);
ok = FALSE;
break;
}
u->uclass = pclass;
sz_strlcpy(u->sound_move,
secfile_lookup_str_default(file, "-", "%s.sound_move",
sec_name));
sz_strlcpy(u->sound_move_alt,
secfile_lookup_str_default(file, "-", "%s.sound_move_alt",
sec_name));
sz_strlcpy(u->sound_fight,
secfile_lookup_str_default(file, "-", "%s.sound_fight",
sec_name));
sz_strlcpy(u->sound_fight_alt,
secfile_lookup_str_default(file, "-", "%s.sound_fight_alt",
sec_name));
if ((str = secfile_lookup_str(file, "%s.graphic", sec_name))) {
sz_strlcpy(u->graphic_str, str);
} else {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
sz_strlcpy(u->graphic_alt,
secfile_lookup_str_default(file, "-", "%s.graphic_alt",
sec_name));
sz_strlcpy(u->graphic_alt2,
secfile_lookup_str_default(file, "-", "%s.graphic_alt2",
sec_name));
if (!secfile_lookup_int(file, &u->build_cost,
"%s.build_cost", sec_name)
|| !secfile_lookup_int(file, &u->pop_cost,
"%s.pop_cost", sec_name)
|| !secfile_lookup_int(file, &u->attack_strength,
"%s.attack", sec_name)
|| !secfile_lookup_int(file, &u->defense_strength,
"%s.defense", sec_name)
|| !secfile_lookup_int(file, &u->move_rate,
"%s.move_rate", sec_name)
|| !secfile_lookup_int(file, &u->vision_radius_sq,
"%s.vision_radius_sq", sec_name)
|| !secfile_lookup_int(file, &u->transport_capacity,
"%s.transport_cap", sec_name)
|| !secfile_lookup_int(file, &u->firepower,
"%s.firepower", sec_name)
|| !secfile_lookup_int(file, &u->fuel,
"%s.fuel", sec_name)
|| !secfile_lookup_int(file, &u->happy_cost,
"%s.uk_happy", sec_name)) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
u->hp
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_HP,
RS_MIN_HP,
RS_MAX_HP,
"%s.hitpoints", sec_name);
u->move_rate *= SINGLE_MOVE;
if (u->firepower <= 0) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\":"
" firepower is %d,"
" but must be at least 1. "
" If you want no attack ability,"
" set the unit's attack strength to 0.",
filename, utype_rule_name(u), u->firepower);
ok = FALSE;
break;
}
lookup_cbonus_list(u->bonuses, file, sec_name, "bonuses");
output_type_iterate(o) {
u->upkeep[o] = secfile_lookup_int_default(file, 0, "%s.uk_%s",
sec_name,
get_output_identifier(o));
} output_type_iterate_end;
slist = secfile_lookup_str_vec(file, &nval, "%s.cargo", sec_name);
BV_CLR_ALL(u->cargo);
for (j = 0; j < nval; j++) {
struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
if (!uclass) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\":"
"has unknown unit class %s as cargo.",
filename, utype_rule_name(u), slist[j]);
ok = FALSE;
break;
}
BV_SET(u->cargo, uclass_index(uclass));
}
free(slist);
if (!ok) {
break;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.targets", sec_name);
BV_CLR_ALL(u->targets);
for (j = 0; j < nval; j++) {
struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
if (!uclass) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\":"
"has unknown unit class %s as target.",
filename, utype_rule_name(u), slist[j]);
ok = FALSE;
break;
}
BV_SET(u->targets, uclass_index(uclass));
}
free(slist);
if (!ok) {
break;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.embarks", sec_name);
BV_CLR_ALL(u->embarks);
for (j = 0; j < nval; j++) {
struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
if (!uclass) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\":"
"has unknown unit class %s as embarkable.",
filename, utype_rule_name(u), slist[j]);
ok = FALSE;
break;
}
BV_SET(u->embarks, uclass_index(uclass));
}
free(slist);
if (!ok) {
break;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.disembarks", sec_name);
BV_CLR_ALL(u->disembarks);
for (j = 0; j < nval; j++) {
struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
if (!uclass) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\":"
"has unknown unit class %s as disembarkable.",
filename, utype_rule_name(u), slist[j]);
ok = FALSE;
break;
}
BV_SET(u->disembarks, uclass_index(uclass));
}
free(slist);
if (!ok) {
break;
}
/* Set also all classes that are never unreachable as targets,
* embarks, and disembarks. */
unit_class_iterate(preachable) {
if (!uclass_has_flag(preachable, UCF_UNREACHABLE)) {
BV_SET(u->targets, uclass_index(preachable));
BV_SET(u->embarks, uclass_index(preachable));
BV_SET(u->disembarks, uclass_index(preachable));
}
} unit_class_iterate_end;
str = secfile_lookup_str_default(file, "Main", "%s.vision_layer",
sec_name);
u->vlayer = vision_layer_by_name(str, fc_strcasecmp);
if (!vision_layer_is_valid(u->vlayer)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\":"
"has unknown vision layer %s.",
filename, utype_rule_name(u), str);
ok = FALSE;
break;
}
u->helptext = lookup_strvec(file, sec_name, "helptext");
u->paratroopers_range = secfile_lookup_int_default(file,
0, "%s.paratroopers_range", sec_name);
u->bombard_rate = secfile_lookup_int_default(file, 0,
"%s.bombard_rate", sec_name);
u->city_slots = secfile_lookup_int_default(file, 0,
"%s.city_slots", sec_name);
u->city_size = secfile_lookup_int_default(file, 1,
"%s.city_size", sec_name);
sval = secfile_lookup_str_default(file, transp_def_type_name(TDT_ALIGHT),
"%s.tp_defense", sec_name);
u->tp_defense = transp_def_type_by_name(sval, fc_strcasecmp);
if (!transp_def_type_is_valid(u->tp_defense)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\":"
" bad tp_defense \"%s\".",
filename, utype_rule_name(u), sval);
ok = FALSE;
break;
}
} unit_type_iterate_end;
}
if (ok) {
/* flags */
unit_type_iterate(u) {
const int i = utype_index(u);
BV_CLR_ALL(u->flags);
fc_assert(!utype_has_flag(u, UTYF_LAST_USER_FLAG - 1));
slist = secfile_lookup_str_vec(file, &nval, "%s.flags",
section_name(section_list_get(sec, i)));
for (j = 0; j < nval; j++) {
sval = slist[j];
if (0 == strcmp(sval, "")) {
continue;
}
ival = unit_type_flag_id_by_name(sval, fc_strcasecmp);
if (!unit_type_flag_id_is_valid(ival)) {
ok = FALSE;
ival = unit_class_flag_id_by_name(sval, fc_strcasecmp);
if (unit_class_flag_id_is_valid(ival)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\": unit_class flag!",
filename, utype_rule_name(u));
} else {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\": bad flag name \"%s\".",
filename, utype_rule_name(u), sval);
}
break;
} else {
BV_SET(u->flags, ival);
}
}
free(slist);
if (!ok) {
break;
}
} unit_type_iterate_end;
}
/* roles */
if (ok) {
unit_type_iterate(u) {
const int i = utype_index(u);
BV_CLR_ALL(u->roles);
slist = secfile_lookup_str_vec(file, &nval, "%s.roles",
section_name(section_list_get(sec, i)));
for (j = 0; j < nval; j++) {
sval = slist[j];
if (strcmp(sval, "") == 0) {
continue;
}
ival = unit_role_id_by_name(sval, fc_strcasecmp);
if (!unit_role_id_is_valid(ival)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\": bad role name \"%s\".",
filename, utype_rule_name(u), sval);
ok = FALSE;
break;
} else {
BV_SET(u->roles, ival - L_FIRST);
}
fc_assert(utype_has_role(u, ival));
}
free(slist);
} unit_type_iterate_end;
}
if (ok) {
/* Some more consistency checking: */
unit_type_iterate(u) {
unit_tech_reqs_iterate(u, padv) {
if (!valid_advance(padv)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unit_type \"%s\": depends on removed tech \"%s\".",
filename, utype_rule_name(u),
advance_rule_name(padv));
ok = FALSE;
break;
}
} unit_tech_reqs_iterate_end;
if (!ok) {
break;
}
} unit_type_iterate_end;
}
section_list_destroy(csec);
section_list_destroy(sec);
if (ok) {
secfile_check_unused(file);
}
return ok;
}
/**********************************************************************//**
Load names of buildings so other rulesets can refer to buildings with
their name.
**************************************************************************/
static bool load_building_names(struct section_file *file,
struct rscompat_info *compat)
{
struct section_list *sec;
int i, nval = 0;
const char *filename = secfile_name(file);
bool ok = TRUE;
const char *flag;
if (!rscompat_check_cap_and_version(file, filename, compat)) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
/* The names: */
sec = secfile_sections_by_name_prefix(file, BUILDING_SECTION_PREFIX);
if (NULL == sec || 0 == (nval = section_list_size(sec))) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": No improvements?!?", filename);
ok = FALSE;
} else {
log_verbose("%d improvement types (including possibly unused)", nval);
if (nval > B_LAST) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many improvements (%d, max %d)",
filename, nval, B_LAST);
ok = FALSE;
}
}
if (ok) {
game.control.num_impr_types = nval;
for (i = 0; i < nval; i++) {
struct impr_type *b = improvement_by_number(i);
if (!ruleset_load_names(&b->name, NULL, file, section_name(section_list_get(sec, i)))) {
ok = FALSE;
break;
}
}
}
/* User building flag names */
for (i = 0;
(flag = secfile_lookup_str_default(file, NULL,
"control.building_flags%d.name",
i));
i++) {
const char *helptxt = secfile_lookup_str_default(file, NULL,
"control.building_flags%d.helptxt", i);
if (impr_flag_id_by_name(flag, fc_strcasecmp)
!= impr_flag_id_invalid()) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Duplicate building flag name '%s'",
filename, flag);
ok = FALSE;
break;
}
if (i > MAX_NUM_USER_BUILDING_FLAGS) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many user building flags!",
filename);
ok = FALSE;
break;
}
set_user_impr_flag_name(IF_USER_FLAG_1 + i, flag, helptxt);
}
section_list_destroy(sec);
return ok;
}
/**********************************************************************//**
Load buildings related ruleset data
**************************************************************************/
static bool load_ruleset_buildings(struct section_file *file,
struct rscompat_info *compat)
{
struct section_list *sec;
const char *item;
int i, nval;
const char *filename = secfile_name(file);
bool ok = TRUE;
sec = secfile_sections_by_name_prefix(file, BUILDING_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
for (i = 0; i < nval && ok; i++) {
struct impr_type *b = improvement_by_number(i);
const char *sec_name = section_name(section_list_get(sec, i));
struct requirement_vector *reqs =
lookup_req_list(file, compat, sec_name, "reqs",
improvement_rule_name(b));
if (reqs == NULL) {
ok = FALSE;
break;
} else {
const char *sval, **slist;
int j, ival;
size_t nflags;
item = secfile_lookup_str(file, "%s.genus", sec_name);
b->genus = impr_genus_id_by_name(item, fc_strcasecmp);
if (!impr_genus_id_is_valid(b->genus)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" improvement \"%s\": couldn't match "
"genus \"%s\".", filename,
improvement_rule_name(b), item);
ok = FALSE;
break;
}
slist = secfile_lookup_str_vec(file, &nflags, "%s.flags", sec_name);
BV_CLR_ALL(b->flags);
for (j = 0; j < nflags; j++) {
sval = slist[j];
if (strcmp(sval, "") == 0) {
continue;
}
ival = impr_flag_id_by_name(sval, fc_strcasecmp);
if (!impr_flag_id_is_valid(ival)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" improvement \"%s\": bad flag name \"%s\".",
filename, improvement_rule_name(b), sval);
ok = FALSE;
break;
} else {
BV_SET(b->flags, ival);
}
}
free(slist);
if (!ok) {
break;
}
if (compat->compat_mode) {
b->genus = rscompat_genus_3_2(compat, b->flags, b->genus);
}
requirement_vector_copy(&b->reqs, reqs);
{
struct requirement_vector *obs_reqs =
lookup_req_list(file, compat, sec_name, "obsolete_by",
improvement_rule_name(b));
if (obs_reqs == NULL) {
ok = FALSE;
break;
} else {
requirement_vector_copy(&b->obsolete_by, obs_reqs);
}
}
if (!secfile_lookup_int(file, &b->build_cost,
"%s.build_cost", sec_name)
|| !secfile_lookup_int(file, &b->upkeep,
"%s.upkeep", sec_name)
|| !secfile_lookup_int(file, &b->sabotage,
"%s.sabotage", sec_name)) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
sz_strlcpy(b->graphic_str,
secfile_lookup_str_default(file, "-",
"%s.graphic", sec_name));
sz_strlcpy(b->graphic_alt,
secfile_lookup_str_default(file, "-",
"%s.graphic_alt", sec_name));
sz_strlcpy(b->graphic_alt2,
secfile_lookup_str_default(file, "-",
"%s.graphic_alt2", sec_name));
sz_strlcpy(b->soundtag,
secfile_lookup_str_default(file, "-",
"%s.sound", sec_name));
sz_strlcpy(b->soundtag_alt,
secfile_lookup_str_default(file, "-",
"%s.sound_alt", sec_name));
sz_strlcpy(b->soundtag_alt2,
secfile_lookup_str_default(file, "-",
"%s.sound_alt2", sec_name));
b->helptext = lookup_strvec(file, sec_name, "helptext");
}
}
section_list_destroy(sec);
if (ok) {
secfile_check_unused(file);
}
return ok;
}
/**********************************************************************//**
Load names of terrain types so other rulesets can refer to terrains with
their name.
**************************************************************************/
static bool load_terrain_names(struct section_file *file,
struct rscompat_info *compat)
{
int nval = 0;
struct section_list *sec = NULL;
const char *flag;
int i;
const char *filename = secfile_name(file);
bool ok = TRUE;
if (!rscompat_check_cap_and_version(file, filename, compat)) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
/* User terrain flag names */
for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
i++) {
const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
i);
if (terrain_flag_id_by_name(flag, fc_strcasecmp)
!= terrain_flag_id_invalid()) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Duplicate terrain flag name '%s'",
filename, flag);
ok = FALSE;
break;
}
if (i > MAX_NUM_USER_TER_FLAGS) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many user terrain flags!",
filename);
ok = FALSE;
break;
}
set_user_terrain_flag_name(TER_USER_1 + i, flag, helptxt);
}
if (ok) {
/* Blank the remaining terrain user flag slots. */
for (; i < MAX_NUM_USER_TER_FLAGS; i++) {
set_user_terrain_flag_name(TER_USER_1 + i, NULL, NULL);
}
}
/* User extra flag names */
for (i = 0;
(flag = secfile_lookup_str_default(file, NULL,
"control.extra_flags%d.name",
i));
i++) {
const char *helptxt = secfile_lookup_str_default(file, NULL,
"control.extra_flags%d.helptxt", i);
if (extra_flag_id_by_name(flag, fc_strcasecmp)
!= extra_flag_id_invalid()) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Duplicate extra flag name '%s'",
filename, flag);
ok = FALSE;
break;
}
if (i > MAX_NUM_USER_EXTRA_FLAGS) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many user extra flags!",
filename);
ok = FALSE;
break;
}
set_user_extra_flag_name(EF_USER_FLAG_1 + i, flag, helptxt);
}
if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
i += add_user_extra_flags_3_2(i);
}
if (ok) {
/* Blank the remaining extra user flag slots. */
for (; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
set_user_extra_flag_name(EF_USER_FLAG_1 + i, NULL, NULL);
}
/* terrain names */
sec = secfile_sections_by_name_prefix(file, TERRAIN_SECTION_PREFIX);
if (NULL == sec || 0 == (nval = section_list_size(sec))) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": ruleset doesn't have any terrains.",
filename);
ok = FALSE;
} else {
if (nval > MAX_NUM_TERRAINS) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many terrains (%d, max %d)",
filename, nval, MAX_NUM_TERRAINS);
ok = FALSE;
}
}
}
if (ok) {
game.control.terrain_count = nval;
/* avoid re-reading files */
if (terrain_sections) {
free(terrain_sections);
}
terrain_sections = fc_calloc(nval, MAX_SECTION_LABEL);
terrain_type_iterate(pterrain) {
const int terri = terrain_index(pterrain);
const char *sec_name = section_name(section_list_get(sec, terri));
if (!ruleset_load_names(&pterrain->name, NULL, file, sec_name)) {
ok = FALSE;
break;
}
section_strlcpy(&terrain_sections[terri * MAX_SECTION_LABEL], sec_name);
} terrain_type_iterate_end;
}
section_list_destroy(sec);
sec = NULL;
/* extra names */
if (ok) {
sec = secfile_sections_by_name_prefix(file, EXTRA_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
if (nval > MAX_EXTRA_TYPES) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many extra types (%d, max %d)",
filename, nval, MAX_EXTRA_TYPES);
ok = FALSE;
}
}
if (ok) {
int idx;
game.control.num_extra_types = nval;
if (extra_sections) {
free(extra_sections);
}
extra_sections = fc_calloc(nval, MAX_SECTION_LABEL);
if (ok) {
for (idx = 0; idx < nval; idx++) {
const char *sec_name = section_name(section_list_get(sec, idx));
struct extra_type *pextra = extra_by_number(idx);
if (!ruleset_load_names(&pextra->name, NULL, file, sec_name)) {
ok = FALSE;
break;
}
section_strlcpy(&extra_sections[idx * MAX_SECTION_LABEL], sec_name);
}
}
}
section_list_destroy(sec);
sec = NULL;
/* Base names */
if (ok) {
sec = secfile_sections_by_name_prefix(file, BASE_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
if (nval > MAX_EXTRA_TYPES) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many base types (%d, max %d)",
filename, nval, MAX_EXTRA_TYPES);
ok = FALSE;
}
game.control.num_base_types = nval;
}
if (ok) {
int idx;
if (base_sections) {
free(base_sections);
}
base_sections = fc_calloc(nval, MAX_SECTION_LABEL);
/* Cannot use base_type_iterate() before bases are added to
* EC_BASE caused_by list. Have to get them by extra_type_by_rule_name() */
for (idx = 0; idx < nval; idx++) {
const char *sec_name = section_name(section_list_get(sec, idx));
const char *base_name = secfile_lookup_str(file, "%s.extra", sec_name);
if (base_name != NULL) {
struct extra_type *pextra = extra_type_by_rule_name(base_name);
if (pextra != NULL) {
base_type_init(pextra, idx);
section_strlcpy(&base_sections[idx * MAX_SECTION_LABEL], sec_name);
} else {
ruleset_error(NULL, LOG_ERROR,
"No extra definition matching base definition \"%s\"",
base_name);
ok = FALSE;
}
} else {
ruleset_error(NULL, LOG_ERROR,
"Base section \"%s\" does not associate base with any extra",
sec_name);
ok = FALSE;
}
}
}
section_list_destroy(sec);
sec = NULL;
/* Road names */
if (ok) {
sec = secfile_sections_by_name_prefix(file, ROAD_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
if (nval > MAX_EXTRA_TYPES) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many road types (%d, max %d)",
filename, nval, MAX_EXTRA_TYPES);
ok = FALSE;
}
game.control.num_road_types = nval;
}
if (ok) {
int idx;
if (road_sections) {
free(road_sections);
}
road_sections = fc_calloc(nval, MAX_SECTION_LABEL);
/* Cannot use extra_type_by_cause_iterate(EC_ROAD) before roads are added to
* EC_ROAD caused_by list. Have to get them by extra_type_by_rule_name() */
for (idx = 0; idx < nval; idx++) {
const char *sec_name = section_name(section_list_get(sec, idx));
const char *road_name = secfile_lookup_str(file, "%s.extra", sec_name);
if (road_name != NULL) {
struct extra_type *pextra = extra_type_by_rule_name(road_name);
if (pextra != NULL) {
road_type_init(pextra, idx);
section_strlcpy(&road_sections[idx * MAX_SECTION_LABEL], sec_name);
} else {
ruleset_error(NULL, LOG_ERROR,
"No extra definition matching road definition \"%s\"",
road_name);
ok = FALSE;
}
} else {
ruleset_error(NULL, LOG_ERROR,
"Road section \"%s\" does not associate road with any extra",
sec_name);
ok = FALSE;
}
}
}
section_list_destroy(sec);
sec = NULL;
/* Resource names */
if (ok) {
sec = secfile_sections_by_name_prefix(file, RESOURCE_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
if (nval > MAX_EXTRA_TYPES) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many resource types (%d, max %d)",
filename, nval, MAX_EXTRA_TYPES);
ok = FALSE;
}
game.control.num_resource_types = nval;
}
if (ok) {
int idx;
if (resource_sections) {
free(resource_sections);
}
resource_sections = fc_calloc(nval, MAX_SECTION_LABEL);
/* Cannot use resource_type_iterate() before resource are added to
* EC_RESOURCE caused_by list. Have to get them by extra_type_by_rule_name() */
for (idx = 0; idx < nval; idx++) {
const char *sec_name = section_name(section_list_get(sec, idx));
const char *resource_name;
struct extra_type *pextra = NULL;
resource_name = secfile_lookup_str_default(file, NULL, "%s.extra", sec_name);
if (resource_name != NULL) {
pextra = extra_type_by_rule_name(resource_name);
if (pextra != NULL) {
resource_type_init(pextra);
section_strlcpy(&resource_sections[idx * MAX_SECTION_LABEL], sec_name);
} else {
ruleset_error(NULL, LOG_ERROR,
"No extra definition matching resource definition \"%s\"",
resource_name);
ok = FALSE;
}
} else {
ruleset_error(NULL, LOG_ERROR,
"Resource section %s does not list extra this resource belongs to.",
sec_name);
ok = FALSE;
}
}
}
section_list_destroy(sec);
return ok;
}
/**********************************************************************//**
Load terrain types related ruleset data
**************************************************************************/
static bool load_ruleset_terrain(struct section_file *file,
struct rscompat_info *compat)
{
size_t nval, nval2;
int j;
bool compat_road = FALSE;
bool compat_rail = FALSE;
bool compat_river = FALSE;
const char **res;
const char *filename = secfile_name(file);
const char *text;
int *res_freq;
bool ok = TRUE;
/* parameters */
terrain_control.ocean_reclaim_requirement_pct
= secfile_lookup_int_default(file, 101,
"parameters.ocean_reclaim_requirement");
terrain_control.land_channel_requirement_pct
= secfile_lookup_int_default(file, 101,
"parameters.land_channel_requirement");
terrain_control.terrain_thaw_requirement_pct
= secfile_lookup_int_default(file, 101,
"parameters.thaw_requirement");
terrain_control.terrain_freeze_requirement_pct
= secfile_lookup_int_default(file, 101,
"parameters.freeze_requirement");
terrain_control.lake_max_size
= secfile_lookup_int_default(file, 0,
"parameters.lake_max_size");
terrain_control.min_start_native_area
= secfile_lookup_int_default(file, 0,
"parameters.min_start_native_area");
terrain_control.move_fragments
= secfile_lookup_int_default(file, 3,
"parameters.move_fragments");
if (terrain_control.move_fragments < 1) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": move_fragments must be at least 1",
filename);
ok = FALSE;
}
init_move_fragments();
terrain_control.igter_cost
= secfile_lookup_int_default(file, 1,
"parameters.igter_cost");
if (terrain_control.igter_cost < 1) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": igter_cost must be at least 1",
filename);
ok = FALSE;
}
terrain_control.infrapoints = FALSE; /* This will be updated if we find
* an placeable extra. */
terrain_control.pythagorean_diagonal
= secfile_lookup_bool_default(file, RS_DEFAULT_PYTHAGOREAN_DIAGONAL,
"parameters.pythagorean_diagonal");
wld.map.server.ocean_resources
= secfile_lookup_bool_default(file, FALSE,
"parameters.ocean_resources");
text = secfile_lookup_str_default(file,
N_("?gui_type:Build Type A Base"),
"extraui.ui_name_base_fortress");
sz_strlcpy(terrain_control.gui_type_base0, text);
text = secfile_lookup_str_default(file,
N_("?gui_type:Build Type B Base"),
"extraui.ui_name_base_airbase");
sz_strlcpy(terrain_control.gui_type_base1, text);
if (ok) {
/* Terrain details */
terrain_type_iterate(pterrain) {
const char **slist;
const int i = terrain_index(pterrain);
const char *tsection = &terrain_sections[i * MAX_SECTION_LABEL];
const char *cstr;
const char *ename;
sz_strlcpy(pterrain->graphic_str,
secfile_lookup_str(file, "%s.graphic", tsection));
sz_strlcpy(pterrain->graphic_alt,
secfile_lookup_str_default(file, "-",
"%s.graphic_alt", tsection));
sz_strlcpy(pterrain->graphic_alt2,
secfile_lookup_str_default(file, "-",
"%s.graphic_alt2", tsection));
pterrain->identifier
= secfile_lookup_str(file, "%s.identifier", tsection)[0];
if ('\0' == pterrain->identifier) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] identifier missing value.",
filename, tsection);
ok = FALSE;
break;
}
if (TERRAIN_UNKNOWN_IDENTIFIER == pterrain->identifier) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] cannot use '%c' as an identifier;"
" it is reserved for unknown terrain.",
filename, tsection, pterrain->identifier);
ok = FALSE;
break;
}
for (j = T_FIRST; j < i; j++) {
if (pterrain->identifier == terrain_by_number(j)->identifier) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] has the same identifier as [%s].",
filename, tsection,
&terrain_sections[j * MAX_SECTION_LABEL]);
ok = FALSE;
break;
}
}
if (!ok) {
break;
}
cstr = secfile_lookup_str(file, "%s.class", tsection);
pterrain->tclass = terrain_class_by_name(cstr, fc_strcasecmp);
if (!terrain_class_is_valid(pterrain->tclass)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": [%s] unknown class \"%s\"",
filename, tsection, cstr);
ok = FALSE;
break;
}
if (!secfile_lookup_int(file, &pterrain->movement_cost,
"%s.movement_cost", tsection)
|| !secfile_lookup_int(file, &pterrain->defense_bonus,
"%s.defense_bonus", tsection)) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
output_type_iterate(o) {
pterrain->output[o]
= secfile_lookup_int_default(file, 0, "%s.%s", tsection,
get_output_identifier(o));
} output_type_iterate_end;
res = secfile_lookup_str_vec(file, &nval, "%s.resources", tsection);
res_freq = secfile_lookup_int_vec(file, &nval2,
"%s.resource_freq", tsection);
if (nval2 > 0 && nval2 != nval) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": [%s] Different lengths for resources "
"and resource frequencies",
filename, tsection);
ok = FALSE;
}
pterrain->resources = fc_calloc(nval + 1, sizeof(*pterrain->resources));
pterrain->resource_freq = fc_calloc(nval + 1,
sizeof(*pterrain->resource_freq));
for (j = 0; j < nval; j++) {
pterrain->resources[j] = lookup_resource(filename, res[j], tsection);
if (pterrain->resources[j] == NULL) {
ok = FALSE;
break;
}
pterrain->resource_freq[j] = j < nval2
? res_freq[j]
: RESOURCE_FREQUENCY_DEFAULT;
if (pterrain->resource_freq[j] < RESOURCE_FREQUENCY_MINIMUM
|| pterrain->resource_freq[j] > RESOURCE_FREQUENCY_MAXIMUM) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": [%s] Resource frequency '%d' "
"outside allowed range",
filename, tsection,
pterrain->resource_freq[j]);
ok = FALSE;
break;
}
}
pterrain->resources[nval] = NULL;
/* Terminating zero technically not necessary */
pterrain->resource_freq[nval] = 0;
free(res);
res = NULL;
free(res_freq);
res_freq = NULL;
if (!ok) {
break;
}
output_type_iterate(o) {
pterrain->road_output_incr_pct[o]
= secfile_lookup_int_default(file, 0, "%s.road_%s_incr_pct",
tsection, get_output_identifier(o));
} output_type_iterate_end;
if (!lookup_time(file, &pterrain->base_time, tsection, "base_time",
filename, NULL, &ok)
|| !lookup_time(file, &pterrain->road_time, tsection, "road_time",
filename, NULL, &ok)) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
if (!lookup_terrain(file, "cultivate_result", filename, pterrain,
&pterrain->cultivate_result, FALSE)) {
ruleset_error(NULL, LOG_ERROR, "%s: No cultivate_result", tsection);
ok = FALSE;
break;
}
if (pterrain->cultivate_result == pterrain) {
ruleset_error(NULL, LOG_ERROR,
"%s: Cultivating result in terrain itself.",
tsection);
ok = FALSE;
break;
}
if (!secfile_lookup_int(file, &pterrain->irrigation_food_incr,
"%s.irrigation_food_incr", tsection)
|| !lookup_time(file, &pterrain->irrigation_time,
tsection, "irrigation_time", filename, NULL, &ok)) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
if (!lookup_terrain(file, "plant_result", filename, pterrain,
&pterrain->plant_result, FALSE)) {
ruleset_error(NULL, LOG_ERROR, "%s: No plant_result", tsection);
ok = FALSE;
break;
}
if (pterrain->plant_result == pterrain) {
ruleset_error(NULL, LOG_ERROR,
"%s: Planting result in terrain itself.",
tsection);
ok = FALSE;
break;
}
if (!secfile_lookup_int(file, &pterrain->mining_shield_incr,
"%s.mining_shield_incr", tsection)
|| !lookup_time(file, &pterrain->mining_time,
tsection, "mining_time", filename, NULL, &ok)) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
if (!lookup_time(file, &pterrain->cultivate_time,
tsection, "cultivate_time", filename, NULL, &ok)) {
ruleset_error(NULL, LOG_ERROR,
"%s: Missing cultivate_time", tsection);
ok = FALSE;
break;
}
if ((pterrain->cultivate_result != NULL
&& pterrain->cultivate_time <= 0)
|| (pterrain->cultivate_result == NULL
&& pterrain->cultivate_time > 0)) {
ruleset_error(NULL, LOG_ERROR,
"%s: cultivate_result and cultivate_time disagree "
"whether cultivating is enabled", tsection);
ok = FALSE;
break;
}
if (!lookup_time(file, &pterrain->plant_time,
tsection, "plant_time", filename, NULL, &ok)) {
ruleset_error(NULL, LOG_ERROR,
"%s: Missing plant_time", tsection);
ok = FALSE;
break;
}
if ((pterrain->plant_result != NULL
&& pterrain->plant_time <= 0)
|| (pterrain->plant_result == NULL
&& pterrain->plant_time > 0)) {
ruleset_error(NULL, LOG_ERROR,
"%s: plant_result and plant_time disagree "
"whether planting is enabled", tsection);
ok = FALSE;
break;
}
if (!lookup_unit_type(file, tsection, "animal",
&pterrain->animal, filename,
rule_name_get(&pterrain->name))) {
ok = FALSE;
break;
}
if (!lookup_terrain(file, "transform_result", filename, pterrain,
&pterrain->transform_result, TRUE)) {
ok = FALSE;
break;
}
if (!lookup_time(file, &pterrain->transform_time,
tsection, "transform_time", filename, NULL, &ok)) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
if ((pterrain->transform_result != NULL
&& pterrain->transform_time <= 0)
|| (pterrain->transform_result == NULL
&& pterrain->transform_time > 0)) {
ruleset_error(NULL, LOG_ERROR,
"%s: transform_result and transform_time disagree "
"whether transforming is enabled", tsection);
ok = FALSE;
break;
}
pterrain->placing_time = 1; /* Default */
lookup_time(file, &pterrain->placing_time,
tsection, "placing_time", filename, NULL, &ok);
pterrain->pillage_time = 1; /* Default */
lookup_time(file, &pterrain->pillage_time,
tsection, "pillage_time", filename, NULL, &ok);
if (!lookup_terrain(file, "warmer_wetter_result", filename, pterrain,
&pterrain->warmer_wetter_result, TRUE)
|| !lookup_terrain(file, "warmer_drier_result", filename, pterrain,
&pterrain->warmer_drier_result, TRUE)
|| !lookup_terrain(file, "cooler_wetter_result", filename, pterrain,
&pterrain->cooler_wetter_result, TRUE)
|| !lookup_terrain(file, "cooler_drier_result", filename, pterrain,
&pterrain->cooler_drier_result, TRUE)) {
ok = FALSE;
break;
}
/* Set default removal times */
extra_type_iterate(pextra) {
pterrain->extra_removal_times[extra_index(pextra)] = 0;
} extra_type_iterate_end;
if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
if (!rscompat_terrain_extra_rmtime_3_2(file, tsection, pterrain)) {
ok = FALSE;
break;
}
}
for (j = 0; (ename = secfile_lookup_str_default(file, NULL,
"%s.extra_settings%d.extra",
tsection, j)); j++) {
const struct extra_type *pextra = extra_type_by_rule_name(ename);
if (pextra != NULL) {
char time_sections[512];
fc_snprintf(time_sections, sizeof(time_sections),
"%s.extra_settings%d", tsection, j);
lookup_time(file, &pterrain->extra_removal_times[extra_index(pextra)],
time_sections, "removal_time", filename, NULL, &ok);
} else {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] has settings for unknown extra \"%s\".",
filename, tsection, ename);
ok = FALSE;
break;
}
}
if (ok) {
slist = secfile_lookup_str_vec(file, &nval, "%s.flags", tsection);
BV_CLR_ALL(pterrain->flags);
for (j = 0; j < nval; j++) {
const char *sval = slist[j];
enum terrain_flag_id flag
= terrain_flag_id_by_name(sval, fc_strcasecmp);
if (!terrain_flag_id_is_valid(flag)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] has unknown flag \"%s\".",
filename, tsection, sval);
ok = FALSE;
break;
} else {
BV_SET(pterrain->flags, flag);
}
}
free(slist);
}
if (!ok) {
break;
}
{
enum mapgen_terrain_property mtp;
for (mtp = mapgen_terrain_property_begin();
mtp != mapgen_terrain_property_end();
mtp = mapgen_terrain_property_next(mtp)) {
pterrain->property[mtp]
= secfile_lookup_int_default(file, 0, "%s.property_%s", tsection,
mapgen_terrain_property_name(mtp));
}
}
slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", tsection);
BV_CLR_ALL(pterrain->native_to);
for (j = 0; j < nval; j++) {
struct unit_class *class = unit_class_by_rule_name(slist[j]);
if (!class) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] is native to unknown unit class \"%s\".",
filename, tsection, slist[j]);
ok = FALSE;
break;
} else {
BV_SET(pterrain->native_to, uclass_index(class));
}
}
free(slist);
if (!ok) {
break;
}
/* Get terrain color */
{
fc_assert_ret_val(pterrain->rgb == NULL, FALSE);
if (!rgbcolor_load(file, &pterrain->rgb, "%s.color", tsection)) {
ruleset_error(NULL, LOG_ERROR,
"Missing terrain color definition: %s",
secfile_error());
ok = FALSE;
break;
}
}
pterrain->helptext = lookup_strvec(file, tsection, "helptext");
} terrain_type_iterate_end;
}
if (ok) {
/* Extra details */
extra_type_iterate(pextra) {
BV_CLR_ALL(pextra->conflicts);
} extra_type_iterate_end;
extra_type_iterate(pextra) {
int eidx = extra_index(pextra);
const char *section = &extra_sections[eidx * MAX_SECTION_LABEL];
const char **slist;
struct requirement_vector *reqs;
const char *catname;
int cj;
enum extra_cause cause;
enum extra_rmcause rmcause;
const char *eus_name;
const char *vis_req_name;
const struct advance *vis_req;
catname = secfile_lookup_str(file, "%s.category", section);
if (catname == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\" has no category.",
filename, extra_rule_name(pextra));
ok = FALSE;
break;
}
pextra->category = extra_category_by_name(catname, fc_strcasecmp);
if (!extra_category_is_valid(pextra->category)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\" has invalid category \"%s\".",
filename, extra_rule_name(pextra), catname);
ok = FALSE;
break;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.causes", section);
pextra->causes = 0;
for (cj = 0; cj < nval; cj++) {
const char *sval = slist[cj];
cause = extra_cause_by_name(sval, fc_strcasecmp);
if (!extra_cause_is_valid(cause)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\": unknown cause \"%s\".",
filename, extra_rule_name(pextra), sval);
ok = FALSE;
break;
} else {
pextra->causes |= (1 << cause);
extra_to_caused_by_list(pextra, cause);
}
}
if (pextra->causes == 0) {
/* Extras that do not have any causes added to EC_NONE list */
extra_to_caused_by_list(pextra, EC_NONE);
}
if (!is_extra_caused_by(pextra, EC_BASE)
&& !is_extra_caused_by(pextra, EC_ROAD)
&& !is_extra_caused_by(pextra, EC_RESOURCE)) {
/* Not a base, road, nor resource, so special */
pextra->data.special_idx = extra_type_list_size(extra_type_list_by_cause(EC_SPECIAL));
extra_to_caused_by_list(pextra, EC_SPECIAL);
}
free(slist);
/* Handle before rscompat_extra_rmcause_3_2() might need the values */
pextra->removal_time = 0; /* Default */
lookup_time(file, &pextra->removal_time, section, "removal_time",
filename, extra_rule_name(pextra), &ok);
pextra->removal_time_factor
= secfile_lookup_int_default(file, 1, "%s.removal_time_factor",
section);
/* Do not clear after this point.
* rscompat_extra_rmcause_3_2() might set a flag we want to keep. */
BV_CLR_ALL(pextra->flags);
slist = secfile_lookup_str_vec(file, &nval, "%s.rmcauses", section);
pextra->rmcauses = 0;
for (j = 0; j < nval; j++) {
const char *sval = slist[j];
if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
sval = rscompat_extra_rmcause_3_2(pextra, sval);
}
rmcause = extra_rmcause_by_name(sval, fc_strcasecmp);
if (!extra_rmcause_is_valid(rmcause)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\": unknown rmcause \"%s\".",
filename, extra_rule_name(pextra), sval);
ok = FALSE;
break;
} else {
pextra->rmcauses |= (1 << rmcause);
extra_to_removed_by_list(pextra, rmcause);
}
}
free(slist);
sz_strlcpy(pextra->activity_gfx,
secfile_lookup_str_default(file, "-",
"%s.activity_gfx", section));
sz_strlcpy(pextra->act_gfx_alt,
secfile_lookup_str_default(file, "-",
"%s.act_gfx_alt", section));
sz_strlcpy(pextra->act_gfx_alt2,
secfile_lookup_str_default(file, "-",
"%s.act_gfx_alt2", section));
sz_strlcpy(pextra->rmact_gfx,
secfile_lookup_str_default(file, "-",
"%s.rmact_gfx", section));
sz_strlcpy(pextra->rmact_gfx_alt,
secfile_lookup_str_default(file, "-",
"%s.rmact_gfx_alt", section));
sz_strlcpy(pextra->rmact_gfx_alt2,
secfile_lookup_str_default(file, "-",
"%s.rmact_gfx_alt2", section));
sz_strlcpy(pextra->graphic_str,
secfile_lookup_str_default(file, "-", "%s.graphic", section));
sz_strlcpy(pextra->graphic_alt,
secfile_lookup_str_default(file, "-",
"%s.graphic_alt", section));
reqs = lookup_req_list(file, compat, section, "reqs", extra_rule_name(pextra));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&pextra->reqs, reqs);
reqs = lookup_req_list(file, compat, section, "rmreqs", extra_rule_name(pextra));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&pextra->rmreqs, reqs);
reqs = lookup_req_list(file, compat, section, "appearance_reqs", extra_rule_name(pextra));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&pextra->appearance_reqs, reqs);
reqs = lookup_req_list(file, compat, section, "disappearance_reqs", extra_rule_name(pextra));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&pextra->disappearance_reqs, reqs);
pextra->buildable = secfile_lookup_bool_default(file,
is_extra_caused_by_worker_action(pextra),
"%s.buildable", section);
pextra->generated = secfile_lookup_bool_default(file, TRUE,
"%s.generated", section);
pextra->build_time = 0; /* Default */
lookup_time(file, &pextra->build_time, section, "build_time",
filename, extra_rule_name(pextra), &ok);
pextra->build_time_factor = secfile_lookup_int_default(file, 1,
"%s.build_time_factor", section);
/* removal_time handled earlier, so that rscompat_extra_rmcause_3_2()
* can use them. */
pextra->infracost = secfile_lookup_int_default(file, 0,
"%s.infracost", section);
if (pextra->infracost > 0) {
terrain_control.infrapoints = TRUE;
}
pextra->defense_bonus = secfile_lookup_int_default(file, 0,
"%s.defense_bonus",
section);
if (pextra->defense_bonus != 0) {
if (extra_has_flag(pextra, EF_NATURAL_DEFENSE)) {
extra_to_caused_by_list(pextra, EC_NATURAL_DEFENSIVE);
} else {
extra_to_caused_by_list(pextra, EC_DEFENSIVE);
}
}
eus_name = secfile_lookup_str_default(file, "Normal", "%s.unit_seen", section);
pextra->eus = extra_unit_seen_type_by_name(eus_name, fc_strcasecmp);
if (!extra_unit_seen_type_is_valid(pextra->eus)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\" has illegal unit_seen value \"%s\".",
filename, extra_rule_name(pextra), eus_name);
ok = FALSE;
break;
}
if (pextra->eus == EUS_HIDDEN) {
extra_type_list_append(extra_type_list_of_unit_hiders(), pextra);
}
pextra->appearance_chance = secfile_lookup_int_default(file, RS_DEFAULT_EXTRA_APPEARANCE,
"%s.appearance_chance",
section);
pextra->disappearance_chance = secfile_lookup_int_default(file,
RS_DEFAULT_EXTRA_DISAPPEARANCE,
"%s.disappearance_chance",
section);
pextra->no_aggr_near_city = secfile_lookup_int_default(file, -1,
"%s.no_aggr_near_city",
section);
slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", section);
BV_CLR_ALL(pextra->native_to);
for (j = 0; j < nval; j++) {
struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
if (uclass == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\" is native to unknown unit class \"%s\".",
filename, extra_rule_name(pextra), slist[j]);
ok = FALSE;
break;
} else {
BV_SET(pextra->native_to, uclass_index(uclass));
}
}
free(slist);
if (!ok) {
break;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
for (j = 0; j < nval; j++) {
const char *sval = slist[j];
enum extra_flag_id flag;
if (compat->compat_mode && compat->version < RSFORMAT_3_2
&& !fc_strcasecmp("NoAggressive", sval)) {
if (pextra->no_aggr_near_city >= 0) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\" has both no_aggr_near_city set and old style "
"NoAggressive flag",
filename, extra_rule_name(pextra));
ok = FALSE;
break;
}
/* Old NoAggressive flag meant distance of 3. */
pextra->no_aggr_near_city = 3;
} else {
flag = extra_flag_id_by_name(sval, fc_strcasecmp);
if (!extra_flag_id_is_valid(flag)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\": unknown flag \"%s\".",
filename, extra_rule_name(pextra), sval);
ok = FALSE;
break;
} else {
BV_SET(pextra->flags, flag);
}
}
}
free(slist);
if (pextra->no_aggr_near_city >= 0) {
extra_to_caused_by_list(pextra, EC_NOT_AGGRESSIVE);
}
if (extra_has_flag(pextra, EF_CAUSE_ZOC)) {
extra_type_list_append(extra_type_list_of_zoccers(), pextra);
}
if (!ok) {
break;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.conflicts", section);
for (j = 0; j < nval; j++) {
const char *sval = slist[j];
struct extra_type *pextra2 = extra_type_by_rule_name(sval);
if (pextra2 == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\": unknown conflict extra \"%s\".",
filename, extra_rule_name(pextra), sval);
ok = FALSE;
break;
} else {
BV_SET(pextra->conflicts, extra_index(pextra2));
BV_SET(pextra2->conflicts, extra_index(pextra));
}
}
free(slist);
if (!ok) {
break;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.hidden_by", section);
BV_CLR_ALL(pextra->hidden_by);
for (j = 0; j < nval; j++) {
const char *sval = slist[j];
const struct extra_type *top = extra_type_by_rule_name(sval);
if (top == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\" hidden by unknown extra \"%s\".",
filename, extra_rule_name(pextra), sval);
ok = FALSE;
break;
} else {
BV_SET(pextra->hidden_by, extra_index(top));
}
}
free(slist);
if (!ok) {
break;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.bridged_over", section);
BV_CLR_ALL(pextra->bridged_over);
for (j = 0; j < nval; j++) {
const char *sval = slist[j];
const struct extra_type *top = extra_type_by_rule_name(sval);
if (top == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\" bridged over unknown extra \"%s\".",
filename, extra_rule_name(pextra), sval);
ok = FALSE;
break;
} else {
BV_SET(pextra->bridged_over, extra_index(top));
}
}
free(slist);
if (!ok) {
break;
}
vis_req_name = secfile_lookup_str_default(file, "None",
"%s.visibility_req", section);
vis_req = advance_by_rule_name(vis_req_name);
if (vis_req == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" %s: unknown visibility_req %s.",
filename, section, vis_req_name);
ok = FALSE;
break;
}
pextra->visibility_req = advance_number(vis_req);
pextra->helptext = lookup_strvec(file, section, "helptext");
if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
rscompat_extra_adjust_3_2(pextra);
}
} extra_type_iterate_end;
}
if (ok) {
int i = 0;
/* Resource details */
extra_type_by_cause_iterate(EC_RESOURCE, presource) {
char identifier[MAX_LEN_NAME];
const char *id;
const char *rsection = &resource_sections[i * MAX_SECTION_LABEL];
if (!presource->data.resource) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\" has \"Resource\" cause but no "
"corresponding [resource_*] section",
filename, extra_rule_name(presource));
ok = FALSE;
break;
}
output_type_iterate (o) {
presource->data.resource->output[o] =
secfile_lookup_int_default(file, 0, "%s.%s", rsection,
get_output_identifier(o));
} output_type_iterate_end;
id = secfile_lookup_str_default(file, NULL, "%s.identifier", rsection);
if (id == NULL) {
presource->data.resource->id_old_save = '\0';
} else {
sz_strlcpy(identifier, id);
presource->data.resource->id_old_save = identifier[0];
if (RESOURCE_NULL_IDENTIFIER == presource->data.resource->id_old_save) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] identifier missing value.",
filename, rsection);
ok = FALSE;
break;
}
if (RESOURCE_NONE_IDENTIFIER == presource->data.resource->id_old_save) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] cannot use '%c' as an identifier;"
" it is reserved.",
filename, rsection, presource->data.resource->id_old_save);
ok = FALSE;
break;
}
}
if (!ok) {
break;
}
i++;
} extra_type_by_cause_iterate_end;
for (j = 0; ok && j < game.control.num_resource_types; j++) {
const char *section = &resource_sections[j * MAX_SECTION_LABEL];
const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
struct extra_type *pextra = extra_type_by_rule_name(extra_name);
if (!is_extra_caused_by(pextra, EC_RESOURCE)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" resource section [%s]: extra \"%s\" does not "
"have \"Resource\" in its causes",
filename, section, extra_name);
ok = FALSE;
}
}
}
if (ok) {
/* This can't be part of previous loop as we don't want random data from previous
* ruleset to play havoc on us when we have only some resource identifiers loaded
* from the new ruleset. */
extra_type_by_cause_iterate(EC_RESOURCE, pres) {
if (pres->data.resource->id_old_save != '\0') {
extra_type_by_cause_iterate(EC_RESOURCE, pres2) {
if (pres->data.resource->id_old_save == pres2->data.resource->id_old_save
&& pres != pres2) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] has the same identifier as [%s].",
filename,
extra_rule_name(pres),
extra_rule_name(pres2));
ok = FALSE;
break;
}
} extra_type_by_cause_iterate_end;
if (!ok) {
break;
}
}
} extra_type_by_cause_iterate_end;
}
if (ok) {
/* Base details */
extra_type_by_cause_iterate(EC_BASE, pextra) {
struct base_type *pbase = extra_base_get(pextra);
const char *section;
const char *gui_str;
if (!pbase) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\" has \"Base\" cause but no "
"corresponding [base_*] section",
filename, extra_rule_name(pextra));
ok = FALSE;
break;
}
section = &base_sections[base_number(pbase) * MAX_SECTION_LABEL];
gui_str = secfile_lookup_str(file, "%s.gui_type", section);
pbase->gui_type = base_gui_type_by_name(gui_str, fc_strcasecmp);
if (!base_gui_type_is_valid(pbase->gui_type)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" base \"%s\": unknown gui_type \"%s\".",
filename, extra_rule_name(pextra), gui_str);
ok = FALSE;
break;
}
pbase->border_sq = secfile_lookup_int_default(file, -1, "%s.border_sq",
section);
pbase->vision_main_sq = secfile_lookup_int_default(file, -1,
"%s.vision_main_sq",
section);
pbase->vision_invis_sq = secfile_lookup_int_default(file, -1,
"%s.vision_invis_sq",
section);
pbase->vision_subs_sq = secfile_lookup_int_default(file, -1,
"%s.vision_subs_sq",
section);
if (!ok) {
break;
}
if (territory_claiming_base(pbase)) {
extra_type_list_append(extra_type_list_of_terr_claimers(), pextra);
extra_type_by_cause_iterate(EC_BASE, pextra2) {
struct base_type *pbase2;
if (pextra == pextra2) {
/* End of the fully initialized bases iteration. */
break;
}
pbase2 = extra_base_get(pextra2);
if (territory_claiming_base(pbase2)) {
BV_SET(pextra->conflicts, extra_index(pextra2));
BV_SET(pextra2->conflicts, extra_index(pextra));
}
} extra_type_by_cause_iterate_end;
}
} extra_type_by_cause_iterate_end;
for (j = 0; ok && j < game.control.num_base_types; j++) {
const char *section = &base_sections[j * MAX_SECTION_LABEL];
const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
struct extra_type *pextra = extra_type_by_rule_name(extra_name);
if (!is_extra_caused_by(pextra, EC_BASE)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" base section [%s]: extra \"%s\" does not have "
"\"Base\" in its causes",
filename, section, extra_name);
ok = FALSE;
}
}
}
if (ok) {
extra_type_by_cause_iterate(EC_ROAD, pextra) {
struct road_type *proad = extra_road_get(pextra);
const char *section;
const char **slist;
const char *special;
const char *modestr;
struct requirement_vector *reqs;
const char *gui_str;
if (!proad) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" extra \"%s\" has \"Road\" cause but no "
"corresponding [road_*] section",
filename, extra_rule_name(pextra));
ok = FALSE;
break;
}
section = &road_sections[road_number(proad) * MAX_SECTION_LABEL];
gui_str = secfile_lookup_str(file, "%s.gui_type", section);
proad->gui_type = road_gui_type_by_name(gui_str, fc_strcasecmp);
if (!road_gui_type_is_valid(proad->gui_type)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" road \"%s\": unknown gui_type \"%s\".",
filename, extra_rule_name(pextra), gui_str);
ok = FALSE;
break;
}
reqs = lookup_req_list(file, compat, section, "first_reqs", extra_rule_name(pextra));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&proad->first_reqs, reqs);
if (!secfile_lookup_int(file, &proad->move_cost,
"%s.move_cost", section)) {
ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
ok = FALSE;
break;
}
modestr = secfile_lookup_str_default(file, "FastAlways", "%s.move_mode",
section);
proad->move_mode = road_move_mode_by_name(modestr, fc_strcasecmp);
if (!road_move_mode_is_valid(proad->move_mode)) {
ruleset_error(NULL, LOG_ERROR,
"Illegal move_mode \"%s\" for road \"%s\"",
modestr, extra_rule_name(pextra));
ok = FALSE;
break;
}
output_type_iterate(o) {
proad->tile_incr_const[o] =
secfile_lookup_int_default(file, 0, "%s.%s_incr_const",
section, get_output_identifier(o));
proad->tile_incr[o] =
secfile_lookup_int_default(file, 0, "%s.%s_incr",
section, get_output_identifier(o));
proad->tile_bonus[o] =
secfile_lookup_int_default(file, 0, "%s.%s_bonus",
section, get_output_identifier(o));
} output_type_iterate_end;
special = secfile_lookup_str_default(file, "None", "%s.compat_special", section);
if (!fc_strcasecmp(special, "Road")) {
if (compat_road) {
ruleset_error(NULL, LOG_ERROR,
"Multiple roads marked as compatibility \"Road\"");
ok = FALSE;
}
compat_road = TRUE;
proad->compat = ROCO_ROAD;
} else if (!fc_strcasecmp(special, "Railroad")) {
if (compat_rail) {
ruleset_error(NULL, LOG_ERROR,
"Multiple roads marked as compatibility \"Railroad\"");
ok = FALSE;
}
compat_rail = TRUE;
proad->compat = ROCO_RAILROAD;
} else if (!fc_strcasecmp(special, "River")) {
if (compat_river) {
ruleset_error(NULL, LOG_ERROR,
"Multiple roads marked as compatibility \"River\"");
ok = FALSE;
}
compat_river = TRUE;
proad->compat = ROCO_RIVER;
} else if (!fc_strcasecmp(special, "None")) {
proad->compat = ROCO_NONE;
} else {
ruleset_error(NULL, LOG_ERROR,
"Illegal compatibility special \"%s\" for road %s",
special, extra_rule_name(pextra));
ok = FALSE;
}
if (!ok) {
break;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.integrates", section);
BV_CLR_ALL(proad->integrates);
for (j = 0; j < nval; j++) {
const char *sval = slist[j];
struct extra_type *textra = extra_type_by_rule_name(sval);
struct road_type *top = NULL;
if (textra != NULL) {
top = extra_road_get(textra);
}
if (top == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" road \"%s\" integrates with unknown road \"%s\".",
filename, extra_rule_name(pextra), sval);
ok = FALSE;
break;
} else {
BV_SET(proad->integrates, road_number(top));
}
}
free(slist);
if (!ok) {
break;
}
slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
BV_CLR_ALL(proad->flags);
for (j = 0; j < nval; j++) {
const char *sval = slist[j];
enum road_flag_id flag = road_flag_id_by_name(sval, fc_strcasecmp);
if (!road_flag_id_is_valid(flag)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" road \"%s\": unknown flag \"%s\".",
filename, extra_rule_name(pextra), sval);
ok = FALSE;
break;
} else {
BV_SET(proad->flags, flag);
}
}
free(slist);
if (!ok) {
break;
}
} extra_type_by_cause_iterate_end;
for (j = 0; ok && j < game.control.num_road_types; j++) {
const char *section = &road_sections[j * MAX_SECTION_LABEL];
const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
struct extra_type *pextra = extra_type_by_rule_name(extra_name);
if (!is_extra_caused_by(pextra, EC_ROAD)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" road section [%s]: extra \"%s\" does not have "
"\"Road\" in its causes",
filename, section, extra_name);
ok = FALSE;
}
}
}
if (ok) {
extra_type_iterate(pextra) {
pextra->bridged = extra_type_list_new();
extra_type_iterate(pbridged) {
if (BV_ISSET(pextra->bridged_over, pbridged->id)) {
extra_type_list_append(pextra->bridged, pbridged);
}
} extra_type_iterate_end;
} extra_type_iterate_end;
}
if (ok) {
secfile_check_unused(file);
}
return ok;
}
/**********************************************************************//**
Load names of governments so other rulesets can refer to governments with
their name. Also load multiplier names/count from governments.ruleset.
**************************************************************************/
static bool load_government_names(struct section_file *file,
struct rscompat_info *compat)
{
int nval = 0;
struct section_list *sec;
const char *filename = secfile_name(file);
bool ok = TRUE;
if (!rscompat_check_cap_and_version(file, filename, compat)) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
sec = secfile_sections_by_name_prefix(file, GOVERNMENT_SECTION_PREFIX);
if (NULL == sec || 0 == (nval = section_list_size(sec))) {
ruleset_error(NULL, LOG_ERROR, "\"%s\": No governments?!?", filename);
ok = FALSE;
} else if (nval > G_LAST) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many governments (%d, max %d)",
filename, nval, G_LAST);
ok = FALSE;
}
if (ok) {
governments_alloc(nval);
/* Government names are needed early so that get_government_by_name will
* work. */
governments_iterate(gov) {
const char *sec_name =
section_name(section_list_get(sec, government_index(gov)));
if (!ruleset_load_names(&gov->name, NULL, file, sec_name)) {
ok = FALSE;
break;
}
} governments_iterate_end;
}
section_list_destroy(sec);
if (ok) {
sec = secfile_sections_by_name_prefix(file, MULTIPLIER_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
if (nval > MAX_NUM_MULTIPLIERS) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many multipliers (%d, max %d)",
filename, nval, MAX_NUM_MULTIPLIERS);
ok = FALSE;
} else {
game.control.num_multipliers = nval;
}
if (ok) {
multipliers_iterate(pmul) {
const char *sec_name =
section_name(section_list_get(sec, multiplier_index(pmul)));
if (!ruleset_load_names(&pmul->name, NULL, file, sec_name)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Cannot load multiplier names",
filename);
ok = FALSE;
break;
}
} multipliers_iterate_end;
}
}
section_list_destroy(sec);
return ok;
}
/**********************************************************************//**
This loads information from given governments.ruleset
**************************************************************************/
static bool load_ruleset_governments(struct section_file *file,
struct rscompat_info *compat)
{
struct section_list *sec;
const char *filename = secfile_name(file);
bool ok = TRUE;
sec = secfile_sections_by_name_prefix(file, GOVERNMENT_SECTION_PREFIX);
game.government_during_revolution
= lookup_government(file, "governments.during_revolution", filename, NULL);
if (game.government_during_revolution == NULL) {
ok = FALSE;
}
if (ok) {
game.info.government_during_revolution_id
= government_number(game.government_during_revolution);
/* Easy ones: */
governments_iterate(g) {
const int i = government_index(g);
const char *sec_name = section_name(section_list_get(sec, i));
struct requirement_vector *reqs
= lookup_req_list(file, compat, sec_name, "reqs", government_rule_name(g));
if (reqs == NULL) {
ok = FALSE;
break;
}
if (NULL != secfile_entry_lookup(file, "%s.ai_better", sec_name)) {
char entry[100];
fc_snprintf(entry, sizeof(entry), "%s.ai_better", sec_name);
g->ai.better = lookup_government(file, entry, filename, NULL);
if (g->ai.better == NULL) {
ok = FALSE;
break;
}
} else {
g->ai.better = NULL;
}
requirement_vector_copy(&g->reqs, reqs);
sz_strlcpy(g->graphic_str,
secfile_lookup_str(file, "%s.graphic", sec_name));
sz_strlcpy(g->graphic_alt,
secfile_lookup_str(file, "%s.graphic_alt", sec_name));
sz_strlcpy(g->sound_str,
secfile_lookup_str_default(file, "-", "%s.sound", sec_name));
sz_strlcpy(g->sound_alt,
secfile_lookup_str_default(file, "-", "%s.sound_alt", sec_name));
sz_strlcpy(g->sound_alt2,
secfile_lookup_str_default(file, "-", "%s.sound_alt2", sec_name));
g->helptext = lookup_strvec(file, sec_name, "helptext");
} governments_iterate_end;
}
if (ok) {
/* Titles */
governments_iterate(g) {
const char *sec_name
= section_name(section_list_get(sec, government_index(g)));
const char *male, *female;
if (!(male = secfile_lookup_str(file, "%s.ruler_male_title", sec_name))
|| !(female = secfile_lookup_str(file, "%s.ruler_female_title",
sec_name))) {
ruleset_error(NULL, LOG_ERROR,
"Lack of default ruler titles for "
"government \"%s\" (nb %d): %s",
government_rule_name(g), government_number(g),
secfile_error());
ok = FALSE;
break;
} else if (NULL == government_ruler_title_new(g, NULL, male, female)) {
ruleset_error(NULL, LOG_ERROR,
"Lack of default ruler titles for "
"government \"%s\" (nb %d).",
government_rule_name(g), government_number(g));
ok = FALSE;
break;
}
} governments_iterate_end;
}
section_list_destroy(sec);
if (ok) {
sec = secfile_sections_by_name_prefix(file, MULTIPLIER_SECTION_PREFIX);
multipliers_iterate(pmul) {
int id = multiplier_index(pmul);
const char *sec_name = section_name(section_list_get(sec, id));
struct requirement_vector *reqs;
if (!secfile_lookup_int(file, &pmul->start, "%s.start", sec_name)) {
ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
ok = FALSE;
break;
}
if (!secfile_lookup_int(file, &pmul->stop, "%s.stop", sec_name)) {
ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
ok = FALSE;
break;
}
if (pmul->stop <= pmul->start) {
ruleset_error(NULL, LOG_ERROR,
"Multiplier \"%s\" stop (%d) must be greater "
"than start (%d)", multiplier_rule_name(pmul),
pmul->stop, pmul->start);
ok = FALSE;
break;
}
if (!secfile_lookup_int(file, &pmul->step, "%s.step", sec_name)) {
ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
ok = FALSE;
break;
}
if (((pmul->stop - pmul->start) % pmul->step) != 0) {
ruleset_error(NULL, LOG_ERROR,
"Multiplier \"%s\" step (%d) does not fit "
"exactly into interval start-stop (%d to %d)",
multiplier_rule_name(pmul), pmul->step,
pmul->start, pmul->stop);
ok = FALSE;
break;
}
if (!secfile_lookup_int(file, &pmul->def, "%s.default", sec_name)) {
ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
ok = FALSE;
break;
}
if (pmul->def < pmul->start || pmul->def > pmul->stop) {
ruleset_error(NULL, LOG_ERROR,
"Multiplier \"%s\" default (%d) not within "
"legal range (%d to %d)", multiplier_rule_name(pmul),
pmul->def, pmul->start, pmul->stop);
ok = FALSE;
break;
}
if (((pmul->def - pmul->start) % pmul->step) != 0) {
ruleset_error(NULL, LOG_ERROR,
"Multiplier \"%s\" default (%d) not legal "
"with respect to step size %d",
multiplier_rule_name(pmul), pmul->def, pmul->step);
ok = FALSE;
break;
}
pmul->offset = secfile_lookup_int_default(file, 0,
"%s.offset", sec_name);
pmul->factor = secfile_lookup_int_default(file, 100,
"%s.factor", sec_name);
if (pmul->factor == 0) {
ruleset_error(NULL, LOG_ERROR,
"Multiplier \"%s\" scaling factor must "
"not be zero", multiplier_rule_name(pmul));
ok = FALSE;
break;
}
pmul->minimum_turns = secfile_lookup_int_default(file, 0,
"%s.minimum_turns",
sec_name);
reqs = lookup_req_list(file, compat, sec_name, "reqs",
multiplier_rule_name(pmul));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&pmul->reqs, reqs);
pmul->helptext = lookup_strvec(file, sec_name, "helptext");
} multipliers_iterate_end;
section_list_destroy(sec);
}
if (ok) {
secfile_check_unused(file);
}
return ok;
}
/**********************************************************************//**
Send information in packet_ruleset_control (numbers of units etc, and
other miscellany) to specified connections.
The client assumes that exactly one ruleset control packet is sent as
a part of each ruleset send. So after sending this packet we have to
resend every other part of the rulesets (and none of them should be
is-info in the network code!). The client frees ruleset data when
receiving this packet and then re-initializes as it receives the
individual ruleset packets. See packhand.c.
**************************************************************************/
static void send_ruleset_control(struct conn_list *dest)
{
int desc_left = game.control.desc_length;
int idx = 0;
lsend_packet_ruleset_control(dest, &(game.control));
if (game.ruleset_summary != NULL) {
struct packet_ruleset_summary summary;
sz_strlcpy(summary.text, game.ruleset_summary);
lsend_packet_ruleset_summary(dest, &summary);
}
while (desc_left > 0) {
struct packet_ruleset_description_part part;
int this_len = desc_left;
if (this_len > MAX_LEN_CONTENT - 21) {
this_len = MAX_LEN_CONTENT - 1;
}
part.text[this_len] = '\0';
strncpy(part.text, &game.ruleset_description[idx], this_len);
idx += this_len;
desc_left -= this_len;
lsend_packet_ruleset_description_part(dest, &part);
}
}
/**********************************************************************//**
Check for duplicate leader names in nation.
If no duplicates return NULL; if yes return pointer to name which is
repeated.
**************************************************************************/
static const char *check_leader_names(struct nation_type *pnation)
{
nation_leader_list_iterate(nation_leaders(pnation), pleader) {
const char *name = nation_leader_name(pleader);
nation_leader_list_iterate(nation_leaders(pnation), prev_leader) {
if (prev_leader == pleader) {
break;
} else if (0 == fc_strcasecmp(name, nation_leader_name(prev_leader))) {
return name;
}
} nation_leader_list_iterate_end;
} nation_leader_list_iterate_end;
return NULL;
}
/**********************************************************************//**
Load names of nations so other rulesets can refer to nations with
their name.
**************************************************************************/
static bool load_nation_names(struct section_file *file,
struct rscompat_info *compat)
{
struct section_list *sec;
int j;
bool ok = TRUE;
const char *filename = secfile_name(file);
if (!rscompat_check_cap_and_version(file, filename, compat)) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
sec = secfile_sections_by_name_prefix(file, NATION_SECTION_PREFIX);
if (NULL == sec) {
ruleset_error(NULL, LOG_ERROR,
"No available nations in this ruleset!");
ok = FALSE;
} else if (section_list_size(sec) > MAX_NUM_NATIONS) {
ruleset_error(NULL, LOG_ERROR,
"Too many nations (max %d, we have %d)!",
MAX_NUM_NATIONS, section_list_size(sec));
ok = FALSE;
} else {
game.control.nation_count = section_list_size(sec);
nations_alloc(game.control.nation_count);
nations_iterate(pl) {
const int i = nation_index(pl);
const char *sec_name = section_name(section_list_get(sec, i));
const char *domain = secfile_lookup_str_default(file, NULL,
"%s.translation_domain", sec_name);
const char *noun_plural = secfile_lookup_str(file,
"%s.plural", sec_name);
if (domain == NULL) {
domain = "freeciv-nations";
}
if (!strcmp("freeciv-core", domain)) {
pl->translation_domain = NULL;
} else if (!strcmp("freeciv-nations", domain)) {
pl->translation_domain = fc_strdup(domain);
} else {
ruleset_error(NULL, LOG_ERROR,
"Unsupported translation domain \"%s\" for %s",
domain, sec_name);
ok = FALSE;
break;
}
if (!ruleset_load_names(&pl->adjective, pl->translation_domain, file, sec_name)) {
ok = FALSE;
break;
}
name_set(&pl->noun_plural, pl->translation_domain, noun_plural);
/* Check if nation name is already defined. */
for (j = 0; j < i && ok; j++) {
struct nation_type *n2 = nation_by_number(j);
/* Compare strings after stripping off qualifiers -- we don't want
* two nations to end up with identical adjectives displayed to users.
* (This check only catches English, not localisations, of course.) */
if (0 == strcmp(Qn_(untranslated_name(&n2->adjective)),
Qn_(untranslated_name(&pl->adjective)))) {
ruleset_error(NULL, LOG_ERROR,
"Two nations defined with the same adjective \"%s\": "
"in section \'%s\' and section \'%s\'",
Qn_(untranslated_name(&pl->adjective)),
section_name(section_list_get(sec, j)), sec_name);
ok = FALSE;
} else if (!strcmp(rule_name_get(&n2->adjective),
rule_name_get(&pl->adjective))) {
/* We cannot have the same rule name, as the game needs them to be
* distinct. */
ruleset_error(NULL, LOG_ERROR,
"Two nations defined with the same rule_name \"%s\": "
"in section \'%s\' and section \'%s\'",
rule_name_get(&pl->adjective),
section_name(section_list_get(sec, j)), sec_name);
ok = FALSE;
} else if (0 == strcmp(Qn_(untranslated_name(&n2->noun_plural)),
Qn_(untranslated_name(&pl->noun_plural)))) {
/* We don't want identical English plural names either. */
ruleset_error(NULL, LOG_ERROR,
"Two nations defined with the same plural name \"%s\": "
"in section \'%s\' and section \'%s\'",
Qn_(untranslated_name(&pl->noun_plural)),
section_name(section_list_get(sec, j)), sec_name);
ok = FALSE;
}
}
if (!ok) {
break;
}
} nations_iterate_end;
}
section_list_destroy(sec);
if (ok) {
sec = secfile_sections_by_name_prefix(file, NATION_GROUP_SECTION_PREFIX);
if (sec != NULL) {
game.control.num_nation_groups = section_list_size(sec);
section_list_iterate(sec, psection) {
struct nation_group *pgroup;
const char *name;
name = secfile_lookup_str(file, "%s.name", section_name(psection));
if (NULL == name) {
ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
ok = FALSE;
break;
}
pgroup = nation_group_new(name);
if (pgroup == NULL) {
ok = FALSE;
break;
}
} section_list_iterate_end;
section_list_destroy(sec);
sec = NULL;
}
}
return ok;
}
/**********************************************************************//**
Check if a string is in a vector (case-insensitively).
**************************************************************************/
static bool is_on_allowed_list(const char *name, const char **list, size_t len)
{
int i;
for (i = 0; i < len; i++) {
if (!fc_strcasecmp(name, list[i])) {
return TRUE;
}
}
return FALSE;
}
/**********************************************************************//**
This function loads a city name list from a section file. The file and
two section names (which will be concatenated) are passed in.
**************************************************************************/
static bool load_city_name_list(struct section_file *file,
struct nation_type *pnation,
const char *secfile_str1,
const char *secfile_str2,
const char **allowed_terrains,
size_t atcount)
{
size_t dim, j;
bool ok = TRUE;
const char **cities = secfile_lookup_str_vec(file, &dim, "%s.%s",
secfile_str1, secfile_str2);
/* Each string will be of the form "<cityname> (<label>, <label>, ...)".
* The cityname is just the name for this city, while each "label" matches
* a terrain type for the city (or "river"), with a preceding ! to negate
* it. The parentheses are optional (but necessary to have the settings,
* of course). Our job is now to parse it. */
for (j = 0; j < dim; j++) {
size_t len = strlen(cities[j]);
char city_name[len + 1], *p, *next, *end;
struct nation_city *pncity;
sz_strlcpy(city_name, cities[j]);
/* Now we wish to determine values for all of the city labels. A value
* of NCP_NONE means no preference (which is necessary so that the use
* of this is optional); NCP_DISLIKE means the label is negated and
* NCP_LIKE means it's labelled. Mostly the parsing just involves
* a lot of ugly string handling... */
if ((p = strchr(city_name, '('))) {
*p++ = '\0';
if (!(end = strchr(p, ')'))) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] %s: city name \"%s\" "
"unmatched parenthesis.", secfile_name(file),
secfile_str1, secfile_str2, cities[j]);
ok = FALSE;
} else {
for (*end++ = '\0'; '\0' != *end; end++) {
if (!fc_isspace(*end)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] %s: city name \"%s\" "
"contains characters after last parenthesis.",
secfile_name(file), secfile_str1, secfile_str2,
cities[j]);
ok = FALSE;
break;
}
}
}
}
/* Build the nation_city. */
remove_leading_trailing_spaces(city_name);
if (check_cityname(city_name)) {
/* The ruleset contains a name that is too long. This shouldn't
* happen - if it does, the author should get immediate feedback. */
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] %s: city name \"%s\" is too long.",
secfile_name(file),
secfile_str1, secfile_str2, city_name);
ok = FALSE;
city_name[MAX_LEN_CITYNAME - 1] = '\0';
}
pncity = nation_city_new(pnation, city_name);
if (NULL != p) {
/* Handle the labels one at a time. */
do {
enum nation_city_preference prefer;
if ((next = strchr(p, ','))) {
*next = '\0';
}
remove_leading_trailing_spaces(p);
/* The ! is used to mark a negative, which is recorded with
* NCP_DISLIKE. Otherwise we use a NCP_LIKE.
*/
if (*p == '!') {
p++;
prefer = NCP_DISLIKE;
} else {
prefer = NCP_LIKE;
}
if (0 == fc_strcasecmp(p, "river")) {
if (game.server.ruledit.allowed_terrains != NULL
&& !is_on_allowed_list(p,
game.server.ruledit.allowed_terrains, atcount)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] %s: city \"%s\" "
"has terrain hint \"%s\" not in allowed_terrains.",
secfile_name(file), secfile_str1, secfile_str2,
city_name, p);
ok = FALSE;
} else {
nation_city_set_river_preference(pncity, prefer);
}
} else {
const struct terrain *pterrain = terrain_by_rule_name(p);
if (NULL == pterrain) {
/* Try with removing frequent trailing 's'. */
size_t l = strlen(p);
if (0 < l && 's' == fc_tolower(p[l - 1])) {
char saved = p[l - 1];
p[l - 1] = '\0';
pterrain = terrain_by_rule_name(p);
if (pterrain == NULL) {
/* Didn't help, restore for later allowed_terrains check */
p[l - 1] = saved;
}
}
}
/* Nationset may have been devised with a specific set of terrains
* in mind which don't quite match this ruleset, in which case we
* (a) quietly ignore any hints mentioned that don't happen to be in
* the current ruleset, (b) enforce that terrains mentioned by nations
* must be on the list */
if (pterrain != NULL && game.server.ruledit.allowed_terrains != NULL) {
if (!is_on_allowed_list(p,
game.server.ruledit.allowed_terrains, atcount)) {
/* Terrain exists, but not intended for these nations */
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] %s: city \"%s\" "
"has terrain hint \"%s\" not in allowed_terrains.",
secfile_name(file), secfile_str1, secfile_str2,
city_name, p);
ok = FALSE;
break;
}
} else if (!pterrain) {
/* Terrain doesn't exist; only complain if it's not on any list */
if (game.server.ruledit.allowed_terrains == NULL
|| !is_on_allowed_list(p,
game.server.ruledit.allowed_terrains, atcount)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] %s: city \"%s\" "
"has unknown terrain hint \"%s\".",
secfile_name(file), secfile_str1, secfile_str2,
city_name, p);
ok = FALSE;
break;
}
}
if (NULL != pterrain) {
nation_city_set_terrain_preference(pncity, pterrain, prefer);
}
}
p = next ? next + 1 : NULL;
} while (NULL != p && '\0' != *p);
}
}
if (NULL != cities) {
free(cities);
}
return ok;
}
/**********************************************************************//**
Load nations.ruleset file
**************************************************************************/
static bool load_ruleset_nations(struct section_file *file,
struct rscompat_info *compat)
{
struct government *gov;
int j;
size_t dim;
char temp_name[MAX_LEN_NAME];
const char **vec;
const char *name, *bad_leader;
const char *sval;
int default_set;
const char *filename = secfile_name(file);
struct section_list *sec = NULL;
enum trait tr;
bool ok = TRUE;
name = secfile_lookup_str_default(file, NULL, "ruledit.nationlist");
if (name != NULL) {
game.server.ruledit.nationlist = fc_strdup(name);
}
vec = secfile_lookup_str_vec(file, &game.server.ruledit.embedded_nations_count,
"ruledit.embedded_nations");
if (vec != NULL) {
/* Copy to persistent vector */
game.server.ruledit.embedded_nations
= fc_malloc(game.server.ruledit.embedded_nations_count * sizeof(char *));
for (j = 0; j < game.server.ruledit.embedded_nations_count; j++) {
game.server.ruledit.embedded_nations[j] = fc_strdup(vec[j]);
}
free(vec);
}
game.default_government = NULL;
ruleset_load_traits(game.server.default_traits, file, "default_traits", "");
for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
if (game.server.default_traits[tr].min < 0) {
game.server.default_traits[tr].min = TRAIT_DEFAULT_VALUE;
}
if (game.server.default_traits[tr].max < 0) {
game.server.default_traits[tr].max = TRAIT_DEFAULT_VALUE;
}
if (game.server.default_traits[tr].fixed < 0) {
int diff = game.server.default_traits[tr].max - game.server.default_traits[tr].min;
/* TODO: Should sometimes round the a / 2 = x.5 results up */
game.server.default_traits[tr].fixed = diff / 2 + game.server.default_traits[tr].min;
}
if (game.server.default_traits[tr].max < game.server.default_traits[tr].min) {
ruleset_error(NULL, LOG_ERROR,
"Default values for trait %s not sane.",
trait_name(tr));
ok = FALSE;
break;
}
}
if (ok) {
vec = secfile_lookup_str_vec(file, &game.server.ruledit.ag_count,
"compatibility.allowed_govs");
if (vec != NULL) {
/* Copy to persistent vector */
game.server.ruledit.nc_agovs
= fc_malloc(game.server.ruledit.ag_count * sizeof(char *));
game.server.ruledit.allowed_govs =
(const char **)game.server.ruledit.nc_agovs;
for (j = 0; j < game.server.ruledit.ag_count; j++) {
game.server.ruledit.allowed_govs[j] = fc_strdup(vec[j]);
}
free(vec);
}
vec = secfile_lookup_str_vec(file, &game.server.ruledit.at_count,
"compatibility.allowed_terrains");
if (vec != NULL) {
/* Copy to persistent vector */
game.server.ruledit.nc_aterrs
= fc_malloc(game.server.ruledit.at_count * sizeof(char *));
game.server.ruledit.allowed_terrains =
(const char **)game.server.ruledit.nc_aterrs;
for (j = 0; j < game.server.ruledit.at_count; j++) {
game.server.ruledit.allowed_terrains[j] = fc_strdup(vec[j]);
}
free(vec);
}
vec = secfile_lookup_str_vec(file, &game.server.ruledit.as_count,
"compatibility.allowed_styles");
if (vec != NULL) {
/* Copy to persistent vector */
game.server.ruledit.nc_astyles
= fc_malloc(game.server.ruledit.as_count * sizeof(char *));
game.server.ruledit.allowed_styles =
(const char **)game.server.ruledit.nc_astyles;
for (j = 0; j < game.server.ruledit.as_count; j++) {
game.server.ruledit.allowed_styles[j] = fc_strdup(vec[j]);
}
free(vec);
}
sval = secfile_lookup_str_default(file, NULL,
"compatibility.default_government");
/* We deliberately don't check this against allowed_govs. It's only
* specified once so not vulnerable to typos, and may usefully be set in
* a specific ruleset to a gov not explicitly known by the nation set. */
if (sval != NULL) {
game.default_government = government_by_rule_name(sval);
if (game.default_government == NULL) {
ruleset_error(NULL, LOG_ERROR,
"Tried to set unknown government type \"%s\" as default_government!",
sval);
ok = FALSE;
} else {
game.info.default_government_id
= government_number(game.default_government);
}
}
}
if (ok) {
sec = secfile_sections_by_name_prefix(file, NATION_SET_SECTION_PREFIX);
if (sec != NULL) {
game.control.num_nation_sets = section_list_size(sec);
section_list_iterate(sec, psection) {
const char *set_name, *set_rule_name, *set_description;
set_name = secfile_lookup_str(file, "%s.name", section_name(psection));
set_rule_name =
secfile_lookup_str(file, "%s.rule_name", section_name(psection));
set_description = secfile_lookup_str_default(file, "", "%s.description",
section_name(psection));
if (NULL == set_name || NULL == set_rule_name) {
ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
ok = FALSE;
break;
}
if (nation_set_new(set_name, set_rule_name, set_description) == NULL) {
ok = FALSE;
break;
}
} section_list_iterate_end;
section_list_destroy(sec);
sec = NULL;
} else {
ruleset_error(NULL, LOG_ERROR,
"At least one nation set [" NATION_SET_SECTION_PREFIX "_*] "
"must be defined.");
ok = FALSE;
}
}
if (ok) {
/* Default set that every nation is a member of. */
sval = secfile_lookup_str_default(file, NULL,
"compatibility.default_nationset");
if (sval != NULL) {
const struct nation_set *pset = nation_set_by_rule_name(sval);
if (pset != NULL) {
default_set = nation_set_number(pset);
} else {
ruleset_error(NULL, LOG_ERROR,
"Unknown default_nationset \"%s\".", sval);
ok = FALSE;
}
} else if (nation_set_count() == 1) {
/* If there's only one set defined, every nation is implicitly a
* member of that set. */
default_set = 0;
} else {
/* No default nation set; every nation must explicitly specify at
* least one set to be a member of. */
default_set = -1;
}
}
if (ok) {
sec = secfile_sections_by_name_prefix(file, NATION_GROUP_SECTION_PREFIX);
if (sec) {
section_list_iterate(sec, psection) {
struct nation_group *pgroup;
bool hidden;
name = secfile_lookup_str(file, "%s.name", section_name(psection));
pgroup = nation_group_by_rule_name(name);
if (pgroup == NULL) {
ok = FALSE;
break;
}
hidden = secfile_lookup_bool_default(file, FALSE, "%s.hidden",
section_name(psection));
nation_group_set_hidden(pgroup, hidden);
if (!secfile_lookup_int(file, &j, "%s.match", section_name(psection))) {
ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
ok = FALSE;
break;
}
nation_group_set_match(pgroup, j);
} section_list_iterate_end;
section_list_destroy(sec);
sec = NULL;
}
}
if (ok) {
sec = secfile_sections_by_name_prefix(file, NATION_SECTION_PREFIX);
nations_iterate(pnation) {
struct nation_type *pconflict;
const int i = nation_index(pnation);
char tmp[200] = "\0";
const char *barb_type;
const char *sec_name = section_name(section_list_get(sec, i));
const char *legend;
/* Nation sets and groups. */
if (default_set >= 0) {
nation_set_list_append(pnation->sets,
nation_set_by_number(default_set));
}
vec = secfile_lookup_str_vec(file, &dim, "%s.groups", sec_name);
for (j = 0; j < dim; j++) {
struct nation_set *pset = nation_set_by_rule_name(vec[j]);
struct nation_group *pgroup = nation_group_by_rule_name(vec[j]);
fc_assert(pset == NULL || pgroup == NULL);
if (NULL != pset) {
nation_set_list_append(pnation->sets, pset);
} else if (NULL != pgroup) {
nation_group_list_append(pnation->groups, pgroup);
} else {
/* For nation authors, this would probably be considered an error.
* But it can happen normally. The civ1 compatibility ruleset only
* uses the nations that were in civ1, so not all of the links will
* exist. */
log_verbose("Nation %s: Unknown set/group \"%s\".",
nation_rule_name(pnation), vec[j]);
}
}
if (NULL != vec) {
free(vec);
}
if (nation_set_list_size(pnation->sets) < 1) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s is not a member of any nation set",
nation_rule_name(pnation));
ok = FALSE;
break;
}
/* Nation conflicts. */
vec = secfile_lookup_str_vec(file, &dim, "%s.conflicts_with", sec_name);
for (j = 0; j < dim; j++) {
pconflict = nation_by_rule_name(vec[j]);
if (pnation == pconflict) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s conflicts with itself",
nation_rule_name(pnation));
ok = FALSE;
break;
} else if (NULL != pconflict) {
nation_list_append(pnation->server.conflicts_with, pconflict);
} else {
/* For nation authors, this would probably be considered an error.
* But it can happen normally. The civ1 compatibility ruleset only
* uses the nations that were in civ1, so not all of the links will
* exist. */
log_verbose("Nation %s: conflicts_with nation \"%s\" is unknown.",
nation_rule_name(pnation), vec[j]);
}
}
if (NULL != vec) {
free(vec);
}
if (!ok) {
break;
}
/* Nation leaders. */
for (j = 0; j < MAX_NUM_LEADERS; j++) {
const char *sexstr;
sex_t sex;
bool is_male = FALSE;
name = secfile_lookup_str(file, "%s.leaders%d.name", sec_name, j);
if (NULL == name) {
/* No more to read. */
break;
}
if (check_name(name)) {
/* The ruleset contains a name that is too long. This shouldn't
* happen - if it does, the author should get immediate feedback */
sz_strlcpy(temp_name, name);
ruleset_error(NULL, LOG_ERROR,
"Nation %s: leader name \"%s\" is too long.",
nation_rule_name(pnation), name);
ok = FALSE;
break;
}
sexstr = secfile_lookup_str(file, "%s.leaders%d.sex", sec_name, j);
if (NULL == sexstr) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s: leader \"%s\": %s.",
nation_rule_name(pnation), name, secfile_error());
ok = FALSE;
break;
}
sex = sex_by_name(sexstr);
switch (sex) {
case SEX_MALE:
is_male = TRUE;
break;
case SEX_FEMALE:
is_male = FALSE;
break;
case SEX_UNKNOWN:
ruleset_error(NULL, LOG_ERROR,
"Nation %s: leader \"%s\" has unsupported "
"sex variant \"%s\".",
nation_rule_name(pnation), name, sexstr);
ok = FALSE;
break;
}
if (ok) {
(void) nation_leader_new(pnation, name, is_male);
}
}
if (!ok) {
break;
}
/* Check the number of leaders. */
if (MAX_NUM_LEADERS == j) {
/* Too much leaders, get the real number defined in the ruleset. */
while (NULL != secfile_entry_lookup(file, "%s.leaders%d.name",
sec_name, j)) {
j++;
}
ruleset_error(NULL, LOG_ERROR,
"Nation %s: Too many leaders; max is %d",
nation_rule_name(pnation), MAX_NUM_LEADERS);
ok = FALSE;
break;
} else if (0 == j) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s: no leaders; at least one is required.",
nation_rule_name(pnation));
ok = FALSE;
break;
}
/* Check if leader name is not already defined in this nation. */
if ((bad_leader = check_leader_names(pnation))) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s: leader \"%s\" defined more than once.",
nation_rule_name(pnation), bad_leader);
ok = FALSE;
break;
}
/* Nation player color preference, if any */
fc_assert_ret_val(pnation->server.rgb == NULL, FALSE);
(void) rgbcolor_load(file, &pnation->server.rgb, "%s.color", sec_name);
/* Load nation traits */
ruleset_load_traits(pnation->server.traits, file, sec_name, "trait_");
for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
bool server_traits_used = TRUE;
if (pnation->server.traits[tr].min < 0) {
pnation->server.traits[tr].min = game.server.default_traits[tr].min;
} else {
server_traits_used = FALSE;
}
if (pnation->server.traits[tr].max < 0) {
pnation->server.traits[tr].max = game.server.default_traits[tr].max;
} else {
server_traits_used = FALSE;
}
if (pnation->server.traits[tr].fixed < 0) {
if (server_traits_used) {
pnation->server.traits[tr].fixed = game.server.default_traits[tr].fixed;
} else {
int diff = pnation->server.traits[tr].max - pnation->server.traits[tr].min;
/* TODO: Should sometimes round the a / 2 = x.5 results up */
pnation->server.traits[tr].fixed = diff / 2 + pnation->server.traits[tr].min;
}
}
if (pnation->server.traits[tr].max < pnation->server.traits[tr].min) {
ruleset_error(NULL, LOG_ERROR,
"%s values for trait %s not sane.",
nation_rule_name(pnation), trait_name(tr));
ok = FALSE;
break;
}
}
if (!ok) {
break;
}
pnation->is_playable =
secfile_lookup_bool_default(file, TRUE, "%s.is_playable", sec_name);
/* Check barbarian type. Default is "None" meaning not a barbarian */
barb_type = secfile_lookup_str_default(file, "None",
"%s.barbarian_type", sec_name);
pnation->barb_type = barbarian_type_by_name(barb_type, fc_strcasecmp);
if (!barbarian_type_is_valid(pnation->barb_type)) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s, barbarian_type is invalid (\"%s\")",
nation_rule_name(pnation), barb_type);
ok = FALSE;
break;
}
if (pnation->barb_type != NOT_A_BARBARIAN
&& pnation->is_playable) {
/* We can't allow players to use barbarian nations, barbarians
* may run out of nations */
ruleset_error(NULL, LOG_ERROR,
"Nation %s marked both barbarian and playable.",
nation_rule_name(pnation));
ok = FALSE;
break;
}
/* Flags */
sz_strlcpy(pnation->flag_graphic_str,
secfile_lookup_str_default(file, "-", "%s.flag", sec_name));
sz_strlcpy(pnation->flag_graphic_alt,
secfile_lookup_str_default(file, "-",
"%s.flag_alt", sec_name));
/* Ruler titles */
for (j = 0;; j++) {
const char *male, *female;
name = secfile_lookup_str_default(file, NULL,
"%s.ruler_titles%d.government",
sec_name, j);
if (NULL == name) {
/* End of the list of ruler titles. */
break;
}
/* NB: even if the government doesn't exist, we load the entries for
* the ruler titles to avoid warnings about unused entries. */
male = secfile_lookup_str(file, "%s.ruler_titles%d.male_title",
sec_name, j);
female = secfile_lookup_str(file, "%s.ruler_titles%d.female_title",
sec_name, j);
gov = government_by_rule_name(name);
/* Nationset may have been devised with a specific set of govs in
* mind which don't quite match this ruleset, in which case we
* (a) quietly ignore any govs mentioned that don't happen to be in
* the current ruleset, (b) enforce that govs mentioned by nations
* must be on the list */
if (gov != NULL && game.server.ruledit.allowed_govs != NULL) {
if (!is_on_allowed_list(name,
game.server.ruledit.allowed_govs,
game.server.ruledit.ag_count)) {
/* Gov exists, but not intended for these nations */
gov = NULL;
ruleset_error(NULL, LOG_ERROR,
"Nation %s: government \"%s\" not in allowed_govs.",
nation_rule_name(pnation), name);
ok = FALSE;
break;
}
} else if (!gov) {
/* Gov doesn't exist; only complain if it's not on any list */
if (game.server.ruledit.allowed_govs == NULL
|| !is_on_allowed_list(name,
game.server.ruledit.allowed_govs,
game.server.ruledit.ag_count)) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s: government \"%s\" not found.",
nation_rule_name(pnation), name);
ok = FALSE;
break;
}
}
if (NULL != male && NULL != female) {
if (gov) {
(void) government_ruler_title_new(gov, pnation, male, female);
}
} else {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
}
if (!ok) {
break;
}
/* City styles */
name = secfile_lookup_str(file, "%s.style", sec_name);
if (!name) {
ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
ok = FALSE;
break;
}
pnation->style = style_by_rule_name(name);
if (pnation->style == NULL) {
if (game.server.ruledit.allowed_styles == NULL
|| !is_on_allowed_list(name,
game.server.ruledit.allowed_styles,
game.server.ruledit.as_count)) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s: Illegal style \"%s\"",
nation_rule_name(pnation), name);
ok = FALSE;
break;
} else {
log_verbose("Nation %s: style \"%s\" not supported in this "
"ruleset; using default.",
nation_rule_name(pnation), name);
pnation->style = style_by_number(0);
}
}
/* Civilwar nations */
vec = secfile_lookup_str_vec(file, &dim,
"%s.civilwar_nations", sec_name);
for (j = 0; j < dim; j++) {
pconflict = nation_by_rule_name(vec[j]);
/* No test for duplicate nations is performed. If there is a duplicate
* entry it will just cause that nation to have an increased
* probability of being chosen. */
if (pconflict == pnation) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s is its own civil war nation",
nation_rule_name(pnation));
ok = FALSE;
break;
} else if (NULL != pconflict) {
nation_list_append(pnation->server.civilwar_nations, pconflict);
nation_list_append(pconflict->server.parent_nations, pnation);
} else {
/* For nation authors, this would probably be considered an error.
* But it can happen normally. The civ1 compatibility ruleset only
* uses the nations that were in civ1, so not all of the links will
* exist. */
log_verbose("Nation %s: civil war nation \"%s\" is unknown.",
nation_rule_name(pnation), vec[j]);
}
}
if (NULL != vec) {
free(vec);
}
if (!ok) {
break;
}
/* Load nation specific initial items */
if (!lookup_tech_list(file, sec_name, "init_techs",
pnation->init_techs, filename)) {
ok = FALSE;
break;
}
if (!lookup_building_list(file, sec_name, "init_buildings",
pnation->init_buildings, filename)) {
ok = FALSE;
break;
}
if (!lookup_unit_list(file, sec_name, "init_units",
pnation->init_units, filename)) {
ok = FALSE;
break;
}
fc_strlcat(tmp, sec_name, 200);
fc_strlcat(tmp, ".init_government", 200);
if (secfile_entry_by_path(file, tmp)) {
pnation->init_government = lookup_government(file, tmp, filename,
NULL);
/* If specified, init_government has to be in this specific ruleset,
* not just allowed_govs */
if (pnation->init_government == NULL) {
ok = FALSE;
break;
}
/* ...but if a list of govs has been specified, enforce that this
* nation's init_government is on the list. */
if (game.server.ruledit.allowed_govs != NULL
&& !is_on_allowed_list(government_rule_name(pnation->init_government),
game.server.ruledit.allowed_govs,
game.server.ruledit.ag_count)) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s: init_government \"%s\" not allowed.",
nation_rule_name(pnation),
government_rule_name(pnation->init_government));
ok = FALSE;
break;
}
}
/* Read default city names. */
if (!load_city_name_list(file, pnation, sec_name, "cities",
game.server.ruledit.allowed_terrains,
game.server.ruledit.at_count)) {
ok = FALSE;
break;
}
legend = secfile_lookup_str_default(file, "", "%s.legend", sec_name);
pnation->legend = fc_strdup(legend);
if (check_strlen(pnation->legend, MAX_LEN_MSG, NULL)) {
ruleset_error(NULL, LOG_ERROR,
"Nation %s: legend \"%s\" is too long.",
nation_rule_name(pnation),
pnation->legend);
ok = FALSE;
break;
}
pnation->player = NULL;
} nations_iterate_end;
section_list_destroy(sec);
sec = NULL;
}
/* Clean up on aborted load */
if (sec != NULL) {
fc_assert(!ok);
section_list_destroy(sec);
}
if (ok) {
secfile_check_unused(file);
}
if (ok) {
/* Update cached number of playable nations in the current set */
count_playable_nations();
/* Sanity checks on all sets */
nation_sets_iterate(pset) {
int num_playable = 0, barb_land_count = 0, barb_sea_count = 0, barb_both_count = 0;
nations_iterate(pnation) {
if (nation_is_in_set(pnation, pset)) {
switch (nation_barbarian_type(pnation)) {
case NOT_A_BARBARIAN:
if (is_nation_playable(pnation)) {
num_playable++;
}
break;
case LAND_BARBARIAN:
barb_land_count++;
break;
case SEA_BARBARIAN:
barb_sea_count++;
break;
case ANIMAL_BARBARIAN:
/* Animals are optional */
break;
case LAND_AND_SEA_BARBARIAN:
barb_both_count++;
break;
default:
fc_assert_ret_val(FALSE, FALSE);
}
}
} nations_iterate_end;
if (num_playable < 1) {
ruleset_error(NULL, LOG_ERROR,
"Nation set \"%s\" has no playable nations. "
"At least one required!", nation_set_rule_name(pset));
ok = FALSE;
break;
}
if (barb_land_count == 0 && barb_both_count == 0) {
ruleset_error(NULL, LOG_ERROR,
"No land barbarian nation defined in set \"%s\". "
"At least one required!", nation_set_rule_name(pset));
ok = FALSE;
break;
}
if (barb_sea_count == 0 && barb_both_count == 0) {
ruleset_error(NULL, LOG_ERROR,
"No sea barbarian nation defined in set \"%s\". "
"At least one required!", nation_set_rule_name(pset));
ok = FALSE;
break;
}
} nation_sets_iterate_end;
}
return ok;
}
/**********************************************************************//**
Load names of nation styles so other rulesets can refer to styles with
their name.
**************************************************************************/
static bool load_style_names(struct section_file *file,
struct rscompat_info *compat)
{
bool ok = TRUE;
struct section_list *sec;
const char *filename = secfile_name(file);
if (!rscompat_check_cap_and_version(file, filename, compat)) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
sec = secfile_sections_by_name_prefix(file, STYLE_SECTION_PREFIX);
if (NULL == sec) {
ruleset_error(NULL, LOG_ERROR,
"No available nation styles in this ruleset!");
ok = FALSE;
} else {
game.control.num_styles = section_list_size(sec);
styles_alloc(game.control.num_styles);
styles_iterate(ps) {
const int i = style_index(ps);
const char *sec_name = section_name(section_list_get(sec, i));
ruleset_load_names(&ps->name, NULL, file, sec_name);
} styles_iterate_end;
}
section_list_destroy(sec);
if (ok) {
/* The citystyle sections: */
int i = 0;
sec = secfile_sections_by_name_prefix(file, CITYSTYLE_SECTION_PREFIX);
if (NULL != sec) {
city_styles_alloc(section_list_size(sec));
section_list_iterate(sec, style) {
if (!ruleset_load_names(&city_styles[i].name, NULL, file, section_name(style))) {
ok = FALSE;
break;
}
i++;
} section_list_iterate_end;
section_list_destroy(sec);
} else {
city_styles_alloc(0);
}
}
return ok;
}
/**********************************************************************//**
Load styles.ruleset file
**************************************************************************/
static bool load_ruleset_styles(struct section_file *file,
struct rscompat_info *compat)
{
struct section_list *sec;
int i;
bool ok = TRUE;
/* City Styles ... */
sec = secfile_sections_by_name_prefix(file, CITYSTYLE_SECTION_PREFIX);
/* Get rest: */
for (i = 0; i < game.control.num_city_styles; i++) {
struct requirement_vector *reqs;
const char *sec_name = section_name(section_list_get(sec, i));
sz_strlcpy(city_styles[i].graphic,
secfile_lookup_str(file, "%s.graphic", sec_name));
sz_strlcpy(city_styles[i].graphic_alt,
secfile_lookup_str(file, "%s.graphic_alt", sec_name));
sz_strlcpy(city_styles[i].citizens_graphic,
secfile_lookup_str_default(file, "-",
"%s.citizens_graphic", sec_name));
reqs = lookup_req_list(file, compat, sec_name, "reqs", city_style_rule_name(i));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&city_styles[i].reqs, reqs);
}
section_list_destroy(sec);
if (ok) {
sec = secfile_sections_by_name_prefix(file, MUSICSTYLE_SECTION_PREFIX);
if (sec != NULL) {
int musi;
game.control.num_music_styles = section_list_size(sec);
music_styles_alloc(game.control.num_music_styles);
musi = 0;
section_list_iterate(sec, psection) {
struct requirement_vector *reqs;
struct music_style *pmus = music_style_by_number(musi);
const char *sec_name = section_name(psection);
sz_strlcpy(pmus->music_peaceful,
secfile_lookup_str_default(file, "-",
"%s.music_peaceful", sec_name));
sz_strlcpy(pmus->music_combat,
secfile_lookup_str_default(file, "-",
"%s.music_combat", sec_name));
reqs = lookup_req_list(file, compat, sec_name, "reqs", "Music Style");
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&pmus->reqs, reqs);
musi++;
} section_list_iterate_end;
}
section_list_destroy(sec);
}
return ok;
}
/**********************************************************************//**
Load a list of unit type flags that must be absent from the actor unit
if an action auto performer should be triggered into an action auto
performer.
**************************************************************************/
static bool load_action_auto_uflag_block(struct section_file *file,
struct action_auto_perf *auto_perf,
const char *uflags_path,
const char *filename)
{
/* Add each listed protected unit type flag as a !present
* requirement. */
if (secfile_entry_lookup(file, "%s", uflags_path)) {
enum unit_type_flag_id *protecor_flag;
size_t psize;
int i;
protecor_flag =
secfile_lookup_enum_vec(file, &psize, unit_type_flag_id,
"%s", uflags_path);
if (!protecor_flag) {
/* Entity exists but couldn't read it. */
ruleset_error(NULL, LOG_ERROR,
"\"%s\": %s: bad unit type flag list.",
filename, uflags_path);
return FALSE;
}
for (i = 0; i < psize; i++) {
requirement_vector_append(&auto_perf->reqs,
req_from_values(VUT_UTFLAG,
REQ_RANGE_LOCAL,
FALSE, FALSE, TRUE,
protecor_flag[i]));
}
free(protecor_flag);
}
return TRUE;
}
/**********************************************************************//**
Load the list of actions an action auto performer should try. The
actions will be tried in the given order.
**************************************************************************/
static bool load_action_auto_actions(struct section_file *file,
struct action_auto_perf *auto_perf,
const char *actions_path,
const char *filename)
{
/* Read the alternative actions. */
if (secfile_entry_lookup(file, "%s", actions_path)) {
enum gen_action *unit_acts;
size_t asize;
int i;
unit_acts = secfile_lookup_enum_vec(file, &asize, gen_action,
"%s", actions_path);
if (!unit_acts) {
/* Entity exists but couldn't read it. */
ruleset_error(NULL, LOG_ERROR,
"\"%s\": %s: bad action list",
filename, actions_path);
return FALSE;
}
for (i = 0; i < asize; i++) {
auto_perf->alternatives[i] = unit_acts[i];
}
free(unit_acts);
}
return TRUE;
}
/**********************************************************************//**
Load missing unit upkeep ruleset settings as action auto performers.
**************************************************************************/
static bool load_muuk_as_action_auto(struct section_file *file,
struct action_auto_perf *auto_perf,
const char *item,
const char *filename)
{
char uflags_path[100];
char action_path[100];
fc_snprintf(uflags_path, sizeof(uflags_path),
"missing_unit_upkeep.%s_protected", item);
fc_snprintf(action_path, sizeof(action_path),
"missing_unit_upkeep.%s_unit_act", item);
return (load_action_auto_uflag_block(file, auto_perf, uflags_path,
filename)
&& load_action_auto_actions(file, auto_perf, action_path,
filename));
}
/**********************************************************************//**
Load cities.ruleset file
**************************************************************************/
static bool load_ruleset_cities(struct section_file *file,
struct rscompat_info *compat)
{
const char *filename = secfile_name(file);
const char *item;
struct section_list *sec;
bool ok = TRUE;
if (!rscompat_check_cap_and_version(file, filename, compat)) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
/* Specialist options */
sec = secfile_sections_by_name_prefix(file, SPECIALIST_SECTION_PREFIX);
if (!sec) {
ruleset_error(NULL, LOG_ERROR, "\"%s\": No specialists.", filename);
ok = FALSE;
} else if (section_list_size(sec) >= SP_MAX) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many specialists (%d, max %d).",
filename, section_list_size(sec), SP_MAX);
ok = FALSE;
}
if (ok) {
int i = 0;
const char *tag;
game.control.num_specialist_types = section_list_size(sec);
section_list_iterate(sec, psection) {
struct specialist *s = specialist_by_number(i);
struct requirement_vector *reqs;
const char *sec_name = section_name(psection);
if (!ruleset_load_names(&s->name, NULL, file, sec_name)) {
ok = FALSE;
break;
}
item = secfile_lookup_str_default(file, untranslated_name(&s->name),
"%s.short_name", sec_name);
name_set(&s->abbreviation, NULL, item);
tag = secfile_lookup_str(file, "%s.graphic", sec_name);
if (tag == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": No graphic tag for specialist at %s.",
filename, sec_name);
ok = FALSE;
break;
}
sz_strlcpy(s->graphic_str, tag);
sz_strlcpy(s->graphic_alt,
secfile_lookup_str_default(file, "-",
"%s.graphic_alt", sec_name));
reqs = lookup_req_list(file, compat, sec_name, "reqs", specialist_rule_name(s));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&s->reqs, reqs);
s->helptext = lookup_strvec(file, sec_name, "helptext");
if (requirement_vector_size(&s->reqs) == 0 && DEFAULT_SPECIALIST == -1) {
DEFAULT_SPECIALIST = i;
}
i++;
} section_list_iterate_end;
}
if (ok && DEFAULT_SPECIALIST == -1) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": must have zero reqs for at least one "
"specialist type.", filename);
ok = FALSE;
}
section_list_destroy(sec);
sec = NULL;
if (ok) {
/* City Parameters */
game.info.celebratesize =
secfile_lookup_int_default(file, GAME_DEFAULT_CELEBRATESIZE,
"parameters.celebrate_size_limit");
game.info.add_to_size_limit =
secfile_lookup_int_default(file, GAME_DEFAULT_ADDTOSIZE, "parameters.add_to_size_limit");
game.info.angrycitizen =
secfile_lookup_bool_default(file, GAME_DEFAULT_ANGRYCITIZEN,
"parameters.angry_citizens");
game.info.changable_tax =
secfile_lookup_bool_default(file, GAME_DEFAULT_CHANGABLE_TAX, "parameters.changable_tax");
game.info.forced_science =
secfile_lookup_int_default(file, 0, "parameters.forced_science");
game.info.forced_luxury =
secfile_lookup_int_default(file, 100, "parameters.forced_luxury");
game.info.forced_gold =
secfile_lookup_int_default(file, 0, "parameters.forced_gold");
if (game.info.forced_science + game.info.forced_luxury
+ game.info.forced_gold != 100) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Forced taxes do not add up in ruleset!",
filename);
ok = FALSE;
}
}
if (ok) {
bool def_ubuild_nat = RS_DEFAULT_UBUILD_NAT;
/* civ1 & 2 didn't reveal tiles */
game.server.vision_reveal_tiles =
secfile_lookup_bool_default(file, GAME_DEFAULT_VISION_REVEAL_TILES,
"parameters.vision_reveal_tiles");
game.info.pop_report_zeroes =
secfile_lookup_int_default(file, 1, "parameters.pop_report_zeroes");
/* Citizens configuration. */
game.info.citizen_nationality =
secfile_lookup_bool_default(file, RS_DEFAULT_NATIONALITY,
"citizen.nationality");
if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
/* Same as old hardcoded behavior */
def_ubuild_nat = TRUE;
}
game.info.unit_builders_nationality =
secfile_lookup_bool_default(file, def_ubuild_nat,
"citizen.ubuilder_nationality");
game.info.citizen_convert_speed =
secfile_lookup_int_default(file, RS_DEFAULT_CONVERT_SPEED,
"citizen.convert_speed");
game.info.citizen_partisans_pct =
secfile_lookup_int_default(file, 0, "citizen.partisans_pct");
game.info.conquest_convert_pct =
secfile_lookup_int_default(file, 0, "citizen.conquest_convert_pct");
}
if (ok) {
/* Missing unit upkeep. */
struct action_auto_perf *auto_perf;
/* Can't pay food upkeep! */
auto_perf = action_auto_perf_slot_number(ACTION_AUTO_UPKEEP_FOOD);
auto_perf->cause = AAPC_UNIT_UPKEEP;
/* This is about food upkeep. */
requirement_vector_append(&auto_perf->reqs,
req_from_str("OutputType", "Local",
FALSE, TRUE, TRUE,
"Food"));
/* Internally represented as an action auto performer rule. */
if (!load_muuk_as_action_auto(file, auto_perf, "food", filename)) {
ok = FALSE;
}
game.info.muuk_food_wipe =
secfile_lookup_bool_default(file, RS_DEFAULT_MUUK_FOOD_WIPE,
"missing_unit_upkeep.food_wipe");
/* Can't pay gold upkeep! */
auto_perf = action_auto_perf_slot_number(ACTION_AUTO_UPKEEP_GOLD);
auto_perf->cause = AAPC_UNIT_UPKEEP;
/* This is about gold upkeep. */
requirement_vector_append(&auto_perf->reqs,
req_from_str("OutputType", "Local",
FALSE, TRUE, TRUE,
"Gold"));
/* Internally represented as an action auto performer rule. */
if (!load_muuk_as_action_auto(file, auto_perf, "gold", filename)) {
ok = FALSE;
}
game.info.muuk_gold_wipe =
secfile_lookup_bool_default(file, RS_DEFAULT_MUUK_GOLD_WIPE,
"missing_unit_upkeep.gold_wipe");
/* Can't pay shield upkeep! */
auto_perf = action_auto_perf_slot_number(ACTION_AUTO_UPKEEP_SHIELD);
auto_perf->cause = AAPC_UNIT_UPKEEP;
/* This is about shield upkeep. */
requirement_vector_append(&auto_perf->reqs,
req_from_str("OutputType", "Local",
FALSE, TRUE, TRUE,
"Shield"));
/* Internally represented as an action auto performer rule. */
if (!load_muuk_as_action_auto(file, auto_perf, "shield", filename)) {
ok = FALSE;
}
game.info.muuk_shield_wipe =
secfile_lookup_bool_default(file, RS_DEFAULT_MUUK_SHIELD_WIPE,
"missing_unit_upkeep.shield_wipe");
}
if (ok) {
secfile_check_unused(file);
}
return ok;
}
/**********************************************************************//**
Load effects.ruleset file
**************************************************************************/
static bool load_ruleset_effects(struct section_file *file,
struct rscompat_info *compat)
{
struct section_list *sec;
const char *filename;
bool ok = TRUE;
filename = secfile_name(file);
if (!rscompat_check_cap_and_version(file, filename, compat)) {
return FALSE;
}
(void) secfile_entry_by_path(file, "datafile.description"); /* unused */
(void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
sec = secfile_sections_by_name_prefix(file, UEFF_SECTION_PREFIX);
if (sec != NULL) {
section_list_iterate(sec, psection) {
const char *sec_name = section_name(psection);
enum effect_type main_type;
enum effect_type ai_valued_as;
const char *type;
type = secfile_lookup_str(file, "%s.type", sec_name);
if (type == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] missing effect type.",
filename, sec_name);
ok = FALSE;
break;
}
main_type = effect_type_by_name(type, fc_strcasecmp);
if (!effect_type_is_valid(main_type)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] lists unknown effect type \"%s\".",
filename, sec_name, type);
ok = FALSE;
break;
}
if (!is_user_effect(main_type)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] type \"%s\" is not an user effect.",
filename, sec_name, type);
ok = FALSE;
break;
}
type = secfile_lookup_str(file, "%s.ai_valued_as", sec_name);
if (type == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] missing ai_valued_as.",
filename, sec_name);
ok = FALSE;
break;
}
ai_valued_as = effect_type_by_name(type, fc_strcasecmp);
if (!effect_type_is_valid(ai_valued_as)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] lists unknown ai_valued_as \"%s\".",
filename, sec_name, type);
ok = FALSE;
break;
}
if (is_user_effect(ai_valued_as)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] ai_valued_as \"%s\" is an user effect.",
filename, sec_name, type);
ok = FALSE;
break;
}
if (user_effect_ai_valued_as(main_type) != main_type) {
/* It has been set already! */
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] Duplicate \"%s\" entry.",
filename, sec_name, type);
ok = FALSE;
break;
}
user_effect_ai_valued_set(main_type, ai_valued_as);
} section_list_iterate_end;
section_list_destroy(sec);
}
/* Parse effects and add them to the effects ruleset cache. */
sec = secfile_sections_by_name_prefix(file, EFFECT_SECTION_PREFIX);
section_list_iterate(sec, psection) {
enum effect_type eff;
int value;
struct multiplier *pmul;
struct effect *peffect;
const char *sec_name = section_name(psection);
struct requirement_vector *reqs;
const char *type;
const char *comment;
type = secfile_lookup_str(file, "%s.type", sec_name);
if (type == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] missing effect type.",
filename, sec_name);
ok = FALSE;
break;
}
eff = effect_type_by_name(type, fc_strcasecmp);
if (!effect_type_is_valid(eff)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] lists unknown effect type \"%s\".",
filename, sec_name, type);
ok = FALSE;
break;
}
value = secfile_lookup_int_default(file, 1, "%s.value", sec_name);
{
const char *multiplier_name
= secfile_lookup_str(file, "%s.multiplier", sec_name);
if (multiplier_name) {
pmul = multiplier_by_rule_name(multiplier_name);
if (!pmul) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] has unknown multiplier \"%s\".",
filename, sec_name, multiplier_name);
ok = FALSE;
break;
}
} else {
pmul = NULL;
}
}
peffect = effect_new(eff, value, pmul);
reqs = lookup_req_list(file, compat, sec_name, "reqs", type);
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_iterate(reqs, preq) {
effect_req_append(peffect, *preq);
} requirement_vector_iterate_end;
comment = secfile_lookup_str_default(file, NULL, "%s.comment", sec_name);
if (comment != NULL) {
peffect->rulesave.comment = fc_strdup(comment);
}
} section_list_iterate_end;
section_list_destroy(sec);
if (ok) {
secfile_check_unused(file);
}
return ok;
}
/**********************************************************************//**
Print an error message if the value is out of range.
**************************************************************************/
static int secfile_lookup_int_default_min_max(struct section_file *file,
int def, int min, int max,
const char *path, ...)
{
char fullpath[256];
int ival;
va_list args;
va_start(args, path);
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
va_end(args);
if (!secfile_lookup_int(file, &ival, "%s", fullpath)) {
ival = def;
}
if (ival < min) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" should be in the interval [%d, %d] "
"but is %d; using the minimal value.",
fullpath, min, max, ival);
ival = min;
}
if (ival > max) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" should be in the interval [%d, %d] "
"but is %d; using the maximal value.",
fullpath, min, max, ival);
ival = max;
}
return ival;
}
/**********************************************************************//**
Load ui_name of one action
**************************************************************************/
static bool load_action_ui_name(struct section_file *file, int act,
const char *entry_name,
const char *compat_name)
{
const char *text;
const char *def = action_ui_name_default(act);
if (compat_name != NULL) {
def = secfile_lookup_str_default(file, def,
"actions.%s", compat_name);
}
text = secfile_lookup_str_default(file, def,
"actions.%s", entry_name);
sz_strlcpy(action_by_number(act)->ui_name, text);
return TRUE;
}
/**********************************************************************//**
Load max range of an action
**************************************************************************/
static bool load_action_range_max(struct section_file *file, action_id act)
{
struct action *paction = action_by_number(act);
const char *vname = action_max_range_ruleset_var_name(act);
if (vname != NULL) {
struct entry *pentry;
int max_range;
pentry = secfile_entry_lookup(file, "actions.%s", vname);
if (pentry == NULL) {
max_range = actres_max_range_default(paction->result);
} else {
const char *custom;
if (entry_type_get(pentry) == ENTRY_INT
&& entry_int_get(pentry, &max_range)) {
/* max_range already assigned */
} else if (entry_type_get(pentry) == ENTRY_STR
&& entry_str_get(pentry, &custom)
&& !fc_strcasecmp(custom, RS_ACTION_NO_MAX_DISTANCE)) {
max_range = ACTION_DISTANCE_UNLIMITED;
} else {
ruleset_error(NULL, LOG_ERROR, "Bad actions.%s",
action_max_range_ruleset_var_name(act));
action_by_number(act)->max_distance = actres_max_range_default(paction->result);
return FALSE;
}
}
action_by_number(act)->max_distance = max_range;
}
return TRUE;
}
/**********************************************************************//**
Load range of an action
**************************************************************************/
static bool load_action_range(struct section_file *file, action_id act)
{
struct action *paction = action_by_number(act);
const char *vname;
if (!load_action_range_max(file, act)) {
return FALSE;
}
vname = action_min_range_ruleset_var_name(act);
if (vname != NULL) {
/* Min range can be loaded from the ruleset. */
action_by_number(act)->min_distance
= secfile_lookup_int_default(file,
actres_min_range_default(paction->result),
"actions.%s",
vname);
}
return TRUE;
}
/**********************************************************************//**
Load kind of an action
**************************************************************************/
static bool load_action_kind(struct section_file *file, action_id act)
{
struct action *paction = action_by_number(act);
const char *var_name = action_target_kind_ruleset_var_name(act);
if (var_name != NULL) {
action_by_number(act)->target_kind
= secfile_lookup_enum_default(file,
actres_target_kind_default(
paction->result),
action_target_kind,
"actions.%s", var_name);
} else {
action_by_number(act)->target_kind
= actres_target_kind_default(paction->result);
}
return TRUE;
}
/**********************************************************************//**
Load if the action always consumes the actor
**************************************************************************/
static bool load_action_actor_consuming_always(struct section_file *file,
action_id act)
{
if (action_actor_consuming_always_ruleset_var_name(act) != NULL) {
/* Actor consumption can be loaded from the ruleset. */
action_by_number(act)->actor_consuming_always
= secfile_lookup_bool_default(
file, RS_DEFAULT_ACTION_ACTOR_CONSUMING_ALWAYS, "actions.%s",
action_actor_consuming_always_ruleset_var_name(act));
}
return TRUE;
}
/**********************************************************************//**
Load what actions can block the action
**************************************************************************/
static bool load_action_blocked_by_list(struct section_file *file,
const char *filename,
struct action *paction)
{
if (action_blocked_by_ruleset_var_name(paction) != NULL) {
/* Action blocking can be loaded from the ruleset. */
char fullpath[1024];
fc_snprintf(fullpath, sizeof(fullpath), "actions.%s",
action_blocked_by_ruleset_var_name(paction));
if (secfile_entry_by_path(file, fullpath)) {
enum gen_action *blocking_actions;
size_t asize;
int j;
blocking_actions =
secfile_lookup_enum_vec(file, &asize, gen_action, "%s", fullpath);
if (!blocking_actions) {
/* Entity exists but couldn't read it. */
ruleset_error(NULL, LOG_ERROR,
"\"%s\": %s: bad action list",
filename, fullpath);
return FALSE;
}
for (j = 0; j < asize; j++) {
BV_SET(paction->blocked_by, blocking_actions[j]);
}
free(blocking_actions);
}
}
return TRUE;
}
/**********************************************************************//**
Load what actions an actor under certain circumstances will be forced to
perform after successfully performing this action.
**************************************************************************/
static bool load_action_post_success_force(struct section_file *file,
const char *filename,
int performer_slot,
struct action *paction)
{
struct action_auto_perf *auto_perf;
char action_list_path[100];
if (action_post_success_forced_ruleset_var_name(paction) == NULL) {
/* Not relevant. */
return TRUE;
}
auto_perf = action_auto_perf_slot_number(performer_slot);
auto_perf->cause = AAPC_POST_ACTION;
/* Limit auto performer to this action. */
requirement_vector_append(&auto_perf->reqs,
req_from_values(VUT_ACTION, REQ_RANGE_LOCAL,
FALSE, TRUE, TRUE,
paction->id));
/* Load the list of actions. */
fc_snprintf(action_list_path, sizeof(action_list_path),
"actions.%s",
action_post_success_forced_ruleset_var_name(paction));
if (!load_action_auto_actions(file, auto_perf,
action_list_path, filename)) {
return FALSE;
}
return TRUE;
}
/**********************************************************************//**
Load a list of actions from the ruleset to a bv_actions bit vector.
**************************************************************************/
static bool lookup_bv_actions(struct section_file *file,
const char *filename,
bv_actions *target,
const char *path)
{
if (secfile_entry_by_path(file, path)) {
enum gen_action *listed_actions;
size_t asize;
int j;
listed_actions = secfile_lookup_enum_vec(file, &asize, gen_action,
"%s", path);
if (!listed_actions) {
/* Entity exists but couldn't read it. */
ruleset_error(NULL, LOG_ERROR, "\"%s\": %s: bad action list",
filename, path);
return FALSE;
}
for (j = 0; j < asize; j++) {
BV_SET(*target, listed_actions[j]);
}
free(listed_actions);
}
return TRUE;
}
/**********************************************************************//**
Load ruleset file.
**************************************************************************/
static bool load_ruleset_game(struct section_file *file, bool act,
struct rscompat_info *compat)
{
const char *sval, **svec;
const char *filename;
int *food_ini;
int i;
size_t teams;
const char *pref_text;
size_t gni_tmp;
struct section_list *sec;
size_t nval;
const char *name;
bool ok = TRUE;
if (file == NULL) {
return FALSE;
}
filename = secfile_name(file);
name = secfile_lookup_str_default(file, NULL, "ruledit.description_file");
if (name != NULL) {
game.server.ruledit.description_file = fc_strdup(name);
}
/* Section: tileset */
pref_text = secfile_lookup_str_default(file, "", "tileset.prefered");
if (pref_text[0] != '\0') {
log_deprecation("Entry tileset.prefered in game.ruleset."
" Use correct spelling tileset.preferred instead");
}
pref_text = secfile_lookup_str_default(file, pref_text, "tileset.preferred");
if (pref_text[0] != '\0') {
/* There was tileset suggestion */
sz_strlcpy(game.control.preferred_tileset, pref_text);
} else {
/* No tileset suggestions */
game.control.preferred_tileset[0] = '\0';
}
/* Section: soundset */
pref_text = secfile_lookup_str_default(file, "", "soundset.prefered");
if (pref_text[0] != '\0') {
log_deprecation("Entry soundset.prefered in game.ruleset."
" Use correct spelling soundset.preferred instead");
}
pref_text = secfile_lookup_str_default(file, pref_text, "soundset.preferred");
if (pref_text[0] != '\0') {
/* There was soundset suggestion */
sz_strlcpy(game.control.preferred_soundset, pref_text);
} else {
/* No soundset suggestions */
game.control.preferred_soundset[0] = '\0';
}
/* Section: musicset */
pref_text = secfile_lookup_str_default(file, "", "musicset.prefered");
if (pref_text[0] != '\0') {
log_deprecation("Entry musicset.prefered in game.ruleset."
" Use correct spelling musicset.preferred instead");
}
pref_text = secfile_lookup_str_default(file, pref_text, "musicset.preferred");
if (pref_text[0] != '\0') {
/* There was musicset suggestion */
sz_strlcpy(game.control.preferred_musicset, pref_text);
} else {
/* No musicset suggestions */
game.control.preferred_musicset[0] = '\0';
}
/* Section: about */
pref_text = secfile_lookup_str(file, "about.name");
/* Ruleset/modpack name found */
sz_strlcpy(game.control.name, pref_text);
pref_text = secfile_lookup_str_default(file, "", "about.version");
if (pref_text[0] != '\0') {
/* Ruleset/modpack version found */
sz_strlcpy(game.control.version, pref_text);
} else {
/* No version information */
game.control.version[0] = '\0';
}
pref_text = secfile_lookup_str_default(file, "", "about.alt_dir");
if (pref_text[0] != '\0') {
/* Alt directory definition found. */
sz_strlcpy(game.control.alt_dir, pref_text);
} else {
/* No alt directory information */
game.control.alt_dir[0] = '\0';
}
pref_text = secfile_lookup_str_default(file, "", "about.summary");
if (pref_text[0] != '\0') {
int len;
/* Ruleset/modpack summary found */
len = strlen(pref_text);
game.ruleset_summary = fc_malloc(len + 1);
fc_strlcpy(game.ruleset_summary, pref_text, len + 1);
} else {
/* No summary */
if (game.ruleset_summary != NULL) {
free(game.ruleset_summary);
game.ruleset_summary = NULL;
}
}
pref_text = secfile_lookup_str_default(file, "", "about.description");
if (pref_text[0] != '\0') {
int len;
/* Ruleset/modpack description found */
len = strlen(pref_text);
game.ruleset_description = fc_malloc(len + 1);
fc_strlcpy(game.ruleset_description, pref_text, len + 1);
game.control.desc_length = len;
} else {
/* No description */
if (game.ruleset_description != NULL) {
free(game.ruleset_description);
game.ruleset_description = NULL;
}
game.control.desc_length = 0;
}
pref_text = secfile_lookup_str_default(file, "", "about.capabilities");
if (pref_text[0] != '\0') {
int len = strlen(pref_text);
game.ruleset_capabilities = fc_malloc(len + 1);
fc_strlcpy(game.ruleset_capabilities, pref_text, len +1);
} else {
game.ruleset_capabilities = fc_malloc(1);
game.ruleset_capabilities[0] = '\0';
}
/* Section: options */
if (!lookup_tech_list(file, "options", "global_init_techs",
game.rgame.global_init_techs, filename)) {
ok = FALSE;
}
if (ok) {
if (!lookup_building_list(file, "options", "global_init_buildings",
game.rgame.global_init_buildings, filename)) {
ok = FALSE;
}
}
if (ok) {
const char **slist;
int j;
game.control.popup_tech_help = secfile_lookup_bool_default(file, FALSE,
"options.popup_tech_help");
/* section: civstyle */
game.info.base_pollution
= secfile_lookup_int_default(file, RS_DEFAULT_BASE_POLLUTION,
"civstyle.base_pollution");
game.info.gameloss_style = GAMELOSS_STYLE_CLASSICAL;
slist = secfile_lookup_str_vec(file, &nval, "civstyle.gameloss_style");
for (j = 0; j < nval; j++) {
enum gameloss_style style;
sval = slist[j];
if (strcmp(sval, "") == 0) {
continue;
}
style = gameloss_style_by_name(sval, fc_strcasecmp);
if (!gameloss_style_is_valid(style)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": bad value \"%s\" for gameloss_style.",
filename, sval);
ok = FALSE;
break;
} else {
game.info.gameloss_style |= style;
}
}
free(slist);
}
if (ok) {
game.info.happy_cost
= secfile_lookup_int_def_min_max(file,
RS_DEFAULT_HAPPY_COST,
RS_MIN_HAPPY_COST,
RS_MAX_HAPPY_COST,
"civstyle.happy_cost");
game.info.food_cost
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_FOOD_COST,
RS_MIN_FOOD_COST,
RS_MAX_FOOD_COST,
"civstyle.food_cost");
game.info.civil_war_enabled
= secfile_lookup_bool_default(file, TRUE, "civstyle.civil_war_enabled");
game.info.civil_war_bonus_celebrating
= secfile_lookup_int_default(file, RS_DEFAULT_CIVIL_WAR_CELEB,
"civstyle.civil_war_bonus_celebrating");
game.info.civil_war_bonus_unhappy
= secfile_lookup_int_default(file, RS_DEFAULT_CIVIL_WAR_UNHAPPY,
"civstyle.civil_war_bonus_unhappy");
game.info.base_bribe_cost
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_BASE_BRIBE_COST,
RS_MIN_BASE_BRIBE_COST,
RS_MAX_BASE_BRIBE_COST,
"civstyle.base_bribe_cost");
game.server.ransom_gold
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_RANSOM_GOLD,
RS_MIN_RANSOM_GOLD,
RS_MAX_RANSOM_GOLD,
"civstyle.ransom_gold");
game.info.pillage_select
= secfile_lookup_bool_default(file, RS_DEFAULT_PILLAGE_SELECT,
"civstyle.pillage_select");
game.info.tech_steal_allow_holes
= secfile_lookup_bool_default(file, RS_DEFAULT_TECH_STEAL_HOLES,
"civstyle.tech_steal_allow_holes");
game.info.tech_trade_allow_holes
= secfile_lookup_bool_default(file, RS_DEFAULT_TECH_TRADE_HOLES,
"civstyle.tech_trade_allow_holes");
game.info.tech_trade_loss_allow_holes
= secfile_lookup_bool_default(file, RS_DEFAULT_TECH_TRADE_LOSS_HOLES,
"civstyle.tech_trade_loss_allow_holes");
game.info.tech_parasite_allow_holes
= secfile_lookup_bool_default(file, RS_DEFAULT_TECH_PARASITE_HOLES,
"civstyle.tech_parasite_allow_holes");
game.info.tech_loss_allow_holes
= secfile_lookup_bool_default(file, RS_DEFAULT_TECH_LOSS_HOLES,
"civstyle.tech_loss_allow_holes");
game.server.upgrade_veteran_loss
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_UPGRADE_VETERAN_LOSS,
RS_MIN_UPGRADE_VETERAN_LOSS,
RS_MAX_UPGRADE_VETERAN_LOSS,
"civstyle.upgrade_veteran_loss");
game.server.autoupgrade_veteran_loss
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_UPGRADE_VETERAN_LOSS,
RS_MIN_UPGRADE_VETERAN_LOSS,
RS_MAX_UPGRADE_VETERAN_LOSS,
"civstyle.autoupgrade_veteran_loss");
game.info.base_tech_cost
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_BASE_TECH_COST,
RS_MIN_BASE_TECH_COST,
RS_MAX_BASE_TECH_COST,
"research.base_tech_cost");
if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
/* base_tech_cost used to be used for this too. */
game.info.min_tech_cost
= secfile_lookup_int_default_min_max(file,
game.info.base_tech_cost,
RS_MIN_MIN_TECH_COST,
RS_MAX_MIN_TECH_COST,
"research.min_tech_cost");
} else {
game.info.min_tech_cost
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_MIN_TECH_COST,
RS_MIN_MIN_TECH_COST,
RS_MAX_MIN_TECH_COST,
"research.min_tech_cost");
}
food_ini = secfile_lookup_int_vec(file, &gni_tmp,
"civstyle.granary_food_ini");
game.info.granary_num_inis = (int) gni_tmp;
if (game.info.granary_num_inis > MAX_GRANARY_INIS) {
ruleset_error(NULL, LOG_ERROR,
"Too many granary_food_ini entries (%d, max %d)",
game.info.granary_num_inis, MAX_GRANARY_INIS);
ok = FALSE;
} else if (game.info.granary_num_inis == 0) {
log_error("No values for granary_food_ini. Using default "
"value %d.", RS_DEFAULT_GRANARY_FOOD_INI);
game.info.granary_num_inis = 1;
game.info.granary_food_ini[0] = RS_DEFAULT_GRANARY_FOOD_INI;
} else {
int gi;
/* check for <= 0 entries */
for (gi = 0; gi < game.info.granary_num_inis; gi++) {
if (food_ini[gi] <= 0) {
if (gi == 0) {
food_ini[gi] = RS_DEFAULT_GRANARY_FOOD_INI;
} else {
food_ini[gi] = food_ini[gi - 1];
}
log_error("Bad value for granary_food_ini[%i]. Using %i.",
gi, food_ini[gi]);
}
game.info.granary_food_ini[gi] = food_ini[gi];
}
}
free(food_ini);
}
if (ok) {
game.info.granary_food_inc
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_GRANARY_FOOD_INC,
RS_MIN_GRANARY_FOOD_INC,
RS_MAX_GRANARY_FOOD_INC,
"civstyle.granary_food_inc");
output_type_iterate(o) {
game.info.min_city_center_output[o]
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_CITY_CENTER_OUTPUT,
RS_MIN_CITY_CENTER_OUTPUT,
RS_MAX_CITY_CENTER_OUTPUT,
"civstyle.min_city_center_%s",
get_output_identifier(o));
} output_type_iterate_end;
}
if (ok) {
const char *tus_text;
game.server.init_vis_radius_sq
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_VIS_RADIUS_SQ,
RS_MIN_VIS_RADIUS_SQ,
RS_MAX_VIS_RADIUS_SQ,
"civstyle.init_vis_radius_sq");
game.info.init_city_radius_sq
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_CITY_RADIUS_SQ,
RS_MIN_CITY_RADIUS_SQ,
RS_MAX_CITY_RADIUS_SQ,
"civstyle.init_city_radius_sq");
tus_text = secfile_lookup_str_default(file, RS_DEFAULT_GOLD_UPKEEP_STYLE,
"civstyle.gold_upkeep_style");
game.info.gold_upkeep_style = gold_upkeep_style_by_name(tus_text,
fc_strcasecmp);
if (!gold_upkeep_style_is_valid(game.info.gold_upkeep_style)) {
ruleset_error(NULL, LOG_ERROR,
"Unknown gold upkeep style \"%s\"",
tus_text);
ok = FALSE;
}
game.info.homeless_gold_upkeep
= secfile_lookup_bool_default(file, FALSE, "civstyle.homeless_gold_upkeep");
if (game.info.homeless_gold_upkeep
&& game.info.gold_upkeep_style == GOLD_UPKEEP_CITY) {
ruleset_error(NULL, LOG_ERROR,
"Cannot have homeless_gold_upkeep while gold_upkeep_style \"City\".");
ok = FALSE;
}
game.info.granularity = secfile_lookup_int_default(file, 1,
"civstyle.output_granularity");
game.info.airlift_from_always_enabled
= secfile_lookup_bool_default(file, FALSE, "civstyle.airlift_from_always_enabled");
game.info.airlift_to_always_enabled
= secfile_lookup_bool_default(file, TRUE, "civstyle.airlift_to_always_enabled");
/* section: wonder_visibility */
if (ok) {
const char *text;
text = secfile_lookup_str_default(file,
RS_DEFAULT_SMALL_WONDER_VISIBILITY,
"wonder_visibility.small_wonders");
game.info.small_wonder_visibility = wonder_visib_type_by_name(text,
fc_strcasecmp);
if (!wonder_visib_type_is_valid(game.info.small_wonder_visibility)) {
ruleset_error(NULL, LOG_ERROR,
"Unknown wonder visibility type \"%s\"",
text);
ok = FALSE;
}
}
/* section: illness */
game.info.illness_on
= secfile_lookup_bool_default(file, RS_DEFAULT_ILLNESS_ON,
"illness.illness_on");
game.info.illness_base_factor
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_ILLNESS_BASE_FACTOR,
RS_MIN_ILLNESS_BASE_FACTOR,
RS_MAX_ILLNESS_BASE_FACTOR,
"illness.illness_base_factor");
game.info.illness_min_size
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_ILLNESS_MIN_SIZE,
RS_MIN_ILLNESS_MIN_SIZE,
RS_MAX_ILLNESS_MIN_SIZE,
"illness.illness_min_size");
game.info.illness_trade_infection
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_ILLNESS_TRADE_INFECTION_PCT,
RS_MIN_ILLNESS_TRADE_INFECTION_PCT,
RS_MAX_ILLNESS_TRADE_INFECTION_PCT,
"illness.illness_trade_infection");
game.info.illness_pollution_factor
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_ILLNESS_POLLUTION_PCT,
RS_MIN_ILLNESS_POLLUTION_PCT,
RS_MAX_ILLNESS_POLLUTION_PCT,
"illness.illness_pollution_factor");
/* section: incite_cost */
game.server.base_incite_cost
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_INCITE_BASE_COST,
RS_MIN_INCITE_BASE_COST,
RS_MAX_INCITE_BASE_COST,
"incite_cost.base_incite_cost");
game.server.incite_improvement_factor
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_INCITE_IMPROVEMENT_FCT,
RS_MIN_INCITE_IMPROVEMENT_FCT,
RS_MAX_INCITE_IMPROVEMENT_FCT,
"incite_cost.improvement_factor");
game.server.incite_unit_factor
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_INCITE_UNIT_FCT,
RS_MIN_INCITE_UNIT_FCT,
RS_MAX_INCITE_UNIT_FCT,
"incite_cost.unit_factor");
game.server.incite_total_factor
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_INCITE_TOTAL_FCT,
RS_MIN_INCITE_TOTAL_FCT,
RS_MAX_INCITE_TOTAL_FCT,
"incite_cost.total_factor");
}
if (ok) {
const char *tus_text;
/* section: combat_rules */
game.info.tired_attack
= secfile_lookup_bool_default(file, RS_DEFAULT_TIRED_ATTACK,
"combat_rules.tired_attack");
game.info.only_killing_makes_veteran
= secfile_lookup_bool_default(file, RS_DEFAULT_ONLY_KILLING_VETERAN,
"combat_rules.only_killing_makes_veteran");
game.info.only_real_fight_makes_veteran
= secfile_lookup_bool_default(file, RS_DEFAULT_ONLY_REAL_FIGHT_VETERAN,
"combat_rules.only_real_fight_makes_veteran");
game.info.combat_odds_scaled_veterancy
= secfile_lookup_bool_default(file, RS_DEFAULT_COMBAT_ODDS_SCALED_VETERANCY,
"combat_rules.combat_odds_scaled_veterancy");
game.info.damage_reduces_bombard_rate
= secfile_lookup_bool_default(file, RS_DEFAULT_DAMAGE_REDUCES_BOMBARD_RATE,
"combat_rules.damage_reduces_bombard_rate");
game.info.low_firepower_badwallattacker
= secfile_lookup_int_default(file, 1,
"combat_rules.low_firepower_badwallattacker");
game.info.low_firepower_pearl_harbour
= secfile_lookup_int_default(file, 1,
"combat_rules.low_firepower_pearl_harbour");
game.info.low_firepower_combat_bonus
= secfile_lookup_int_default(file, 1,
"combat_rules.low_firepower_combat_bonus");
game.info.low_firepower_nonnat_bombard
= secfile_lookup_int_default(file, 1,
"combat_rules.low_firepower_nonnat_bombard");
game.info.nuke_pop_loss_pct = secfile_lookup_int_default_min_max(file,
RS_DEFAULT_NUKE_POP_LOSS_PCT,
RS_MIN_NUKE_POP_LOSS_PCT,
RS_MAX_NUKE_POP_LOSS_PCT,
"combat_rules.nuke_pop_loss_pct");
game.info.nuke_defender_survival_chance_pct = secfile_lookup_int_default_min_max(file,
RS_DEFAULT_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT,
RS_MIN_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT,
RS_MAX_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT,
"combat_rules.nuke_defender_survival_chance_pct");
/* section: borders */
game.info.border_city_radius_sq
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_BORDER_RADIUS_SQ_CITY,
RS_MIN_BORDER_RADIUS_SQ_CITY,
RS_MAX_BORDER_RADIUS_SQ_CITY,
"borders.radius_sq_city");
game.info.border_size_effect
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_BORDER_SIZE_EFFECT,
RS_MIN_BORDER_SIZE_EFFECT,
RS_MAX_BORDER_SIZE_EFFECT,
"borders.size_effect");
game.info.border_city_permanent_radius_sq
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_BORDER_RADIUS_SQ_CITY_PERMANENT,
RS_MIN_BORDER_RADIUS_SQ_CITY_PERMANENT,
RS_MAX_BORDER_RADIUS_SQ_CITY_PERMANENT,
"borders.radius_sq_city_permanent");
/* section: research */
tus_text = secfile_lookup_str_default(file, RS_DEFAULT_TECH_COST_STYLE,
"research.tech_cost_style");
game.info.tech_cost_style = tech_cost_style_by_name(tus_text,
fc_strcasecmp);
if (!tech_cost_style_is_valid(game.info.tech_cost_style)) {
ruleset_error(NULL, LOG_ERROR,
"Unknown tech cost style \"%s\"",
tus_text);
ok = FALSE;
}
tus_text = secfile_lookup_str_default(file, RS_DEFAULT_TECH_LEAKAGE,
"research.tech_leakage");
game.info.tech_leakage = tech_leakage_style_by_name(tus_text,
fc_strcasecmp);
if (!tech_leakage_style_is_valid(game.info.tech_leakage)) {
ruleset_error(NULL, LOG_ERROR,
"Unknown tech leakage \"%s\"",
tus_text);
ok = FALSE;
}
if (game.info.tech_cost_style == TECH_COST_CIV1CIV2
&& game.info.tech_leakage != TECH_LEAKAGE_NONE) {
log_error("Only tech_leakage \"%s\" supported with "
"tech_cost_style \"%s\". ",
tech_leakage_style_name(TECH_LEAKAGE_NONE),
tech_cost_style_name(TECH_COST_CIV1CIV2));
log_error("Switching to tech_leakage \"%s\".",
tech_leakage_style_name(TECH_LEAKAGE_NONE));
game.info.tech_leakage = TECH_LEAKAGE_NONE;
}
game.info.base_tech_cost
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_BASE_TECH_COST,
RS_MIN_BASE_TECH_COST,
RS_MAX_BASE_TECH_COST,
"research.base_tech_cost");
tus_text = secfile_lookup_str_default(file, RS_DEFAULT_TECH_UPKEEP_STYLE,
"research.tech_upkeep_style");
game.info.tech_upkeep_style = tech_upkeep_style_by_name(tus_text, fc_strcasecmp);
if (!tech_upkeep_style_is_valid(game.info.tech_upkeep_style)) {
ruleset_error(NULL, LOG_ERROR,
"Unknown tech upkeep style \"%s\"",
tus_text);
ok = FALSE;
}
}
if (ok) {
game.info.tech_upkeep_divider
= secfile_lookup_int_default_min_max(file,
RS_DEFAULT_TECH_UPKEEP_DIVIDER,
RS_MIN_TECH_UPKEEP_DIVIDER,
RS_MAX_TECH_UPKEEP_DIVIDER,
"research.tech_upkeep_divider");
sval = secfile_lookup_str_default(file, NULL, "research.free_tech_method");
if (sval == NULL) {
ruleset_error(NULL, LOG_ERROR,
"No free_tech_method given");
ok = FALSE;
} else {
game.info.free_tech_method = free_tech_method_by_name(sval, fc_strcasecmp);
if (!free_tech_method_is_valid(game.info.free_tech_method)) {
ruleset_error(NULL, LOG_ERROR,
"Bad value %s for free_tech_method.", sval);
ok = FALSE;
}
}
}
if (ok) {
int cf;
/* section: culture */
game.info.culture_vic_points
= secfile_lookup_int_default(file, RS_DEFAULT_CULTURE_VIC_POINTS,
"culture.victory_min_points");
game.info.culture_vic_lead
= secfile_lookup_int_default(file, RS_DEFAULT_CULTURE_VIC_LEAD,
"culture.victory_lead_pct");
game.info.culture_migration_pml
= secfile_lookup_int_default(file, RS_DEFAULT_CULTURE_MIGRATION_PML,
"culture.migration_pml");
game.info.history_interest_pml
= secfile_lookup_int_default(file, RS_DEFAULT_HISTORY_INTEREST_PML,
"culture.history_interest_pml");
/* section: calendar */
game.calendar.calendar_skip_0
= secfile_lookup_bool_default(file, RS_DEFAULT_CALENDAR_SKIP_0,
"calendar.skip_year_0");
game.server.start_year
= secfile_lookup_int_default(file, GAME_DEFAULT_START_YEAR,
"calendar.start_year");
game.calendar.calendar_fragments
= secfile_lookup_int_default(file, 0, "calendar.fragments");
if (game.calendar.calendar_fragments > MAX_CALENDAR_FRAGMENTS) {
ruleset_error(NULL, LOG_ERROR,
"Too many calendar fragments. Max is %d",
MAX_CALENDAR_FRAGMENTS);
ok = FALSE;
game.calendar.calendar_fragments = 0;
}
sz_strlcpy(game.calendar.positive_year_label,
secfile_lookup_str_default(file,
RS_DEFAULT_POS_YEAR_LABEL,
"calendar.positive_label"));
sz_strlcpy(game.calendar.negative_year_label,
secfile_lookup_str_default(file,
RS_DEFAULT_NEG_YEAR_LABEL,
"calendar.negative_label"));
for (cf = 0; cf < game.calendar.calendar_fragments; cf++) {
const char *fname;
fname = secfile_lookup_str_default(file, NULL, "calendar.fragment_name%d", cf);
if (fname != NULL) {
strncpy(game.calendar.calendar_fragment_name[cf], fname,
sizeof(game.calendar.calendar_fragment_name[cf]));
}
}
}
if (ok) {
/* section playercolors */
struct rgbcolor *prgbcolor = NULL;
bool color_read = TRUE;
/* Check if the player list is defined and empty. */
if (playercolor_count() != 0) {
ok = FALSE;
} else {
i = 0;
while (color_read) {
prgbcolor = NULL;
color_read = rgbcolor_load(file, &prgbcolor, "playercolors.colorlist%d", i);
if (color_read) {
playercolor_add(prgbcolor);
}
i++;
}
if (playercolor_count() == 0) {
ruleset_error(NULL, LOG_ERROR, "No player colors defined!");
ok = FALSE;
}
if (ok) {
fc_assert(game.plr_bg_color == NULL);
if (!rgbcolor_load(file, &game.plr_bg_color, "playercolors.background")) {
ruleset_error(NULL, LOG_ERROR,
"No background player color defined! (%s)",
secfile_error());
ok = FALSE;
}
}
}
}
if (ok) {
/* section: teams */
svec = secfile_lookup_str_vec(file, &teams, "teams.names");
if (team_slot_count() < teams) {
teams = team_slot_count();
}
game.server.ruledit.named_teams = teams;
for (i = 0; i < teams; i++) {
team_slot_set_defined_name(team_slot_by_number(i), svec[i]);
}
free(svec);
sec = secfile_sections_by_name_prefix(file, DISASTER_SECTION_PREFIX);
nval = (NULL != sec ? section_list_size(sec) : 0);
if (nval > MAX_DISASTER_TYPES) {
int num = nval; /* No "size_t" to printf */
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Too many disaster types (%d, max %d)",
filename, num, MAX_DISASTER_TYPES);
section_list_destroy(sec);
ok = FALSE;
} else {
game.control.num_disaster_types = nval;
}
}
if (ok) {
disaster_type_iterate(pdis) {
int id = disaster_index(pdis);
int j;
size_t eff_count;
struct requirement_vector *reqs;
const char *sec_name = section_name(section_list_get(sec, id));
if (!ruleset_load_names(&pdis->name, NULL, file, sec_name)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Cannot load disaster names",
filename);
ok = FALSE;
break;
}
reqs = lookup_req_list(file, compat, sec_name, "reqs", disaster_rule_name(pdis));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&pdis->reqs, reqs);
pdis->frequency = secfile_lookup_int_default(file, GAME_DEFAULT_DISASTER_FREQ,
"%s.frequency", sec_name);
svec = secfile_lookup_str_vec(file, &eff_count, "%s.effects", sec_name);
BV_CLR_ALL(pdis->effects);
for (j = 0; j < eff_count; j++) {
const char *dsval = svec[j];
enum disaster_effect_id effect;
effect = disaster_effect_id_by_name(dsval, fc_strcasecmp);
if (!disaster_effect_id_is_valid(effect)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" disaster \"%s\": unknown effect \"%s\".",
filename, disaster_rule_name(pdis), dsval);
ok = FALSE;
break;
} else {
BV_SET(pdis->effects, effect);
}
}
free(svec);
if (!ok) {
break;
}
} disaster_type_iterate_end;
section_list_destroy(sec);
}
if (ok) {
sec = secfile_sections_by_name_prefix(file, ACHIEVEMENT_SECTION_PREFIX);
achievements_iterate(pach) {
int id = achievement_index(pach);
const char *sec_name = section_name(section_list_get(sec, id));
const char *typename;
const char *msg;
typename = secfile_lookup_str_default(file, NULL, "%s.type", sec_name);
pach->type = achievement_type_by_name(typename, fc_strcasecmp);
if (!achievement_type_is_valid(pach->type)) {
ruleset_error(NULL, LOG_ERROR,
"Achievement has unknown type \"%s\".",
typename != NULL ? typename : "(NULL)");
ok = FALSE;
}
if (ok) {
pach->unique = secfile_lookup_bool_default(file, GAME_DEFAULT_ACH_UNIQUE,
"%s.unique", sec_name);
pach->value = secfile_lookup_int_default(file, GAME_DEFAULT_ACH_VALUE,
"%s.value", sec_name);
pach->culture = secfile_lookup_int_default(file, 0,
"%s.culture", sec_name);
msg = secfile_lookup_str_default(file, NULL, "%s.first_msg", sec_name);
if (msg == NULL) {
ruleset_error(NULL, LOG_ERROR,
"Achievement %s has no first msg!", sec_name);
ok = FALSE;
} else {
pach->first_msg = fc_strdup(msg);
}
}
if (ok) {
msg = secfile_lookup_str_default(file, NULL, "%s.cons_msg", sec_name);
if (msg == NULL) {
if (!pach->unique) {
ruleset_error(NULL, LOG_ERROR,
"Achievement %s has no msg for consecutive gainers!",
sec_name);
ok = FALSE;
}
} else {
pach->cons_msg = fc_strdup(msg);
}
}
if (!ok) {
break;
}
} achievements_iterate_end;
section_list_destroy(sec);
}
if (ok) {
for (i = 0; (name = secfile_lookup_str_default(file, NULL,
"trade.settings%d.type",
i)); i++) {
enum trade_route_type type = trade_route_type_by_name(name);
if (type == TRT_LAST) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unknown trade route type \"%s\".",
filename, name);
ok = FALSE;
} else {
struct trade_route_settings *set = trade_route_settings_by_type(type);
const char *cancelling;
const char *bonus;
set->trade_pct = secfile_lookup_int_default(file, 100,
"trade.settings%d.pct", i);
cancelling = secfile_lookup_str_default(file, "Active",
"trade.settings%d.cancelling", i);
set->cancelling = trade_route_cancelling_type_by_name(cancelling);
if (set->cancelling == TRI_LAST) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unknown trade route cancelling type \"%s\".",
filename, cancelling);
ok = FALSE;
}
bonus = secfile_lookup_str_default(file, "None", "trade.settings%d.bonus", i);
set->bonus_type = trade_route_bonus_type_by_name(bonus, fc_strcasecmp);
if (!trade_route_bonus_type_is_valid(set->bonus_type)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unknown trade route bonus type \"%s\".",
filename, bonus);
ok = FALSE;
}
}
}
}
if (ok) {
const char *str;
bool reveal_default = FALSE;
game.info.min_trade_route_val
= secfile_lookup_int_default(file, 0, "trade.min_trade_route_val");
if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
/* Old hardcoded behavior was to reveal the trade partner. */
reveal_default = TRUE;
}
game.info.reveal_trade_partner
= secfile_lookup_bool_default(file, reveal_default,
"trade.reveal_trade_partner");
str = secfile_lookup_str_default(file,
goods_selection_method_name(RS_DEFAULT_GOODS_SELECTION),
"trade.goods_selection");
game.info.goods_selection = goods_selection_method_by_name(str, fc_strcasecmp);
if (!goods_selection_method_is_valid(game.info.goods_selection)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" goods selection method \"%s\" unknown.",
filename, str);
ok = FALSE;
}
}
if (ok) {
sec = secfile_sections_by_name_prefix(file, GOODS_SECTION_PREFIX);
goods_type_iterate(pgood) {
int id = goods_index(pgood);
const char *sec_name = section_name(section_list_get(sec, id));
struct requirement_vector *reqs;
const char **slist;
int j;
reqs = lookup_req_list(file, compat, sec_name, "reqs", goods_rule_name(pgood));
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&pgood->reqs, reqs);
pgood->from_pct = secfile_lookup_int_default(file, 100,
"%s.from_pct", sec_name);
pgood->to_pct = secfile_lookup_int_default(file, 100,
"%s.to_pct", sec_name);
pgood->onetime_pct = secfile_lookup_int_default(file, 100,
"%s.onetime_pct", sec_name);
slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
BV_CLR_ALL(pgood->flags);
for (j = 0; j < nval; j++) {
enum goods_flag_id flag;
sval = slist[j];
flag = goods_flag_id_by_name(sval, fc_strcasecmp);
if (!goods_flag_id_is_valid(flag)) {
ruleset_error(NULL, LOG_ERROR, "\"%s\" good \"%s\": unknown flag \"%s\".",
filename, goods_rule_name(pgood), sval);
ok = FALSE;
break;
} else {
BV_SET(pgood->flags, flag);
}
}
free(slist);
pgood->helptext = lookup_strvec(file, sec_name, "helptext");
} goods_type_iterate_end;
section_list_destroy(sec);
}
if (ok) {
sec = secfile_sections_by_name_prefix(file, CLAUSE_SECTION_PREFIX);
if (sec != NULL) {
int num = section_list_size(sec);
for (i = 0; i < num; i++) {
const char *sec_name = section_name(section_list_get(sec, i));
const char *clause_name = secfile_lookup_str_default(file, NULL,
"%s.type", sec_name);
enum clause_type type = clause_type_by_name(clause_name, fc_strcasecmp);
struct clause_info *info;
struct requirement_vector *reqs;
if (!clause_type_is_valid(type)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unknown clause type \"%s\".",
filename, clause_name);
ok = FALSE;
break;
}
info = clause_info_get(type);
if (info->enabled) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" duplicate clause type \"%s\" definition.",
filename, clause_name);
ok = FALSE;
break;
}
reqs = lookup_req_list(file, compat, sec_name, "giver_reqs", clause_name);
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&info->giver_reqs, reqs);
reqs = lookup_req_list(file, compat, sec_name, "receiver_reqs", clause_name);
if (reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&info->receiver_reqs, reqs);
info->enabled = TRUE;
}
}
section_list_destroy(sec);
}
if (ok) {
sec = secfile_sections_by_name_prefix(file, COUNTER_SECTION_PREFIX);
if (sec != NULL) {
int num = section_list_size(sec);
int curr;
for (curr = 0; curr < num; curr++) {
struct counter *pcount = counter_by_id(curr);
const char *sec_name = section_name(section_list_get(sec, curr));
const char *counter_type = secfile_lookup_str_default(file, NULL,
"%s.type",
sec_name);
enum counter_behavior cb = counter_behavior_by_name(counter_type,
fc_strcasecmp);
if (!counter_behavior_is_valid(cb)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" unknown counter type \"%s\".",
filename, counter_type);
ok = FALSE;
break;
}
if (!ruleset_load_names(&pcount->name, NULL, file, sec_name)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": Cannot load counter names",
filename);
ok = FALSE;
break;
}
pcount->helptext = lookup_strvec(file, sec_name, "helptext");
pcount->type = cb;
if (!secfile_lookup_int(file, &pcount->checkpoint,
"%s.checkpoint", sec_name)) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\": No checkpoint value",
filename);
ok = FALSE;
break;
}
pcount->target = CTGT_CITY;
pcount->index = curr;
pcount->def = secfile_lookup_int_default(file, 0,
"%s.def",
sec_name);
attach_city_counter(pcount);
}
}
}
/* secfile_check_unused() is not here, but only after also settings section
* has been loaded. */
return ok;
}
/**********************************************************************//**
Loads action information from a file
**************************************************************************/
static bool load_ruleset_actions(struct section_file *file,
struct section_file *gamefile,
struct rscompat_info *compat)
{
bool ok = TRUE;
const char *filename = secfile_name(file);
struct section_list *sec;
struct action_auto_perf *auto_perf;
struct requirement_vector *reqs;
/* Auto attack. */
/* Action auto performers aren't ready to be exposed in the ruleset
* yet. The behavior when two action auto performers for the same
* cause can fire isn't set in stone yet. How is one of them chosen?
* What if all the actions of the chosen action auto performer turned
* out to be illegal but one of the other action auto performers that
* fired has legal actions? These issues can decide what other action
* rules action auto performers can represent in the future. Deciding
* should therefore wait until a rule needs action auto performers to
* work a certain way. */
/* Only one action auto performer, ACTION_AUTO_MOVED_ADJ, is caused
* by AAPC_UNIT_MOVED_ADJ. It is therefore safe to expose the full
* requirement vector to the ruleset. */
/* A unit moved next to this unit and the autoattack server setting
* is enabled. */
auto_perf = action_auto_perf_slot_number(ACTION_AUTO_MOVED_ADJ);
auto_perf->cause = AAPC_UNIT_MOVED_ADJ;
reqs = lookup_req_list(file, compat,
"auto_attack", "if_attacker",
"auto_attack");
if (reqs == NULL) {
ok = FALSE;
} else {
requirement_vector_copy(&auto_perf->reqs, reqs);
if (!load_action_auto_actions(file, auto_perf,
"auto_attack.attack_actions",
filename)) {
/* Failed to load auto attack actions */
ruleset_error(NULL, LOG_ERROR,
"\"%s\": %s: failed load %s.",
filename, "auto_attack", "attack_actions");
ok = FALSE;
}
}
/* Section: actions */
if (ok) {
action_iterate(act_id) {
struct action *paction = action_by_number(act_id);
if (!load_action_blocked_by_list(file, filename, paction)) {
ok = FALSE;
break;
}
} action_iterate_end;
if (ok) {
if (!lookup_bv_actions(file, filename,
&game.info.diplchance_initial_odds,
"actions.diplchance_initial_odds")) {
ok = FALSE;
}
}
if (ok) {
/* If the "Poison City" action or the "Poison City Escape" action
* should empty the granary. */
/* TODO: empty granary and reduce population should become separate
* action effect flags when actions are generalized. */
game.info.poison_empties_food_stock
= secfile_lookup_bool_default(file,
RS_DEFAULT_POISON_EMPTIES_FOOD_STOCK,
"actions.poison_empties_food_stock");
/* If the "Steal Maps" action or the "Steal Maps Escape" action always
* will reveal all cities when successful. */
game.info.steal_maps_reveals_all_cities
= secfile_lookup_bool_default(file,
RS_DEFAULT_STEAL_MAP_REVEALS_CITIES,
"actions.steal_maps_reveals_all_cities");
/* Allow setting certain properties for some actions before
* generalized actions. */
action_iterate(act_id) {
if (!load_action_range(file, act_id)) {
ok = FALSE;
} else if (!load_action_kind(file, act_id)) {
ok = FALSE;
} else if (!load_action_actor_consuming_always(file, act_id)) {
ok = FALSE;
} else {
load_action_ui_name(file, act_id,
action_ui_name_ruleset_var_name(act_id),
rscompat_action_ui_name_3_2(compat, act_id));
}
if (!ok) {
break;
}
} action_iterate_end;
if (ok && compat->compat_mode && compat->version < RSFORMAT_3_2) {
secfile_entry_ignore_by_path(file, "actions.ui_name_clean_pollution");
secfile_entry_ignore_by_path(file, "actions.ui_name_clean_fallout");
}
}
if (ok) {
/* The quiet (don't auto generate help for) property of all actions
* live in a single enum vector. This avoids generic action
* expectations. */
if (secfile_entry_by_path(file, "actions.quiet_actions")) {
enum gen_action *quiet_actions;
size_t asize;
int j;
quiet_actions =
secfile_lookup_enum_vec(file, &asize, gen_action,
"actions.quiet_actions");
if (!quiet_actions) {
/* Entity exists but couldn't read it. */
ruleset_error(NULL, LOG_ERROR,
"\"%s\": actions.quiet_actions: bad action list",
filename);
ok = FALSE;
} else {
for (j = 0; j < asize; j++) {
/* Don't auto generate help text for this action. */
action_by_number(quiet_actions[j])->quiet = TRUE;
}
free(quiet_actions);
}
}
}
if (ok) {
/* Hard code action sub results for now. */
/* Unit Enter Hut */
action_by_result_iterate(paction, ACTRES_HUT_ENTER) {
BV_SET(paction->sub_results, ACT_SUB_RES_HUT_ENTER);
} action_by_result_iterate_end;
BV_SET(action_by_number(ACTION_PARADROP_ENTER)->sub_results,
ACT_SUB_RES_HUT_ENTER);
BV_SET(action_by_number(ACTION_PARADROP_ENTER_CONQUER)->sub_results,
ACT_SUB_RES_HUT_ENTER);
BV_SET(action_by_number(ACTION_TELEPORT_ENTER)->sub_results,
ACT_SUB_RES_HUT_ENTER);
BV_SET(action_by_number(ACTION_TELEPORT_ENTER_CONQUER)->sub_results,
ACT_SUB_RES_HUT_ENTER);
/* Unit Frighten Hut */
action_by_result_iterate(paction, ACTRES_HUT_FRIGHTEN) {
BV_SET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN);
} action_by_result_iterate_end;
BV_SET(action_by_number(ACTION_PARADROP_FRIGHTEN)->sub_results,
ACT_SUB_RES_HUT_FRIGHTEN);
BV_SET(action_by_number(ACTION_PARADROP_FRIGHTEN_CONQUER)->sub_results,
ACT_SUB_RES_HUT_FRIGHTEN);
BV_SET(action_by_number(ACTION_TELEPORT_FRIGHTEN)->sub_results,
ACT_SUB_RES_HUT_FRIGHTEN);
BV_SET(action_by_number(ACTION_TELEPORT_FRIGHTEN_CONQUER)->sub_results,
ACT_SUB_RES_HUT_FRIGHTEN);
/* Unit May Embark */
action_iterate(act_id) {
struct action *paction = action_by_number(act_id);
if (secfile_lookup_bool_default(gamefile, FALSE,
"civstyle.paradrop_to_transport")
&& (action_has_result(paction, ACTRES_PARADROP)
|| action_has_result(paction, ACTRES_PARADROP_CONQUER))) {
BV_SET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK);
}
/* Embark actions will always embark, not maybe embark. */
} action_iterate_end;
/* Non Lethal bombard */
BV_SET(action_by_number(ACTION_BOMBARD)->sub_results,
ACT_SUB_RES_NON_LETHAL);
BV_SET(action_by_number(ACTION_BOMBARD2)->sub_results,
ACT_SUB_RES_NON_LETHAL);
BV_SET(action_by_number(ACTION_BOMBARD3)->sub_results,
ACT_SUB_RES_NON_LETHAL);
}
}
if (ok) {
/* Forced actions after another action was successfully performed. */
if (!load_action_post_success_force(file, filename,
ACTION_AUTO_POST_BRIBE,
action_by_number(
ACTION_SPY_BRIBE_UNIT))) {
ok = FALSE;
} else if (!load_action_post_success_force(file, filename,
ACTION_AUTO_POST_ATTACK,
action_by_number(
ACTION_ATTACK))) {
ok = FALSE;
} else if (!load_action_post_success_force(file, filename,
ACTION_AUTO_POST_ATTACK2,
action_by_number(
ACTION_ATTACK2))) {
ok = FALSE;
} else if (!load_action_post_success_force(file, filename,
ACTION_AUTO_POST_COLLECT_RANSOM,
action_by_number(
ACTION_COLLECT_RANSOM))) {
ok = FALSE;
} else if (!load_action_post_success_force(file, filename,
ACTION_AUTO_POST_WIPE_UNITS,
action_by_number(
ACTION_WIPE_UNITS))) {
ok = FALSE;
}
/* No "Suicide Attack". Can't act when dead. */
}
if (ok) {
/* The city that made the unit's current tile native is gone.
* Evaluated against an adjacent tile. */
auto_perf = action_auto_perf_slot_number(ACTION_AUTO_ESCAPE_CITY);
auto_perf->cause = AAPC_CITY_GONE;
/* I have no objections to moving this out of game's actions to
* cities.ruleset, units.ruleset or an other location in game.ruleset
* you find more suitable. -- Sveinung */
if (!load_action_auto_actions(file, auto_perf,
"actions.escape_city", filename)) {
ok = FALSE;
}
}
if (ok) {
/* The unit's stack has been defeated and is scheduled for execution
* but the unit has the CanEscape unit type flag.
* Evaluated against an adjacent tile. */
auto_perf = action_auto_perf_slot_number(ACTION_AUTO_ESCAPE_STACK);
auto_perf->cause = AAPC_UNIT_STACK_DEATH;
/* I have no objections to moving this out of game's actions to
* cities.ruleset, units.ruleset or an other location in game.ruleset
* you find more suitable. -- Sveinung */
if (!load_action_auto_actions(file, auto_perf,
"actions.unit_stack_death", filename)) {
ok = FALSE;
}
}
if (ok) {
sec = secfile_sections_by_name_prefix(file,
ACTION_ENABLER_SECTION_PREFIX);
if (sec) {
section_list_iterate(sec, psection) {
struct action_enabler *enabler;
const char *sec_name = section_name(psection);
struct action *paction;
struct requirement_vector *actor_reqs;
struct requirement_vector *target_reqs;
const char *action_text;
const char *orig_name;
enabler = action_enabler_new();
orig_name = secfile_lookup_str(file, "%s.action", sec_name);
action_text = rscompat_action_rule_name_3_2(compat, orig_name);
if (action_text == NULL) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] missing action to enable.",
filename, sec_name);
ok = FALSE;
break;
}
paction = action_by_rule_name(action_text);
if (!paction) {
ruleset_error(NULL, LOG_ERROR,
"\"%s\" [%s] lists unknown action type \"%s\".",
filename, sec_name, action_text);
ok = FALSE;
break;
}
enabler->action = action_id(paction);
actor_reqs = lookup_req_list(file, compat, sec_name, "actor_reqs", action_text);
if (actor_reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&enabler->actor_reqs, actor_reqs);
target_reqs = lookup_req_list(file, compat, sec_name, "target_reqs", action_text);
if (target_reqs == NULL) {
ok = FALSE;
break;
}
requirement_vector_copy(&enabler->target_reqs, target_reqs);
rscompat_action_enabler_adjust_3_2(compat, enabler, orig_name);
action_enabler_add(enabler);
} section_list_iterate_end;
section_list_destroy(sec);
}
}
return ok;
}
/**********************************************************************//**
Send the units ruleset information (all individual unit classes) to the
specified connections.
**************************************************************************/
static void send_ruleset_unit_classes(struct conn_list *dest)
{
struct packet_ruleset_unit_class packet;
struct packet_ruleset_unit_class_flag fpacket;
int i;
for (i = 0; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
const char *flagname;
const char *helptxt;
fpacket.id = i + UCF_USER_FLAG_1;
flagname = unit_class_flag_id_name(i + UCF_USER_FLAG_1);
if (flagname == NULL) {
fpacket.name[0] = '\0';
} else {
sz_strlcpy(fpacket.name, flagname);
}
helptxt = unit_class_flag_helptxt(i + UCF_USER_FLAG_1);
if (helptxt == NULL) {
fpacket.helptxt[0] = '\0';
} else {
sz_strlcpy(fpacket.helptxt, helptxt);
}
lsend_packet_ruleset_unit_class_flag(dest, &fpacket);
}
unit_class_iterate(c) {
packet.id = uclass_number(c);
sz_strlcpy(packet.name, untranslated_name(&c->name));
sz_strlcpy(packet.rule_name, rule_name_get(&c->name));
packet.min_speed = c->min_speed;
packet.hp_loss_pct = c->hp_loss_pct;
packet.non_native_def_pct = c->non_native_def_pct;
packet.flags = c->flags;
PACKET_STRVEC_COMPUTE(packet.helptext, c->helptext);
lsend_packet_ruleset_unit_class(dest, &packet);
} unit_class_iterate_end;
}
/**********************************************************************//**
Send the units ruleset information (all individual units) to the
specified connections.
**************************************************************************/
static void send_ruleset_units(struct conn_list *dest)
{
struct packet_ruleset_unit packet;
#ifdef FREECIV_WEB
struct packet_web_ruleset_unit_addition web_packet;
#endif /* FREECIV_WEB */
struct packet_ruleset_unit_flag fpacket;
int i;
for (i = 0; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
const char *flagname;
const char *helptxt;
fpacket.id = i + UTYF_USER_FLAG_1;
flagname = unit_type_flag_id_name(i + UTYF_USER_FLAG_1);
if (flagname == NULL) {
fpacket.name[0] = '\0';
} else {
sz_strlcpy(fpacket.name, flagname);
}
helptxt = unit_type_flag_helptxt(i + UTYF_USER_FLAG_1);
if (helptxt == NULL) {
fpacket.helptxt[0] = '\0';
} else {
sz_strlcpy(fpacket.helptxt, helptxt);
}
lsend_packet_ruleset_unit_flag(dest, &fpacket);
}
unit_type_iterate(u) {
packet.id = utype_number(u);
sz_strlcpy(packet.name, untranslated_name(&u->name));
sz_strlcpy(packet.rule_name, rule_name_get(&u->name));
sz_strlcpy(packet.sound_move, u->sound_move);
sz_strlcpy(packet.sound_move_alt, u->sound_move_alt);
sz_strlcpy(packet.sound_fight, u->sound_fight);
sz_strlcpy(packet.sound_fight_alt, u->sound_fight_alt);
sz_strlcpy(packet.graphic_str, u->graphic_str);
sz_strlcpy(packet.graphic_alt, u->graphic_alt);
sz_strlcpy(packet.graphic_alt2, u->graphic_alt2);
packet.unit_class_id = uclass_number(utype_class(u));
packet.build_cost = u->build_cost;
packet.pop_cost = u->pop_cost;
packet.attack_strength = u->attack_strength;
packet.defense_strength = u->defense_strength;
packet.move_rate = u->move_rate;
i = 0;
requirement_vector_iterate(&u->build_reqs, req) {
packet.build_reqs[i++] = *req;
} requirement_vector_iterate_end;
packet.build_reqs_count = i;
packet.vision_radius_sq = u->vision_radius_sq;
packet.transport_capacity = u->transport_capacity;
packet.hp = u->hp;
packet.firepower = u->firepower;
packet.obsoleted_by = u->obsoleted_by
? utype_number(u->obsoleted_by)
: utype_count();
packet.converted_to = u->converted_to
? utype_number(u->converted_to)
: utype_count();
packet.convert_time = u->convert_time;
packet.fuel = u->fuel;
packet.flags = u->flags;
packet.roles = u->roles;
packet.happy_cost = u->happy_cost;
output_type_iterate(o) {
packet.upkeep[o] = u->upkeep[o];
} output_type_iterate_end;
packet.paratroopers_range = u->paratroopers_range;
packet.bombard_rate = u->bombard_rate;
packet.city_size = u->city_size;
packet.city_slots = u->city_slots;
packet.tp_defense = u->tp_defense;
packet.cargo = u->cargo;
packet.targets = u->targets;
packet.embarks = u->embarks;
packet.disembarks = u->disembarks;
packet.vlayer = u->vlayer;
if (u->veteran == NULL) {
/* Use the default veteran system. */
packet.veteran_levels = 0;
} else {
/* Per unit veteran system definition. */
packet.veteran_levels = utype_veteran_levels(u);
for (i = 0; i < packet.veteran_levels; i++) {
const struct veteran_level *vlevel = utype_veteran_level(u, i);
sz_strlcpy(packet.veteran_name[i], untranslated_name(&vlevel->name));
packet.power_fact[i] = vlevel->power_fact;
packet.move_bonus[i] = vlevel->move_bonus;
packet.base_raise_chance[i] = vlevel->base_raise_chance;
packet.work_raise_chance[i] = vlevel->work_raise_chance;
}
}
PACKET_STRVEC_COMPUTE(packet.helptext, u->helptext);
packet.worker = u->adv.worker;
#ifdef FREECIV_WEB
web_packet.id = utype_number(u);
BV_CLR_ALL(web_packet.utype_actions);
action_iterate(act) {
if (utype_can_do_action(u, act)) {
BV_SET(web_packet.utype_actions, act);
}
} action_iterate_end;
#endif /* FREECIV_WEB */
lsend_packet_ruleset_unit(dest, &packet);
web_lsend_packet(ruleset_unit_addition, dest, &web_packet);
combat_bonus_list_iterate(u->bonuses, pbonus) {
struct packet_ruleset_unit_bonus bonuspacket;
bonuspacket.unit = packet.id;
bonuspacket.flag = pbonus->flag;
bonuspacket.type = pbonus->type;
bonuspacket.value = pbonus->value;
bonuspacket.quiet = pbonus->quiet;
lsend_packet_ruleset_unit_bonus(dest, &bonuspacket);
} combat_bonus_list_iterate_end;
} unit_type_iterate_end;
}
/**********************************************************************//**
Send the specialists ruleset information (all individual specialist
types) to the specified connections.
**************************************************************************/
static void send_ruleset_specialists(struct conn_list *dest)
{
struct packet_ruleset_specialist packet;
specialist_type_iterate(spec_id) {
struct specialist *s = specialist_by_number(spec_id);
int j;
packet.id = spec_id;
sz_strlcpy(packet.plural_name, untranslated_name(&s->name));
sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
sz_strlcpy(packet.short_name, untranslated_name(&s->abbreviation));
sz_strlcpy(packet.graphic_str, s->graphic_str);
sz_strlcpy(packet.graphic_alt, s->graphic_alt);
j = 0;
requirement_vector_iterate(&s->reqs, preq) {
packet.reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.reqs_count = j;
PACKET_STRVEC_COMPUTE(packet.helptext, s->helptext);
lsend_packet_ruleset_specialist(dest, &packet);
} specialist_type_iterate_end;
}
/**********************************************************************//**
Send the techs class information to the specified connections.
**************************************************************************/
static void send_ruleset_tech_classes(struct conn_list *dest)
{
struct packet_ruleset_tech_class packet;
tech_class_iterate(ptclass) {
packet.id = ptclass->idx;
sz_strlcpy(packet.name, untranslated_name(&ptclass->name));
sz_strlcpy(packet.rule_name, rule_name_get(&ptclass->name));
packet.cost_pct = ptclass->cost_pct;
lsend_packet_ruleset_tech_class(dest, &packet);
} tech_class_iterate_end;
}
/**********************************************************************//**
Send the techs ruleset information (all individual advances) to the
specified connections.
**************************************************************************/
static void send_ruleset_techs(struct conn_list *dest)
{
struct packet_ruleset_tech packet;
struct packet_ruleset_tech_flag fpacket;
int i;
for (i = 0; i < MAX_NUM_USER_TECH_FLAGS; i++) {
const char *flagname;
const char *helptxt;
fpacket.id = i + TECH_USER_1;
flagname = tech_flag_id_name_cb(i + TECH_USER_1);
if (flagname == NULL) {
fpacket.name[0] = '\0';
} else {
sz_strlcpy(fpacket.name, flagname);
}
helptxt = tech_flag_helptxt(i + TECH_USER_1);
if (helptxt == NULL) {
fpacket.helptxt[0] = '\0';
} else {
sz_strlcpy(fpacket.helptxt, helptxt);
}
lsend_packet_ruleset_tech_flag(dest, &fpacket);
}
advance_iterate(a) {
packet.id = advance_number(a);
packet.removed = !valid_advance(a);
if (a->tclass == NULL) {
packet.tclass = 0;
} else {
packet.tclass = a->tclass->idx;
}
sz_strlcpy(packet.name, untranslated_name(&a->name));
sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
sz_strlcpy(packet.graphic_str, a->graphic_str);
sz_strlcpy(packet.graphic_alt, a->graphic_alt);
/* Current size of the packet's research_reqs requirement vector. */
i = 0;
/* The requirements req1 and req2 are needed to research a tech. Send
* them in the research_reqs requirement vector. Range is set to player
* since pooled research is configurable. */
if ((a->require[AR_ONE] != A_NEVER)
&& advance_number(a->require[AR_ONE]) > A_NONE) {
packet.research_reqs[i++]
= req_from_values(VUT_ADVANCE, REQ_RANGE_PLAYER,
FALSE, TRUE, FALSE,
advance_number(a->require[AR_ONE]));
}
if ((a->require[AR_TWO] != A_NEVER)
&& advance_number(a->require[AR_TWO]) > A_NONE) {
packet.research_reqs[i++]
= req_from_values(VUT_ADVANCE, REQ_RANGE_PLAYER,
FALSE, TRUE, FALSE,
advance_number(a->require[AR_TWO]));;
}
/* The requirements of the tech's research_reqs also goes in the
* packet's research_reqs requirement vector. */
requirement_vector_iterate(&a->research_reqs, req) {
packet.research_reqs[i++] = *req;
} requirement_vector_iterate_end;
/* The packet's research_reqs should contain req1, req2 and the
* requirements of the tech's research_reqs. */
packet.research_reqs_count = i;
packet.root_req = a->require[AR_ROOT]
? advance_number(a->require[AR_ROOT])
: advance_count();
packet.flags = a->flags;
packet.cost = a->cost;
packet.num_reqs = a->num_reqs;
PACKET_STRVEC_COMPUTE(packet.helptext, a->helptext);
lsend_packet_ruleset_tech(dest, &packet);
} advance_iterate_end;
}
/**********************************************************************//**
Send the counters ruleset information to the specified connections.
**************************************************************************/
static void send_ruleset_counters(struct conn_list *dest)
{
city_counters_iterate(pcount) {
struct packet_ruleset_counter packet;
sz_strlcpy(packet.name, untranslated_name(&pcount->name));
sz_strlcpy(packet.rule_name, rule_name_get(&pcount->name));
packet.checkpoint = pcount->checkpoint;
packet.behavior = pcount->type;
packet.type = pcount->target;
packet.def = pcount->def;
PACKET_STRVEC_COMPUTE(packet.helptext, pcount->helptext);
lsend_packet_ruleset_counter(dest, &packet);
} city_counters_iterate_end;
}
/**********************************************************************//**
Send the buildings ruleset information (all individual improvements and
wonders) to the specified connections.
**************************************************************************/
static void send_ruleset_buildings(struct conn_list *dest)
{
int i;
for (i = 0; i < MAX_NUM_USER_BUILDING_FLAGS; i++) {
struct packet_ruleset_impr_flag fpacket;
const char *flagname;
const char *helptxt;
fpacket.id = i + IF_USER_FLAG_1;
flagname = impr_flag_id_name(i + IF_USER_FLAG_1);
if (flagname == NULL) {
fpacket.name[0] = '\0';
} else {
sz_strlcpy(fpacket.name, flagname);
}
helptxt = impr_flag_helptxt(i + IF_USER_FLAG_1);
if (helptxt == NULL) {
fpacket.helptxt[0] = '\0';
} else {
sz_strlcpy(fpacket.helptxt, helptxt);
}
lsend_packet_ruleset_impr_flag(dest, &fpacket);
}
improvement_iterate(b) {
struct packet_ruleset_building packet;
int j;
packet.id = improvement_number(b);
packet.genus = b->genus;
sz_strlcpy(packet.name, untranslated_name(&b->name));
sz_strlcpy(packet.rule_name, rule_name_get(&b->name));
sz_strlcpy(packet.graphic_str, b->graphic_str);
sz_strlcpy(packet.graphic_alt, b->graphic_alt);
sz_strlcpy(packet.graphic_alt2, b->graphic_alt2);
j = 0;
requirement_vector_iterate(&b->reqs, preq) {
packet.reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.reqs_count = j;
j = 0;
requirement_vector_iterate(&b->obsolete_by, pobs) {
packet.obs_reqs[j++] = *pobs;
} requirement_vector_iterate_end;
packet.obs_count = j;
packet.build_cost = b->build_cost;
packet.upkeep = b->upkeep;
packet.sabotage = b->sabotage;
packet.flags = b->flags;
sz_strlcpy(packet.soundtag, b->soundtag);
sz_strlcpy(packet.soundtag_alt, b->soundtag_alt);
sz_strlcpy(packet.soundtag_alt2, b->soundtag_alt2);
PACKET_STRVEC_COMPUTE(packet.helptext, b->helptext);
lsend_packet_ruleset_building(dest, &packet);
} improvement_iterate_end;
}
/**********************************************************************//**
Send the terrain ruleset information (terrain_control, and the individual
terrain types) to the specified connections.
**************************************************************************/
static void send_ruleset_terrain(struct conn_list *dest)
{
struct packet_ruleset_terrain packet;
struct packet_ruleset_terrain_flag fpacket;
int i;
lsend_packet_ruleset_terrain_control(dest, &terrain_control);
for (i = 0; i < MAX_NUM_USER_TER_FLAGS; i++) {
const char *flagname;
const char *helptxt;
fpacket.id = i + TER_USER_1;
flagname = terrain_flag_id_name_cb(i + TER_USER_1);
if (flagname == NULL) {
fpacket.name[0] = '\0';
} else {
sz_strlcpy(fpacket.name, flagname);
}
helptxt = terrain_flag_helptxt(i + TER_USER_1);
if (helptxt == NULL) {
fpacket.helptxt[0] = '\0';
} else {
sz_strlcpy(fpacket.helptxt, helptxt);
}
lsend_packet_ruleset_terrain_flag(dest, &fpacket);
}
terrain_type_iterate(pterrain) {
packet.id = terrain_number(pterrain);
packet.tclass = pterrain->tclass;
packet.native_to = pterrain->native_to;
sz_strlcpy(packet.name, untranslated_name(&pterrain->name));
sz_strlcpy(packet.rule_name, rule_name_get(&pterrain->name));
sz_strlcpy(packet.graphic_str, pterrain->graphic_str);
sz_strlcpy(packet.graphic_alt, pterrain->graphic_alt);
sz_strlcpy(packet.graphic_alt2, pterrain->graphic_alt2);
packet.movement_cost = pterrain->movement_cost;
packet.defense_bonus = pterrain->defense_bonus;
output_type_iterate(o) {
packet.output[o] = pterrain->output[o];
} output_type_iterate_end;
packet.num_resources = 0;
terrain_resources_iterate(pterrain, res, freq) {
packet.resources[packet.num_resources] = extra_number(res);
packet.resource_freq[packet.num_resources] = freq;
packet.num_resources++;
} terrain_resources_iterate_end;
output_type_iterate(o) {
packet.road_output_incr_pct[o] = pterrain->road_output_incr_pct[o];
} output_type_iterate_end;
packet.base_time = pterrain->base_time;
packet.road_time = pterrain->road_time;
packet.cultivate_result = (pterrain->cultivate_result
? terrain_number(pterrain->cultivate_result)
: terrain_count());
packet.cultivate_time = pterrain->cultivate_time;
packet.plant_result = (pterrain->plant_result
? terrain_number(pterrain->plant_result)
: terrain_count());
packet.plant_time = pterrain->plant_time;
packet.irrigation_food_incr = pterrain->irrigation_food_incr;
packet.irrigation_time = pterrain->irrigation_time;
packet.mining_shield_incr = pterrain->mining_shield_incr;
packet.mining_time = pterrain->mining_time;
packet.animal = (pterrain->animal == NULL ? -1 : utype_number(pterrain->animal));
packet.transform_result = (pterrain->transform_result
? terrain_number(pterrain->transform_result)
: terrain_count());
packet.placing_time = pterrain->placing_time;
packet.pillage_time = pterrain->pillage_time;
packet.transform_time = pterrain->transform_time;
packet.extra_count = game.control.num_extra_types;
for (i = 0; i < game.control.num_extra_types; i++) {
packet.extra_removal_times[i] = pterrain->extra_removal_times[i];
}
packet.flags = pterrain->flags;
packet.color_red = pterrain->rgb->r;
packet.color_green = pterrain->rgb->g;
packet.color_blue = pterrain->rgb->b;
PACKET_STRVEC_COMPUTE(packet.helptext, pterrain->helptext);
lsend_packet_ruleset_terrain(dest, &packet);
} terrain_type_iterate_end;
}
/**********************************************************************//**
Send the resource ruleset information to the specified connections.
**************************************************************************/
static void send_ruleset_resources(struct conn_list *dest)
{
struct packet_ruleset_resource packet;
extra_type_by_cause_iterate(EC_RESOURCE, presource) {
packet.id = extra_index(presource);
output_type_iterate(o) {
packet.output[o] = presource->data.resource->output[o];
} output_type_iterate_end;
lsend_packet_ruleset_resource(dest, &packet);
} extra_type_by_cause_iterate_end;
}
/**********************************************************************//**
Send the extra ruleset information (all individual extra types) to the
specified connections.
**************************************************************************/
static void send_ruleset_extras(struct conn_list *dest)
{
int i;
for (i = 0; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
struct packet_ruleset_extra_flag fpacket;
const char *flagname;
const char *helptxt;
fpacket.id = i + EF_USER_FLAG_1;
flagname = extra_flag_id_name(i + EF_USER_FLAG_1);
if (flagname == NULL) {
fpacket.name[0] = '\0';
} else {
sz_strlcpy(fpacket.name, flagname);
}
helptxt = extra_flag_helptxt(i + EF_USER_FLAG_1);
if (helptxt == NULL) {
fpacket.helptxt[0] = '\0';
} else {
sz_strlcpy(fpacket.helptxt, helptxt);
}
lsend_packet_ruleset_extra_flag(dest, &fpacket);
}
extra_type_iterate(e) {
struct packet_ruleset_extra packet;
int j;
packet.id = extra_number(e);
sz_strlcpy(packet.name, untranslated_name(&e->name));
sz_strlcpy(packet.rule_name, rule_name_get(&e->name));
packet.category = e->category;
BV_CLR_ALL(packet.causes);
for (j = 0; j < EC_COUNT; j++) {
if (is_extra_caused_by(e, j)) {
BV_SET(packet.causes, j);
}
}
BV_CLR_ALL(packet.rmcauses);
for (j = 0; j < ERM_COUNT; j++) {
if (is_extra_removed_by(e, j)) {
BV_SET(packet.rmcauses, j);
}
}
sz_strlcpy(packet.activity_gfx, e->activity_gfx);
sz_strlcpy(packet.act_gfx_alt, e->act_gfx_alt);
sz_strlcpy(packet.act_gfx_alt2, e->act_gfx_alt2);
sz_strlcpy(packet.rmact_gfx, e->rmact_gfx);
sz_strlcpy(packet.rmact_gfx_alt, e->rmact_gfx_alt);
sz_strlcpy(packet.rmact_gfx_alt2, e->rmact_gfx_alt2);
sz_strlcpy(packet.graphic_str, e->graphic_str);
sz_strlcpy(packet.graphic_alt, e->graphic_alt);
j = 0;
requirement_vector_iterate(&e->reqs, preq) {
packet.reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.reqs_count = j;
j = 0;
requirement_vector_iterate(&e->rmreqs, preq) {
packet.rmreqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.rmreqs_count = j;
packet.appearance_chance = e->appearance_chance;
j = 0;
requirement_vector_iterate(&e->appearance_reqs, preq) {
packet.appearance_reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.appearance_reqs_count = j;
packet.disappearance_chance = e->disappearance_chance;
j = 0;
requirement_vector_iterate(&e->disappearance_reqs, preq) {
packet.disappearance_reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.disappearance_reqs_count = j;
packet.visibility_req = e->visibility_req;
packet.buildable = e->buildable;
packet.generated = e->generated;
packet.build_time = e->build_time;
packet.build_time_factor = e->build_time_factor;
packet.removal_time = e->removal_time;
packet.removal_time_factor = e->removal_time_factor;
packet.infracost = e->infracost;
packet.defense_bonus = e->defense_bonus;
packet.eus = e->eus;
packet.no_aggr_near_city = e->no_aggr_near_city;
packet.native_to = e->native_to;
packet.flags = e->flags;
packet.hidden_by = e->hidden_by;
packet.bridged_over = e->bridged_over;
packet.conflicts = e->conflicts;
PACKET_STRVEC_COMPUTE(packet.helptext, e->helptext);
lsend_packet_ruleset_extra(dest, &packet);
} extra_type_iterate_end;
}
/**********************************************************************//**
Send the base ruleset information (all individual base types) to the
specified connections.
**************************************************************************/
static void send_ruleset_bases(struct conn_list *dest)
{
extra_type_by_cause_iterate(EC_BASE, pextra) {
struct base_type *b = extra_base_get(pextra);
struct packet_ruleset_base packet;
packet.id = base_number(b);
packet.gui_type = b->gui_type;
packet.border_sq = b->border_sq;
packet.vision_main_sq = b->vision_main_sq;
packet.vision_invis_sq = b->vision_invis_sq;
packet.vision_subs_sq = b->vision_subs_sq;
lsend_packet_ruleset_base(dest, &packet);
} extra_type_by_cause_iterate_end;
}
/**********************************************************************//**
Send the road ruleset information (all individual road types) to the
specified connections.
**************************************************************************/
static void send_ruleset_roads(struct conn_list *dest)
{
struct packet_ruleset_road packet;
extra_type_by_cause_iterate(EC_ROAD, pextra) {
struct road_type *r = extra_road_get(pextra);
int j;
packet.id = road_number(r);
packet.gui_type = r->gui_type;
j = 0;
requirement_vector_iterate(&r->first_reqs, preq) {
packet.first_reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.first_reqs_count = j;
packet.move_cost = r->move_cost;
packet.move_mode = r->move_mode;
output_type_iterate(o) {
packet.tile_incr_const[o] = r->tile_incr_const[o];
packet.tile_incr[o] = r->tile_incr[o];
packet.tile_bonus[o] = r->tile_bonus[o];
} output_type_iterate_end;
packet.compat = r->compat;
packet.integrates = r->integrates;
packet.flags = r->flags;
lsend_packet_ruleset_road(dest, &packet);
} extra_type_by_cause_iterate_end;
}
/**********************************************************************//**
Send the goods ruleset information (all individual goods types) to the
specified connections.
**************************************************************************/
static void send_ruleset_goods(struct conn_list *dest)
{
struct packet_ruleset_goods packet;
goods_type_iterate(g) {
int j;
packet.id = goods_number(g);
sz_strlcpy(packet.name, untranslated_name(&g->name));
sz_strlcpy(packet.rule_name, rule_name_get(&g->name));
j = 0;
requirement_vector_iterate(&g->reqs, preq) {
packet.reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.reqs_count = j;
packet.from_pct = g->from_pct;
packet.to_pct = g->to_pct;
packet.onetime_pct = g->onetime_pct;
packet.flags = g->flags;
PACKET_STRVEC_COMPUTE(packet.helptext, g->helptext);
lsend_packet_ruleset_goods(dest, &packet);
} goods_type_iterate_end;
}
/**********************************************************************//**
Send the disaster ruleset information (all individual disaster types) to the
specified connections.
**************************************************************************/
static void send_ruleset_disasters(struct conn_list *dest)
{
struct packet_ruleset_disaster packet;
disaster_type_iterate(d) {
int j;
packet.id = disaster_number(d);
sz_strlcpy(packet.name, untranslated_name(&d->name));
sz_strlcpy(packet.rule_name, rule_name_get(&d->name));
j = 0;
requirement_vector_iterate(&d->reqs, preq) {
packet.reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.reqs_count = j;
packet.frequency = d->frequency;
packet.effects = d->effects;
lsend_packet_ruleset_disaster(dest, &packet);
} disaster_type_iterate_end;
}
/**********************************************************************//**
Send the achievement ruleset information (all individual achievement types)
to the specified connections.
**************************************************************************/
static void send_ruleset_achievements(struct conn_list *dest)
{
struct packet_ruleset_achievement packet;
achievements_iterate(a) {
packet.id = achievement_number(a);
sz_strlcpy(packet.name, untranslated_name(&a->name));
sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
packet.type = a->type;
packet.unique = a->unique;
packet.value = a->value;
lsend_packet_ruleset_achievement(dest, &packet);
} achievements_iterate_end;
}
/**********************************************************************//**
Send action ruleset information to the specified connections.
**************************************************************************/
static void send_ruleset_actions(struct conn_list *dest)
{
struct packet_ruleset_action packet;
action_iterate(act) {
struct action *paction = action_by_number(act);
packet.id = act;
sz_strlcpy(packet.ui_name, action_by_number(act)->ui_name);
packet.quiet = action_by_number(act)->quiet;
packet.result = paction->result;
packet.sub_results = paction->sub_results;
packet.actor_consuming_always = paction->actor_consuming_always;
packet.act_kind = action_by_number(act)->actor_kind;
packet.tgt_kind = action_by_number(act)->target_kind;
packet.sub_tgt_kind = action_id_get_sub_target_kind(act);
packet.min_distance = action_by_number(act)->min_distance;
packet.max_distance = action_by_number(act)->max_distance;
packet.blocked_by = action_by_number(act)->blocked_by;
lsend_packet_ruleset_action(dest, &packet);
} action_iterate_end;
}
/**********************************************************************//**
Send the action enabler ruleset information to the specified connections.
**************************************************************************/
static void send_ruleset_action_enablers(struct conn_list *dest)
{
int counter;
struct packet_ruleset_action_enabler packet;
action_enablers_iterate(enabler) {
packet.enabled_action = enabler_get_action_id(enabler);
counter = 0;
requirement_vector_iterate(&enabler->actor_reqs, req) {
packet.actor_reqs[counter++] = *req;
} requirement_vector_iterate_end;
packet.actor_reqs_count = counter;
counter = 0;
requirement_vector_iterate(&enabler->target_reqs, req) {
packet.target_reqs[counter++] = *req;
} requirement_vector_iterate_end;
packet.target_reqs_count = counter;
lsend_packet_ruleset_action_enabler(dest, &packet);
} action_enablers_iterate_end;
}
/**********************************************************************//**
Send action auto performer ruleset information to the specified
connections.
**************************************************************************/
static void send_ruleset_action_auto_performers(struct conn_list *dest)
{
int counter;
int id;
struct packet_ruleset_action_auto packet;
id = 0;
action_auto_perf_iterate(aperf) {
packet.id = id++;
packet.cause = aperf->cause;
counter = 0;
requirement_vector_iterate(&aperf->reqs, req) {
packet.reqs[counter++] = *req;
} requirement_vector_iterate_end;
packet.reqs_count = counter;
for (counter = 0;
/* Can't list more actions than all actions. */
counter < NUM_ACTIONS
/* ACTION_NONE terminates the list. */
&& aperf->alternatives[counter] != ACTION_NONE;
counter++) {
packet.alternatives[counter] = aperf->alternatives[counter];
}
packet.alternatives_count = counter;
lsend_packet_ruleset_action_auto(dest, &packet);
} action_auto_perf_iterate_end;
}
/**********************************************************************//**
Send the trade route types ruleset information (all individual
trade route types) to the specified connections.
**************************************************************************/
static void send_ruleset_trade_routes(struct conn_list *dest)
{
struct packet_ruleset_trade packet;
enum trade_route_type type;
for (type = TRT_NATIONAL; type < TRT_LAST; type++) {
struct trade_route_settings *set = trade_route_settings_by_type(type);
packet.id = type;
packet.trade_pct = set->trade_pct;
packet.cancelling = set->cancelling;
packet.bonus_type = set->bonus_type;
lsend_packet_ruleset_trade(dest, &packet);
}
}
/**********************************************************************//**
Send the government ruleset information to the specified connections.
One packet per government type, and for each type one per ruler title.
**************************************************************************/
static void send_ruleset_governments(struct conn_list *dest)
{
struct packet_ruleset_government gov;
struct packet_ruleset_government_ruler_title title;
int j;
governments_iterate(g) {
/* Send one packet_government */
gov.id = government_number(g);
j = 0;
requirement_vector_iterate(&g->reqs, preq) {
gov.reqs[j++] = *preq;
} requirement_vector_iterate_end;
gov.reqs_count = j;
sz_strlcpy(gov.name, untranslated_name(&g->name));
sz_strlcpy(gov.rule_name, rule_name_get(&g->name));
sz_strlcpy(gov.graphic_str, g->graphic_str);
sz_strlcpy(gov.graphic_alt, g->graphic_alt);
sz_strlcpy(gov.sound_str, g->sound_str);
sz_strlcpy(gov.sound_alt, g->sound_alt);
sz_strlcpy(gov.sound_alt2, g->sound_alt2);
PACKET_STRVEC_COMPUTE(gov.helptext, g->helptext);
lsend_packet_ruleset_government(dest, &gov);
/* Send one packet_government_ruler_title per ruler title. */
ruler_titles_iterate(government_ruler_titles(g), pruler_title) {
const struct nation_type *pnation = ruler_title_nation(pruler_title);
title.gov = government_number(g);
title.nation = pnation ? nation_number(pnation) : nation_count();
sz_strlcpy(title.male_title,
ruler_title_male_untranslated_name(pruler_title));
sz_strlcpy(title.female_title,
ruler_title_female_untranslated_name(pruler_title));
lsend_packet_ruleset_government_ruler_title(dest, &title);
} ruler_titles_iterate_end;
} governments_iterate_end;
}
/**********************************************************************//**
Send the nations ruleset information (info on each nation) to the
specified connections.
**************************************************************************/
static void send_ruleset_nations(struct conn_list *dest)
{
struct packet_ruleset_nation_sets sets_packet;
struct packet_ruleset_nation_groups groups_packet;
struct packet_ruleset_nation packet;
int i;
sets_packet.nsets = nation_set_count();
i = 0;
nation_sets_iterate(pset) {
sz_strlcpy(sets_packet.names[i], nation_set_untranslated_name(pset));
sz_strlcpy(sets_packet.rule_names[i], nation_set_rule_name(pset));
sz_strlcpy(sets_packet.descriptions[i], nation_set_description(pset));
i++;
} nation_sets_iterate_end;
lsend_packet_ruleset_nation_sets(dest, &sets_packet);
groups_packet.ngroups = nation_group_count();
i = 0;
nation_groups_iterate(pgroup) {
sz_strlcpy(groups_packet.groups[i],
nation_group_untranslated_name(pgroup));
groups_packet.hidden[i] = pgroup->hidden;
i++;
} nation_groups_iterate_end;
lsend_packet_ruleset_nation_groups(dest, &groups_packet);
nations_iterate(n) {
packet.id = nation_number(n);
if (n->translation_domain == NULL) {
packet.translation_domain[0] = '\0';
} else {
sz_strlcpy(packet.translation_domain, n->translation_domain);
}
sz_strlcpy(packet.adjective, untranslated_name(&n->adjective));
sz_strlcpy(packet.rule_name, rule_name_get(&n->adjective));
sz_strlcpy(packet.noun_plural, untranslated_name(&n->noun_plural));
sz_strlcpy(packet.graphic_str, n->flag_graphic_str);
sz_strlcpy(packet.graphic_alt, n->flag_graphic_alt);
i = 0;
nation_leader_list_iterate(nation_leaders(n), pleader) {
sz_strlcpy(packet.leader_name[i], nation_leader_name(pleader));
packet.leader_is_male[i] = nation_leader_is_male(pleader);
i++;
} nation_leader_list_iterate_end;
packet.leader_count = i;
packet.style = style_number(n->style);
packet.is_playable = n->is_playable;
packet.barbarian_type = n->barb_type;
sz_strlcpy(packet.legend, n->legend);
i = 0;
nation_set_list_iterate(n->sets, pset) {
packet.sets[i++] = nation_set_number(pset);
} nation_set_list_iterate_end;
packet.nsets = i;
i = 0;
nation_group_list_iterate(n->groups, pgroup) {
packet.groups[i++] = nation_group_number(pgroup);
} nation_group_list_iterate_end;
packet.ngroups = i;
packet.init_government_id = n->init_government
? government_number(n->init_government) : government_count();
fc_assert(ARRAY_SIZE(packet.init_techs) == ARRAY_SIZE(n->init_techs));
for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
if (n->init_techs[i] != A_LAST) {
packet.init_techs[i] = n->init_techs[i];
} else {
break;
}
}
packet.init_techs_count = i;
fc_assert(ARRAY_SIZE(packet.init_units) == ARRAY_SIZE(n->init_units));
for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
const struct unit_type *t = n->init_units[i];
if (t) {
packet.init_units[i] = utype_number(t);
} else {
break;
}
}
packet.init_units_count = i;
fc_assert(ARRAY_SIZE(packet.init_buildings)
== ARRAY_SIZE(n->init_buildings));
for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
if (n->init_buildings[i] != B_LAST) {
/* Impr_type_id to int */
packet.init_buildings[i] = n->init_buildings[i];
} else {
break;
}
}
packet.init_buildings_count = i;
lsend_packet_ruleset_nation(dest, &packet);
} nations_iterate_end;
/* Send initial values of is_pickable */
send_nation_availability(dest, FALSE);
}
/**********************************************************************//**
Send the nation style ruleset information (each style) to the specified
connections.
**************************************************************************/
static void send_ruleset_styles(struct conn_list *dest)
{
struct packet_ruleset_style packet;
styles_iterate(s) {
packet.id = style_index(s);
sz_strlcpy(packet.name, untranslated_name(&s->name));
sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
lsend_packet_ruleset_style(dest, &packet);
} styles_iterate_end;
}
/**********************************************************************//**
Send the clause type ruleset information to the specified connections.
**************************************************************************/
static void send_ruleset_clauses(struct conn_list *dest)
{
struct packet_ruleset_clause packet;
int i;
for (i = 0; i < CLAUSE_COUNT; i++) {
struct clause_info *info = clause_info_get(i);
int j;
packet.type = i;
packet.enabled = info->enabled;
j = 0;
requirement_vector_iterate(&info->giver_reqs, preq) {
packet.giver_reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.giver_reqs_count = j;
j = 0;
requirement_vector_iterate(&info->receiver_reqs, preq) {
packet.receiver_reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.receiver_reqs_count = j;
lsend_packet_ruleset_clause(dest, &packet);
}
}
/**********************************************************************//**
Send the multiplier ruleset information to the specified
connections.
**************************************************************************/
static void send_ruleset_multipliers(struct conn_list *dest)
{
multipliers_iterate(pmul) {
int j;
struct packet_ruleset_multiplier packet;
packet.id = multiplier_number(pmul);
packet.start = pmul->start;
packet.stop = pmul->stop;
packet.step = pmul->step;
packet.def = pmul->def;
packet.offset = pmul->offset;
packet.factor = pmul->factor;
packet.minimum_turns = pmul->minimum_turns;
sz_strlcpy(packet.name, untranslated_name(&pmul->name));
sz_strlcpy(packet.rule_name, rule_name_get(&pmul->name));
j = 0;
requirement_vector_iterate(&pmul->reqs, preq) {
packet.reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.reqs_count = j;
PACKET_STRVEC_COMPUTE(packet.helptext, pmul->helptext);
lsend_packet_ruleset_multiplier(dest, &packet);
} multipliers_iterate_end;
}
/**********************************************************************//**
Send the city-style ruleset information (each style) to the specified
connections.
**************************************************************************/
static void send_ruleset_cities(struct conn_list *dest)
{
struct packet_ruleset_city city_p;
int k, j;
for (k = 0; k < game.control.num_city_styles; k++) {
city_p.style_id = k;
j = 0;
requirement_vector_iterate(&city_styles[k].reqs, preq) {
city_p.reqs[j++] = *preq;
} requirement_vector_iterate_end;
city_p.reqs_count = j;
sz_strlcpy(city_p.name, untranslated_name(&city_styles[k].name));
sz_strlcpy(city_p.rule_name, rule_name_get(&city_styles[k].name));
sz_strlcpy(city_p.graphic, city_styles[k].graphic);
sz_strlcpy(city_p.graphic_alt, city_styles[k].graphic_alt);
sz_strlcpy(city_p.citizens_graphic, city_styles[k].citizens_graphic);
lsend_packet_ruleset_city(dest, &city_p);
}
}
/**********************************************************************//**
Send the music-style ruleset information (each style) to the specified
connections.
**************************************************************************/
static void send_ruleset_musics(struct conn_list *dest)
{
struct packet_ruleset_music packet;
music_styles_iterate(pmus) {
int j;
packet.id = pmus->id;
sz_strlcpy(packet.music_peaceful, pmus->music_peaceful);
sz_strlcpy(packet.music_combat, pmus->music_combat);
j = 0;
requirement_vector_iterate(&(pmus->reqs), preq) {
packet.reqs[j++] = *preq;
} requirement_vector_iterate_end;
packet.reqs_count = j;
lsend_packet_ruleset_music(dest, &packet);
} music_styles_iterate_end;
}
/**********************************************************************//**
Send information in packet_ruleset_game (miscellaneous rules) to the
specified connections.
**************************************************************************/
static void send_ruleset_game(struct conn_list *dest)
{
struct packet_ruleset_game misc_p;
int i;
fc_assert_ret(game.veteran != NULL);
/* Per unit veteran system definition. */
misc_p.veteran_levels = game.veteran->levels;
for (i = 0; i < misc_p.veteran_levels; i++) {
const struct veteran_level *vlevel = game.veteran->definitions + i;
sz_strlcpy(misc_p.veteran_name[i], untranslated_name(&vlevel->name));
misc_p.power_fact[i] = vlevel->power_fact;
misc_p.move_bonus[i] = vlevel->move_bonus;
misc_p.base_raise_chance[i] = vlevel->base_raise_chance;
misc_p.work_raise_chance[i] = vlevel->work_raise_chance;
}
fc_assert(sizeof(misc_p.global_init_techs)
== sizeof(game.rgame.global_init_techs));
fc_assert(ARRAY_SIZE(misc_p.global_init_techs)
== ARRAY_SIZE(game.rgame.global_init_techs));
for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
if (game.rgame.global_init_techs[i] != A_LAST) {
misc_p.global_init_techs[i] = game.rgame.global_init_techs[i];
} else {
break;
}
}
misc_p.global_init_techs_count = i;
fc_assert(ARRAY_SIZE(misc_p.global_init_buildings)
== ARRAY_SIZE(game.rgame.global_init_buildings));
for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
if (game.rgame.global_init_buildings[i] != B_LAST) {
/* Impr_type_id to int */
misc_p.global_init_buildings[i] =
game.rgame.global_init_buildings[i];
} else {
break;
}
}
misc_p.global_init_buildings_count = i;
misc_p.default_specialist = DEFAULT_SPECIALIST;
fc_assert_ret(game.plr_bg_color != NULL);
misc_p.background_red = game.plr_bg_color->r;
misc_p.background_green = game.plr_bg_color->g;
misc_p.background_blue = game.plr_bg_color->b;
lsend_packet_ruleset_game(dest, &misc_p);
}
/**********************************************************************//**
Send all team names defined in the ruleset file(s) to the
specified connections.
**************************************************************************/
static void send_ruleset_team_names(struct conn_list *dest)
{
struct packet_team_name_info team_name_info_p;
team_slots_iterate(tslot) {
const char *name = team_slot_defined_name(tslot);
if (NULL == name) {
/* End of defined names. */
break;
}
team_name_info_p.team_id = team_slot_index(tslot);
sz_strlcpy(team_name_info_p.team_name, name);
lsend_packet_team_name_info(dest, &team_name_info_p);
} team_slots_iterate_end;
}
/**********************************************************************//**
Make it clear to everyone that requested ruleset has not been loaded.
**************************************************************************/
static void notify_ruleset_fallback(const char *msg)
{
notify_conn(NULL, NULL, E_LOG_FATAL, ftc_warning, "%s", msg);
}
/**********************************************************************//**
Loads the rulesets.
**************************************************************************/
bool load_rulesets(const char *restore, const char *alt, bool compat_mode,
rs_conversion_logger logger,
bool act, bool buffer_script, bool load_luadata)
{
set_ruleset_compat_mode(compat_mode);
if (load_rulesetdir(game.server.rulesetdir, compat_mode, logger,
act, buffer_script, load_luadata)) {
set_ruleset_compat_mode(FALSE);
return TRUE;
}
if (alt != NULL) {
if (load_rulesetdir(alt, compat_mode, logger, act, buffer_script,
load_luadata)) {
sz_strlcpy(game.server.rulesetdir, alt);
set_ruleset_compat_mode(FALSE);
return TRUE;
}
}
/* Fallback to previous one. */
if (restore != NULL) {
if (load_rulesetdir(restore, compat_mode, logger, act, buffer_script, TRUE)) {
sz_strlcpy(game.server.rulesetdir, restore);
notify_ruleset_fallback(_("Ruleset couldn't be loaded. Keeping previous one."));
set_ruleset_compat_mode(FALSE);
/* We're in sane state as restoring previous ruleset succeeded,
* but return failure to indicate that this is not what caller
* wanted. */
return FALSE;
}
}
set_ruleset_compat_mode(FALSE);
/* Fallback to default one, but not if that's what we tried already */
if (strcmp(GAME_DEFAULT_RULESETDIR, game.server.rulesetdir)
&& (restore == NULL || strcmp(GAME_DEFAULT_RULESETDIR, restore))) {
if (load_rulesetdir(GAME_DEFAULT_RULESETDIR, FALSE, NULL, act, buffer_script, TRUE)) {
/* We're in sane state as fallback ruleset loading succeeded,
* but return failure to indicate that this is not what caller
* wanted. */
sz_strlcpy(game.server.rulesetdir, GAME_DEFAULT_RULESETDIR);
notify_ruleset_fallback(_("Ruleset couldn't be loaded. Switching to default one."));
return FALSE;
}
}
#ifdef FREECIV_WEB
log_normal(_("Cannot load any ruleset. Freeciv-web ruleset is available from "
"https://github.com/freeciv/freeciv-web"));
#endif /* FREECIV_WEB */
/* Cannot load even default ruleset, we're in completely unusable state */
exit(EXIT_FAILURE);
RETURN_VALUE_AFTER_EXIT(FALSE);
}
/**********************************************************************//**
Destroy secfile. Handle NULL parameter gracefully.
**************************************************************************/
static void nullcheck_secfile_destroy(struct section_file *file)
{
if (file != NULL) {
secfile_destroy(file);
}
}
/**********************************************************************//**
Completely deinitialize ruleset system. Server is not in usable
state after this.
**************************************************************************/
void rulesets_deinit(void)
{
script_server_free();
requirement_vector_free(&reqs_list);
}
/**********************************************************************//**
Loads the rulesets from directory.
This may be called more than once and it will free any stale data.
**************************************************************************/
static bool load_rulesetdir(const char *rsdir, bool compat_mode,
rs_conversion_logger logger,
bool act, bool buffer_script, bool load_luadata)
{
struct section_file *techfile, *unitfile, *buildfile, *govfile, *terrfile;
struct section_file *stylefile, *cityfile, *nationfile, *effectfile, *gamefile;
struct section_file *actionfile;
bool ok = TRUE;
struct rscompat_info compat_info;
log_normal(_("Loading rulesets."));
rscompat_init_info(&compat_info);
compat_info.compat_mode = compat_mode;
compat_info.log_cb = logger;
game_ruleset_free();
/* Reset the list of available player colors. */
playercolor_free();
playercolor_init();
game_ruleset_init();
if (script_buffer != NULL) {
FC_FREE(script_buffer);
script_buffer = NULL;
}
if (parser_buffer != NULL) {
FC_FREE(parser_buffer);
parser_buffer = NULL;
}
server.playable_nations = 0;
gamefile = openload_ruleset_file("game", rsdir);
if (gamefile != NULL) {
/* Needed here to fill compat_info. RSFORMAT_3_2 specific arrangement. */
ok = load_game_names(gamefile, &compat_info);
} else {
ok = FALSE;
}
techfile = openload_ruleset_file("techs", rsdir);
if (compat_info.version >= RSFORMAT_3_2) {
actionfile = openload_ruleset_file("actions", rsdir);
} else {
actionfile = NULL;
}
buildfile = openload_ruleset_file("buildings", rsdir);
govfile = openload_ruleset_file("governments", rsdir);
unitfile = openload_ruleset_file("units", rsdir);
terrfile = openload_ruleset_file("terrain", rsdir);
stylefile = openload_ruleset_file("styles", rsdir);
cityfile = openload_ruleset_file("cities", rsdir);
nationfile = openload_ruleset_file("nations", rsdir);
effectfile = openload_ruleset_file("effects", rsdir);
if (load_luadata) {
game.server.luadata = openload_luadata_file(rsdir);
} else {
game.server.luadata = NULL;
}
if (techfile == NULL
|| buildfile == NULL
|| govfile == NULL
|| unitfile == NULL
|| terrfile == NULL
|| stylefile == NULL
|| cityfile == NULL
|| nationfile == NULL
|| effectfile == NULL
|| (actionfile == NULL && (!compat_info.compat_mode || compat_info.version >= RSFORMAT_3_2))
|| gamefile == NULL) {
ok = FALSE;
}
if (ok) {
/* Note: Keep load_game_names() first so that compat_info.version is
* correctly initialized. (Currently handled above already) */
ok = (actionfile == NULL || load_action_names(actionfile, &compat_info))
&& load_tech_names(techfile, &compat_info)
&& load_building_names(buildfile, &compat_info)
&& load_government_names(govfile, &compat_info)
&& load_unit_names(unitfile, &compat_info)
&& load_terrain_names(terrfile, &compat_info)
&& load_style_names(stylefile, &compat_info)
&& load_nation_names(nationfile, &compat_info);
}
if (ok) {
/* 3.1 rulesets have no actions.ruleset. */
if (compat_info.compat_mode && compat_info.version < RSFORMAT_3_2) {
ok = load_ruleset_actions(gamefile, gamefile, &compat_info);
} else {
ok = load_ruleset_actions(actionfile, gamefile, &compat_info);
}
}
if (ok) {
ok = rscompat_names(&compat_info);
}
if (ok) {
ok = load_ruleset_techs(techfile, &compat_info);
}
if (ok) {
ok = load_ruleset_styles(stylefile, &compat_info);
}
if (ok) {
ok = load_ruleset_cities(cityfile, &compat_info);
}
if (ok) {
ok = load_ruleset_governments(govfile, &compat_info);
}
if (ok) {
/* Terrain must precede nations and units */
ok = load_ruleset_terrain(terrfile, &compat_info);
}
if (ok) {
ok = load_ruleset_units(unitfile, &compat_info);
}
if (ok) {
ok = load_ruleset_buildings(buildfile, &compat_info);
}
if (ok) {
ok = load_ruleset_nations(nationfile, &compat_info);
}
if (ok) {
ok = load_ruleset_effects(effectfile, &compat_info);
}
if (ok) {
ok = load_ruleset_game(gamefile, act, &compat_info);
}
if (ok) {
/* Init nations we just loaded. */
update_nations_with_startpos();
/* Needed by role_unit_precalcs(). */
unit_type_action_cache_init();
/* Prepare caches we want to sanity check. */
role_unit_precalcs();
road_integrators_cache_init();
actions_rs_pre_san_gen();
ok = autoadjust_ruleset_data()
&& sanity_check_ruleset_data(&compat_info);
}
if (ok) {
/* Only load settings for a sane ruleset */
ok = settings_ruleset(gamefile, "settings", act,
compat_info.compat_mode
&& compat_info.version < RSFORMAT_3_2);
if (ok) {
secfile_check_unused(gamefile);
}
}
nullcheck_secfile_destroy(techfile);
nullcheck_secfile_destroy(stylefile);
nullcheck_secfile_destroy(cityfile);
nullcheck_secfile_destroy(govfile);
nullcheck_secfile_destroy(terrfile);
nullcheck_secfile_destroy(unitfile);
nullcheck_secfile_destroy(buildfile);
nullcheck_secfile_destroy(nationfile);
nullcheck_secfile_destroy(effectfile);
nullcheck_secfile_destroy(actionfile);
nullcheck_secfile_destroy(gamefile);
if (extra_sections) {
free(extra_sections);
extra_sections = NULL;
}
if (base_sections) {
free(base_sections);
base_sections = NULL;
}
if (road_sections) {
free(road_sections);
road_sections = NULL;
}
if (resource_sections) {
free(resource_sections);
resource_sections = NULL;
}
if (terrain_sections) {
free(terrain_sections);
terrain_sections = NULL;
}
if (ok) {
rscompat_postprocess(&compat_info);
}
if (ok) {
char **buffer = buffer_script ? &script_buffer : NULL;
script_server_free();
script_server_init();
ok = (openload_script_file("script", rsdir, buffer, FALSE) == TRI_YES);
}
if (ok) {
enum fc_tristate pret;
char **buffer = buffer_script ? &parser_buffer : NULL;
pret = openload_script_file("parser", rsdir, buffer, compat_info.compat_mode);
if (pret == TRI_MAYBE && buffer_script) {
parser_buffer = fc_strdup(
"-- This file is for lua-functionality for parsing luadata.txt\n-- of this ruleset.");
}
ok = (pret != TRI_NO);
}
if (ok && !buffer_script) {
ok = (openload_script_file("default", rsdir, NULL, FALSE) == TRI_YES);
}
if (ok && act) {
/* Populate remaining caches. */
techs_precalc_data();
improvement_feature_cache_init();
unit_class_iterate(pclass) {
set_unit_class_caches(pclass);
} unit_class_iterate_end;
unit_type_iterate(ptype) {
ptype->unknown_move_cost = utype_unknown_move_cost(ptype);
set_unit_type_caches(ptype);
} unit_type_iterate_end;
city_production_caravan_shields_init();
/* Build advisors unit class cache corresponding to loaded rulesets */
adv_units_ruleset_init();
CALL_FUNC_EACH_AI(units_ruleset_init);
/* We may need to adjust the number of AI players
* if the number of available nations changed. */
(void) aifill(game.info.aifill);
}
return ok;
}
/**********************************************************************//**
Reload the game settings saved in the ruleset file.
**************************************************************************/
bool reload_rulesets_settings(void)
{
struct section_file *file;
bool ok = TRUE;
file = openload_ruleset_file("game", game.server.rulesetdir);
if (file == NULL) {
ruleset_error(NULL, LOG_ERROR,
"Could not load game.ruleset:\n%s",
secfile_error());
ok = FALSE;
}
if (ok) {
settings_ruleset(file, "settings", TRUE, FALSE);
secfile_destroy(file);
}
return ok;
}
/**********************************************************************//**
Send all ruleset information to the specified connections.
**************************************************************************/
void send_rulesets(struct conn_list *dest)
{
conn_list_compression_freeze(dest);
/* ruleset_control also indicates to client that ruleset sending starts. */
send_ruleset_control(dest);
/* Currently containing control-kind of data of nation sets and groups,
* this too must be sent before any requirement vector may depend on
* that data. */
send_ruleset_nations(dest);
send_ruleset_game(dest);
send_ruleset_disasters(dest);
send_ruleset_achievements(dest);
send_ruleset_counters(dest);
send_ruleset_trade_routes(dest);
send_ruleset_team_names(dest);
send_ruleset_actions(dest);
send_ruleset_action_enablers(dest);
send_ruleset_action_auto_performers(dest);
send_ruleset_tech_classes(dest);
send_ruleset_techs(dest);
send_ruleset_governments(dest);
send_ruleset_unit_classes(dest);
send_ruleset_units(dest);
send_ruleset_specialists(dest);
send_ruleset_extras(dest);
send_ruleset_bases(dest);
send_ruleset_roads(dest);
send_ruleset_resources(dest);
send_ruleset_terrain(dest);
send_ruleset_goods(dest);
send_ruleset_buildings(dest);
send_ruleset_styles(dest);
send_ruleset_clauses(dest);
send_ruleset_cities(dest);
send_ruleset_multipliers(dest);
send_ruleset_musics(dest);
send_ruleset_cache(dest);
/* Indicate client that all rulesets have now been sent. */
lsend_packet_rulesets_ready(dest);
/* changed game settings will be send in
* connecthand.c:establish_new_connection() */
conn_list_compression_thaw(dest);
}
|