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
|
/***********************************************************************
Freeciv - Copyright (C) 1996-2004 - The Freeciv Project
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
/* utility */
#include "astring.h"
#include "fcintl.h"
#include "game.h"
#include "ioz.h"
#include "log.h"
#include "registry.h"
#include "shared.h"
#include "string_vector.h"
/* common */
#include "map.h"
/* server */
#include "aiiface.h"
#include "gamehand.h"
#include "maphand.h"
#include "meta.h"
#include "nation.h"
#include "notify.h"
#include "plrhand.h"
#include "report.h"
#include "rscompat.h"
#include "rssanity.h"
#include "setcompat.h"
#include "srv_main.h"
#include "stdinhand.h"
#include "settings.h"
/* The following classes determine what can be changed when.
* Actually, some of them have the same "changeability", but
* different types are separated here in case they have
* other uses.
* Also, SSET_GAME_INIT/SSET_RULES separate the two sections
* of server settings sent to the client.
* See the settings[] array and setting_is_changeable() for what
* these correspond to and explanations.
*/
enum sset_class {
SSET_MAP_SIZE,
SSET_MAP_GEN,
SSET_MAP_ADD,
SSET_PLAYERS,
SSET_PLAYERS_CHANGEABLE,
SSET_GAME_INIT,
SSET_RULES,
SSET_RULES_SCENARIO,
SSET_RULES_FLEXIBLE,
SSET_META
};
typedef bool (*bool_validate_func_t) (bool value, struct connection *pconn,
char *reject_msg,
size_t reject_msg_len);
typedef bool (*int_validate_func_t) (int value, struct connection *pconn,
char *reject_msg,
size_t reject_msg_len);
typedef bool (*string_validate_func_t) (const char * value,
struct connection *pconn,
char *reject_msg,
size_t reject_msg_len);
typedef bool (*enum_validate_func_t) (int value, struct connection *pconn,
char *reject_msg,
size_t reject_msg_len);
typedef bool (*bitwise_validate_func_t) (unsigned value,
struct connection *pconn,
char *reject_msg,
size_t reject_msg_len);
typedef void (*action_callback_func_t) (const struct setting *pset);
typedef const char *(*help_callback_func_t) (const struct setting *pset);
typedef const struct sset_val_name * (*val_name_func_t) (int value);
struct setting {
const char *name;
enum sset_class sclass;
/* What access level viewing and setting the setting requires. */
enum cmdlevel access_level_read;
enum cmdlevel access_level_write;
/*
* Should be less than 42 chars (?), or shorter if the values may
* have more than about 4 digits. Don't put "." on the end.
*/
const char *short_help;
/*
* May be empty string, if short_help is sufficient. Need not
* include embedded newlines (but may, for formatting); lines will
* be wrapped (and indented) automatically. Should have punctuation
* etc, and should end with a "."
*/
const char *extra_help;
/* help function */
const help_callback_func_t help_func;
enum sset_type stype;
enum sset_category scategory;
enum sset_level slevel;
/*
* About the *_validate functions: If the function is non-NULL, it
* is called with the new value, and returns whether the change is
* legal. The char * is an error message in the case of reject.
*/
union {
/*** bool part ***/
struct {
bool *const pvalue;
const bool default_value;
const bool_validate_func_t validate;
const val_name_func_t name;
bool game_value;
} boolean;
/*** int part ***/
struct {
int *const pvalue;
const int default_value;
const int min_value;
const int max_value;
const int_validate_func_t validate;
int game_value;
} integer;
/*** string part ***/
struct {
char *const value;
const char *const default_value;
const size_t value_size;
const string_validate_func_t validate;
char *game_value;
} string;
/*** enumerator part ***/
struct {
void *const pvalue;
const int store_size;
const int default_value;
const enum_validate_func_t validate;
const val_name_func_t name;
int game_value;
} enumerator;
/*** bitwise part ***/
struct {
unsigned *const pvalue;
const unsigned default_value;
const bitwise_validate_func_t validate;
const val_name_func_t name;
unsigned game_value;
} bitwise;
};
/* action function */
const action_callback_func_t action;
/* Lock for game settings */
enum setting_lock_level lock;
/* Remember if there's also ruleset lock. */
bool rslock;
bool ruleset_settable;
/* It's not "default", even if value is the same as default */
enum setting_default_level setdef;
enum setting_default_level game_setdef;
};
static struct {
bool init;
struct setting_list *level[OLEVELS_NUM];
} setting_sorted = { .init = FALSE };
static void setting_ruleset_setdef(struct setting *pset);
static bool setting_ruleset_one(struct section_file *file,
const char *name, const char *path,
bool compat);
static void setting_game_set(struct setting *pset, bool init);
static void setting_game_free(struct setting *pset);
static void setting_game_restore(struct setting *pset);
static void settings_list_init(void);
static void settings_list_free(void);
int settings_list_cmp(const struct setting *const *pset1,
const struct setting *const *pset2);
#define settings_snprintf(_buf, _buf_len, format, ...) \
if (_buf != NULL) { \
fc_snprintf(_buf, _buf_len, format, ## __VA_ARGS__); \
}
static bool set_enum_value(struct setting *pset, int val);
/****************************************************************************
Enumerator name accessors.
Important note about compatibility:
1) you cannot modify the support name of an existent value. However, in a
development, you can modify it if it wasn't included in any stable
branch before.
2) Take care of modifying the pretty name of an existent value: make sure
to modify the help texts which are using it.
****************************************************************************/
#define NAME_CASE(_val, _support, _pretty) \
case _val: \
{ \
static const struct sset_val_name name = { _support, _pretty }; \
return &name; \
}
/************************************************************************//**
Caravan bonus style setting names accessor.
****************************************************************************/
static const struct sset_val_name *caravanbonusstyle_name(int caravanbonus)
{
switch (caravanbonus) {
/* TRANS: Description of caravan bonus style setting value. */
NAME_CASE(CBS_CLASSIC, "CLASSIC", N_("Classic Freeciv"));
NAME_CASE(CBS_LOGARITHMIC, "LOGARITHMIC", N_("Log^2 N style"));
}
return NULL;
}
/************************************************************************//**
Map size definition setting names accessor. This setting has an
hard-coded dependence in "server/meta.c".
****************************************************************************/
static const struct sset_val_name *mapsize_name(int mapsize)
{
switch (mapsize) {
NAME_CASE(MAPSIZE_FULLSIZE, "FULLSIZE", N_("Number of tiles"));
NAME_CASE(MAPSIZE_PLAYER, "PLAYER", N_("Tiles per player"));
NAME_CASE(MAPSIZE_XYSIZE, "XYSIZE", N_("Width and height"));
}
return NULL;
}
/************************************************************************//**
Topology setting names accessor.
****************************************************************************/
static const struct sset_val_name *topology_name(int topology_bit)
{
switch (1 << topology_bit) {
NAME_CASE(TF_ISO, "ISO", N_("Isometric"));
NAME_CASE(TF_HEX, "HEX", N_("Hexagonal"));
}
return NULL;
}
/************************************************************************//**
Map wrap setting names accessor.
****************************************************************************/
static const struct sset_val_name *wrap_name(int wrap_bit)
{
switch (1 << wrap_bit) {
NAME_CASE(WRAP_X, "WRAPX", N_("Wrap East-West"));
NAME_CASE(WRAP_Y, "WRAPY", N_("Wrap North-South"));
}
return NULL;
}
/************************************************************************//**
Trade revenue style setting names accessor.
****************************************************************************/
static const struct sset_val_name *traderevenuestyle_name(int revenue_style)
{
switch (revenue_style) {
/* TRANS: Description of trade revenue style setting value. */
NAME_CASE(TRS_CLASSIC, "CLASSIC", N_("Classic Freeciv"));
NAME_CASE(TRS_SIMPLE, "SIMPLE", N_("Proportional to tile trade"));
}
return NULL;
}
/************************************************************************//**
Generator setting names accessor.
****************************************************************************/
static const struct sset_val_name *generator_name(int generator)
{
switch (generator) {
NAME_CASE(MAPGEN_SCENARIO, "SCENARIO", N_("Scenario map"));
NAME_CASE(MAPGEN_RANDOM, "RANDOM", N_("Fully random height"));
NAME_CASE(MAPGEN_FRACTAL, "FRACTAL", N_("Pseudo-fractal height"));
NAME_CASE(MAPGEN_ISLAND, "ISLAND", N_("Island-based"));
NAME_CASE(MAPGEN_FAIR, "FAIR", N_("Fair islands"));
NAME_CASE(MAPGEN_FRACTURE, "FRACTURE", N_("Fracture map"));
}
return NULL;
}
/************************************************************************//**
Start position setting names accessor.
****************************************************************************/
static const struct sset_val_name *startpos_name(int startpos)
{
switch (startpos) {
NAME_CASE(MAPSTARTPOS_DEFAULT, "DEFAULT",
N_("Generator's choice"));
NAME_CASE(MAPSTARTPOS_SINGLE, "SINGLE",
N_("One player per continent"));
NAME_CASE(MAPSTARTPOS_2or3, "2or3",
N_("Two or three players per continent"));
NAME_CASE(MAPSTARTPOS_ALL, "ALL",
N_("All players on a single continent"));
NAME_CASE(MAPSTARTPOS_VARIABLE, "VARIABLE",
N_("Depending on size of continents"));
}
return NULL;
}
/************************************************************************//**
Team placement setting names accessor.
****************************************************************************/
static const struct sset_val_name *teamplacement_name(int team_placement)
{
switch (team_placement) {
NAME_CASE(TEAM_PLACEMENT_DISABLED, "DISABLED",
N_("Disabled"));
NAME_CASE(TEAM_PLACEMENT_CLOSEST, "CLOSEST",
N_("As close as possible"));
NAME_CASE(TEAM_PLACEMENT_CONTINENT, "CONTINENT",
N_("On the same continent"));
NAME_CASE(TEAM_PLACEMENT_HORIZONTAL, "HORIZONTAL",
N_("Horizontal placement"));
NAME_CASE(TEAM_PLACEMENT_VERTICAL, "VERTICAL",
N_("Vertical placement"));
}
return NULL;
}
/************************************************************************//**
Persistentready setting names accessor.
****************************************************************************/
static const struct sset_val_name *persistentready_name(int persistent_ready)
{
switch (persistent_ready) {
NAME_CASE(PERSISTENTR_DISABLED, "DISABLED",
N_("Disabled"));
NAME_CASE(PERSISTENTR_CONNECTED, "CONNECTED",
N_("As long as connected"));
}
return NULL;
}
/************************************************************************//**
Victory conditions setting names accessor.
****************************************************************************/
static const struct sset_val_name *victory_conditions_name(int condition_bit)
{
switch (condition_bit) {
NAME_CASE(VC_SPACERACE, "SPACERACE", N_("Spacerace"));
NAME_CASE(VC_ALLIED, "ALLIED", N_("Allied victory"));
NAME_CASE(VC_CULTURE, "CULTURE", N_("Culture victory"));
};
return NULL;
}
/************************************************************************//**
Autosaves setting names accessor.
****************************************************************************/
static const struct sset_val_name *autosaves_name(int autosaves_bit)
{
switch (autosaves_bit) {
NAME_CASE(AS_TURN, "TURN", N_("New turn"));
NAME_CASE(AS_GAME_OVER, "GAMEOVER", N_("Game over"));
NAME_CASE(AS_QUITIDLE, "QUITIDLE", N_("No player connections"));
NAME_CASE(AS_INTERRUPT, "INTERRUPT", N_("Server interrupted"));
NAME_CASE(AS_TIMER, "TIMER", N_("Timer"));
};
return NULL;
}
/************************************************************************//**
Borders setting names accessor.
****************************************************************************/
static const struct sset_val_name *borders_name(int borders)
{
switch (borders) {
NAME_CASE(BORDERS_DISABLED, "DISABLED", N_("Disabled"));
NAME_CASE(BORDERS_ENABLED, "ENABLED", N_("Enabled"));
NAME_CASE(BORDERS_SEE_INSIDE, "SEE_INSIDE",
N_("See everything inside borders"));
NAME_CASE(BORDERS_EXPAND, "EXPAND",
N_("Borders expand to unknown, revealing tiles"));
}
return NULL;
}
/************************************************************************//**
Trait distribution setting names accessor.
****************************************************************************/
static const struct sset_val_name *trait_dist_name(int trait_dist)
{
switch (trait_dist) {
NAME_CASE(TDM_FIXED, "FIXED", N_("Fixed"));
NAME_CASE(TDM_EVEN, "EVEN", N_("Even"));
}
return NULL;
}
/************************************************************************//**
Player colors configuration setting names accessor.
****************************************************************************/
static const struct sset_val_name *plrcol_name(int plrcol)
{
switch (plrcol) {
NAME_CASE(PLRCOL_PLR_ORDER, "PLR_ORDER", N_("Per-player, in order"));
NAME_CASE(PLRCOL_PLR_RANDOM, "PLR_RANDOM", N_("Per-player, random"));
NAME_CASE(PLRCOL_PLR_SET, "PLR_SET", N_("Set manually"));
NAME_CASE(PLRCOL_TEAM_ORDER, "TEAM_ORDER", N_("Per-team, in order"));
NAME_CASE(PLRCOL_NATION_ORDER, "NATION_ORDER", N_("Per-nation, in order"));
}
return NULL;
}
/************************************************************************//**
Happyborders setting names accessor.
****************************************************************************/
static const struct sset_val_name *happyborders_name(int happyborders)
{
switch (happyborders) {
NAME_CASE(HB_DISABLED, "DISABLED", N_("Borders are not helping"));
NAME_CASE(HB_NATIONAL, "NATIONAL", N_("Happy within own borders"));
NAME_CASE(HB_ALLIANCE, "ALLIED", N_("Happy within allied borders"));
}
return NULL;
}
/************************************************************************//**
Diplomacy setting names accessor.
****************************************************************************/
static const struct sset_val_name *diplomacy_name(int diplomacy)
{
switch (diplomacy) {
NAME_CASE(DIPLO_FOR_ALL, "ALL", N_("Enabled for everyone"));
NAME_CASE(DIPLO_FOR_HUMANS, "HUMAN",
N_("Only allowed between human players"));
NAME_CASE(DIPLO_FOR_AIS, "AI", N_("Only allowed between AI players"));
NAME_CASE(DIPLO_NO_AIS, "NOAI", N_("Only allowed when human involved"));
NAME_CASE(DIPLO_NO_MIXED, "NOMIXED", N_("Only allowed between two humans, or two AI players"));
NAME_CASE(DIPLO_FOR_TEAMS, "TEAM", N_("Restricted to teams"));
NAME_CASE(DIPLO_DISABLED, "DISABLED", N_("Disabled for everyone"));
}
return NULL;
}
/************************************************************************//**
City names setting names accessor.
****************************************************************************/
static const struct sset_val_name *citynames_name(int citynames)
{
switch (citynames) {
NAME_CASE(CNM_NO_RESTRICTIONS, "NO_RESTRICTIONS", N_("No restrictions"));
NAME_CASE(CNM_PLAYER_UNIQUE, "PLAYER_UNIQUE", N_("Unique to a player"));
NAME_CASE(CNM_GLOBAL_UNIQUE, "GLOBAL_UNIQUE", N_("Globally unique"));
NAME_CASE(CNM_NO_STEALING, "NO_STEALING", N_("No city name stealing"));
}
return NULL;
}
/************************************************************************//**
Barbarian setting names accessor.
****************************************************************************/
static const struct sset_val_name *barbarians_name(int barbarians)
{
switch (barbarians) {
NAME_CASE(BARBS_DISABLED, "DISABLED", N_("No barbarians"));
NAME_CASE(BARBS_HUTS_ONLY, "HUTS_ONLY", N_("Only in huts"));
NAME_CASE(BARBS_NORMAL, "NORMAL", N_("Normal rate of appearance"));
NAME_CASE(BARBS_FREQUENT, "FREQUENT", N_("Frequent barbarian uprising"));
NAME_CASE(BARBS_HORDES, "HORDES", N_("Raging hordes"));
}
return NULL;
}
/************************************************************************//**
Revolution length type setting names accessor.
****************************************************************************/
static const struct sset_val_name *revolentype_name(int revolentype)
{
switch (revolentype) {
NAME_CASE(REVOLEN_FIXED, "FIXED", N_("Fixed to 'revolen' turns"));
NAME_CASE(REVOLEN_RANDOM, "RANDOM", N_("Randomly 1-'revolen' turns"));
NAME_CASE(REVOLEN_QUICKENING, "QUICKENING", N_("First time 'revolen', then always quicker"));
NAME_CASE(REVOLEN_RANDQUICK, "RANDQUICK", N_("Random, max always quicker"));
}
return NULL;
}
/************************************************************************//**
Revealmap setting names accessor.
****************************************************************************/
static const struct sset_val_name *revealmap_name(int bit)
{
switch (1 << bit) {
NAME_CASE(REVEAL_MAP_START, "START", N_("Reveal map at game start"));
NAME_CASE(REVEAL_MAP_DEAD, "DEAD", N_("Unfog map for dead players"));
}
return NULL;
}
/************************************************************************//**
Airlifting style setting names accessor.
****************************************************************************/
static const struct sset_val_name *airliftingstyle_name(int bit)
{
switch (1 << bit) {
NAME_CASE(AIRLIFTING_ALLIED_SRC, "FROM_ALLIES",
N_("Allows units to be airlifted from allied cities"));
NAME_CASE(AIRLIFTING_ALLIED_DEST, "TO_ALLIES",
N_("Allows units to be airlifted to allied cities"));
NAME_CASE(AIRLIFTING_UNLIMITED_SRC, "SRC_UNLIMITED",
N_("Unlimited units from source city"));
NAME_CASE(AIRLIFTING_UNLIMITED_DEST, "DEST_UNLIMITED",
N_("Unlimited units to destination city"));
}
return NULL;
}
/************************************************************************//**
Phase mode names accessor.
****************************************************************************/
static const struct sset_val_name *phasemode_name(int phasemode)
{
switch (phasemode) {
NAME_CASE(PMT_CONCURRENT, "ALL", N_("All players move concurrently"));
NAME_CASE(PMT_PLAYERS_ALTERNATE,
"PLAYER", N_("All players alternate movement"));
NAME_CASE(PMT_TEAMS_ALTERNATE, "TEAM", N_("Team alternate movement"));
}
return NULL;
}
/************************************************************************//**
Scorelog level names accessor.
****************************************************************************/
static const struct sset_val_name *
scoreloglevel_name(enum scorelog_level sl_level)
{
switch (sl_level) {
NAME_CASE(SL_ALL, "ALL", N_("All players"));
NAME_CASE(SL_HUMANS, "HUMANS", N_("Human players only"));
}
return NULL;
}
/************************************************************************//**
Savegame compress type names accessor.
****************************************************************************/
static const struct sset_val_name *
compresstype_name(enum fz_method compresstype)
{
switch (compresstype) {
NAME_CASE(FZ_PLAIN, "PLAIN", N_("No compression"));
#ifdef FREECIV_HAVE_LIBZ
NAME_CASE(FZ_ZLIB, "LIBZ", N_("Using zlib (gzip format)"));
#endif
#ifdef FREECIV_HAVE_LIBBZ2
case FZ_BZIP2:
break;
#endif
#ifdef FREECIV_HAVE_LIBLZMA
NAME_CASE(FZ_XZ, "XZ", N_("Using xz"));
#endif
#ifdef FREECIV_HAVE_LIBZSTD
NAME_CASE(FZ_ZSTD, "ZSTD", N_("Using zstd"));
#endif
}
return NULL;
}
/************************************************************************//**
AI level names accessor.
****************************************************************************/
static const struct sset_val_name *
ailevel_name(enum ai_level lvl)
{
const char *lvlname;
if (lvl >= AI_LEVEL_AWAY) {
return NULL;
}
lvlname = ai_level_name(lvl);
if (lvlname != NULL) {
static struct sset_val_name name[AI_LEVEL_COUNT];
name[lvl].support = lvlname;
name[lvl].pretty = ai_level_translated_name(lvl);
return &name[lvl];
}
return NULL;
}
/************************************************************************//**
Names accessor for boolean settings (disable/enable).
****************************************************************************/
static const struct sset_val_name *bool_name(int enable)
{
switch (enable) {
NAME_CASE(FALSE, "DISABLED", N_("disabled"));
NAME_CASE(TRUE, "ENABLED", N_("enabled"));
}
return NULL;
}
#undef NAME_CASE
/****************************************************************************
Help callback functions.
****************************************************************************/
/************************************************************************//**
Help about phasemode setting
****************************************************************************/
static const char *phasemode_help(const struct setting *pset)
{
static char pmhelp[512];
/* Translated here */
fc_snprintf(pmhelp, sizeof(pmhelp),
_("This setting controls whether players may make "
"moves at the same time during a turn. Change "
"in setting takes effect next turn. Currently, at least "
"to the end of this turn, mode is \"%s\"."),
phasemode_name(game.info.phase_mode)->pretty);
return pmhelp;
}
/************************************************************************//**
Help about huts setting
****************************************************************************/
static const char *huts_help(const struct setting *pset)
{
if (wld.map.server.huts_absolute >= 0) {
static char hutshelp[512];
/* Translated here */
fc_snprintf(hutshelp, sizeof(hutshelp),
_("%s\n"
"Currently this setting is being overridden by an "
"old scenario or savegame, which has set the absolute "
"number of huts to %d. Explicitly set this setting "
"again to make it take effect instead."),
_(pset->extra_help), wld.map.server.huts_absolute);
return hutshelp;
}
return pset->extra_help;
}
/****************************************************************************
Action callback functions.
****************************************************************************/
/************************************************************************//**
(De)initialize the score log.
****************************************************************************/
static void scorelog_action(const struct setting *pset)
{
if (*pset->boolean.pvalue) {
log_civ_score_init();
} else {
log_civ_score_free();
}
}
/************************************************************************//**
Create the selected number of AI's.
****************************************************************************/
static void aifill_action(const struct setting *pset)
{
const char *msg = aifill(*pset->integer.pvalue);
if (msg) {
log_normal(_("Warning: aifill not met: %s."), msg);
notify_conn(NULL, NULL, E_SETTING, ftc_server,
_("Warning: aifill not met: %s."), msg);
}
}
/************************************************************************//**
Restrict to the selected nation set.
****************************************************************************/
static void nationset_action(const struct setting *pset)
{
/* If any player's existing selection is invalid, abort it */
players_iterate(pplayer) {
if (pplayer->nation != NULL) {
if (!nation_is_in_current_set(pplayer->nation)) {
(void) player_set_nation(pplayer, NO_NATION_SELECTED);
send_player_info_c(pplayer, game.est_connections);
}
}
} players_iterate_end;
count_playable_nations();
(void) aifill(game.info.aifill);
/* There might now be too many players for the available nations.
* Rather than getting rid of some players arbitrarily, we let the
* situation persist for all already-connected players; the server
* will simply refuse to start until someone reduces the number of
* players. This policy also avoids annoyance if nationset is
* accidentally and transiently set to an unintended value.
* (However, new connections will start out detached.) */
if (normal_player_count() > server.playable_nations) {
notify_conn(NULL, NULL, E_SETTING, ftc_server, "%s",
_("Warning: not enough nations in this nation set "
"for all current players."));
}
send_nation_availability(game.est_connections, TRUE);
}
/************************************************************************//**
Clear any user-set player colors in modes other than PLRCOL_PLR_SET.
****************************************************************************/
static void plrcol_action(const struct setting *pset)
{
if (!game_was_started()) {
if (read_enum_value(pset) != PLRCOL_PLR_SET) {
players_iterate(pplayer) {
server_player_set_color(pplayer, NULL);
} players_iterate_end;
}
/* Update clients with new color scheme. */
send_player_info_c(NULL, NULL);
}
}
/************************************************************************//**
Toggle player AI status.
****************************************************************************/
static void autotoggle_action(const struct setting *pset)
{
if (*pset->boolean.pvalue) {
players_iterate(pplayer) {
if (is_human(pplayer) && !pplayer->is_connected) {
toggle_ai_player_direct(NULL, pplayer);
send_player_info_c(pplayer, game.est_connections);
}
} players_iterate_end;
}
}
/************************************************************************//**
Enact a change in the 'timeout' server setting immediately, if the game
is afoot.
****************************************************************************/
static void timeout_action(const struct setting *pset)
{
if (S_S_RUNNING == server_state()) {
int timeout = *pset->integer.pvalue;
if (game.info.turn != 1 || game.info.first_timeout == -1) {
/* This may cause the current turn to end immediately. */
game.tinfo.seconds_to_phasedone = timeout;
}
send_game_info(NULL);
}
}
/************************************************************************//**
Enact a change in the 'first_timeout' server setting immediately, if the game
is afoot.
****************************************************************************/
static void first_timeout_action(const struct setting *pset)
{
if (S_S_RUNNING == server_state()) {
int timeout = *pset->integer.pvalue;
if (game.info.turn == 1) {
/* This may cause the current turn to end immediately. */
if (timeout != -1) {
game.tinfo.seconds_to_phasedone = timeout;
} else {
game.tinfo.seconds_to_phasedone = game.info.timeout;
}
}
send_game_info(NULL);
}
}
/************************************************************************//**
Clean out absolute number of huts when relative setting set.
****************************************************************************/
static void huts_action(const struct setting *pset)
{
wld.map.server.huts_absolute = -1;
}
/************************************************************************//**
Topology setting changed.
****************************************************************************/
static void topology_action(const struct setting *pset)
{
struct packet_set_topology packet;
packet.topology_id = *pset->integer.pvalue;
packet.wrap_id = wld.map.wrap_id;
conn_list_iterate(game.est_connections, pconn) {
send_packet_set_topology(pconn, &packet);
} conn_list_iterate_end;
}
/************************************************************************//**
Map wrap setting changed.
****************************************************************************/
static void wrap_action(const struct setting *pset)
{
struct packet_set_topology packet;
packet.topology_id = wld.map.topology_id;
packet.wrap_id = *pset->integer.pvalue;
conn_list_iterate(game.est_connections, pconn) {
send_packet_set_topology(pconn, &packet);
} conn_list_iterate_end;
}
/************************************************************************//**
Update metaserver message string from changed user meta server message
string.
****************************************************************************/
static void metamessage_action(const struct setting *pset)
{
/* Set the metaserver message based on the new meta server user message.
* An empty user metaserver message results in an automatic meta message.
* A non empty user meta message results in the user meta message. */
set_user_meta_message_string(pset->string.value);
if (is_metaserver_open()) {
/* Update the meta server. */
send_server_info_to_metaserver(META_INFO);
}
}
/************************************************************************//**
Change the default AI type.
****************************************************************************/
static void aitype_action(const struct setting *pset)
{
if (!set_default_ai_type_name(pset->string.value)) {
log_warn(_("Failed to update default AI type."));
}
}
/****************************************************************************
Validation callback functions.
****************************************************************************/
/************************************************************************//**
Verify the selected savename definition.
****************************************************************************/
static bool savename_validate(const char *value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
char buf[MAX_LEN_PATH];
generate_save_name(value, buf, sizeof(buf), NULL);
if (!is_safe_filename(buf)) {
settings_snprintf(reject_msg, reject_msg_len,
_("Invalid save name definition: '%s' "
"(resolves to '%s')."), value, buf);
return FALSE;
}
return TRUE;
}
/************************************************************************//**
Verify the value of the generator option (notably the MAPGEN_SCENARIO
case).
****************************************************************************/
static bool generator_validate(int value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
if (map_is_empty()) {
if (MAPGEN_SCENARIO == value
&& (NULL != caller || !game.scenario.is_scenario)) {
settings_snprintf(reject_msg, reject_msg_len,
_("You cannot disable the map generator."));
return FALSE;
}
return TRUE;
} else {
if (MAPGEN_SCENARIO != value) {
settings_snprintf(reject_msg, reject_msg_len,
_("You cannot require a map generator "
"when a map is loaded."));
return FALSE;
}
}
return TRUE;
}
/************************************************************************//**
Verify the name for the score log file.
****************************************************************************/
#ifndef FREECIV_WEB
static bool scorefile_validate(const char *value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
if (!is_safe_filename(value)) {
settings_snprintf(reject_msg, reject_msg_len,
_("Invalid score name definition: '%s'."), value);
return FALSE;
}
return TRUE;
}
#endif /* !FREECIV_WEB */
/************************************************************************//**
Verify that a given demography string is valid. See
game.demography.
****************************************************************************/
static bool demography_callback(const char *value,
struct connection *caller,
char *reject_msg,
size_t reject_msg_len)
{
int error;
if (is_valid_demography(value, &error)) {
return TRUE;
} else {
settings_snprintf(reject_msg, reject_msg_len,
_("Demography string validation failed at character: "
"'%c'. Try \"/help demography\"."), value[error]);
return FALSE;
}
}
/************************************************************************//**
Autosaves setting callback
****************************************************************************/
static bool autosaves_callback(unsigned value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
if (S_S_RUNNING == server_state()) {
if ((value & (1 << AS_TIMER))
&& !(game.server.autosaves & (1 << AS_TIMER))) {
game.server.save_timer = timer_renew(game.server.save_timer,
TIMER_USER, TIMER_ACTIVE,
game.server.save_timer != NULL
? NULL : "save interval");
timer_start(game.server.save_timer);
} else if (!(value & (1 << AS_TIMER))
&& (game.server.autosaves & (1 << AS_TIMER))) {
timer_stop(game.server.save_timer);
timer_destroy(game.server.save_timer);
game.server.save_timer = NULL;
}
}
return TRUE;
}
/************************************************************************//**
Verify that a given allowtake string is valid.
See game.allow_take.
****************************************************************************/
static bool allowtake_callback(const char *value,
struct connection *caller,
char *reject_msg,
size_t reject_msg_len)
{
int len = strlen(value), i;
bool havecharacter_state = FALSE;
/* We check each character individually to see if it's valid. This
* does not check for duplicate entries.
*
* We also track the state of the machine. havecharacter_state is
* true if the preceding character was a primary label, e.g.
* NHhAadb. It is false if the preceding character was a modifier
* or if this is the first character. */
for (i = 0; i < len; i++) {
/* Check to see if the character is a primary label. */
if (strchr("HhAadbOo", value[i])) {
havecharacter_state = TRUE;
continue;
}
/* If we've already passed a primary label, check to see if the
* character is a modifier. */
if (havecharacter_state && strchr("1234", value[i])) {
havecharacter_state = FALSE;
continue;
}
/* Looks like the character was invalid. */
settings_snprintf(reject_msg, reject_msg_len,
_("Allowed take string validation failed at "
"character: '%c'. Try \"/help allowtake\"."),
value[i]);
return FALSE;
}
/* All characters were valid. */
return TRUE;
}
/************************************************************************//**
Verify that a given startunits string is valid. See
game.server.start_units.
****************************************************************************/
static bool startunits_callback(const char *value,
struct connection *caller,
char *reject_msg,
size_t reject_msg_len)
{
int len = strlen(value), i;
Unit_Class_id first_role;
bool firstnative = FALSE;
if (len == 0) {
return TRUE;
}
/* We check each character individually to see if it's valid. */
for (i = 0; i < len; i++) {
if (strchr("cwxksfdDaA", value[i])) {
continue;
}
/* Looks like the character was invalid. */
settings_snprintf(reject_msg, reject_msg_len,
_("Starting units string validation failed at "
"character '%c'. Try \"/help startunits\"."),
value[i]);
return FALSE;
}
/* Check the first character to make sure it can use a startpos. */
first_role = uclass_index(utype_class(get_role_unit(
crole_to_role_id(value[0]), 0)));
terrain_type_iterate(pterrain) {
if (terrain_has_flag(pterrain, TER_STARTER)
&& BV_ISSET(pterrain->native_to, first_role)) {
firstnative = TRUE;
break;
}
} terrain_type_iterate_end;
if (!firstnative) {
/* Loading would cause an infinite loop hunting for a valid startpos. */
settings_snprintf(reject_msg, reject_msg_len,
_("The first starting unit must be native to at "
"least one \"Starter\" terrain. "
"Try \"/help startunits\"."));
return FALSE;
}
/* Everything seems fine. */
return TRUE;
}
/************************************************************************//**
Verify that a given endturn is valid.
****************************************************************************/
static bool endturn_callback(int value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
if (value < game.info.turn) {
/* Tried to set endturn earlier than current turn */
settings_snprintf(reject_msg, reject_msg_len,
_("Cannot set endturn earlier than current turn."));
return FALSE;
}
return TRUE;
}
/************************************************************************//**
Verify that a given maxplayers is valid.
****************************************************************************/
static bool maxplayers_callback(int value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
if (value < player_count()) {
settings_snprintf(reject_msg, reject_msg_len,
_("Number of players (%d) is higher than requested "
"value (%d). Keeping old value."), player_count(),
value);
return FALSE;
}
/* If any start positions are defined by a scenario, we can only
* accommodate as many players as we have start positions. */
if (server_state() < S_S_RUNNING
&& 0 < map_startpos_count() && value > map_startpos_count()) {
settings_snprintf(reject_msg, reject_msg_len,
_("Requested value (%d) is greater than number of "
"available start positions (%d). Keeping old value."),
value, map_startpos_count());
return FALSE;
}
return TRUE;
}
/************************************************************************//**
Validate the 'nationset' server setting.
****************************************************************************/
static bool nationset_callback(const char *value,
struct connection *caller,
char *reject_msg,
size_t reject_msg_len)
{
if (strlen(value) == 0) {
return TRUE;
} else if (nation_set_by_rule_name(value)) {
return TRUE;
} else {
settings_snprintf(reject_msg, reject_msg_len,
/* TRANS: do not translate 'list nationsets' */
_("Unknown nation set \"%s\". See '%slist nationsets' "
"for possible values."), value, caller ? "/" : "");
return FALSE;
}
}
/************************************************************************//**
Validate the 'timeout' server setting.
****************************************************************************/
static bool timeout_callback(int value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
/* Disallow low timeout values for non-hack connections. */
if (caller && caller->access_level < ALLOW_HACK
&& value < 30 && value != 0) {
settings_snprintf(reject_msg, reject_msg_len,
_("You are not allowed to set timeout values less "
"than 30 seconds."));
return FALSE;
}
if (value == -1 && game.server.unitwaittime != 0) {
/* autogame only with 'unitwaittime' = 0 */
settings_snprintf(reject_msg, reject_msg_len,
/* TRANS: Do not translate setting names in ''. */
_("For autogames ('timeout' = -1) 'unitwaittime' "
"should be deactivated (= 0)."));
return FALSE;
}
if (value > 0 && value < game.server.unitwaittime * 3 / 2) {
/* for normal games 'timeout' should be at least 3/2 times the value
* of 'unitwaittime' */
settings_snprintf(reject_msg, reject_msg_len,
/* TRANS: Do not translate setting names in ''. */
_("'timeout' can not be lower than 3/2 of the "
"'unitwaittime' setting (= %d). Please change "
"'unitwaittime' first."), game.server.unitwaittime);
return FALSE;
}
return TRUE;
}
/************************************************************************//**
Validate the 'first_timeout' server setting.
****************************************************************************/
static bool first_timeout_callback(int value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
/* Disallow low timeout values for non-hack connections. */
if (caller && caller->access_level < ALLOW_HACK
&& value < 30 && value != 0) {
settings_snprintf(reject_msg, reject_msg_len,
_("You are not allowed to set timeout values less "
"than 30 seconds."));
return FALSE;
}
return TRUE;
}
/************************************************************************//**
Check 'timeout' setting if 'unitwaittime' is changed.
****************************************************************************/
static bool unitwaittime_callback(int value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
if (game.info.timeout == -1 && value != 0) {
settings_snprintf(reject_msg, reject_msg_len,
/* TRANS: Do not translate setting names in ''. */
_("For autogames ('timeout' = -1) 'unitwaittime' "
"should be deactivated (= 0)."));
return FALSE;
}
if (game.info.timeout > 0 && value > game.info.timeout * 2 / 3) {
settings_snprintf(reject_msg, reject_msg_len,
/* TRANS: Do not translate setting names in ''. */
_("'unitwaittime' has to be lower than 2/3 of the "
"'timeout' setting (= %d). Please change 'timeout' "
"first."), game.info.timeout);
return FALSE;
}
return TRUE;
}
/************************************************************************//**
Mapsize setting validation callback.
****************************************************************************/
static bool mapsize_callback(int value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
if (value == MAPSIZE_XYSIZE && MAP_IS_ISOMETRIC
&& wld.map.ysize % 2 != 0) {
/* An isometric map needs a even ysize. It is calculated automatically
* for all settings but mapsize=XYSIZE. */
settings_snprintf(reject_msg, reject_msg_len,
_("For an isometric or hexagonal map the ysize must be "
"even."));
return FALSE;
}
return TRUE;
}
/************************************************************************//**
xsize setting validation callback.
****************************************************************************/
static bool xsize_callback(int value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
int size = value * wld.map.ysize;
if (size < MAP_MIN_SIZE * 1000) {
settings_snprintf(reject_msg, reject_msg_len,
_("The map size (%d * %d = %d) must be larger than "
"%d tiles."), value, wld.map.ysize, size,
MAP_MIN_SIZE * 1000);
return FALSE;
} else if (size > MAP_MAX_SIZE * 1000) {
settings_snprintf(reject_msg, reject_msg_len,
_("The map size (%d * %d = %d) must be lower than "
"%d tiles."), value, wld.map.ysize, size,
MAP_MAX_SIZE * 1000);
return FALSE;
}
return TRUE;
}
/************************************************************************//**
ysize setting validation callback.
****************************************************************************/
static bool ysize_callback(int value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
int size = wld.map.xsize * value;
if (size < MAP_MIN_SIZE * 1000) {
settings_snprintf(reject_msg, reject_msg_len,
_("The map size (%d * %d = %d) must be larger than "
"%d tiles."), wld.map.xsize, value, size,
MAP_MIN_SIZE * 1000);
return FALSE;
} else if (size > MAP_MAX_SIZE * 1000) {
settings_snprintf(reject_msg, reject_msg_len,
_("The map size (%d * %d = %d) must be lower than "
"%d tiles."), wld.map.xsize, value, size,
MAP_MAX_SIZE * 1000);
return FALSE;
} else if (wld.map.server.mapsize == MAPSIZE_XYSIZE && MAP_IS_ISOMETRIC
&& value % 2 != 0) {
/* An isometric map needs a even ysize. It is calculated automatically
* for all settings but mapsize=XYSIZE. */
settings_snprintf(reject_msg, reject_msg_len,
_("For an isometric or hexagonal map the ysize must be "
"even."));
return FALSE;
}
return TRUE;
}
/************************************************************************//**
Topology setting validation callback.
****************************************************************************/
static bool topology_callback(unsigned value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
if (wld.map.server.mapsize == MAPSIZE_XYSIZE
&& ((value & (TF_ISO)) != 0 || (value & (TF_HEX)) != 0)
&& wld.map.ysize % 2 != 0) {
/* An isometric map needs a even ysize. It is calculated automatically
* for all settings but mapsize=XYSIZE. */
settings_snprintf(reject_msg, reject_msg_len,
_("For an isometric or hexagonal map the ysize must be "
"even."));
return FALSE;
}
#ifdef FREECIV_WEB
/* Remember to update the help text too if Freeciv-web gets the ability
* to display other map topologies. */
/* Are you removing this because Freeciv-web gained the ability to
* display isometric maps? Why don't you remove the Freeciv-web
* specific MAP_DEFAULT_TOPO too? */
if ((value & (TF_ISO)) != 0
|| (value & (TF_HEX)) != 0) {
/* The Freeciv-web client can't display these topologies yet. */
settings_snprintf(reject_msg, reject_msg_len,
_("Freeciv-web doesn't support this topology."));
return FALSE;
}
#endif /* FREECIV_WEB */
return TRUE;
}
/************************************************************************//**
AI type setting validation callback.
****************************************************************************/
static bool aitype_callback(const char *value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
if (ai_type_by_name(value) == NULL) {
settings_snprintf(reject_msg, reject_msg_len,
_("No such AI type loaded."));
return FALSE;
}
return TRUE;
}
/************************************************************************//**
Map wrap setting validation callback.
****************************************************************************/
static bool wrap_callback(unsigned value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
#ifdef FREECIV_WEB
/* Remember to update the help text too if Freeciv-web gets the ability
* to display other map wraps. */
if ((value & (WRAP_Y)) != 0) {
/* The Freeciv-web client can't display wraps mapped this way. */
settings_snprintf(reject_msg, reject_msg_len,
_("Freeciv-web doesn't support this map wrap."));
return FALSE;
}
#endif /* FREECIV_WEB */
return TRUE;
}
/************************************************************************//**
Validate that the player color mode can be used.
****************************************************************************/
static bool plrcol_validate(int value, struct connection *caller,
char *reject_msg, size_t reject_msg_len)
{
enum plrcolor_mode mode = value;
if (mode == PLRCOL_NATION_ORDER) {
nations_iterate(pnation) {
if (nation_color(pnation)) {
/* At least one nation has a color. Allow this mode. */
return TRUE;
}
} nations_iterate_end;
settings_snprintf(reject_msg, reject_msg_len,
_("No nations in the currently loaded ruleset have "
"associated colors."));
return FALSE;
}
return TRUE;
}
#define GEN_BOOL(name, value, sclass, scateg, slevel, al_read, al_write, \
short_help, extra_help, func_validate, func_action, \
_default) \
{name, sclass, al_read, al_write, short_help, extra_help, NULL, SST_BOOL, \
scateg, slevel, \
INIT_BRACE_BEGIN \
.boolean = {&value, _default, func_validate, bool_name, \
FALSE} INIT_BRACE_END , func_action, FALSE, .ruleset_settable = TRUE},
#define GEN_INT(name, value, sclass, scateg, slevel, al_read, al_write, \
short_help, extra_help, func_help, \
func_validate, func_action, \
_min, _max, _default) \
{name, sclass, al_read, al_write, short_help, extra_help, func_help, \
SST_INT, scateg, slevel, \
INIT_BRACE_BEGIN \
.integer = {(int *) &value, _default, _min, _max, func_validate, \
0} INIT_BRACE_END, \
func_action, FALSE, .ruleset_settable = TRUE},
#define GEN_STRING(name, value, sclass, scateg, slevel, al_read, al_write, \
short_help, extra_help, func_validate, func_action, \
_default) \
{name, sclass, al_read, al_write, short_help, extra_help, NULL, \
SST_STRING, scateg, slevel, \
INIT_BRACE_BEGIN \
.string = {value, _default, sizeof(value), func_validate, ""} \
INIT_BRACE_END, \
func_action, FALSE, .ruleset_settable = TRUE},
#define GEN_STRING_NRS(name, value, sclass, scateg, slevel, al_read, al_write, \
short_help, extra_help, func_validate, func_action, \
_default) \
{name, sclass, al_read, al_write, short_help, extra_help, NULL, \
SST_STRING, scateg, slevel, \
INIT_BRACE_BEGIN \
.string = {value, _default, sizeof(value), func_validate, ""} \
INIT_BRACE_END, \
func_action, FALSE, .ruleset_settable = FALSE},
#define GEN_ENUM(name, value, sclass, scateg, slevel, al_read, al_write, \
short_help, extra_help, func_help, func_validate, \
func_action, func_name, _default) \
{ name, sclass, al_read, al_write, short_help, extra_help, func_help, \
SST_ENUM, scateg, slevel, \
INIT_BRACE_BEGIN \
.enumerator = { &value, sizeof(value), _default, \
func_validate, \
(val_name_func_t) func_name, 0 } INIT_BRACE_END, \
func_action, FALSE, .ruleset_settable = TRUE},
#define GEN_BITWISE(name, value, sclass, scateg, slevel, al_read, al_write, \
short_help, extra_help, func_validate, func_action, \
func_name, _default) \
{ name, sclass, al_read, al_write, short_help, extra_help, NULL, \
SST_BITWISE, scateg, slevel, \
INIT_BRACE_BEGIN \
.bitwise = { (unsigned *) (void *) &value, _default, func_validate, \
func_name, 0 } INIT_BRACE_END, \
func_action, FALSE, .ruleset_settable = TRUE},
/* game settings */
static struct setting settings[] = {
/* These should be grouped by sclass */
/* Map size parameters: adjustable if we don't yet have a map */
GEN_ENUM("mapsize", wld.map.server.mapsize, SSET_MAP_SIZE,
SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Map size definition"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes are setting names and shouldn't be translated. The
* strings between parentheses and in uppercase must stay as
* untranslated. */
N_("Chooses the method used to define the map size. Other options "
"specify the parameters for each method.\n"
"- \"Number of tiles\" (FULLSIZE): Map area (option 'size').\n"
"- \"Tiles per player\" (PLAYER): Number of (land) tiles per "
"player (option 'tilesperplayer').\n"
"- \"Width and height\" (XYSIZE): Map width and height in "
"tiles (options 'xsize' and 'ysize')."), NULL,
mapsize_callback, NULL, mapsize_name, MAP_DEFAULT_MAPSIZE)
GEN_INT("size", wld.map.server.size, SSET_MAP_SIZE,
SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Map area (in thousands of tiles)"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes are setting names and shouldn't be translated. The
* strings between parentheses and in uppercase must stay as
* untranslated. */
N_("This value is used to determine the map area.\n"
" size = 4 is a normal map of 4,000 tiles (default)\n"
" size = 20 is a huge map of 20,000 tiles\n"
"For this option to take effect, the \"Map size definition\" "
"option ('mapsize') must be set to \"Number of tiles\" "
"(FULLSIZE)."), NULL, NULL, NULL,
MAP_MIN_SIZE, MAP_MAX_SIZE, MAP_DEFAULT_SIZE)
GEN_INT("tilesperplayer", wld.map.server.tilesperplayer, SSET_MAP_SIZE,
SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Number of (land) tiles per player"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes are setting names and shouldn't be translated. The
* strings between parentheses and in uppercase must stay as
* untranslated. */
N_("This value is used to determine the map dimensions. It "
"calculates the map size at game start based on the number "
"of players and the value of the setting 'landmass'.\n"
"For this option to take effect, the \"Map size definition\" "
"option ('mapsize') must be set to \"Tiles per player\" "
"(PLAYER)."),
NULL, NULL, NULL, MAP_MIN_TILESPERPLAYER,
MAP_MAX_TILESPERPLAYER, MAP_DEFAULT_TILESPERPLAYER)
GEN_INT("xsize", wld.map.xsize, SSET_MAP_SIZE,
SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Map width in tiles"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes are setting names and shouldn't be translated. The
* strings between parentheses and in uppercase must stay as
* untranslated. */
N_("Defines the map width.\n"
"For this option to take effect, the \"Map size definition\" "
"option ('mapsize') must be set to \"Width and height\" "
"(XYSIZE)."),
NULL, xsize_callback, NULL,
MAP_MIN_LINEAR_SIZE, MAP_MAX_LINEAR_SIZE, MAP_DEFAULT_LINEAR_SIZE)
GEN_INT("ysize", wld.map.ysize, SSET_MAP_SIZE,
SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Map height in tiles"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes are setting names and shouldn't be translated. The
* strings between parentheses and in uppercase must stay as
* untranslated. */
N_("Defines the map height.\n"
"For this option to take effect, the \"Map size definition\" "
"option ('mapsize') must be set to \"Width and height\" "
"(XYSIZE)."),
NULL, ysize_callback, NULL,
MAP_MIN_LINEAR_SIZE, MAP_MAX_LINEAR_SIZE, MAP_DEFAULT_LINEAR_SIZE)
GEN_BITWISE("topology", wld.map.topology_id, SSET_MAP_SIZE,
SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Map topology"),
#ifdef FREECIV_WEB
/* TRANS: Freeciv-web version of the help text. */
N_("Freeciv-web maps are always two-dimensional.\n"),
#else /* FREECIV_WEB */
/* TRANS: do not edit the ugly ASCII art */
N_("Freeciv maps are always two-dimensional. "
"Individual tiles may "
"be rectangular or hexagonal, with either an overhead "
"(\"classic\") or isometric alignment.\n"
"To play with a particular topology, clients will need a "
"matching tileset.\n"
"Overhead rectangular: Isometric rectangular:\n"
" _________ /\\/\\/\\/\\/\\\n"
" |_|_|_|_|_| /\\/\\/\\/\\/\\/\n"
" |_|_|_|_|_| \\/\\/\\/\\/\\/\\\n"
" |_|_|_|_|_| /\\/\\/\\/\\/\\/\n"
" \\/\\/\\/\\/\\/\n"
"Hex: Iso-hex:\n"
" /\\/\\/\\/\\/\\/\\ _ _ _ _ _\n"
" | | | | | | | / \\_/ \\_/ \\_/ \\_/ \\\n"
" \\/\\/\\/\\/\\/\\/\\"
" \\_/ \\_/ \\_/ \\_/ \\_/\n"
" | | | | | | | / \\_/ \\_/ \\_/ \\_/ \\\n"
" \\/\\/\\/\\/\\/\\/"
" \\_/ \\_/ \\_/ \\_/ \\_/\n"),
#endif /* FREECIV_WEB */
topology_callback, topology_action, topology_name, MAP_DEFAULT_TOPO)
GEN_BITWISE("wrap", wld.map.wrap_id, SSET_MAP_SIZE,
SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Map wrap"),
#ifdef FREECIV_WEB
/* TRANS: Freeciv-web version of the help text. */
N_("Freeciv-web maps may wrap "
"at the east-west directions to form a flat map or a "
"cylinder.\n"),
#else /* FREECIV_WEB */
/* TRANS: do not edit the ugly ASCII art */
N_("Freeciv maps may wrap at "
"the north-south and east-west directions to form a flat "
"map, a cylinder, or a torus (donut)."),
#endif /* FREECIV_WEB */
wrap_callback, wrap_action, wrap_name, MAP_DEFAULT_WRAP)
GEN_ENUM("generator", wld.map.server.generator,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Method used to generate map"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes (except 'fair') are setting names and shouldn't be
* translated. The strings between parentheses and in uppercase
* must stay as untranslated. */
N_("Specifies the algorithm used to generate the map. If the "
"default value of the 'startpos' option is used, then the "
"chosen generator chooses an appropriate 'startpos' setting; "
"otherwise, the generated map tries to accommodate the "
"chosen 'startpos' setting.\n"
"- \"Scenario map\" (SCENARIO): indicates a pre-generated map. "
"By default, if the scenario does not specify start positions, "
"they will be allocated depending on the size of continents.\n"
"- \"Fully random height\" (RANDOM): generates maps with a "
"number of equally spaced, relatively small islands. By default, "
"start positions are allocated depending on continent size.\n"
"- \"Pseudo-fractal height\" (FRACTAL): generates Earthlike "
"worlds with one or more large continents and a scattering of "
"smaller islands. By default, players are all placed on a "
"single continent.\n"
"- \"Island-based\" (ISLAND): generates 'fair' maps with a "
"number of similarly-sized and -shaped islands, each with "
"approximately the same ratios of terrain types. By default, "
"each player gets their own island.\n"
"- \"Fair islands\" (FAIR): generates the exact copy of the "
"same island for every player or every team.\n"
"- \"Fracture map\" (FRACTURE): generates maps from a fracture "
"pattern. Tends to place hills and mountains along the edges "
"of the continents.\n"
"If the requested generator is incompatible with other server "
"settings, the server may fall back to another generator."),
NULL, generator_validate, NULL, generator_name, MAP_DEFAULT_GENERATOR)
GEN_ENUM("startpos", wld.map.server.startpos,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Method used to choose start positions"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes (except 'best') are setting names and shouldn't be
* translated. The strings between parentheses and in uppercase
* must stay as untranslated. */
N_("The method used to choose where each player's initial units "
"start on the map. (For scenarios which include pre-set "
"start positions, this setting is ignored.)\n"
"- \"Generator's choice\" (DEFAULT): the start position "
"placement will depend on the map generator chosen. See the "
"'generator' setting.\n"
"- \"One player per continent\" (SINGLE): one player is "
"placed on each of a set of continents of approximately "
"equivalent value (if possible).\n"
"- \"Two or three players per continent\" (2or3): similar "
"to SINGLE except that two players will be placed on each "
"continent, with three on the 'best' continent if there is an "
"odd number of players.\n"
"- \"All players on a single continent\" (ALL): all players "
"will start on the 'best' available continent.\n"
"- \"Depending on size of continents\" (VARIABLE): players "
"will be placed on the 'best' available continents such that, "
"as far as possible, the number of players on each continent "
"is proportional to its value.\n"
"If the server cannot satisfy the requested setting due to "
"there being too many players for continents, it may fall "
"back to one of the others. (However, map generators try to "
"create the right number of continents for the choice of this "
"'startpos' setting and the number of players, so this is "
"unlikely to occur.)"),
NULL, NULL, NULL, startpos_name, MAP_DEFAULT_STARTPOS)
GEN_ENUM("teamplacement", wld.map.server.team_placement,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Method used for placement of team mates"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes are setting names and shouldn't be translated. The
* strings between parentheses and in uppercase must stay as
* untranslated. */
N_("After start positions have been generated thanks to the "
"'startpos' setting, this setting controls how the start "
"positions will be assigned to the different players of the "
"same team.\n"
"- \"Disabled\" (DISABLED): the start positions will be "
"randomly assigned to players, regardless of teams.\n"
"- \"As close as possible\" (CLOSEST): players will be "
"placed as close as possible, regardless of continents.\n"
"- \"On the same continent\" (CONTINENT): if possible, place "
"all players of the same team onto the same "
"island/continent.\n"
"- \"Horizontal placement\" (HORIZONTAL): players of the same "
"team will be placed horizontally.\n"
"- \"Vertical placement\" (VERTICAL): players of the same "
"team will be placed vertically."),
NULL, NULL, NULL, teamplacement_name, MAP_DEFAULT_TEAM_PLACEMENT)
GEN_BOOL("tinyisles", wld.map.server.tinyisles,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Presence of 1x1 islands"),
N_("This setting controls whether the map generator is allowed "
"to make islands of one only tile size."), NULL, NULL,
MAP_DEFAULT_TINYISLES)
GEN_BOOL("separatepoles", wld.map.server.separatepoles,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Whether the poles are separate continents"),
N_("If this setting is disabled, the continents may attach to "
"poles."), NULL, NULL, MAP_DEFAULT_SEPARATE_POLES)
GEN_INT("flatpoles", wld.map.server.flatpoles,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL, ALLOW_NONE, ALLOW_BASIC,
N_("How much the land at the poles is flattened"),
/* TRANS: The strings in quotes shouldn't be translated. */
N_("Controls how much the height of the poles is flattened "
"during map generation, preventing a diversity of land "
"terrain there. 0 is no flattening, 100 is maximum "
"flattening. Only affects the 'RANDOM' and 'FRACTAL' "
"map generators."), NULL,
NULL, NULL,
MAP_MIN_FLATPOLES, MAP_MAX_FLATPOLES, MAP_DEFAULT_FLATPOLES)
GEN_INT("northlatitude", wld.map.north_latitude,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Northernmost latitude"),
/* TRANS: The string between single quotes is a setting name
* and should not be translated. */
N_("Combined with 'southlatitude', controls what climatic "
"zones exist on the map. Higher values are further north, "
"lower values are further south.\n"
"\n"
"1000 and -1000 gives a full planetary map.\n"
"1000 and 0 gives only a northern hemisphere.\n"
" 500 and 500 gives a map with the same middle-latitude "
"climate everywhere.\n"
" 300 and -300 gives an equatorial map.\n"
"\n"
"In rulesets that support it, latitude may also have certain "
"effects during gameplay."), NULL,
NULL, NULL,
MAP_MIN_LATITUDE_BOUND, MAP_MAX_LATITUDE_BOUND,
MAP_DEFAULT_NORTH_LATITUDE)
GEN_INT("southlatitude", wld.map.south_latitude,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Southernmost latitude"),
/* TRANS: The string between single quotes is a setting name
* and should not be translated. */
N_("Combined with 'northlatitude', controls what climatic "
"zones exist on the map. Higher values are further north, "
"lower values are further south.\n"
"\n"
"1000 and -1000 gives a full planetary map.\n"
"1000 and 0 gives only a northern hemisphere.\n"
" 500 and 500 gives a map with the same middle-latitude "
"climate everywhere.\n"
" 300 and -300 gives an equatorial map.\n"
"\n"
"In rulesets that support it, latitude may also have certain "
"effects during gameplay."), NULL,
NULL, NULL,
MAP_MIN_LATITUDE_BOUND, MAP_MAX_LATITUDE_BOUND,
MAP_DEFAULT_SOUTH_LATITUDE)
GEN_INT("temperature", wld.map.server.temperature,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Average temperature of the planet"),
N_("Small values will give a cold map, while larger values will "
"give a hotter map.\n"
"\n"
"100 means a very dry and hot planet with no polar arctic "
"zones, only tropical and dry zones.\n"
" 70 means a hot planet with little polar ice.\n"
" 50 means a temperate planet with normal polar, cold, "
"temperate, and tropical zones; a desert zone overlaps "
"tropical and temperate zones.\n"
" 30 means a cold planet with small tropical zones.\n"
" 0 means a very cold planet with large polar zones and no "
"tropics."),
NULL, NULL, NULL,
MAP_MIN_TEMPERATURE, MAP_MAX_TEMPERATURE, MAP_DEFAULT_TEMPERATURE)
GEN_INT("landmass", wld.map.server.landpercent,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Percentage of the map that is land"),
N_("This setting gives the approximate percentage of the map "
"that will be made into land."), NULL, NULL, NULL,
MAP_MIN_LANDMASS, MAP_MAX_LANDMASS, MAP_DEFAULT_LANDMASS)
GEN_INT("steepness", wld.map.server.steepness,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Amount of hills/mountains"),
N_("Small values give flat maps, while higher values give a "
"steeper map with more hills and mountains."),
NULL, NULL, NULL,
MAP_MIN_STEEPNESS, MAP_MAX_STEEPNESS, MAP_DEFAULT_STEEPNESS)
GEN_INT("wetness", wld.map.server.wetness,
SSET_MAP_GEN, SSET_GEOLOGY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Amount of water on landmasses"),
N_("Small values mean lots of dry, desert-like land; "
"higher values give a wetter map with more swamps, "
"jungles, and rivers."), NULL, NULL, NULL,
MAP_MIN_WETNESS, MAP_MAX_WETNESS, MAP_DEFAULT_WETNESS)
GEN_BOOL("globalwarming", game.info.global_warming,
SSET_RULES, SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Global warming"),
N_("If turned off, global warming will not occur "
"as a result of pollution. This setting does not "
"affect pollution."), NULL, NULL,
GAME_DEFAULT_GLOBAL_WARMING)
GEN_INT("globalwarming_percent", game.server.global_warming_percent,
SSET_RULES, SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Global warming percent"),
N_("This is a multiplier for the rate of accumulation of global "
"warming."), NULL, NULL, NULL,
GAME_MIN_GLOBAL_WARMING_PERCENT,
GAME_MAX_GLOBAL_WARMING_PERCENT,
GAME_DEFAULT_GLOBAL_WARMING_PERCENT)
GEN_BOOL("nuclearwinter", game.info.nuclear_winter,
SSET_RULES, SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Nuclear winter"),
N_("If turned off, nuclear winter will not occur "
"as a result of nuclear war."), NULL, NULL,
GAME_DEFAULT_NUCLEAR_WINTER)
GEN_INT("nuclearwinter_percent", game.server.nuclear_winter_percent,
SSET_RULES, SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Nuclear winter percent"),
N_("This is a multiplier for the rate of accumulation of nuclear "
"winter."), NULL, NULL, NULL,
GAME_MIN_NUCLEAR_WINTER_PERCENT,
GAME_MAX_NUCLEAR_WINTER_PERCENT,
GAME_DEFAULT_NUCLEAR_WINTER_PERCENT)
GEN_INT("mapseed", wld.map.server.seed_setting,
SSET_MAP_GEN, SSET_INTERNAL, SSET_RARE,
#ifdef FREECIV_WEB
ALLOW_NONE, ALLOW_BASIC,
#else /* FREECIV_WEB */
ALLOW_HACK, ALLOW_HACK,
#endif /* FREECIV_WEB */
N_("Map generation random seed"),
N_("The same seed will always produce the same map; "
"for zero (the default) a seed will be generated randomly, "
"based on gameseed. If also gameseed is zero, "
"the map will be completely random."),
NULL, NULL, NULL,
MAP_MIN_SEED, MAP_MAX_SEED, MAP_DEFAULT_SEED)
/* Map additional stuff: huts and specials. gameseed also goes here
* because huts and specials are the first time the gameseed gets used (?)
* These are done when the game starts, so these are historical and
* fixed after the game has started.
*/
GEN_INT("gameseed", game.server.seed_setting,
SSET_MAP_ADD, SSET_INTERNAL, SSET_RARE,
#ifdef FREECIV_WEB
ALLOW_NONE, ALLOW_BASIC,
#else /* FREECIV_WEB */
ALLOW_HACK, ALLOW_HACK,
#endif /* FREECIV_WEB */
N_("Game random seed"),
N_("For zero (the default) a seed will be chosen based "
"on system entropy or, failing that, the current time."),
NULL, NULL, NULL,
GAME_MIN_SEED, GAME_MAX_SEED, GAME_DEFAULT_SEED)
GEN_INT("specials", wld.map.server.riches,
SSET_MAP_ADD, SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Amount of \"special\" resource tiles"),
N_("Special resources improve the basic terrain type they "
"are on. The server variable's scale is parts per "
"thousand."), NULL, NULL, NULL,
MAP_MIN_RICHES, MAP_MAX_RICHES, MAP_DEFAULT_RICHES)
GEN_INT("huts", wld.map.server.huts,
SSET_MAP_ADD, SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Amount of huts (bonus extras)"),
N_("Huts are tile extras that usually may be investigated by "
"units. "
"The server variable's scale is huts per thousand tiles."),
huts_help, NULL, huts_action,
MAP_MIN_HUTS, MAP_MAX_HUTS, MAP_DEFAULT_HUTS)
GEN_INT("animals", wld.map.server.animals,
SSET_MAP_ADD, SSET_GEOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Amount of animals"),
N_("Number of animals initially created on terrains "
"defined for them in the ruleset (if the ruleset supports it). "
"The server variable's scale is animals per "
"thousand tiles."), NULL, NULL, NULL,
MAP_MIN_ANIMALS, MAP_MAX_ANIMALS, MAP_DEFAULT_ANIMALS)
/* Options affecting numbers of players and AI players. These only
* affect the start of the game and can not be adjusted after that.
*/
GEN_INT("minplayers", game.server.min_players,
SSET_PLAYERS, SSET_INTERNAL, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Minimum number of players"),
N_("There must be at least this many players (connected "
"human players) before the game can start."),
NULL, NULL, NULL,
GAME_MIN_MIN_PLAYERS, GAME_MAX_MIN_PLAYERS, GAME_DEFAULT_MIN_PLAYERS)
GEN_INT("maxplayers", game.server.max_players,
SSET_PLAYERS_CHANGEABLE, SSET_INTERNAL, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Maximum number of players"),
N_("The maximal number of human and AI players who can be in "
"the game. When this number of players are connected in "
"the pregame state, any new players who try to connect "
"will be rejected.\n"
"When playing a scenario which defines player start positions, "
"this setting cannot be set to greater than the number of "
"defined start positions."),
NULL, maxplayers_callback, NULL,
GAME_MIN_MAX_PLAYERS, GAME_MAX_MAX_PLAYERS, GAME_DEFAULT_MAX_PLAYERS)
GEN_INT("aifill", game.info.aifill,
SSET_PLAYERS, SSET_INTERNAL, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Limited number of AI players"),
N_("If set to a positive value, then AI players will be "
"automatically created or removed to keep the total "
"number of players at this amount. As more players join, "
"these AI players will be replaced. When set to zero, "
"all AI players will be removed."),
NULL, NULL, aifill_action,
GAME_MIN_AIFILL, GAME_MAX_AIFILL, GAME_DEFAULT_AIFILL)
GEN_ENUM("persistentready", game.info.persistent_ready,
SSET_META, SSET_NETWORK, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("When the Readiness of a player gets autotoggled off"),
N_("In pre-game, usually when new players join or old ones leave, "
"those who have already accepted game to start by toggling \"Ready\" "
"get that autotoggled off in the changed situation. This setting "
"can be used to make readiness more persistent."),
NULL, NULL, NULL, persistentready_name, GAME_DEFAULT_PERSISTENTREADY)
GEN_STRING("nationset", game.server.nationset,
SSET_PLAYERS, SSET_INTERNAL, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Set of nations to choose from"),
/* TRANS: do not translate '/list nationsets' */
N_("Controls the set of nations allowed in the game. The "
"choices are defined by the ruleset.\n"
"Only nations in the set selected here will be allowed in "
"any circumstances, including new players and civil war; "
"small sets may thus limit the number of players in a game.\n"
"If this is left blank, the ruleset's default nation set is "
"used.\n"
"See '/list nationsets' for possible choices for the "
"currently loaded ruleset."),
nationset_callback, nationset_action, GAME_DEFAULT_NATIONSET)
GEN_INT("ec_turns", game.server.event_cache.turns,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Event cache for this number of turns"),
N_("Event messages are saved for this number of turns. A value of "
"0 deactivates the event cache."),
NULL, NULL, NULL, GAME_MIN_EVENT_CACHE_TURNS, GAME_MAX_EVENT_CACHE_TURNS,
GAME_DEFAULT_EVENT_CACHE_TURNS)
GEN_INT("ec_max_size", game.server.event_cache.max_size,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Size of the event cache"),
N_("This defines the maximal number of events in the event cache."),
NULL, NULL, NULL, GAME_MIN_EVENT_CACHE_MAX_SIZE,
GAME_MAX_EVENT_CACHE_MAX_SIZE, GAME_DEFAULT_EVENT_CACHE_MAX_SIZE)
GEN_BOOL("ec_chat", game.server.event_cache.chat,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Save chat messages in the event cache"),
N_("If turned on, chat messages will be saved in the event "
"cache."), NULL, NULL, GAME_DEFAULT_EVENT_CACHE_CHAT)
GEN_BOOL("ec_info", game.server.event_cache.info,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Print turn and time for each cached event"),
/* TRANS: Don't translate the text between single quotes. */
N_("If turned on, all cached events will be marked by the turn "
"and time of the event like '(T2 - 15:29:52)'."),
NULL, NULL, GAME_DEFAULT_EVENT_CACHE_INFO)
/* Game initialization parameters (only affect the first start of the game,
* and not reloads). Can not be changed after first start of game.
*/
GEN_STRING("startunits", game.server.start_units,
SSET_GAME_INIT, SSET_SOCIOLOGY, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("List of players' initial units"),
N_("This should be a string of characters, each of which "
"specifies a unit role. The first character must be native to "
"at least one \"Starter\" terrain. The characters and their "
"meanings are:\n"
" c = City founder (eg., Settlers)\n"
" w = Terrain worker (eg., Engineers)\n"
" x = Explorer (eg., Explorer)\n"
" k = Gameloss (eg., King)\n"
" s = Diplomat (eg., Diplomat)\n"
" f = Ferryboat (eg., Trireme)\n"
" d = Ok defense unit (eg., Warriors)\n"
" D = Good defense unit (eg., Phalanx)\n"
" a = Fast attack unit (eg., Horsemen)\n"
" A = Strong attack unit (eg., Catapult)\n"),
startunits_callback, NULL, GAME_DEFAULT_START_UNITS)
GEN_BOOL("startcity", game.server.start_city,
SSET_GAME_INIT, SSET_SOCIOLOGY, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Whether player starts with a city"),
N_("If this is set, game will start with player's first "
"city already founded to starting location."),
NULL, NULL, GAME_DEFAULT_START_CITY)
GEN_INT("dispersion", game.server.dispersion,
SSET_GAME_INIT, SSET_SOCIOLOGY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Area where initial units are located"),
N_("This is the radius within "
"which the initial units are dispersed."),
NULL, NULL, NULL,
GAME_MIN_DISPERSION, GAME_MAX_DISPERSION, GAME_DEFAULT_DISPERSION)
GEN_INT("gold", game.info.gold,
SSET_GAME_INIT, SSET_ECONOMICS, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Starting gold per player"),
N_("At the beginning of the game, each player is given this "
"much gold."), NULL, NULL, NULL,
GAME_MIN_GOLD, GAME_MAX_GOLD, GAME_DEFAULT_GOLD)
GEN_INT("infrapoints", game.info.infrapoints,
SSET_GAME_INIT, SSET_ECONOMICS, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Starting infrapoints per player"),
N_("At the beginning of the game, each player is given this "
"many infrapoints."), NULL, NULL, NULL,
GAME_MIN_INFRA, GAME_MAX_INFRA, GAME_DEFAULT_INFRA)
GEN_INT("techlevel", game.info.tech,
SSET_GAME_INIT, SSET_SCIENCE, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Number of initial techs per player"),
/* TRANS: The string between single quotes is a setting name and
* should not be translated. */
N_("At the beginning of the game, each player is given this "
"many technologies. The technologies chosen are random for "
"each player. Depending on the value of tech_cost_style in "
"the ruleset, a big value for 'techlevel' can make the next "
"techs really expensive."), NULL, NULL, NULL,
GAME_MIN_TECHLEVEL, GAME_MAX_TECHLEVEL, GAME_DEFAULT_TECHLEVEL)
GEN_INT("sciencebox", game.info.sciencebox,
SSET_RULES_SCENARIO, SSET_SCIENCE, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Technology cost multiplier percentage"),
N_("This affects how quickly players can research new "
"technology. All tech costs are multiplied by this amount "
"(as a percentage). The base tech costs are determined by "
"the ruleset or other game settings."),
NULL, NULL, NULL, GAME_MIN_SCIENCEBOX, GAME_MAX_SCIENCEBOX,
GAME_DEFAULT_SCIENCEBOX)
GEN_BOOL("multiresearch", game.server.multiresearch,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Allow researching multiple technologies"),
N_("Allows switching to any technology without wasting old "
"research. Bulbs are never transferred to new technology. "
"Techpenalty options are ineffective after enabling that "
"option."), NULL, NULL,
GAME_DEFAULT_MULTIRESEARCH)
GEN_INT("techpenalty", game.server.techpenalty,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Percentage penalty when changing tech"),
N_("If you change your current research technology, and you have "
"positive research points, you lose this percentage of those "
"research points. This does not apply when you have just gained "
"a technology this turn."), NULL, NULL, NULL,
GAME_MIN_TECHPENALTY, GAME_MAX_TECHPENALTY,
GAME_DEFAULT_TECHPENALTY)
GEN_INT("techlost_recv", game.server.techlost_recv,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Chance to lose a technology while receiving it"),
N_("The chance that learning a technology by treaty or theft "
"will fail."),
NULL, NULL, NULL, GAME_MIN_TECHLOST_RECV, GAME_MAX_TECHLOST_RECV,
GAME_DEFAULT_TECHLOST_RECV)
GEN_INT("techlost_donor", game.server.techlost_donor,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Chance to lose a technology while giving it"),
N_("The chance that your civilization will lose a technology if "
"you teach it to someone else by treaty, or if it is stolen "
"from you."),
NULL, NULL, NULL, GAME_MIN_TECHLOST_DONOR, GAME_MAX_TECHLOST_DONOR,
GAME_DEFAULT_TECHLOST_DONOR)
GEN_INT("techleak", game.info.tech_leak_pct,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Tech leakage percent"),
N_("The rate of the tech leakage. This multiplied by the "
"percentage of players who know the tech tell which "
"percentage of tech's bulb cost gets leaked each turn. "
"This setting has no effect if the ruleset has disabled "
"tech leakage."),
NULL, NULL, NULL, GAME_MIN_TECHLEAK, GAME_MAX_TECHLEAK,
GAME_DEFAULT_TECHLEAK)
GEN_BOOL("team_pooled_research", game.info.team_pooled_research,
SSET_RULES, SSET_SCIENCE, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Team pooled research"),
N_("If this setting is turned on, then the team mates will share "
"the science research. Else, every player of the team will "
"have to make its own."),
NULL, NULL, GAME_DEFAULT_TEAM_POOLED_RESEARCH)
GEN_INT("diplbulbcost", game.server.diplbulbcost,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Penalty when getting tech from treaty"),
N_("For each technology you gain from a diplomatic treaty, you "
"lose research points equal to this percentage of the cost to "
"research a new technology. If this is non-zero, you can end up "
"with negative research points."),
NULL, NULL, NULL,
GAME_MIN_DIPLBULBCOST, GAME_MAX_DIPLBULBCOST, GAME_DEFAULT_DIPLBULBCOST)
GEN_INT("diplgoldcost", game.server.diplgoldcost,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Penalty when getting gold from treaty"),
N_("When transferring gold in diplomatic treaties, this percentage "
"of the agreed sum is lost to both parties; it is deducted from "
"the donor but not received by the recipient."),
NULL, NULL, NULL,
GAME_MIN_DIPLGOLDCOST, GAME_MAX_DIPLGOLDCOST, GAME_DEFAULT_DIPLGOLDCOST)
GEN_INT("incite_gold_loss_chance", game.server.incite_gold_loss_chance,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Probability of gold loss during inciting revolt"),
N_("When unit trying to incite revolt is eliminated, half of the gold "
"(or quarter, if unit was caught), prepared to bribe citizens, "
"can be lost or captured by enemy."),
NULL, NULL, NULL,
GAME_MIN_INCITE_GOLD_LOSS_CHANCE, GAME_MAX_INCITE_GOLD_LOSS_CHANCE,
GAME_DEFAULT_INCITE_GOLD_LOSS_CHANCE)
GEN_INT("incite_gold_capt_chance", game.server.incite_gold_capt_chance,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Probability of gold capture during inciting revolt"),
N_("When unit trying to incite revolt is eliminated and lose its "
"gold, there is chance that this gold would be captured by "
"city defender. Transfer tax would be applied, though. "
"This setting is irrelevant, if incite_gold_loss_chance is zero."),
NULL, NULL, NULL,
GAME_MIN_INCITE_GOLD_CAPT_CHANCE, GAME_MAX_INCITE_GOLD_CAPT_CHANCE,
GAME_DEFAULT_INCITE_GOLD_CAPT_CHANCE)
GEN_INT("conquercost", game.server.conquercost,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Penalty when getting tech from conquering"),
N_("For each technology you gain by conquering an enemy city, you "
"lose research points equal to this percentage of the cost to "
"research a new technology. If this is non-zero, you can end up "
"with negative research points."),
NULL, NULL, NULL,
GAME_MIN_CONQUERCOST, GAME_MAX_CONQUERCOST,
GAME_DEFAULT_CONQUERCOST)
GEN_INT("freecost", game.server.freecost,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Penalty when getting a free tech"),
/* TRANS: The strings between single quotes are setting names and
* shouldn't be translated. */
N_("For each technology you gain \"for free\" (other than "
"covered by 'diplcost' or 'conquercost': for instance, from huts "
"or from Great Library effects), you lose research points "
"equal to this percentage of the cost to research a new "
"technology. If this is non-zero, you can end up "
"with negative research points."),
NULL, NULL, NULL,
GAME_MIN_FREECOST, GAME_MAX_FREECOST, GAME_DEFAULT_FREECOST)
GEN_INT("techlossforgiveness", game.info.techloss_forgiveness,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Research point debt threshold for losing tech"),
N_("When you have negative research points, and your shortfall is "
"greater than this percentage of the cost of your current "
"research, you forget a technology you already knew.\n"
"The special value -1 prevents loss of technology regardless of "
"research points."),
NULL, NULL, NULL,
GAME_MIN_TECHLOSSFG, GAME_MAX_TECHLOSSFG,
GAME_DEFAULT_TECHLOSSFG)
GEN_INT("techlossrestore", game.server.techloss_restore,
SSET_RULES, SSET_SCIENCE, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Research points restored after losing a tech"),
N_("When you lose a technology due to a negative research balance "
"(see 'techlossforgiveness'), this percentage of its research "
"cost is credited to your research balance (this may not be "
"sufficient to make it positive).\n"
"The special value -1 means that your research balance is always "
"restored to zero, regardless of your previous shortfall."),
NULL, NULL, NULL,
GAME_MIN_TECHLOSSREST, GAME_MAX_TECHLOSSREST,
GAME_DEFAULT_TECHLOSSREST)
GEN_INT("foodbox", game.info.foodbox,
SSET_RULES, SSET_ECONOMICS, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Food required for a city to grow"),
N_("This is the base amount of food required to grow a city. "
"This value is multiplied by another factor that comes from "
"the ruleset and is dependent on the size of the city."),
NULL, NULL, NULL,
GAME_MIN_FOODBOX, GAME_MAX_FOODBOX, GAME_DEFAULT_FOODBOX)
GEN_INT("aqueductloss", game.server.aqueductloss,
SSET_RULES, SSET_ECONOMICS, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Percentage food lost when city can't grow"),
N_("If a city would expand, but it can't because it lacks some "
"prerequisite (traditionally an Aqueduct or Sewer System), "
"this is the base percentage of its foodbox that is lost "
"each turn; the penalty may be reduced by buildings or other "
"circumstances, depending on the ruleset."),
NULL, NULL, NULL,
GAME_MIN_AQUEDUCTLOSS, GAME_MAX_AQUEDUCTLOSS,
GAME_DEFAULT_AQUEDUCTLOSS)
GEN_INT("shieldbox", game.info.shieldbox,
SSET_RULES, SSET_ECONOMICS, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Multiplier percentage for production costs"),
N_("This affects how quickly units and buildings can be "
"produced. The base costs are multiplied by this value (as "
"a percentage)."),
NULL, NULL, NULL,
GAME_MIN_SHIELDBOX, GAME_MAX_SHIELDBOX, GAME_DEFAULT_SHIELDBOX)
/* Notradesize and fulltradesize used to have callbacks to prevent them
* from being set illegally (notradesize > fulltradesize). However this
* provided a problem when setting them both through the client's settings
* dialog, since they cannot both be set atomically. So the callbacks were
* removed and instead the game now knows how to deal with invalid
* settings. */
GEN_INT("fulltradesize", game.info.fulltradesize,
SSET_RULES, SSET_ECONOMICS, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Minimum city size to get full trade"),
/* TRANS: The strings between single quotes are setting names and
* shouldn't be translated. */
N_("There is a trade penalty in all cities smaller than this. "
"The penalty is 100% (no trade at all) for sizes up to "
"'notradesize', and decreases gradually to 0% (no penalty "
"except the normal corruption) for size='fulltradesize'. "
"See also 'notradesize'."), NULL, NULL, NULL,
GAME_MIN_FULLTRADESIZE, GAME_MAX_FULLTRADESIZE,
GAME_DEFAULT_FULLTRADESIZE)
GEN_INT("notradesize", game.info.notradesize,
SSET_RULES, SSET_ECONOMICS, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Maximum size of a city without trade"),
/* TRANS: The strings between single quotes are setting names and
* shouldn't be translated. */
N_("Cities do not produce any trade at all unless their size "
"is larger than this amount. The produced trade increases "
"gradually for cities larger than 'notradesize' and smaller "
"than 'fulltradesize'. See also 'fulltradesize'."),
NULL, NULL, NULL,
GAME_MIN_NOTRADESIZE, GAME_MAX_NOTRADESIZE,
GAME_DEFAULT_NOTRADESIZE)
GEN_INT("tradeworldrelpct", game.info.trade_world_rel_pct,
SSET_RULES, SSET_ECONOMICS, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("How largely trade distance is relative to world size"),
/* TRANS: The strings between single quotes are setting names and
* shouldn't be translated. */
N_("When determining trade between cities, the distance factor "
"can be partly or fully relative to world size. This setting "
"determines how big percentage of the bonus calculation is "
"relative to world size, and how much only absolute distance "
"matters."),
NULL, NULL, NULL,
GAME_MIN_TRADEWORLDRELPCT, GAME_MAX_TRADEWORLDRELPCT,
GAME_DEFAULT_TRADEWORLDRELPCT)
GEN_INT("citymindist", game.info.citymindist,
SSET_RULES, SSET_SOCIOLOGY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Minimum distance between cities"),
N_("When a player attempts to found a new city, it is prevented "
"if the distance from any existing city is less than this "
"setting. For example, when this setting is 3, there must be "
"at least two clear tiles in any direction between all existing "
"cities and the new city site. A value of 1 removes any such "
"restriction on city placement."),
NULL, NULL, NULL,
GAME_MIN_CITYMINDIST, GAME_MAX_CITYMINDIST,
GAME_DEFAULT_CITYMINDIST)
GEN_BOOL("trading_tech", game.info.trading_tech,
SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Technology trading"),
N_("If turned off, trading technologies in the diplomacy dialog "
"is not allowed."), NULL, NULL,
GAME_DEFAULT_TRADING_TECH)
GEN_BOOL("trading_gold", game.info.trading_gold,
SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Gold trading"),
N_("If turned off, trading gold in the diplomacy dialog "
"is not allowed."), NULL, NULL,
GAME_DEFAULT_TRADING_GOLD)
GEN_BOOL("trading_city", game.info.trading_city,
SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("City trading"),
N_("If turned off, trading cities in the diplomacy dialog "
"is not allowed."), NULL, NULL,
GAME_DEFAULT_TRADING_CITY)
GEN_ENUM("caravan_bonus_style", game.info.caravan_bonus_style,
SSET_RULES, SSET_ECONOMICS, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Caravan bonus style"),
N_("The formula for the bonus when a caravan enters a city. "
"CLASSIC bonuses are proportional to distance and trade "
"of source and destination with multipliers for overseas and "
"international destinations. LOGARITHMIC bonuses are "
"proportional to log^2(distance + trade)."),
NULL, NULL, NULL, caravanbonusstyle_name,
GAME_DEFAULT_CARAVAN_BONUS_STYLE)
GEN_ENUM("trade_revenue_style", game.info.trade_revenue_style,
SSET_RULES, SSET_ECONOMICS, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Trade revenue style"),
N_("The formula for the trade a city receives from a trade route. "
"CLASSIC revenues are given by the sum of the two city sizes "
"plus the distance between them, with multipliers for overseas "
"and international routes. "
"SIMPLE revenues are proportional to the average trade of the "
"two cities."),
NULL, NULL, NULL, traderevenuestyle_name,
GAME_DEFAULT_TRADE_REVENUE_STYLE)
GEN_INT("trademindist", game.info.trademindist,
SSET_RULES, SSET_ECONOMICS, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Minimum distance for trade routes"),
N_("In order for two cities in the same civilization to establish "
"a trade route, they must be at least this far apart on the "
"map. For square grids, the distance is calculated as "
"\"Manhattan distance\", that is, the sum of the displacements "
"along the x and y directions."), NULL, NULL, NULL,
GAME_MIN_TRADEMINDIST, GAME_MAX_TRADEMINDIST,
GAME_DEFAULT_TRADEMINDIST)
GEN_INT("rapturedelay", game.info.rapturedelay,
SSET_RULES, SSET_SOCIOLOGY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Number of turns between rapture effect"),
N_("Sets the number of turns between rapture growth of a city. "
"If set to n a city will grow after celebrating for n+1 "
"turns."),
NULL, NULL, NULL,
GAME_MIN_RAPTUREDELAY, GAME_MAX_RAPTUREDELAY,
GAME_DEFAULT_RAPTUREDELAY)
GEN_INT("disasters", game.info.disasters,
SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Frequency of disasters"),
N_("Affects how often random disasters happen to cities, "
"if any are defined by the ruleset. The relative frequency "
"of disaster types is set by the ruleset. Zero prevents "
"any random disasters from occurring."),
NULL, NULL, NULL,
GAME_MIN_DISASTERS, GAME_MAX_DISASTERS,
GAME_DEFAULT_DISASTERS)
GEN_ENUM("traitdistribution", game.server.trait_dist,
SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("AI trait distribution method"),
N_("How trait values are given to AI players."),
NULL, NULL, NULL, trait_dist_name, GAME_DEFAULT_TRAIT_DIST_MODE)
GEN_INT("razechance", game.server.razechance,
SSET_RULES, SSET_MILITARY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Chance for conquered building destruction"),
N_("When a player conquers a city, each city improvement has this "
"percentage chance to be destroyed."), NULL, NULL, NULL,
GAME_MIN_RAZECHANCE, GAME_MAX_RAZECHANCE, GAME_DEFAULT_RAZECHANCE)
GEN_INT("occupychance", game.server.occupychance,
SSET_RULES, SSET_MILITARY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Chance of moving into tile after attack"),
N_("If set to 0, combat is Civ1/2-style (when you attack, "
"you remain in place). If set to 100, attacking units "
"will always move into the tile they attacked when they win "
"the combat (and no enemy units remain in the tile). If "
"set to a value between 0 and 100, this will be used as "
"the percent chance of \"occupying\" territory."),
NULL, NULL, NULL,
GAME_MIN_OCCUPYCHANCE, GAME_MAX_OCCUPYCHANCE,
GAME_DEFAULT_OCCUPYCHANCE)
GEN_BOOL("autoattack", game.server.autoattack, SSET_RULES_FLEXIBLE, SSET_MILITARY,
SSET_SITUATIONAL, ALLOW_NONE, ALLOW_BASIC,
N_("Turn on/off server-side autoattack"),
N_("If set to on, units with moves left will automatically "
"consider attacking enemy units that move adjacent to them."),
NULL, NULL, GAME_DEFAULT_AUTOATTACK)
GEN_BOOL("killstack", game.info.killstack,
SSET_RULES_SCENARIO, SSET_MILITARY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Do all units in tile die with defender"),
N_("If this is enabled, each time a defender unit loses in combat, "
"and is not inside a city or suitable base, all units in the same "
"tile are destroyed along with the defender. If this is disabled, "
"only the defender unit is destroyed."),
NULL, NULL, GAME_DEFAULT_KILLSTACK)
GEN_BOOL("killcitizen", game.info.killcitizen,
SSET_RULES, SSET_MILITARY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Reduce city population after attack"),
N_("This flag indicates whether a city's population is reduced "
"after a successful attack by an enemy unit. If this is "
"disabled, population is never reduced. Even when this is "
"enabled, only some units may kill citizens."),
NULL, NULL, GAME_DEFAULT_KILLCITIZEN)
GEN_INT("killunhomed", game.server.killunhomed,
SSET_RULES, SSET_MILITARY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Slowly kill units without home cities (e.g., starting units)"),
N_("If greater than 0, then every unit without a homecity will "
"lose hitpoints each turn. The number of hitpoints lost is "
"given by 'killunhomed' percent of the hitpoints of the unit "
"type. At least one hitpoint is lost every turn until the "
"death of the unit."),
NULL, NULL, NULL, GAME_MIN_KILLUNHOMED, GAME_MAX_KILLUNHOMED,
GAME_DEFAULT_KILLUNHOMED)
GEN_ENUM("borders", game.info.borders,
SSET_RULES, SSET_MILITARY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("National borders"),
N_("If this is not disabled, then any land tiles around a "
"city or border-claiming extra (like the classic ruleset's "
"Fortress base) will be owned by that nation. "
"SEE_INSIDE and EXPAND makes everything inside a player's "
"borders visible at once. ENABLED will, in some rulesets, "
"grant the same visibility if certain conditions are met."),
NULL, NULL, NULL, borders_name, GAME_DEFAULT_BORDERS)
GEN_ENUM("happyborders", game.info.happyborders,
SSET_RULES, SSET_MILITARY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Units inside borders cause no unhappiness"),
N_("If this is set, units will not cause unhappiness when "
"inside your borders, or even allies borders, depending "
"on value."), NULL, NULL, NULL,
happyborders_name, GAME_DEFAULT_HAPPYBORDERS)
GEN_ENUM("diplomacy", game.info.diplomacy,
SSET_RULES, SSET_MILITARY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Ability to do diplomacy with other players"),
N_("This setting controls the ability to do diplomacy with "
"other players."),
NULL, NULL, NULL, diplomacy_name, GAME_DEFAULT_DIPLOMACY)
GEN_ENUM("citynames", game.server.allowed_city_names,
SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Allowed city names"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between parentheses
* and in uppercase must not be translated. */
N_("- \"No restrictions\" (NO_RESTRICTIONS): players can have "
"multiple cities with the same names.\n"
"- \"Unique to a player\" (PLAYER_UNIQUE): one player can't "
"have multiple cities with the same name.\n"
"- \"Globally unique\" (GLOBAL_UNIQUE): all cities in a game "
"have to have different names.\n"
"- \"No city name stealing\" (NO_STEALING): like "
"\"Globally unique\", but a player isn't allowed to use a "
"default city name of another nation unless it is a default "
"for their nation also."),
NULL, NULL, NULL, citynames_name, GAME_DEFAULT_ALLOWED_CITY_NAMES)
GEN_ENUM("plrcolormode", game.server.plrcolormode,
SSET_RULES, SSET_INTERNAL, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("How to pick player colors"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single quotes
* are setting names and shouldn't be translated. The strings
* between parentheses and in uppercase must not be translated. */
N_("This setting determines how player colors are chosen. Player "
"colors are used in the Nations report, for national borders on "
"the map, and so on.\n"
"- \"Per-player, in order\" (PLR_ORDER): colors are assigned to "
"individual players in order from a list defined by the "
"ruleset.\n"
"- \"Per-player, random\" (PLR_RANDOM): colors are assigned "
"to individual players randomly from the set defined by the "
"ruleset.\n"
"- \"Set manually\" (PLR_SET): colors can be set with the "
"'playercolor' command before the game starts; these are not "
"restricted to the ruleset colors. Any players for which no "
"color is set when the game starts get a random color from the "
"ruleset.\n"
"- \"Per-team, in order\" (TEAM_ORDER): colors are assigned to "
"teams from the list in the ruleset. Every player on the same "
"team gets the same color.\n"
"- \"Per-nation, in order\" (NATION_ORDER): if the ruleset "
"defines a color for a player's nation, the player takes that "
"color. Any players whose nations don't have associated colors "
"get a random color from the list in the ruleset.\n"
"Regardless of this setting, individual player colors can be "
"changed after the game starts with the 'playercolor' command."),
NULL, plrcol_validate, plrcol_action, plrcol_name,
GAME_DEFAULT_PLRCOLORMODE)
/* Flexible rules: these can be changed after the game has started.
*
* The distinction between "rules" and "flexible rules" is not always
* clearcut, and some existing cases may be largely historical or
* accidental. However some generalizations can be made:
*
* -- Low-level game mechanics should not be flexible (eg, rulesets).
* -- Options which would affect the game "state" (city production etc)
* should not be flexible (eg, foodbox).
* -- Options which are explicitly sent to the client (eg, in
* packet_game_info) should probably not be flexible, or at
* least need extra care to be flexible.
*/
GEN_ENUM("barbarians", game.server.barbarianrate,
SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Barbarian appearance frequency"),
/* TRANS: The string between single quotes is a setting name and
* should not be translated. */
N_("This setting controls how frequently the barbarians appear "
"in the game. See also the 'onsetbarbs' setting."),
NULL, NULL, NULL, barbarians_name, GAME_DEFAULT_BARBARIANRATE)
GEN_INT("onsetbarbs", game.server.onsetbarbarian,
SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Barbarian onset turn"),
N_("Barbarians will not appear before this turn."),
NULL, NULL, NULL,
GAME_MIN_ONSETBARBARIAN, GAME_MAX_ONSETBARBARIAN,
GAME_DEFAULT_ONSETBARBARIAN)
GEN_ENUM("revolentype", game.info.revolentype,
SSET_RULES, SSET_SOCIOLOGY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Way to determine revolution length"),
N_("Which method is used in determining how long period of anarchy "
"lasts when changing government. The actual value is set with "
"'revolen' setting. The 'quickening' methods depend on how "
"many times any player has changed to this type of government "
"before, so it becomes easier to establish a new system of "
"government if it has been done before."),
NULL, NULL, NULL, revolentype_name, GAME_DEFAULT_REVOLENTYPE)
GEN_INT("revolen", game.server.revolution_length,
SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Length of revolution"),
N_("When changing governments, a period of anarchy will occur. "
"Value of this setting, used the way 'revolentype' setting "
"dictates, defines the length of the anarchy."),
NULL, NULL, NULL,
GAME_MIN_REVOLUTION_LENGTH, GAME_MAX_REVOLUTION_LENGTH,
GAME_DEFAULT_REVOLUTION_LENGTH)
GEN_BOOL("fogofwar", game.info.fogofwar,
SSET_RULES, SSET_MILITARY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Whether to enable fog of war"),
N_("If this is enabled, only those units and cities within "
"the vision range of your own units and cities will be "
"revealed to you. You will not see new cities or terrain "
"changes in tiles not observed."),
NULL, NULL, GAME_DEFAULT_FOGOFWAR)
GEN_BOOL("foggedborders", game.server.foggedborders,
SSET_RULES, SSET_MILITARY, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Whether fog of war applies to border changes"),
N_("If this setting is enabled, players will not be able "
"to see changes in tile ownership if they do not have "
"direct sight of the affected tiles. Otherwise, players "
"can see any or all changes to borders as long as they "
"have previously seen the tiles."),
NULL, NULL, GAME_DEFAULT_FOGGEDBORDERS)
GEN_BITWISE("airliftingstyle", game.info.airlifting_style,
SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC, N_("Airlifting style"),
/* TRANS: The strings between double quotes are also
* translated separately (they must match!). The strings
* between parenthesis and in uppercase must not be
* translated. */
N_("This setting affects airlifting units between cities. It "
"can be a set of the following values:\n"
"- \"Allows units to be airlifted from allied cities\" "
"(FROM_ALLIES).\n"
"- \"Allows units to be airlifted to allied cities\" "
"(TO_ALLIES).\n"
"- \"Unlimited units from source city\" (SRC_UNLIMITED): "
"airlifting from a city doesn't reduce the "
"airlifted counter. It depends on the ruleset whether "
"this is possible even with zero airlift capacity.\n"
"- \"Unlimited units to destination city\" "
"(DEST_UNLIMITED): airlifting to a city doesn't "
"reduce the airlifted counter. It depends on the ruleset "
"whether this is possible even with zero airlift capacity."),
NULL, NULL, airliftingstyle_name, GAME_DEFAULT_AIRLIFTINGSTYLE)
GEN_INT("diplchance", game.server.diplchance,
SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Base chance for diplomats and spies to succeed"),
N_("The base chance of a spy returning from a successful mission and "
"the base chance of success for diplomats and spies for most "
"aggressive mission types. Not all the mission types use diplchance "
"as a base chance – a ruleset can even say that no action at all does. "
"Unit Bribing, and Unit Sabotaging never do. "
"Non-aggressive missions typically have no base chance "
"at all, but always success."),
NULL, NULL, NULL,
GAME_MIN_DIPLCHANCE, GAME_MAX_DIPLCHANCE, GAME_DEFAULT_DIPLCHANCE)
GEN_BITWISE("victories", game.info.victory_conditions,
SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("What kinds of victories are possible"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes are setting names and shouldn't be translated. The
* strings between parentheses and in uppercase must stay as
* untranslated. */
N_("This setting controls how game can be won. One can always "
"win by conquering entire planet, but other victory conditions "
"can be enabled or disabled:\n"
"- \"Spacerace\" (SPACERACE): Spaceship is built and travels to "
"Alpha Centauri.\n"
"- \"Allied\" (ALLIED): After defeating enemies, all remaining "
"players are allied.\n"
"- \"Culture\" (CULTURE): Player meets ruleset defined cultural "
"domination criteria.\n"),
NULL, NULL, victory_conditions_name, GAME_DEFAULT_VICTORY_CONDITIONS)
GEN_BOOL("endspaceship", game.server.endspaceship, SSET_RULES_FLEXIBLE,
SSET_SCIENCE, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Should the game end if the spaceship arrives?"),
N_("If this option is turned on, the game will end with the "
"arrival of a spaceship at Alpha Centauri."),
NULL, NULL, GAME_DEFAULT_END_SPACESHIP)
GEN_INT("spaceship_travel_pct", game.server.spaceship_travel_pct,
SSET_RULES_FLEXIBLE, SSET_SCIENCE, SSET_VITAL, ALLOW_NONE,
ALLOW_BASIC,
N_("Percentage to multiply spaceship travel time by"),
N_("This percentage is multiplied onto the time it will take for "
"a spaceship to arrive at Alpha Centauri."), NULL, NULL, NULL,
GAME_MIN_SPACESHIP_TRAVEL_PCT, GAME_MAX_SPACESHIP_TRAVEL_PCT,
GAME_DEFAULT_SPACESHIP_TRAVEL_PCT)
GEN_INT("civilwarsize", game.server.civilwarsize,
SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Minimum number of cities for civil war"),
N_("A civil war is triggered when a player has at least this "
"many cities and the player's capital is captured. If "
"this option is set to the maximum value, civil wars are "
"turned off altogether."), NULL, NULL, NULL,
GAME_MIN_CIVILWARSIZE, GAME_MAX_CIVILWARSIZE,
GAME_DEFAULT_CIVILWARSIZE)
GEN_BOOL("restrictinfra", game.info.restrictinfra,
SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Restrict the use of the infrastructure for enemy units"),
N_("If this option is enabled, the use of roads and rails "
"will be restricted for enemy units."), NULL, NULL,
GAME_DEFAULT_RESTRICTINFRA)
GEN_BOOL("unreachableprotects", game.info.unreachable_protects,
SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Does unreachable unit protect reachable ones"),
N_("This option controls whether tiles with both unreachable "
"and reachable units can be attacked. If disabled, any "
"tile with reachable units can be attacked. If enabled, "
"tiles with an unreachable unit in them cannot be attacked. "
"Some units in some rulesets may override this, never "
"protecting reachable units on their tile."),
NULL, NULL, GAME_DEFAULT_UNRPROTECTS)
GEN_INT("contactturns", game.server.contactturns,
SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Turns until player contact is lost"),
N_("Players may meet for diplomacy this number of turns "
"after their units have last met, even when they do not have "
"an embassy. If set to zero, then players cannot meet unless "
"they have an embassy."),
NULL, NULL, NULL,
GAME_MIN_CONTACTTURNS, GAME_MAX_CONTACTTURNS,
GAME_DEFAULT_CONTACTTURNS)
GEN_BOOL("savepalace", game.server.savepalace,
SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Rebuild palace whenever capital is conquered"),
N_("If this is turned on, when the capital is conquered the "
"palace is automatically rebuilt for free in another randomly "
"chosen city. This is significant because the technology "
"requirement for building a palace will be ignored. (In "
"some rulesets, buildings other than the palace are affected "
"by this setting.)"),
NULL, NULL, GAME_DEFAULT_SAVEPALACE)
GEN_BOOL("homecaughtunits", game.server.homecaughtunits,
SSET_RULES_FLEXIBLE, SSET_MILITARY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Give caught units a homecity"),
/* TRANS: The string between single quotes is a setting name and
* should not be translated. */
N_("If unset, caught units will have no homecity and will be "
"subject to the 'killunhomed' option."),
NULL, NULL, GAME_DEFAULT_HOMECAUGHTUNITS)
GEN_BOOL("naturalcitynames", game.server.natural_city_names,
SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Whether to use natural city names"),
N_("If enabled, the default city names will be determined based "
"on the surrounding terrain."),
NULL, NULL, GAME_DEFAULT_NATURALCITYNAMES)
GEN_BOOL("migration", game.server.migration,
SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Whether to enable citizen migration"),
/* TRANS: The strings between single quotes are setting names
* and should not be translated. */
N_("This is the master setting that controls whether citizen "
"migration is active in the game. If enabled, citizens may "
"automatically move from less desirable cities to more "
"desirable ones. The \"desirability\" of a given city is "
"calculated from a number of factors. In general larger "
"cities with more income and improvements will be preferred. "
"Citizens will never migrate out of the capital, or cause "
"a wonder to be lost by disbanding a city. A number of other "
"settings control how migration behaves:\n"
" 'mgr_turninterval' - How often citizens try to migrate.\n"
" 'mgr_foodneeded' - Whether destination food is checked.\n"
" 'mgr_distance' - How far citizens will migrate.\n"
" 'mgr_worldchance' - Chance for inter-nation migration.\n"
" 'mgr_nationchance' - Chance for intra-nation migration."),
NULL, NULL, GAME_DEFAULT_MIGRATION)
GEN_INT("mgr_turninterval", game.server.mgr_turninterval,
SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Number of turns between migrations from a city"),
/* TRANS: Do not translate 'migration' setting name. */
N_("This setting controls the number of turns between migration "
"checks for a given city. The interval is calculated from "
"the founding turn of the city. So for example if this "
"setting is 5, citizens will look for a suitable migration "
"destination every five turns from the founding of their "
"current city. Migration will never occur the same turn "
"that a city is built. This setting has no effect unless "
"migration is enabled by the 'migration' setting."),
NULL, NULL, NULL,
GAME_MIN_MGR_TURNINTERVAL, GAME_MAX_MGR_TURNINTERVAL,
GAME_DEFAULT_MGR_TURNINTERVAL)
GEN_BOOL("mgr_foodneeded", game.server.mgr_foodneeded,
SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Whether migration is limited by food"),
/* TRANS: Do not translate 'migration' setting name. */
N_("If this setting is enabled, citizens will not migrate to "
"cities which would not have enough food to support them. "
"This setting has no effect unless migration is enabled by "
"the 'migration' setting."), NULL, NULL,
GAME_DEFAULT_MGR_FOODNEEDED)
GEN_INT("mgr_distance", game.server.mgr_distance,
SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Maximum distance citizens may migrate"),
/* TRANS: Do not translate 'migration' setting name. */
N_("This setting controls how far citizens may look for a "
"suitable migration destination when deciding which city "
"to migrate to. The value is added to the candidate target "
"city's radius and compared to the distance between the "
"two cities. If the distance is lower or equal, migration "
"is possible. (So with a setting of 0, citizens will only "
"consider migrating if their city's center is within the "
"destination city's working radius.) This setting has no "
"effect unless migration is enabled by the 'migration' "
"setting."),
NULL, NULL, NULL, GAME_MIN_MGR_DISTANCE, GAME_MAX_MGR_DISTANCE,
GAME_DEFAULT_MGR_DISTANCE)
GEN_INT("mgr_nationchance", game.server.mgr_nationchance,
SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Percent probability for migration within the same nation"),
/* TRANS: Do not translate 'migration' setting name. */
N_("This setting controls how likely it is for citizens to "
"migrate between cities owned by the same player. Zero "
"indicates migration will never occur, 100 means that "
"migration will always occur if the citizens find a suitable "
"destination. This setting has no effect unless migration "
"is activated by the 'migration' setting."),
NULL, NULL, NULL,
GAME_MIN_MGR_NATIONCHANCE, GAME_MAX_MGR_NATIONCHANCE,
GAME_DEFAULT_MGR_NATIONCHANCE)
GEN_INT("mgr_worldchance", game.server.mgr_worldchance,
SSET_RULES_FLEXIBLE, SSET_SOCIOLOGY, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Percent probability for migration between foreign cities"),
/* TRANS: Do not translate 'migration' setting name. */
N_("This setting controls how likely it is for migration "
"to occur between cities owned by different players. "
"Zero indicates migration will never occur, 100 means "
"that citizens will always migrate if they find a suitable "
"destination. This setting has no effect if migration is "
"not enabled by the 'migration' setting."),
NULL, NULL, NULL,
GAME_MIN_MGR_WORLDCHANCE, GAME_MAX_MGR_WORLDCHANCE,
GAME_DEFAULT_MGR_WORLDCHANCE)
/* Meta options: these don't affect the internal rules of the game, but
* do affect players. Also options which only produce extra server
* "output" and don't affect the actual game.
* ("endturn" is here, and not RULES_FLEXIBLE, because it doesn't
* affect what happens in the game, it just determines when the
* players stop playing and look at the score.)
*/
GEN_STRING("allowtake", game.server.allow_take,
SSET_META, SSET_NETWORK, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Players that users are allowed to take"),
/* TRANS: the strings in double quotes are server command names
* and should not be translated. */
N_("This should be a string of characters, each of which "
"specifies a type or status of a civilization (player).\n"
"Clients will only be permitted to take or observe those "
"players which match one of the specified letters. This "
"only affects future uses of the \"take\" or \"observe\" "
"commands; it is not retroactive. The characters and their "
"meanings are:\n"
" o,O = Global observer\n"
" b = Barbarian players\n"
" d = Dead players\n"
" a,A = AI players\n"
" h,H = Human players\n"
"The first description on this list which matches a "
"player is the one which applies. Thus 'd' does not "
"include dead barbarians, 'a' does not include dead AI "
"players, and so on. Upper case letters apply before "
"the game has started, lower case letters afterwards.\n"
"Each character above may be followed by one of the "
"following numbers to allow or restrict the manner "
"of connection:\n"
"(none) = Controller allowed, observers allowed, "
"can displace connections. (Displacing a connection means "
"that you may take over a player, even when another user "
"already controls that player.)\n"
" 1 = Controller allowed, observers allowed, "
"can't displace connections;\n"
" 2 = Controller allowed, no observers allowed, "
"can displace connections;\n"
" 3 = Controller allowed, no observers allowed, "
"can't displace connections;\n"
" 4 = No controller allowed, observers allowed"),
allowtake_callback, NULL, GAME_DEFAULT_ALLOW_TAKE)
GEN_BOOL("autotoggle", game.server.auto_ai_toggle,
SSET_META, SSET_NETWORK, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Whether AI-status toggles with connection"),
N_("If enabled, AI status is turned off when a player "
"connects, and on when a player disconnects."),
NULL, autotoggle_action, GAME_DEFAULT_AUTO_AI_TOGGLE)
GEN_INT("endturn", game.server.end_turn,
SSET_META, SSET_SOCIOLOGY, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Turn the game ends"),
N_("The game will end at the end of the given turn."),
NULL, endturn_callback, NULL,
GAME_MIN_END_TURN, GAME_MAX_END_TURN, GAME_DEFAULT_END_TURN)
GEN_BITWISE("revealmap", game.server.revealmap, SSET_GAME_INIT,
SSET_MILITARY, SSET_SITUATIONAL, ALLOW_NONE, ALLOW_BASIC,
N_("Reveal the map"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes are setting names and shouldn't be translated. The
* strings between parentheses and in uppercase must not be
* translated. */
N_("If \"Reveal map at game start\" (START) is set, the "
"initial state of the entire map will be known to all "
"players from the start of the game, although it may "
"still be fogged (depending on the 'fogofwar' setting). "
"If \"Unfog map for dead players\" (DEAD) is set, dead "
"players can see the entire map, if they are alone in "
"their team."),
NULL, NULL, revealmap_name, GAME_DEFAULT_REVEALMAP)
GEN_INT("timeout", game.info.timeout,
SSET_META, SSET_INTERNAL, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Maximum seconds per turn"),
/* TRANS: \"Turn Done\" refers to the client button; it is also
* translated separately, the translation should be the same.
* \"timeoutincrease\" is a command name and must not to be
* translated. */
N_("If all players have not hit \"Turn Done\" before this "
"time is up, then the turn ends automatically. Zero "
"means there is no timeout. In servers compiled with "
"debugging, a timeout of -1 sets the autogame test mode. "
"Only connections with hack level access may set the "
"timeout to fewer than 30 seconds. Use this with the "
"command \"timeoutincrease\" to have a dynamic timer. "
"The first turn is treated as a special case and is controlled "
"by the 'first_timeout' setting."),
NULL, timeout_callback, timeout_action,
GAME_MIN_TIMEOUT, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUT)
GEN_INT("first_timeout", game.info.first_timeout,
SSET_META, SSET_INTERNAL, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("First turn timeout"),
/* TRANS: The strings between single quotes are setting names and
* should not be translated. */
N_("If greater than 0, T1 will last for 'first_timeout' seconds.\n"
"If set to 0, T1 will not have a timeout.\n"
"If set to -1, the special treatment of T1 will be disabled.\n"
"See also 'timeout'."),
NULL, first_timeout_callback, first_timeout_action,
GAME_MIN_FIRST_TIMEOUT, GAME_MAX_FIRST_TIMEOUT,
GAME_DEFAULT_FIRST_TIMEOUT)
GEN_INT("timeaddenemymove", game.server.timeoutaddenemymove,
SSET_META, SSET_INTERNAL, SSET_VITAL, ALLOW_NONE, ALLOW_BASIC,
N_("Timeout at least n seconds when enemy moved"),
N_("Any time a unit moves while in sight of an enemy player, "
"the remaining timeout is increased to this value."),
NULL, NULL, NULL,
0, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUTADDEMOVE)
GEN_INT("unitwaittime", game.server.unitwaittime,
SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_VITAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Minimum time between unit actions over turn change"),
/* TRANS: The string between single quotes is a setting name and
* should not be translated. */
N_("This setting gives the minimum amount of time in seconds "
"between unit moves and other significant actions (such as "
"building cities) after a turn change occurs. For example, "
"if this setting is set to 20 and a unit moves 5 seconds "
"before the turn change, it will not be able to move or act "
"in the next turn for at least 15 seconds. This value is "
"limited to a maximum value of 2/3 'timeout'."),
NULL, unitwaittime_callback, NULL, GAME_MIN_UNITWAITTIME,
GAME_MAX_UNITWAITTIME, GAME_DEFAULT_UNITWAITTIME)
/* This setting points to the "stored" value; changing it won't have
* an effect until the next synchronization point (i.e., the start of
* the next turn). */
GEN_ENUM("phasemode", game.server.phase_mode_stored,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Control of simultaneous player/team phases"),
N_("This setting controls whether players may make "
"moves at the same time during a turn. Change "
"in setting takes effect next turn."),
phasemode_help, NULL, NULL, phasemode_name, GAME_DEFAULT_PHASE_MODE)
GEN_INT("nettimeout", game.server.tcptimeout,
SSET_META, SSET_NETWORK, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Seconds to let a client's network connection block"),
N_("If a network connection is blocking for a time greater than "
"this value, then the connection is closed. Zero "
"means there is no timeout (although connections will be "
"automatically disconnected eventually)."),
NULL, NULL, NULL,
GAME_MIN_TCPTIMEOUT, GAME_MAX_TCPTIMEOUT, GAME_DEFAULT_TCPTIMEOUT)
GEN_INT("netwait", game.server.netwait,
SSET_META, SSET_NETWORK, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Max seconds for network buffers to drain"),
N_("The server will wait for up to the value of this "
"parameter in seconds, for all client connection network "
"buffers to unblock. Zero means the server will not "
"wait at all."), NULL, NULL, NULL,
GAME_MIN_NETWAIT, GAME_MAX_NETWAIT, GAME_DEFAULT_NETWAIT)
GEN_INT("pingtime", game.server.pingtime,
SSET_META, SSET_NETWORK, SSET_RARE, ALLOW_NONE, ALLOW_BASIC,
N_("Seconds between PINGs"),
N_("The server will poll the clients with a PING request "
"each time this period elapses."), NULL, NULL, NULL,
GAME_MIN_PINGTIME, GAME_MAX_PINGTIME, GAME_DEFAULT_PINGTIME)
GEN_INT("pingtimeout", game.server.pingtimeout,
SSET_META, SSET_NETWORK, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Time to cut a client"),
N_("If a client doesn't reply to a PING in this time the "
"client is disconnected."), NULL, NULL, NULL,
GAME_MIN_PINGTIMEOUT, GAME_MAX_PINGTIMEOUT, GAME_DEFAULT_PINGTIMEOUT)
GEN_BOOL("iphide", game.server.ip_hide,
SSET_META, SSET_NETWORK, SSET_RARE,
ALLOW_NONE, ALLOW_HACK,
N_("Keep client IP hidden"),
N_("Don't tell client IP address to other clients. Server operator "
"can still see it. Also, changing this setting cannot do anything "
"to the information already sent before."),
NULL, NULL, GAME_DEFAULT_IPHIDE)
GEN_BOOL("turnblock", game.server.turnblock,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Turn-blocking game play mode"),
N_("If this is turned on, the game turn is not advanced "
"until all players have finished their turn, including "
"disconnected players."),
NULL, NULL, GAME_DEFAULT_TURNBLOCK)
GEN_BOOL("fixedlength", game.server.fixedlength,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Fixed-length turns play mode"),
/* TRANS: \"Turn Done\" refers to the client button; it is also
* translated separately, the translation should be the same. */
N_("If this is turned on the game turn will not advance "
"until the timeout has expired, even after all players "
"have clicked on \"Turn Done\"."),
NULL, NULL, FALSE)
GEN_INT("top_cities", game.info.top_cities_count,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("Number of cities in Top Cities report"),
N_("How many cities should the Top Cities report contain? "
"If this is zero, Top Cities report is not available "
"at all."), NULL, NULL, NULL,
GAME_MIN_TOP_CITIES_COUNT, GAME_MAX_TOP_CITIES_COUNT,
GAME_DEFAULT_TOP_CITIES_COUNT)
GEN_STRING("demography", game.server.demography,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_NONE, ALLOW_BASIC,
N_("What is in the Demographics report"),
/* TRANS: The strings between double quotes should be
* translated. */
N_("This should be a string of characters, each of which "
"specifies the inclusion of a line of information "
"in the Demographics report.\n"
"The characters and their meanings are:\n"
" N = include Population\n"
" P = include Production\n"
" A = include Land Area\n"
" L = include Literacy\n"
" R = include Research Speed\n"
" S = include Settled Area\n"
" E = include Economics\n"
" M = include Military Service\n"
" O = include Pollution\n"
" C = include Culture\n"
"Additionally, the following characters control whether "
"or not certain columns are displayed in the report:\n"
" q = display \"quantity\" column\n"
" r = display \"rank\" column\n"
" b = display \"best nation\" column\n"
"The order of characters is not significant, but "
"their capitalization is."),
demography_callback, NULL, GAME_DEFAULT_DEMOGRAPHY)
GEN_INT("saveturns", game.server.save_nturns,
SSET_META, SSET_INTERNAL, SSET_VITAL, ALLOW_HACK, ALLOW_HACK,
N_("Turns per auto-save"),
/* TRANS: The string between double quotes is also translated
* separately (it must match!). The string between single
* quotes is a setting name and shouldn't be translated. */
N_("How many turns elapse between automatic game saves. This "
"setting only has an effect when the 'autosaves' setting "
"includes \"New turn\"."), NULL, NULL, NULL,
GAME_MIN_SAVETURNS, GAME_MAX_SAVETURNS, GAME_DEFAULT_SAVETURNS)
GEN_INT("savefrequency", game.server.save_frequency,
SSET_META, SSET_INTERNAL, SSET_VITAL, ALLOW_HACK, ALLOW_HACK,
N_("Minutes per auto-save"),
/* TRANS: The string between double quotes is also translated
* separately (it must match!). The string between single
* quotes is a setting name and shouldn't be translated. */
N_("How many minutes elapse between automatic game saves. "
"Unlike other save types, this save is only meant as backup "
"for computer memory, and it always uses the same name, older "
"saves are not kept. This setting only has an effect when the "
"'autosaves' setting includes \"Timer\"."), NULL, NULL, NULL,
GAME_MIN_SAVEFREQUENCY, GAME_MAX_SAVEFREQUENCY, GAME_DEFAULT_SAVEFREQUENCY)
GEN_BITWISE("autosaves", game.server.autosaves,
SSET_META, SSET_INTERNAL, SSET_VITAL, ALLOW_HACK, ALLOW_HACK,
N_("Which savegames are generated automatically"),
/* TRANS: The strings between double quotes are also translated
* separately (they must match!). The strings between single
* quotes are setting names and shouldn't be translated. The
* strings between parentheses and in uppercase must stay as
* untranslated. */
N_("This setting controls which autosave types get generated:\n"
"- \"New turn\" (TURN): Save when turn begins, once every "
"'saveturns' turns.\n"
"- \"Game over\" (GAMEOVER): Final save when game ends.\n"
"- \"No player connections\" (QUITIDLE): "
"Save before server restarts due to lack of players.\n"
"- \"Server interrupted\" (INTERRUPT): Save when server "
"quits due to interrupt.\n"
"- \"Timer\" (TIMER): Save every 'savefrequency' minutes."),
autosaves_callback, NULL, autosaves_name, GAME_DEFAULT_AUTOSAVES)
GEN_BOOL("threaded_save", game.server.threaded_save,
SSET_META, SSET_INTERNAL, SSET_RARE, ALLOW_HACK, ALLOW_HACK,
N_("Whether to do saving in separate thread"),
/* TRANS: The string between single quotes is a setting name and
* should not be translated. */
N_("If this is turned in, compressing and saving the actual "
"file containing the game situation takes place in "
"the background while game otherwise continues. This way "
"users are not required to wait for the save to finish."),
NULL, NULL, GAME_DEFAULT_THREADED_SAVE)
GEN_INT("compress", game.server.save_compress_level,
SSET_META, SSET_INTERNAL, SSET_RARE, ALLOW_HACK, ALLOW_HACK,
N_("Savegame compression level"),
/* TRANS: 'compresstype' setting name should not be translated. */
N_("If non-zero, saved games will be compressed depending on the "
"'compresstype' setting. Larger values will give better "
"compression but take longer."),
NULL, NULL, NULL,
GAME_MIN_COMPRESS_LEVEL, GAME_MAX_COMPRESS_LEVEL, GAME_DEFAULT_COMPRESS_LEVEL)
GEN_ENUM("compresstype", game.server.save_compress_type,
SSET_META, SSET_INTERNAL, SSET_RARE, ALLOW_HACK, ALLOW_HACK,
N_("Savegame compression algorithm"),
N_("Compression library to use for savegames."),
NULL, NULL, NULL, compresstype_name, GAME_DEFAULT_COMPRESS_TYPE)
GEN_STRING("savename", game.server.save_name,
SSET_META, SSET_INTERNAL, SSET_VITAL, ALLOW_HACK, ALLOW_HACK,
N_("Definition of the save file name"),
/* TRANS: %R, %S, %T and %Y must not be translated. The
* strings (examples and setting names) between single quotes
* neither. The strings between <> should be translated.
* xgettext:no-c-format */
N_("Within the string the following custom formats are "
"allowed:\n"
" %R = <reason>\n"
" %S = <suffix>\n"
" %T = <turn-number>\n"
" %Y = <game-year>\n"
"\n"
"Example: 'freeciv-T%04T-Y%+05Y-%R' => "
"'freeciv-T0100-Y00001-manual'\n"
"\n"
"Be careful to use at least one of %T and %Y, else newer "
"savegames will overwrite old ones. If none of the formats "
"is used '-T%04T-Y%05Y-%R' is appended to the value of "
"'savename'."),
savename_validate, NULL, GAME_DEFAULT_SAVE_NAME)
GEN_BOOL("scorelog", game.server.scorelog,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
#ifdef FREECIV_WEB
ALLOW_NONE, ALLOW_CTRL,
#else /* FREECIV_WEB */
ALLOW_HACK, ALLOW_HACK,
#endif /* FREECIV_WEB */
N_("Whether to log player statistics"),
/* TRANS: The string between single quotes is a setting name and
* should not be translated. */
N_("If this is turned on, player statistics are appended to "
"the file defined by the option 'scorefile' every turn. "
"These statistics can be used to create power graphs after "
"the game."), NULL, scorelog_action, GAME_DEFAULT_SCORELOG)
GEN_ENUM("scoreloglevel", game.server.scoreloglevel,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_HACK, ALLOW_HACK,
N_("Scorelog level"),
N_("Whether scores are logged for all players including AIs, "
"or only for human players."), NULL, NULL, NULL,
scoreloglevel_name, GAME_DEFAULT_SCORELOGLEVEL)
#ifndef FREECIV_WEB
GEN_STRING("scorefile", game.server.scorefile,
SSET_META, SSET_INTERNAL, SSET_SITUATIONAL,
ALLOW_HACK, ALLOW_HACK,
N_("Name for the score log file"),
/* TRANS: Don't translate the string in single quotes. */
N_("The default name for the score log file is "
"'freeciv-score.log'."),
scorefile_validate, NULL, GAME_DEFAULT_SCOREFILE)
#endif /* !FREECIV_WEB */
GEN_INT("maxconnectionsperhost", game.server.maxconnectionsperhost,
SSET_RULES_FLEXIBLE, SSET_NETWORK, SSET_RARE,
ALLOW_NONE, ALLOW_BASIC,
N_("Maximum number of connections to the server per host"),
N_("New connections from a given host will be rejected if "
"the total number of connections from the very same host "
"equals or exceeds this value. A value of 0 means that "
"there is no limit, at least up to the maximum number of "
"connections supported by the server."), NULL, NULL, NULL,
GAME_MIN_MAXCONNECTIONSPERHOST, GAME_MAX_MAXCONNECTIONSPERHOST,
GAME_DEFAULT_MAXCONNECTIONSPERHOST)
GEN_INT("kicktime", game.server.kick_time,
SSET_RULES_FLEXIBLE, SSET_NETWORK, SSET_RARE,
ALLOW_HACK, ALLOW_HACK,
N_("Time before a kicked user can reconnect"),
/* TRANS: the string in double quotes is a server command name and
* should not be translated */
N_("Gives the time in seconds before a user kicked using the "
"\"kick\" command may reconnect. Changing this setting will "
"affect users kicked in the past."), NULL, NULL, NULL,
GAME_MIN_KICK_TIME, GAME_MAX_KICK_TIME, GAME_DEFAULT_KICK_TIME)
GEN_INT("luatimeout", game.lua_timeout,
SSET_RULES_FLEXIBLE, SSET_INTERNAL, SSET_RARE, ALLOW_HACK, ALLOW_HACK,
N_("Lua timeout"),
N_("Time in seconds that a single lua script can run before it gets "
"forcibly terminated."), NULL, NULL, NULL,
GAME_MIN_LUA_TIMEOUT, GAME_MAX_LUA_TIMEOUT, GAME_DEFAULT_LUA_TIMEOUT)
GEN_STRING_NRS("metamessage", game.server.meta_info.user_message,
SSET_META, SSET_INTERNAL, SSET_RARE, ALLOW_CTRL, ALLOW_CTRL,
N_("Metaserver info line"),
N_("User defined metaserver info line. For most of the time "
"a user defined metamessage will be used instead of an "
"automatically generated message. "
"Set to empty (\"\", not \"empty\") to always use an "
"automatically generated meta server message."),
NULL, metamessage_action, GAME_DEFAULT_USER_META_MESSAGE)
GEN_ENUM("ailevel", game.info.skill_level,
SSET_META, SSET_INTERNAL, SSET_VITAL, ALLOW_NONE, ALLOW_CTRL,
N_("Level of new AIs"),
N_("Difficulty level of any AI players to be created now on. "
"Changing value of this setting does not affect "
"existing players."), NULL, NULL, NULL,
ailevel_name, GAME_DEFAULT_SKILL_LEVEL)
GEN_STRING_NRS("aitype", game.server.default_ai_type_name,
SSET_META, SSET_INTERNAL, SSET_RARE, ALLOW_HACK, ALLOW_HACK,
N_("Default AI type"),
N_("Name of the default AI type. New AI players will be "
"created with that type by default. Changing this "
"setting does not affect existing AI players."),
aitype_callback, aitype_action, AI_MOD_DEFAULT)
};
#undef GEN_BOOL
#undef GEN_INT
#undef GEN_STRING
#undef GEN_ENUM
#undef GEN_BITWISE
/* The number of settings, not including the END. */
static const int SETTINGS_NUM = ARRAY_SIZE(settings);
/************************************************************************//**
Returns the setting to the given id.
****************************************************************************/
struct setting *setting_by_number(int id)
{
return (0 <= id && id < SETTINGS_NUM ? settings + id : NULL);
}
/************************************************************************//**
Returns the setting to the given name.
****************************************************************************/
struct setting *setting_by_name(const char *name)
{
fc_assert_ret_val(name, NULL);
settings_iterate(SSET_ALL, pset) {
if (0 == strcmp(name, pset->name)) {
return pset;
}
} settings_iterate_end;
return NULL;
}
/************************************************************************//**
Returns the id to the given setting.
****************************************************************************/
int setting_number(const struct setting *pset)
{
fc_assert_ret_val(pset != NULL, -1);
return pset - settings;
}
/************************************************************************//**
Access function for the setting name.
****************************************************************************/
const char *setting_name(const struct setting *pset)
{
return pset->name;
}
/************************************************************************//**
Access function for the short help (not translated yet) of the setting.
****************************************************************************/
const char *setting_short_help(const struct setting *pset)
{
return pset->short_help;
}
/************************************************************************//**
Access function for the long (extra) help of the setting.
If 'constant' is TRUE, static, not-yet-translated string is always returned.
****************************************************************************/
const char *setting_extra_help(const struct setting *pset, bool constant)
{
if (!constant && pset->help_func != NULL) {
return pset->help_func(pset);
}
return _(pset->extra_help);
}
/************************************************************************//**
Access function for the setting type.
****************************************************************************/
enum sset_type setting_type(const struct setting *pset)
{
return pset->stype;
}
/************************************************************************//**
Access function for the setting level (used by the /show command).
****************************************************************************/
enum sset_level setting_level(const struct setting *pset)
{
return pset->slevel;
}
/************************************************************************//**
Access function for the setting category.
****************************************************************************/
enum sset_category setting_category(const struct setting *pset)
{
return pset->scategory;
}
/************************************************************************//**
Returns whether the specified server setting (option) can currently
be changed without breaking data consistency (map dimension options
can't change when map has already been created with certain dimensions)
****************************************************************************/
static bool setting_is_free_to_change(const struct setting *pset,
char *reject_msg,
size_t reject_msg_len)
{
switch (pset->sclass) {
case SSET_MAP_SIZE:
case SSET_MAP_GEN:
/* Only change map options if we don't yet have a map: */
if (map_is_empty()) {
return TRUE;
}
settings_snprintf(reject_msg, reject_msg_len,
_("The setting '%s' can't be modified after the map "
"is fixed."), setting_name(pset));
return FALSE;
case SSET_RULES_SCENARIO:
/* Like SSET_RULES except that it can be changed before the game starts
* for heavy scenarios. A heavy scenario comes with players. It can
* include cities, units, diplomatic relations and other complex
* state. Make sure that changing a setting can't make the state of a
* heavy scenario illegal if you want to change it from SSET_RULES to
* SSET_RULES_SCENARIO. */
if (game.scenario.is_scenario && game.scenario.players
&& server_state() == S_S_INITIAL) {
/* Special case detected. */
return TRUE;
}
/* The special case didn't make it legal to change the setting. Don't
* give up. It could still be legal. Fall through so the non special
* cases are checked too. */
fc__fallthrough;
case SSET_MAP_ADD:
case SSET_PLAYERS:
case SSET_GAME_INIT:
case SSET_RULES:
/* Only change start params and most rules if we don't yet have a map,
* or if we do have a map but its a scenario one (ie, the game has
* never actually been started).
*/
if (map_is_empty() || game.info.is_new_game) {
return TRUE;
}
settings_snprintf(reject_msg, reject_msg_len,
_("The setting '%s' can't be modified after the game "
"has started."), setting_name(pset));
return FALSE;
case SSET_PLAYERS_CHANGEABLE:
case SSET_RULES_FLEXIBLE:
case SSET_META:
/* These can always be changed: */
return TRUE;
}
log_error("Wrong class variant for setting %s (%d): %d.",
setting_name(pset), setting_number(pset), pset->sclass);
settings_snprintf(reject_msg, reject_msg_len, _("Internal error."));
return FALSE;
}
/************************************************************************//**
Returns whether the specified server setting (option) can currently
be changed by the caller. If it returns FALSE, the reason of the failure
is available by the function setting_error().
****************************************************************************/
bool setting_is_changeable(const struct setting *pset,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
if (caller
&& (caller->access_level < pset->access_level_write)) {
settings_snprintf(reject_msg, reject_msg_len,
_("You are not allowed to change the setting '%s'."),
setting_name(pset));
return FALSE;
}
switch (pset->lock) {
case SLOCK_NONE:
break;
case SLOCK_RULESET:
/* Setting is locked by the ruleset */
settings_snprintf(reject_msg, reject_msg_len,
_("The setting '%s' is locked by the ruleset."),
setting_name(pset));
return FALSE;
case SLOCK_ADMIN:
/* Setting is locked by admin */
settings_snprintf(reject_msg, reject_msg_len,
_("The setting '%s' is locked by admin."),
setting_name(pset));
return FALSE;
}
return setting_is_free_to_change(pset, reject_msg, reject_msg_len);
}
/************************************************************************//**
Returns whether the specified server setting (option) can be seen by a
caller with the specified access level.
****************************************************************************/
bool setting_is_visible_at_level(const struct setting *pset,
enum cmdlevel plevel)
{
return (plevel >= pset->access_level_read);
}
/************************************************************************//**
Returns whether the specified server setting (option) can be seen by the
caller.
****************************************************************************/
bool setting_is_visible(const struct setting *pset,
struct connection *caller)
{
return (!caller
|| setting_is_visible_at_level(pset, caller->access_level));
}
/************************************************************************//**
Convert the string prefix to an integer representation.
NB: This function is used for SST_ENUM *and* SST_BITWISE.
FIXME: this mostly duplicate match_prefix_full().
****************************************************************************/
static enum m_pre_result
setting_match_prefix_base(const val_name_func_t name_fn,
const char *prefix, int *ind_result,
const char **matches, size_t max_matches,
size_t *pnum_matches)
{
const struct sset_val_name *name;
size_t len = strlen(prefix);
size_t num_matches;
int i;
*pnum_matches = 0;
if (0 == len) {
return M_PRE_EMPTY;
}
for (i = 0, num_matches = 0; (name = name_fn(i)); i++) {
if (0 == fc_strncasecmp(name->support, prefix, len)) {
if (strlen(name->support) == len) {
*ind_result = i;
return M_PRE_EXACT;
}
if (num_matches < max_matches) {
matches[num_matches] = name->support;
(*pnum_matches)++;
}
if (0 == num_matches++) {
*ind_result = i;
}
}
}
if (1 == num_matches) {
return M_PRE_ONLY;
} else if (1 < num_matches) {
return M_PRE_AMBIGUOUS;
} else {
return M_PRE_FAIL;
}
}
/************************************************************************//**
Convert the string prefix to an integer representation.
NB: This function is used for SST_ENUM *and* SST_BITWISE.
****************************************************************************/
static bool setting_match_prefix(const val_name_func_t name_fn,
const char *prefix, int *pvalue,
char *reject_msg,
size_t reject_msg_len)
{
const char *matches[16];
size_t num_matches;
switch (setting_match_prefix_base(name_fn, prefix, pvalue, matches,
ARRAY_SIZE(matches), &num_matches)) {
case M_PRE_EXACT:
case M_PRE_ONLY:
return TRUE; /* Ok. */
case M_PRE_AMBIGUOUS:
{
struct astring astr = ASTRING_INIT;
fc_assert(2 <= num_matches);
settings_snprintf(reject_msg, reject_msg_len,
_("\"%s\" prefix is ambiguous. Candidates are: %s."),
prefix,
astr_build_and_list(&astr, matches, num_matches));
astr_free(&astr);
}
return FALSE;
case M_PRE_EMPTY:
settings_snprintf(reject_msg, reject_msg_len, _("Missing value."));
return FALSE;
case M_PRE_LONG:
case M_PRE_FAIL:
case M_PRE_LAST:
break;
}
settings_snprintf(reject_msg, reject_msg_len,
_("No match for \"%s\"."), prefix);
return FALSE;
}
/************************************************************************//**
Compute the string representation of the value for this boolean setting.
****************************************************************************/
static const char *setting_bool_to_str(const struct setting *pset,
bool value, bool pretty,
char *buf, size_t buf_len)
{
const struct sset_val_name *name = pset->boolean.name(value);
if (pretty) {
fc_snprintf(buf, buf_len, "%s", Q_(name->pretty));
} else {
fc_strlcpy(buf, name->support, buf_len);
}
return buf;
}
/************************************************************************//**
Returns TRUE if 'val' is a valid value for this setting. If it's not,
the reason of the failure is available in the optional parameter
'reject_msg'.
FIXME: also check the access level of pconn.
****************************************************************************/
static bool setting_bool_validate_base(const struct setting *pset,
const char *val, int *pint_val,
struct connection *caller,
char *reject_msg,
size_t reject_msg_len)
{
char buf[256];
if (SST_BOOL != pset->stype) {
settings_snprintf(reject_msg, reject_msg_len,
_("This setting is not a boolean."));
return FALSE;
}
sz_strlcpy(buf, val);
remove_leading_trailing_spaces(buf);
return (setting_match_prefix(pset->boolean.name, buf, pint_val,
reject_msg, reject_msg_len)
&& (NULL == pset->boolean.validate
|| pset->boolean.validate(0 != *pint_val, caller, reject_msg,
reject_msg_len)));
}
/************************************************************************//**
Set the setting to 'val'. Returns TRUE on success. If it's not,
the reason of the failure is available in the optional parameter
'reject_msg'.
****************************************************************************/
bool setting_bool_set(struct setting *pset, const char *val,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
int int_val;
if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
|| !setting_bool_validate_base(pset, val, &int_val, caller,
reject_msg, reject_msg_len)) {
return FALSE;
}
*pset->boolean.pvalue = (0 != int_val);
return TRUE;
}
/************************************************************************//**
Get value of boolean setting
****************************************************************************/
bool setting_bool_get(struct setting *pset)
{
fc_assert(setting_type(pset) == SST_BOOL);
return *pset->boolean.pvalue;
}
/************************************************************************//**
Returns TRUE if 'val' is a valid value for this setting. If it's not,
the reason of the failure is available in the optional parameter
'reject_msg'.
****************************************************************************/
bool setting_bool_validate(const struct setting *pset, const char *val,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
int int_val;
return setting_bool_validate_base(pset, val, &int_val, caller,
reject_msg, reject_msg_len);
}
/************************************************************************//**
Convert the integer to the long support string representation of a boolean
setting. This function must match the secfile_enum_name_data_fn_t type.
****************************************************************************/
static const char *setting_bool_secfile_str(secfile_data_t data, int val)
{
const struct sset_val_name *name =
((const struct setting *) data)->boolean.name(val);
return (NULL != name ? name->support : NULL);
}
/************************************************************************//**
Compute the string representation of the value for this integer setting.
****************************************************************************/
static const char *setting_int_to_str(const struct setting *pset,
int value, bool pretty,
char *buf, size_t buf_len)
{
fc_snprintf(buf, buf_len, "%d", value);
return buf;
}
/************************************************************************//**
Returns the minimal integer value for this setting.
****************************************************************************/
int setting_int_min(const struct setting *pset)
{
fc_assert_ret_val(pset->stype == SST_INT, 0);
return pset->integer.min_value;
}
/************************************************************************//**
Returns the maximal integer value for this setting.
****************************************************************************/
int setting_int_max(const struct setting *pset)
{
fc_assert_ret_val(pset->stype == SST_INT, 0);
return pset->integer.max_value;
}
/************************************************************************//**
Set the setting to 'val'. Returns TRUE on success. If it fails, the
reason of the failure is available by the function setting_error().
****************************************************************************/
bool setting_int_set(struct setting *pset, int val,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
|| !setting_int_validate(pset, val, caller, reject_msg,
reject_msg_len)) {
return FALSE;
}
*pset->integer.pvalue = val;
return TRUE;
}
/************************************************************************//**
Returns TRUE if 'val' is a valid value for this setting. If it's not,
the reason of the failure is available by the function setting_error().
FIXME: also check the access level of pconn.
****************************************************************************/
bool setting_int_validate(const struct setting *pset, int val,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
if (SST_INT != pset->stype) {
settings_snprintf(reject_msg, reject_msg_len,
_("This setting is not an integer."));
return FALSE;
}
if (val < pset->integer.min_value || val > pset->integer.max_value) {
settings_snprintf(reject_msg, reject_msg_len,
_("Value out of range: %d (min: %d; max: %d)."),
val, pset->integer.min_value, pset->integer.max_value);
return FALSE;
}
return (!pset->integer.validate
|| pset->integer.validate(val, caller, reject_msg,
reject_msg_len));
}
/************************************************************************//**
Get value of integer setting
****************************************************************************/
int setting_int_get(struct setting *pset)
{
fc_assert(setting_type(pset) == SST_INT);
return *pset->integer.pvalue;
}
/************************************************************************//**
Compute the string representation of the value for this string setting.
****************************************************************************/
static const char *setting_str_to_str(const struct setting *pset,
const char *value, bool pretty,
char *buf, size_t buf_len)
{
if (pretty) {
fc_snprintf(buf, buf_len, "\"%s\"", value);
} else {
fc_strlcpy(buf, value, buf_len);
}
return buf;
}
/************************************************************************//**
Set the setting to 'val'. Returns TRUE on success. If it fails, the
reason of the failure is available by the function setting_error().
****************************************************************************/
bool setting_str_set(struct setting *pset, const char *val,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
|| !setting_str_validate(pset, val, caller, reject_msg,
reject_msg_len)) {
return FALSE;
}
fc_strlcpy(pset->string.value, val, pset->string.value_size);
return TRUE;
}
/************************************************************************//**
Returns TRUE if 'val' is a valid value for this setting. If it's not,
the reason of the failure is available by the function setting_error().
FIXME: also check the access level of pconn.
****************************************************************************/
bool setting_str_validate(const struct setting *pset, const char *val,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
if (SST_STRING != pset->stype) {
settings_snprintf(reject_msg, reject_msg_len,
_("This setting is not a string."));
return FALSE;
}
if (strlen(val) >= pset->string.value_size) {
settings_snprintf(reject_msg, reject_msg_len,
_("String value too long (max length: %lu)."),
(unsigned long) pset->string.value_size);
return FALSE;
}
return (!pset->string.validate
|| pset->string.validate(val, caller, reject_msg,
reject_msg_len));
}
/************************************************************************//**
Get value of string setting
****************************************************************************/
char *setting_str_get(struct setting *pset)
{
fc_assert(setting_type(pset) == SST_STRING);
return pset->string.value;
}
/************************************************************************//**
Convert the integer to the long support string representation of an
enumerator. This function must match the secfile_enum_name_data_fn_t type.
****************************************************************************/
const char *setting_enum_secfile_str(secfile_data_t data, int val)
{
struct sf_cb_data *info = (struct sf_cb_data *)data;
const struct sset_val_name *name;
name = info->set->enumerator.name(val);
if (info->compat && name != NULL) {
const char *ret = setcompat_current_val_from_previous(info->set,
name->support);
if (ret != NULL) {
return ret;
}
}
return (NULL != name ? name->support : NULL);
}
/************************************************************************//**
Convert the integer to the string representation of an enumerator.
Return NULL if 'val' is not a valid enumerator.
****************************************************************************/
const char *setting_enum_val(const struct setting *pset, int val, bool pretty)
{
const struct sset_val_name *name;
fc_assert_ret_val(SST_ENUM == pset->stype, NULL);
name = pset->enumerator.name(val);
if (NULL == name) {
return NULL;
} else if (pretty) {
return _(name->pretty);
} else {
return name->support;
}
}
/************************************************************************//**
Compute the string representation of the value for this enumerator
setting.
****************************************************************************/
static const char *setting_enum_to_str(const struct setting *pset,
int value, bool pretty,
char *buf, size_t buf_len)
{
const struct sset_val_name *name = pset->enumerator.name(value);
if (pretty) {
fc_snprintf(buf, buf_len, "\"%s\" (%s)",
Q_(name->pretty), name->support);
} else {
fc_strlcpy(buf, name->support, buf_len);
}
return buf;
}
/************************************************************************//**
Returns TRUE if 'val' is a valid value for this setting. If it's not,
the reason of the failure is available in the optional parameter
'reject_msg'.
FIXME: also check the access level of pconn.
****************************************************************************/
static bool setting_enum_validate_base(const struct setting *pset,
const char *val, int *pint_val,
struct connection *caller,
char *reject_msg,
size_t reject_msg_len)
{
char buf[256];
if (SST_ENUM != pset->stype) {
settings_snprintf(reject_msg, reject_msg_len,
_("This setting is not an enumerator."));
return FALSE;
}
sz_strlcpy(buf, val);
remove_leading_trailing_spaces(buf);
return (setting_match_prefix(pset->enumerator.name, buf, pint_val,
reject_msg, reject_msg_len)
&& (NULL == pset->enumerator.validate
|| pset->enumerator.validate(*pint_val, caller, reject_msg,
reject_msg_len)));
}
/************************************************************************//**
Helper function to write value to enumerator setting
****************************************************************************/
static bool set_enum_value(struct setting *pset, int val)
{
switch (pset->enumerator.store_size) {
case sizeof(int):
{
int *to_int = pset->enumerator.pvalue;
*to_int = val;
}
break;
case sizeof(char):
{
char *to_char = pset->enumerator.pvalue;
*to_char = (char) val;
}
break;
case sizeof(short):
{
short *to_short = pset->enumerator.pvalue;
*to_short = (short) val;
}
break;
default:
return FALSE;
}
return TRUE;
}
/************************************************************************//**
Helper function to read value from enumerator setting
****************************************************************************/
int read_enum_value(const struct setting *pset)
{
int val;
switch (pset->enumerator.store_size) {
case sizeof(int):
val = *((int *)pset->enumerator.pvalue);
break;
case sizeof(char):
val = *((char *)pset->enumerator.pvalue);
break;
case sizeof(short):
val = *((short *)pset->enumerator.pvalue);
break;
default:
log_error("Illegal enum store size %d, can't read value", pset->enumerator.store_size);
return 0;
}
return val;
}
/************************************************************************//**
Set the setting to 'val'. Returns TRUE on success. If it fails, the
reason of the failure is available in the optional parameter
'reject_msg'.
****************************************************************************/
bool setting_enum_set(struct setting *pset, const char *val,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
int int_val;
if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)) {
return FALSE;
}
if (!setting_enum_validate_base(pset, val, &int_val, caller,
reject_msg, reject_msg_len)) {
return FALSE;
}
if (!set_enum_value(pset, int_val)) {
log_error("Illegal enumerator value size %d for %s",
pset->enumerator.store_size, val);
return FALSE;
}
return TRUE;
}
/************************************************************************//**
Returns TRUE if 'val' is a valid value for this setting. If it's not,
the reason of the failure is available in the optional parameter
'reject_msg'.
****************************************************************************/
bool setting_enum_validate(const struct setting *pset, const char *val,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
int int_val;
return setting_enum_validate_base(pset, val, &int_val, caller,
reject_msg, reject_msg_len);
}
/************************************************************************//**
Convert the integer to the long support string representation of an
enumerator. This function must match the secfile_enum_name_data_fn_t type.
****************************************************************************/
const char *setting_bitwise_secfile_str(secfile_data_t data, int bit)
{
struct sf_cb_data *info = (struct sf_cb_data *)data;
const struct sset_val_name *name = info->set->bitwise.name(bit);
if (info->compat && name == NULL) {
if (!fc_strcasecmp("topology", setting_name(info->set))) {
if ((1 << bit) == TF_OLD_WRAPX) {
return "WrapX";
}
if ((1 << bit) == TF_OLD_WRAPY) {
return "WrapY";
}
}
}
return (NULL != name ? name->support : NULL);
}
/************************************************************************//**
Convert the bit number to its string representation.
Return NULL if 'bit' is not a valid bit.
****************************************************************************/
const char *setting_bitwise_bit(const struct setting *pset,
int bit, bool pretty)
{
const struct sset_val_name *name;
fc_assert_ret_val(SST_BITWISE == pset->stype, NULL);
name = pset->bitwise.name(bit);
if (NULL == name) {
return NULL;
} else if (pretty) {
return _(name->pretty);
} else {
return name->support;
}
}
/************************************************************************//**
Compute the string representation of the value for this bitwise setting.
****************************************************************************/
static const char *setting_bitwise_to_str(const struct setting *pset,
unsigned value, bool pretty,
char *buf, size_t buf_len)
{
const struct sset_val_name *name;
char *old_buf = buf;
int bit;
if (pretty) {
char buf2[256];
struct astring astr = ASTRING_INIT;
struct strvec *vec = strvec_new();
size_t len;
for (bit = 0; (name = pset->bitwise.name(bit)); bit++) {
if ((1 << bit) & value) {
/* TRANS: only emphasizing a string. */
fc_snprintf(buf2, sizeof(buf2), _("\"%s\""), Q_(name->pretty));
strvec_append(vec, buf2);
}
}
if (0 == strvec_size(vec)) {
/* No value. */
fc_assert(0 == value);
/* TRANS: Bitwise setting has no bits set. */
fc_strlcpy(buf, _("empty value"), buf_len);
strvec_destroy(vec);
return buf;
}
strvec_to_and_list(vec, &astr);
strvec_destroy(vec);
fc_strlcpy(buf, astr_str(&astr), buf_len);
astr_free(&astr);
fc_strlcat(buf, " (", buf_len);
len = strlen(buf);
buf += len;
buf_len -= len;
}
/* Long support part. */
buf[0] = '\0';
for (bit = 0; (name = pset->bitwise.name(bit)); bit++) {
if ((1 << bit) & value) {
if ('\0' != buf[0]) {
fc_strlcat(buf, "|", buf_len);
}
fc_strlcat(buf, name->support, buf_len);
}
}
if (pretty) {
fc_strlcat(buf, ")", buf_len);
}
return old_buf;
}
/************************************************************************//**
Returns TRUE if 'val' is a valid value for this setting. If it's not,
the reason of the failure is available in the optional parameter
'reject_msg'.
FIXME: also check the access level of pconn.
****************************************************************************/
static bool setting_bitwise_validate_base(const struct setting *pset,
const char *val,
unsigned *pint_val,
struct connection *caller,
char *reject_msg,
size_t reject_msg_len)
{
char buf[256];
const char *p;
int bit;
if (SST_BITWISE != pset->stype) {
settings_snprintf(reject_msg, reject_msg_len,
_("This setting is not a bitwise."));
return FALSE;
}
*pint_val = 0;
/* Value names are separated by '|'. */
do {
p = strchr(val, '|');
if (NULL != p) {
p++;
fc_strlcpy(buf, val, MIN(p - val, sizeof(buf)));
} else {
/* Last segment, full copy. */
sz_strlcpy(buf, val);
}
remove_leading_trailing_spaces(buf);
if (NULL == p && '\0' == buf[0] && 0 == *pint_val) {
/* Empty string = value 0. */
break;
} else if (!setting_match_prefix(pset->bitwise.name, buf, &bit,
reject_msg, reject_msg_len)) {
return FALSE;
}
*pint_val |= 1 << bit;
val = p;
} while (NULL != p);
return (NULL == pset->bitwise.validate
|| pset->bitwise.validate(*pint_val, caller,
reject_msg, reject_msg_len));
}
/************************************************************************//**
Set the setting to 'val'. Returns TRUE on success. If it fails, the
reason of the failure is available in the optional parameter
'reject_msg'.
****************************************************************************/
bool setting_bitwise_set(struct setting *pset, const char *val,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
unsigned int_val;
if (!setting_is_changeable(pset, caller, reject_msg, reject_msg_len)
|| !setting_bitwise_validate_base(pset, val, &int_val, caller,
reject_msg, reject_msg_len)) {
return FALSE;
}
*pset->bitwise.pvalue = int_val;
return TRUE;
}
/************************************************************************//**
Returns TRUE if 'val' is a valid value for this setting. If it's not,
the reason of the failure is available in the optional parameter
'reject_msg'.
****************************************************************************/
bool setting_bitwise_validate(const struct setting *pset, const char *val,
struct connection *caller, char *reject_msg,
size_t reject_msg_len)
{
unsigned int_val;
return setting_bitwise_validate_base(pset, val, &int_val, caller,
reject_msg, reject_msg_len);
}
/************************************************************************//**
Get value of bitwise setting
****************************************************************************/
int setting_bitwise_get(struct setting *pset)
{
fc_assert(setting_type(pset) == SST_BITWISE);
return *pset->bitwise.pvalue;
}
/************************************************************************//**
Compute the name of the current value of the setting.
****************************************************************************/
const char *setting_value_name(const struct setting *pset, bool pretty,
char *buf, size_t buf_len)
{
fc_assert_ret_val(NULL != pset, NULL);
fc_assert_ret_val(NULL != buf, NULL);
fc_assert_ret_val(0 < buf_len, NULL);
switch (pset->stype) {
case SST_BOOL:
return setting_bool_to_str(pset, *pset->boolean.pvalue,
pretty, buf, buf_len);
case SST_INT:
return setting_int_to_str(pset, *pset->integer.pvalue,
pretty, buf, buf_len);
case SST_STRING:
return setting_str_to_str(pset, pset->string.value,
pretty, buf, buf_len);
case SST_ENUM:
return setting_enum_to_str(pset, read_enum_value(pset),
pretty, buf, buf_len);
case SST_BITWISE:
return setting_bitwise_to_str(pset, *pset->bitwise.pvalue,
pretty, buf, buf_len);
case SST_COUNT:
/* Error logged below. */
break;
}
log_error("%s(): Setting \"%s\" (nb %d) not handled in switch statement.",
__FUNCTION__, setting_name(pset), setting_number(pset));
return NULL;
}
/************************************************************************//**
Compute the name of the default value of the setting.
****************************************************************************/
const char *setting_default_name(const struct setting *pset, bool pretty,
char *buf, size_t buf_len)
{
fc_assert_ret_val(NULL != pset, NULL);
fc_assert_ret_val(NULL != buf, NULL);
fc_assert_ret_val(0 < buf_len, NULL);
switch (pset->stype) {
case SST_BOOL:
return setting_bool_to_str(pset, pset->boolean.default_value,
pretty, buf, buf_len);
case SST_INT:
return setting_int_to_str(pset, pset->integer.default_value,
pretty, buf, buf_len);
case SST_STRING:
return setting_str_to_str(pset, pset->string.default_value,
pretty, buf, buf_len);
case SST_ENUM:
return setting_enum_to_str(pset, pset->enumerator.default_value,
pretty, buf, buf_len);
case SST_BITWISE:
return setting_bitwise_to_str(pset, pset->bitwise.default_value,
pretty, buf, buf_len);
case SST_COUNT:
/* Error logged below. */
break;
}
log_error("%s(): Setting \"%s\" (nb %d) not handled in switch statement.",
__FUNCTION__, setting_name(pset), setting_number(pset));
return NULL;
}
/************************************************************************//**
Update the setting to the default value
****************************************************************************/
void setting_set_to_default(struct setting *pset)
{
switch (pset->stype) {
case SST_BOOL:
(*pset->boolean.pvalue) = pset->boolean.default_value;
break;
case SST_INT:
(*pset->integer.pvalue) = pset->integer.default_value;
break;
case SST_STRING:
fc_strlcpy(pset->string.value, pset->string.default_value,
pset->string.value_size);
break;
case SST_ENUM:
set_enum_value(pset, pset->enumerator.default_value);
break;
case SST_BITWISE:
(*pset->bitwise.pvalue) = pset->bitwise.default_value;
break;
case SST_COUNT:
fc_assert(pset->stype != SST_COUNT);
break;
}
pset->setdef = SETDEF_INTERNAL;
}
/************************************************************************//**
Execute the action callback if needed.
****************************************************************************/
void setting_action(const struct setting *pset)
{
if (pset->action != NULL) {
pset->action(pset);
}
}
/************************************************************************//**
Load game settings from ruleset file 'game.ruleset'.
****************************************************************************/
bool settings_ruleset(struct section_file *file, const char *section,
bool act, bool compat)
{
const char *name;
int j;
/* Unlock all settings. */
settings_iterate(SSET_ALL, pset) {
setting_ruleset_lock_clear(pset);
if (pset->ruleset_settable && !setting_locked(pset)) {
setting_set_to_default(pset);
}
} settings_iterate_end;
/* Settings */
if (NULL == secfile_section_by_name(file, section)) {
/* No settings in ruleset file */
log_verbose("no [%s] section for game settings in %s", section,
secfile_name(file));
} else {
bool rscompat_special_handling = FALSE;
for (j = 0; (name = secfile_lookup_str_default(file, NULL, "%s.set%d.name",
section, j)); j++) {
char path[256];
if (compat && rscompat_setting_needs_special_handling(name)) {
/* Skip this setting for now; handle it later */
rscompat_special_handling = TRUE;
continue;
}
fc_snprintf(path, sizeof(path), "%s.set%d", section, j);
if (compat) {
name = setcompat_current_name_from_previous(name);
}
if (!setting_ruleset_one(file, name, path, compat)) {
log_error("unknown unsettable setting in '%s': %s",
secfile_name(file), name);
}
}
if (compat && rscompat_special_handling) {
rscompat_settings_do_special_handling(file, section,
setting_ruleset_setdef);
}
}
/* Execute all setting actions to consider actions due to the
* default values. */
if (act) {
settings_iterate(SSET_ALL, pset) {
if (pset->ruleset_settable) {
setting_action(pset);
}
} settings_iterate_end;
}
autolock_settings();
/* send game settings */
send_server_settings(NULL);
return TRUE;
}
/***********************************************************************//**
Mark a setting as having been set by the ruleset.
***************************************************************************/
static inline void setting_ruleset_setdef(struct setting *pset)
{
pset->setdef = SETDEF_RULESET;
}
/************************************************************************//**
Set one setting from the game.ruleset file.
****************************************************************************/
static bool setting_ruleset_one(struct section_file *file,
const char *name, const char *path,
bool compat)
{
struct setting *pset = NULL;
char reject_msg[256], buf[256];
bool lock;
struct sf_cb_data info = { pset, compat };
settings_iterate(SSET_ALL, pset_check) {
if (0 == fc_strcasecmp(setting_name(pset_check), name)) {
pset = pset_check;
break;
}
} settings_iterate_end;
if (pset == NULL || !pset->ruleset_settable) {
/* No setting found or it's not settable by ruleset */
return FALSE;
}
if (!setting_locked(pset)) {
info.set = pset;
info.compat = compat;
switch (pset->stype) {
case SST_BOOL:
{
int ival;
bool val;
/* Allow string with same boolean representation as accepted on
* server command line */
if (secfile_lookup_enum_data(file, &ival, FALSE,
setting_bool_secfile_str, pset,
"%s.value", path)) {
val = (ival != 0);
} else if (!secfile_lookup_bool(file, &val, "%s.value", path)) {
log_error("Can't read value for setting '%s': %s", name,
secfile_error());
break;
}
if (val != *pset->boolean.pvalue) {
if (NULL == pset->boolean.validate
|| pset->boolean.validate(val, NULL, reject_msg,
sizeof(reject_msg))) {
*pset->boolean.pvalue = val;
log_normal(_("Ruleset: '%s' has been set to %s."),
setting_name(pset),
setting_value_name(pset, TRUE, buf, sizeof(buf)));
} else {
log_error("%s", reject_msg);
}
}
}
break;
case SST_INT:
{
int val;
if (!secfile_lookup_int(file, &val, "%s.value", path)) {
log_error("Can't read value for setting '%s': %s", name,
secfile_error());
} else if (val != *pset->integer.pvalue) {
if (setting_int_set(pset, val, NULL, reject_msg,
sizeof(reject_msg))) {
log_normal(_("Ruleset: '%s' has been set to %s."),
setting_name(pset),
setting_value_name(pset, TRUE, buf, sizeof(buf)));
} else {
log_error("%s", reject_msg);
}
}
}
break;
case SST_STRING:
{
const char *val = secfile_lookup_str(file, "%s.value", path);
if (NULL == val) {
log_error("Can't read value for setting '%s': %s", name,
secfile_error());
} else if (0 != strcmp(val, pset->string.value)) {
if (setting_str_set(pset, val, NULL, reject_msg,
sizeof(reject_msg))) {
log_normal(_("Ruleset: '%s' has been set to %s."),
setting_name(pset),
setting_value_name(pset, TRUE, buf, sizeof(buf)));
} else {
log_error("%s", reject_msg);
}
}
}
break;
case SST_ENUM:
{
int val;
if (!secfile_lookup_enum_data(file, &val, FALSE,
setting_enum_secfile_str, &info,
"%s.value", path)) {
log_error("Can't read value for setting '%s': %s",
name, secfile_error());
} else if (val != read_enum_value(pset)) {
if (NULL == pset->enumerator.validate
|| pset->enumerator.validate(val, NULL, reject_msg,
sizeof(reject_msg))) {
set_enum_value(pset, val);
log_normal(_("Ruleset: '%s' has been set to %s."),
setting_name(pset),
setting_value_name(pset, TRUE, buf, sizeof(buf)));
} else {
log_error("%s", reject_msg);
}
}
}
break;
case SST_BITWISE:
{
int val;
if (!secfile_lookup_enum_data(file, &val, TRUE,
setting_bitwise_secfile_str, &info,
"%s.value", path)) {
log_error("Can't read value for setting '%s': %s",
name, secfile_error());
} else if (val != *pset->bitwise.pvalue) {
/* RSFORMAT_3_1 */
if (compat && !fc_strcasecmp("topology", name)) {
struct setting *wrap = setting_by_name("wrap");
if (val & TF_OLD_WRAPX) {
if (val & TF_OLD_WRAPY) {
setting_bitwise_set(wrap, "WrapX|WrapY", NULL, NULL, 0);
} else {
setting_bitwise_set(wrap, "WrapX", NULL, NULL, 0);
}
} else if (val & TF_OLD_WRAPY) {
setting_bitwise_set(wrap, "WrapY", NULL, NULL, 0);
} else {
setting_bitwise_set(wrap, "", NULL, NULL, 0);
}
val &= ~(TF_OLD_WRAPX | TF_OLD_WRAPY);
log_normal(_("Ruleset: '%s' has been set to %s."),
setting_name(wrap),
setting_value_name(wrap, TRUE, buf, sizeof(buf)));
}
if (NULL == pset->bitwise.validate
|| pset->bitwise.validate((unsigned) val, NULL,
reject_msg, sizeof(reject_msg))) {
*pset->bitwise.pvalue = val;
log_normal(_("Ruleset: '%s' has been set to %s."),
setting_name(pset),
setting_value_name(pset, TRUE, buf, sizeof(buf)));
} else {
log_error("%s", reject_msg);
}
}
}
break;
case SST_COUNT:
fc_assert(pset->stype != SST_COUNT);
break;
}
setting_ruleset_setdef(pset);
}
/* set lock */
lock = secfile_lookup_bool_default(file, FALSE, "%s.lock", path);
if (lock) {
/* Set lock */
setting_ruleset_lock_set(pset);
log_normal(_("Ruleset: '%s' has been locked by the ruleset."),
setting_name(pset));
}
return TRUE;
}
/************************************************************************//**
Returns whether the setting has non-default value.
****************************************************************************/
bool setting_non_default(const struct setting *pset)
{
switch (setting_type(pset)) {
case SST_BOOL:
return (*pset->boolean.pvalue != pset->boolean.default_value);
case SST_INT:
return (*pset->integer.pvalue != pset->integer.default_value);
case SST_STRING:
return (0 != strcmp(pset->string.value, pset->string.default_value));
case SST_ENUM:
return (read_enum_value(pset) != pset->enumerator.default_value);
case SST_BITWISE:
return (*pset->bitwise.pvalue != pset->bitwise.default_value);
case SST_COUNT:
/* Error logged below. */
break;
}
log_error("%s(): Setting \"%s\" (nb %d) not handled in switch statement.",
__FUNCTION__, setting_name(pset), setting_number(pset));
return FALSE;
}
/************************************************************************//**
Returns if the setting is locked by the ruleset.
****************************************************************************/
bool setting_locked(const struct setting *pset)
{
return pset->lock != SLOCK_NONE;
}
/************************************************************************//**
Returns if the setting is locked by the ruleset.
****************************************************************************/
bool setting_ruleset_locked(const struct setting *pset)
{
return pset->rslock;
}
/************************************************************************//**
Set ruleset level lock for the setting
****************************************************************************/
void setting_ruleset_lock_set(struct setting *pset)
{
if (pset->lock < SLOCK_RULESET) {
/* No downgrading the lock */
pset->lock = SLOCK_RULESET;
}
pset->rslock = TRUE;
}
/************************************************************************//**
Set admin level lock for the setting
****************************************************************************/
void setting_admin_lock_set(struct setting *pset)
{
pset->lock = SLOCK_ADMIN;
}
/************************************************************************//**
Clear ruleset level lock from the setting
****************************************************************************/
void setting_ruleset_lock_clear(struct setting *pset)
{
if (pset->lock == SLOCK_RULESET) {
/* No clearing upper level locks */
pset->lock = SLOCK_RULESET;
}
pset->rslock = FALSE;
}
/************************************************************************//**
Clear admin level lock from the setting
****************************************************************************/
void setting_admin_lock_clear(struct setting *pset)
{
if (pset->rslock) {
pset->lock = SLOCK_RULESET;
} else {
pset->lock = SLOCK_NONE;
}
}
/************************************************************************//**
Save the setting value of the current game.
****************************************************************************/
static void setting_game_set(struct setting *pset, bool init)
{
switch (setting_type(pset)) {
case SST_BOOL:
pset->boolean.game_value = *pset->boolean.pvalue;
break;
case SST_INT:
pset->integer.game_value = *pset->integer.pvalue;
break;
case SST_STRING:
if (init) {
pset->string.game_value
= fc_calloc(1, pset->string.value_size
* sizeof(pset->string.game_value));
}
fc_strlcpy(pset->string.game_value, pset->string.value,
pset->string.value_size);
break;
case SST_ENUM:
pset->enumerator.game_value = read_enum_value(pset);
break;
case SST_BITWISE:
pset->bitwise.game_value = *pset->bitwise.pvalue;
break;
case SST_COUNT:
fc_assert(setting_type(pset) != SST_COUNT);
break;
}
pset->game_setdef = pset->setdef;
}
/************************************************************************//**
Free the memory used for the settings at game start.
****************************************************************************/
static void setting_game_free(struct setting *pset)
{
if (setting_type(pset) == SST_STRING) {
FC_FREE(pset->string.game_value);
}
}
/************************************************************************//**
Restore the setting to the value used at the start of the current game.
****************************************************************************/
static void setting_game_restore(struct setting *pset)
{
char reject_msg[256] = "", buf[256];
bool res = FALSE;
if (!setting_is_changeable(pset, NULL, reject_msg, sizeof(reject_msg))) {
log_debug("Can't restore '%s': %s", setting_name(pset),
reject_msg);
return;
}
if (pset->game_setdef == SETDEF_INTERNAL) {
setting_set_to_default(pset);
return;
}
switch (setting_type(pset)) {
case SST_BOOL:
res = (NULL != setting_bool_to_str(pset, pset->boolean.game_value,
FALSE, buf, sizeof(buf))
&& setting_bool_set(pset, buf, NULL, reject_msg,
sizeof(reject_msg)));
break;
case SST_INT:
res = setting_int_set(pset, pset->integer.game_value, NULL, reject_msg,
sizeof(reject_msg));
break;
case SST_STRING:
res = setting_str_set(pset, pset->string.game_value, NULL, reject_msg,
sizeof(reject_msg));
break;
case SST_ENUM:
res = (NULL != setting_enum_to_str(pset, pset->enumerator.game_value,
FALSE, buf, sizeof(buf))
&& setting_enum_set(pset, buf, NULL, reject_msg,
sizeof(reject_msg)));
break;
case SST_BITWISE:
res = (NULL != setting_bitwise_to_str(pset, pset->bitwise.game_value,
FALSE, buf, sizeof(buf))
&& setting_bitwise_set(pset, buf, NULL, reject_msg,
sizeof(reject_msg)));
break;
case SST_COUNT:
res = FALSE;
break;
}
if (!res) {
log_error("Error restoring setting '%s' to the value from game start: "
"%s", setting_name(pset), reject_msg);
}
}
/************************************************************************//**
Save setting values at the start of the game.
****************************************************************************/
void settings_game_start(void)
{
settings_iterate(SSET_ALL, pset) {
setting_game_set(pset, FALSE);
} settings_iterate_end;
/* Settings from the start of the game are saved. */
game.server.settings_gamestart_valid = TRUE;
}
/************************************************************************//**
Save game settings.
****************************************************************************/
void settings_game_save(struct section_file *file, const char *section)
{
int set_count = 0;
settings_iterate(SSET_ALL, pset) {
char errbuf[200];
struct sf_cb_data info = { pset, FALSE };
if (/* It's explicitly set to some value to save */
setting_get_setdef(pset) == SETDEF_CHANGED
/* It must be same at loading time as it was saving time, even if
* freeciv's default has changed. */
|| !setting_is_free_to_change(pset, errbuf, sizeof(errbuf))) {
bool gamestart = game.server.settings_gamestart_valid;
secfile_insert_str(file, setting_name(pset),
"%s.set%d.name", section, set_count);
switch (setting_type(pset)) {
case SST_BOOL:
secfile_insert_bool(file, *pset->boolean.pvalue,
"%s.set%d.value", section, set_count);
if (gamestart) {
secfile_insert_bool(file, pset->boolean.game_value,
"%s.set%d.gamestart", section, set_count);
}
break;
case SST_INT:
secfile_insert_int(file, *pset->integer.pvalue,
"%s.set%d.value", section, set_count);
if (gamestart) {
secfile_insert_int(file, pset->integer.game_value,
"%s.set%d.gamestart", section, set_count);
}
break;
case SST_STRING:
secfile_insert_str(file, pset->string.value,
"%s.set%d.value", section, set_count);
if (gamestart) {
secfile_insert_str(file, pset->string.game_value,
"%s.set%d.gamestart", section, set_count);
}
break;
case SST_ENUM:
secfile_insert_enum_data(file, read_enum_value(pset), FALSE,
setting_enum_secfile_str, &info,
"%s.set%d.value", section, set_count);
if (gamestart) {
secfile_insert_enum_data(file, pset->enumerator.game_value, FALSE,
setting_enum_secfile_str, &info,
"%s.set%d.gamestart", section, set_count);
}
break;
case SST_BITWISE:
secfile_insert_enum_data(file, *pset->bitwise.pvalue, TRUE,
setting_bitwise_secfile_str, &info,
"%s.set%d.value", section, set_count);
if (gamestart) {
secfile_insert_enum_data(file, pset->bitwise.game_value, TRUE,
setting_bitwise_secfile_str, &info,
"%s.set%d.gamestart", section, set_count);
}
break;
case SST_COUNT:
fc_assert(setting_type(pset) != SST_COUNT);
secfile_insert_str(file, "Unknown setting type",
"%s.set%d.value", section, set_count);
if (gamestart) {
secfile_insert_str(file, "Unknown setting type",
"%s.set%d.gamestart", section, set_count);
}
break;
}
if (gamestart) {
secfile_insert_str(file, setting_default_level_name(pset->game_setdef),
"%s.set%d.gamesetdef", section, set_count);
}
set_count++;
}
} settings_iterate_end;
secfile_insert_int(file, set_count, "%s.set_count", section);
secfile_insert_bool(file, game.server.settings_gamestart_valid,
"%s.gamestart_valid", section);
}
/************************************************************************//**
Restore all settings from a savegame.
****************************************************************************/
void settings_game_load(struct section_file *file, const char *section)
{
const char *name;
char reject_msg[256], buf[256];
int i, set_count;
int oldcitymindist = game.info.citymindist; /* backwards compat, see below */
/* Compatibility with savegames created with older versions is usually
* handled as conversions in savecompat.c compat_load_<version>() */
if (!secfile_lookup_int(file, &set_count, "%s.set_count", section)) {
/* Old savegames and scenarios doesn't contain this, not an error. */
log_verbose("Can't read the number of settings in the save file.");
return;
}
/* Check if the saved settings are valid settings from game start. */
game.server.settings_gamestart_valid
= secfile_lookup_bool_default(file, FALSE, "%s.gamestart_valid",
section);
for (i = 0; i < set_count; i++) {
name = secfile_lookup_str(file, "%s.set%d.name", section, i);
settings_iterate(SSET_ALL, pset) {
struct sf_cb_data info = { pset, FALSE };
if (fc_strcasecmp(setting_name(pset), name) != 0) {
continue;
}
/* Load the current value of the setting. */
switch (pset->stype) {
case SST_BOOL:
{
bool val;
if (!secfile_lookup_bool(file, &val, "%s.set%d.value", section,
i)) {
log_verbose("Option '%s' not defined in the savegame: %s", name,
secfile_error());
} else {
pset->setdef = SETDEF_CHANGED;
if (val != *pset->boolean.pvalue) {
if (setting_is_changeable(pset, NULL, reject_msg,
sizeof(reject_msg))
&& (NULL == pset->boolean.validate
|| pset->boolean.validate(val, NULL, reject_msg,
sizeof(reject_msg)))) {
*pset->boolean.pvalue = val;
log_normal(_("Savegame: '%s' has been set to %s."),
setting_name(pset),
setting_value_name(pset, TRUE, buf, sizeof(buf)));
} else {
log_error("Savegame: error restoring '%s' . (%s)",
setting_name(pset), reject_msg);
}
} else {
log_normal(_("Savegame: '%s' explicitly set to value same as default."),
setting_name(pset));
}
}
}
break;
case SST_INT:
{
int val;
if (!secfile_lookup_int(file, &val, "%s.set%d.value", section, i)) {
log_verbose("Option '%s' not defined in the savegame: %s", name,
secfile_error());
} else {
pset->setdef = SETDEF_CHANGED;
if (val != *pset->integer.pvalue) {
if (setting_is_changeable(pset, NULL, reject_msg,
sizeof(reject_msg))
&& (NULL == pset->integer.validate
|| pset->integer.validate(val, NULL, reject_msg,
sizeof(reject_msg)))) {
*pset->integer.pvalue = val;
log_normal(_("Savegame: '%s' has been set to %s."),
setting_name(pset),
setting_value_name(pset, TRUE, buf, sizeof(buf)));
} else {
log_error("Savegame: error restoring '%s' . (%s)",
setting_name(pset), reject_msg);
}
} else {
log_normal(_("Savegame: '%s' explicitly set to value same as default."),
setting_name(pset));
}
}
}
break;
case SST_STRING:
{
const char *val = secfile_lookup_str(file, "%s.set%d.value",
section, i);
if (NULL == val) {
log_verbose("Option '%s' not defined in the savegame: %s", name,
secfile_error());
} else {
pset->setdef = SETDEF_CHANGED;
if (0 != strcmp(val, pset->string.value)) {
if (setting_str_set(pset, val, NULL, reject_msg,
sizeof(reject_msg))) {
log_normal(_("Savegame: '%s' has been set to %s."),
setting_name(pset),
setting_value_name(pset, TRUE, buf, sizeof(buf)));
} else {
log_error("Savegame: error restoring '%s' . (%s)",
setting_name(pset), reject_msg);
}
} else {
log_normal(_("Savegame: '%s' explicitly set to value same as default."),
setting_name(pset));
}
}
}
break;
case SST_ENUM:
{
int val;
if (!secfile_lookup_enum_data(file, &val, FALSE,
setting_enum_secfile_str, &info,
"%s.set%d.value", section, i)) {
log_verbose("Option '%s' not defined in the savegame: %s", name,
secfile_error());
} else {
pset->setdef = SETDEF_CHANGED;
if (val != read_enum_value(pset)) {
if (setting_is_changeable(pset, NULL, reject_msg,
sizeof(reject_msg))
&& (NULL == pset->enumerator.validate
|| pset->enumerator.validate(val, NULL, reject_msg,
sizeof(reject_msg)))) {
set_enum_value(pset, val);
log_normal(_("Savegame: '%s' has been set to %s."),
setting_name(pset),
setting_value_name(pset, TRUE, buf, sizeof(buf)));
} else {
log_error("Savegame: error restoring '%s' . (%s)",
setting_name(pset), reject_msg);
}
} else {
log_normal(_("Savegame: '%s' explicitly set to value same as default."),
setting_name(pset));
}
}
}
break;
case SST_BITWISE:
{
int val;
if (!secfile_lookup_enum_data(file, &val, TRUE,
setting_bitwise_secfile_str, &info,
"%s.set%d.value", section, i)) {
log_verbose("Option '%s' not defined in the savegame: %s", name,
secfile_error());
} else {
pset->setdef = SETDEF_CHANGED;
if (val != *pset->bitwise.pvalue) {
if (setting_is_changeable(pset, NULL, reject_msg,
sizeof(reject_msg))
&& (NULL == pset->bitwise.validate
|| pset->bitwise.validate(val, NULL, reject_msg,
sizeof(reject_msg)))) {
*pset->bitwise.pvalue = val;
log_normal(_("Savegame: '%s' has been set to %s."),
setting_name(pset),
setting_value_name(pset, TRUE, buf, sizeof(buf)));
} else {
log_error("Savegame: error restoring '%s' . (%s)",
setting_name(pset), reject_msg);
}
} else {
log_normal(_("Savegame: '%s' explicitly set to value same as default."),
setting_name(pset));
}
}
}
break;
case SST_COUNT:
fc_assert(pset->stype != SST_COUNT);
break;
}
if (game.server.settings_gamestart_valid) {
const char *sdname;
/* Load the value of the setting at the start of the game. */
switch (pset->stype) {
case SST_BOOL:
pset->boolean.game_value =
secfile_lookup_bool_default(file, *pset->boolean.pvalue,
"%s.set%d.gamestart", section, i);
break;
case SST_INT:
pset->integer.game_value =
secfile_lookup_int_default(file, *pset->integer.pvalue,
"%s.set%d.gamestart", section, i);
break;
case SST_STRING:
fc_strlcpy(pset->string.game_value,
secfile_lookup_str_default(file, pset->string.value,
"%s.set%d.gamestart",
section, i),
pset->string.value_size);
break;
case SST_ENUM:
pset->enumerator.game_value =
secfile_lookup_enum_default_data(file,
read_enum_value(pset), FALSE, setting_enum_secfile_str,
&info, "%s.set%d.gamestart", section, i);
break;
case SST_BITWISE:
pset->bitwise.game_value =
secfile_lookup_enum_default_data(file,
*pset->bitwise.pvalue, TRUE, setting_bitwise_secfile_str,
&info, "%s.set%d.gamestart", section, i);
break;
case SST_COUNT:
fc_assert(pset->stype != SST_COUNT);
break;
}
sdname
= secfile_lookup_str_default(file,
setting_default_level_name(SETDEF_CHANGED),
"%s.set%d.gamesetdef", section, i);
pset->game_setdef = setting_default_level_by_name(sdname,
fc_strcasecmp);
if (!setting_default_level_is_valid(pset->game_setdef)) {
log_error("Setting %s has invalid gamesetdef value %s",
setting_name(pset), sdname);
pset->game_setdef = SETDEF_CHANGED;
}
} else {
pset->game_setdef = SETDEF_CHANGED;
}
} settings_iterate_end;
}
/* Backwards compatibility for pre-2.4 savegames: citymindist=0 used to mean
* take from ruleset min_dist_bw_cities, but that no longer exists.
* This is here rather than in savegame2.c compat functions, as we need
* to have loaded the relevant ruleset to know what to set it to (the
* ruleset and any 'citymindist' setting it contains will have been loaded
* before this function was called). */
if (game.info.citymindist == 0) {
game.info.citymindist = oldcitymindist;
}
settings_iterate(SSET_ALL, pset) {
/* Have to do this at the end due to dependencies ('aifill' and
* 'maxplayer'). */
setting_action(pset);
} settings_iterate_end;
}
/************************************************************************//**
Reset all settings to the values at game start.
****************************************************************************/
bool settings_game_reset(void)
{
if (!game.server.settings_gamestart_valid) {
log_debug("No saved settings from the game start available.");
return FALSE;
}
settings_iterate(SSET_ALL, pset) {
setting_game_restore(pset);
} settings_iterate_end;
return TRUE;
}
/************************************************************************//**
Initialize stuff related to this code module.
****************************************************************************/
void settings_init(bool act)
{
settings_list_init();
settings_iterate(SSET_ALL, pset) {
setting_ruleset_lock_clear(pset);
setting_admin_lock_clear(pset);
setting_set_to_default(pset);
setting_game_set(pset, TRUE);
if (act) {
setting_action(pset);
}
} settings_iterate_end;
settings_list_update();
}
/************************************************************************//**
Reset all settings iff they are changeable.
****************************************************************************/
void settings_reset(void)
{
settings_iterate(SSET_ALL, pset) {
if (setting_is_changeable(pset, NULL, NULL, 0)) {
setting_set_to_default(pset);
setting_action(pset);
}
} settings_iterate_end;
}
/************************************************************************//**
Update stuff every turn that is related to this code module. Run this
on turn end.
****************************************************************************/
void settings_turn(void)
{
/* Nothing at the moment. */
}
/************************************************************************//**
Deinitialize stuff related to this code module.
****************************************************************************/
void settings_free(void)
{
settings_iterate(SSET_ALL, pset) {
setting_game_free(pset);
} settings_iterate_end;
settings_list_free();
}
/************************************************************************//**
Returns the total number of settings.
****************************************************************************/
int settings_number(void)
{
return SETTINGS_NUM;
}
/************************************************************************//**
Tell the client about just one server setting. Call this after a setting
is saved.
****************************************************************************/
void send_server_setting(struct conn_list *dest, const struct setting *pset)
{
if (!dest) {
dest = game.est_connections;
}
#define PACKET_COMMON_INIT(packet, pset, pconn) \
memset(&packet, 0, sizeof(packet)); \
packet.id = setting_number(pset); \
packet.is_visible = setting_is_visible(pset, pconn); \
packet.is_changeable = setting_is_changeable(pset, pconn, NULL, 0); \
packet.initial_setting = game.info.is_new_game; \
packet.setdef = setting_get_setdef(pset);
switch (setting_type(pset)) {
case SST_BOOL:
{
struct packet_server_setting_bool packet;
conn_list_iterate(dest, pconn) {
PACKET_COMMON_INIT(packet, pset, pconn);
if (packet.is_visible) {
packet.val = *pset->boolean.pvalue;
packet.default_val = pset->boolean.default_value;
}
send_packet_server_setting_bool(pconn, &packet);
} conn_list_iterate_end;
}
break;
case SST_INT:
{
struct packet_server_setting_int packet;
conn_list_iterate(dest, pconn) {
PACKET_COMMON_INIT(packet, pset, pconn);
if (packet.is_visible) {
packet.val = *pset->integer.pvalue;
packet.default_val = pset->integer.default_value;
packet.min_val = pset->integer.min_value;
packet.max_val = pset->integer.max_value;
}
send_packet_server_setting_int(pconn, &packet);
} conn_list_iterate_end;
}
break;
case SST_STRING:
{
struct packet_server_setting_str packet;
conn_list_iterate(dest, pconn) {
PACKET_COMMON_INIT(packet, pset, pconn);
if (packet.is_visible) {
sz_strlcpy(packet.val, pset->string.value);
sz_strlcpy(packet.default_val, pset->string.default_value);
}
send_packet_server_setting_str(pconn, &packet);
} conn_list_iterate_end;
}
break;
case SST_ENUM:
{
struct packet_server_setting_enum packet;
const struct sset_val_name *val_name;
int i;
conn_list_iterate(dest, pconn) {
PACKET_COMMON_INIT(packet, pset, pconn);
if (packet.is_visible) {
packet.val = read_enum_value(pset);
packet.default_val = pset->enumerator.default_value;
for (i = 0; (val_name = pset->enumerator.name(i)); i++) {
sz_strlcpy(packet.support_names[i], val_name->support);
/* Send untranslated string */
sz_strlcpy(packet.pretty_names[i], val_name->pretty);
}
packet.values_num = i;
fc_assert(i <= ARRAY_SIZE(packet.support_names));
fc_assert(i <= ARRAY_SIZE(packet.pretty_names));
}
send_packet_server_setting_enum(pconn, &packet);
} conn_list_iterate_end;
}
break;
case SST_BITWISE:
{
struct packet_server_setting_bitwise packet;
const struct sset_val_name *val_name;
int i;
conn_list_iterate(dest, pconn) {
PACKET_COMMON_INIT(packet, pset, pconn);
if (packet.is_visible) {
packet.val = *pset->bitwise.pvalue;
packet.default_val = pset->bitwise.default_value;
for (i = 0; (val_name = pset->bitwise.name(i)); i++) {
sz_strlcpy(packet.support_names[i], val_name->support);
/* Send untranslated string */
sz_strlcpy(packet.pretty_names[i], val_name->pretty);
}
packet.bits_num = i;
fc_assert(i <= ARRAY_SIZE(packet.support_names));
fc_assert(i <= ARRAY_SIZE(packet.pretty_names));
}
send_packet_server_setting_bitwise(pconn, &packet);
} conn_list_iterate_end;
}
break;
case SST_COUNT:
fc_assert(setting_type(pset) != SST_COUNT);
break;
}
#undef PACKET_INIT
}
/************************************************************************//**
Tell the client about all server settings.
****************************************************************************/
void send_server_settings(struct conn_list *dest)
{
settings_iterate(SSET_ALL, pset) {
send_server_setting(dest, pset);
} settings_iterate_end;
}
/************************************************************************//**
Send the server settings that got a different visibility or changability
after a connection access level change. Usually called when the access
level of the user changes.
****************************************************************************/
void send_server_access_level_settings(struct conn_list *dest,
enum cmdlevel old_level,
enum cmdlevel new_level)
{
enum cmdlevel min_level;
enum cmdlevel max_level;
if (old_level == new_level) {
return;
}
if (old_level < new_level) {
min_level = old_level;
max_level = new_level;
} else {
min_level = new_level;
max_level = old_level;
}
settings_iterate(SSET_ALL, pset) {
if ((pset->access_level_read >= min_level
&& pset->access_level_read <= max_level)
|| (pset->access_level_write >= min_level
&& pset->access_level_write <= max_level)) {
send_server_setting(dest, pset);
}
} settings_iterate_end;
}
/************************************************************************//**
Tell the client about all server settings.
****************************************************************************/
void send_server_setting_control(struct connection *pconn)
{
struct packet_server_setting_control control;
struct packet_server_setting_const setting;
int i;
control.settings_num = SETTINGS_NUM;
/* Fill in the category strings. */
fc_assert(SSET_NUM_CATEGORIES <= ARRAY_SIZE(control.category_names));
control.categories_num = SSET_NUM_CATEGORIES;
for (i = 0; i < SSET_NUM_CATEGORIES; i++) {
/* Send untranslated name */
sz_strlcpy(control.category_names[i], sset_category_name(i));
}
/* Send off the control packet. */
send_packet_server_setting_control(pconn, &control);
pconn->server.settings_sent = TRUE;
/* Send the constant and common part of the settings. */
settings_iterate(SSET_ALL, pset) {
setting.id = setting_number(pset);
sz_strlcpy(setting.name, setting_name(pset));
/* Send untranslated strings to client */
sz_strlcpy(setting.short_help, setting_short_help(pset));
sz_strlcpy(setting.extra_help, setting_extra_help(pset, TRUE));
setting.category = pset->scategory;
send_packet_server_setting_const(pconn, &setting);
} settings_iterate_end;
}
/************************************************************************//**
Initialise sorted settings.
****************************************************************************/
static void settings_list_init(void)
{
struct setting *pset;
int i;
fc_assert_ret(!setting_sorted.init);
/* Do it for all values of enum sset_level. */
for (i = 0; i < OLEVELS_NUM; i++) {
setting_sorted.level[i] = setting_list_new();
}
for (i = 0; (pset = setting_by_number(i)); i++) {
/* Add the setting to the list of all settings. */
setting_list_append(setting_sorted.level[SSET_ALL], pset);
switch (setting_level(pset)) {
case SSET_NONE:
/* No setting should be in this level. */
fc_assert_msg(setting_level(pset) != SSET_NONE,
"No setting level defined for '%s'.", setting_name(pset));
break;
case SSET_ALL:
/* Done above - list of all settings. */
break;
case SSET_VITAL:
setting_list_append(setting_sorted.level[SSET_VITAL], pset);
break;
case SSET_SITUATIONAL:
setting_list_append(setting_sorted.level[SSET_SITUATIONAL], pset);
break;
case SSET_RARE:
setting_list_append(setting_sorted.level[SSET_RARE], pset);
break;
case SSET_CHANGED:
case SSET_LOCKED:
/* This is done in settings_list_update. */
break;
case OLEVELS_NUM:
/* No setting should be in this level. */
fc_assert_msg(setting_level(pset) != OLEVELS_NUM,
"Invalid setting level for '%s' (%s).",
setting_name(pset), sset_level_name(setting_level(pset)));
break;
}
}
/* Sort the lists. */
for (i = 0; i < OLEVELS_NUM; i++) {
setting_list_sort(setting_sorted.level[i], settings_list_cmp);
}
setting_sorted.init = TRUE;
}
/************************************************************************//**
Update sorted settings (changed and locked values).
****************************************************************************/
void settings_list_update(void)
{
struct setting *pset;
int i;
fc_assert_ret(setting_sorted.init);
/* Clear the lists for changed and locked values. */
setting_list_clear(setting_sorted.level[SSET_CHANGED]);
setting_list_clear(setting_sorted.level[SSET_LOCKED]);
/* Refill them. */
for (i = 0; (pset = setting_by_number(i)); i++) {
if (setting_non_default(pset)) {
setting_list_append(setting_sorted.level[SSET_CHANGED], pset);
}
if (setting_locked(pset)) {
setting_list_append(setting_sorted.level[SSET_LOCKED], pset);
}
}
/* Sort them. */
setting_list_sort(setting_sorted.level[SSET_CHANGED], settings_list_cmp);
setting_list_sort(setting_sorted.level[SSET_LOCKED], settings_list_cmp);
}
/************************************************************************//**
Update sorted settings (changed and locked values).
****************************************************************************/
int settings_list_cmp(const struct setting *const *ppset1,
const struct setting *const *ppset2)
{
const struct setting *pset1 = *ppset1;
const struct setting *pset2 = *ppset2;
return fc_strcasecmp(setting_name(pset1), setting_name(pset2));
}
/************************************************************************//**
Get a settings list of a certain level. Call settings_list_update() before
if something was changed.
****************************************************************************/
struct setting_list *settings_list_get(enum sset_level level)
{
fc_assert_ret_val(setting_sorted.init, NULL);
fc_assert_ret_val(setting_sorted.level[level] != NULL, NULL);
fc_assert_ret_val(sset_level_is_valid(level), NULL);
return setting_sorted.level[level];
}
/************************************************************************//**
Free sorted settings.
****************************************************************************/
static void settings_list_free(void)
{
int i;
fc_assert_ret(setting_sorted.init);
/* Free the lists. */
for (i = 0; i < OLEVELS_NUM; i++) {
setting_list_destroy(setting_sorted.level[i]);
}
setting_sorted.init = FALSE;
}
/************************************************************************//**
Mark setting changed
****************************************************************************/
void setting_changed(struct setting *pset)
{
pset->setdef = SETDEF_CHANGED;
}
/************************************************************************//**
Is the setting in changed state, or the default
****************************************************************************/
enum setting_default_level setting_get_setdef(const struct setting *pset)
{
return pset->setdef;
}
|