File: options.c

package info (click to toggle)
freeciv 2.6.2-1~bpo10+1
  • links: PTS, VCS
  • area: main
  • in suites: buster-backports
  • size: 212,500 kB
  • sloc: ansic: 443,831; cpp: 29,541; sh: 7,982; makefile: 7,886; python: 1,933; xml: 945
file content (6357 lines) | stat: -rw-r--r-- 275,061 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
/***********************************************************************
 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
***********************************************************************/

#ifdef HAVE_CONFIG_H
#include <fc_config.h>
#endif

#include <stdarg.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>

/* utility */
#include "capability.h"
#include "fcintl.h"
#include "ioz.h"
#include "log.h"
#include "mem.h"
#include "registry.h"
#include "shared.h"
#include "string_vector.h"
#include "support.h"

/* common */
#include "events.h"
#include "version.h"

/* client/agents */
#include "cma_fec.h"

/* client/include */
#include "chatline_g.h"
#include "dialogs_g.h"
#include "gui_main_g.h"
#include "menu_g.h"
#include "optiondlg_g.h"
#include "repodlgs_g.h"
#include "voteinfo_bar_g.h"

/* client */
#include "audio.h"
#include "cityrepdata.h"
#include "client_main.h"
#include "climisc.h"
#include "connectdlg_common.h"
#include "global_worklist.h"
#include "mapctrl_common.h"
#include "mapview_common.h"
#include "music.h"
#include "overview_common.h"
#include "packhand_gen.h"
#include "plrdlg_common.h"
#include "repodlgs_common.h"
#include "servers.h"
#include "themes_common.h"
#include "tilespec.h"

#include "options.h"


struct client_options gui_options = {
/** Defaults for options normally on command line **/

  .default_user_name = "\0",
  .default_server_host = "localhost",
  .default_server_port = DEFAULT_SOCK_PORT,
  .default_metaserver = DEFAULT_METASERVER_OPTION,
  .default_tileset_overhead_name = "\0",
  .default_tileset_iso_name = "\0",
  .default_tileset_hex_name = "\0",
  .default_tileset_isohex_name = "\0",
  .default_sound_set_name = "stdsounds",
  .default_music_set_name = "stdmusic",
  .default_sound_plugin_name = "\0",
  .default_chat_logfile = GUI_DEFAULT_CHAT_LOGFILE,

  .save_options_on_exit = TRUE,

  .use_prev_server = FALSE,
  .heartbeat_enabled = FALSE,

/** Migrations **/
  .first_boot = FALSE,
  .default_tileset_name = "\0",
  .gui_gtk3_22_migrated_from_gtk3 = FALSE,
  .gui_gtk3_migrated_from_gtk2 = FALSE,
  .gui_sdl2_migrated_from_sdl = FALSE,
  .gui_gtk2_migrated_from_2_5 = FALSE,
  .gui_gtk3_migrated_from_2_5 = FALSE,
  .gui_qt_migrated_from_2_5 = FALSE,

  .migrate_fullscreen = FALSE,

/** Local Options: **/

  .solid_color_behind_units = FALSE,
  .sound_bell_at_new_turn = FALSE,
  .smooth_move_unit_msec = 30,
  .smooth_center_slide_msec = 200,
  .smooth_combat_step_msec = 10,
  .ai_manual_turn_done = TRUE,
  .auto_center_on_unit = TRUE,
  .auto_center_on_automated = TRUE,
  .auto_center_on_combat = FALSE,
  .auto_center_each_turn = TRUE,
  .wakeup_focus = TRUE,
  .goto_into_unknown = TRUE,
  .center_when_popup_city = TRUE,
  .concise_city_production = FALSE,
  .auto_turn_done = FALSE,
  .meta_accelerators = TRUE,
  .ask_city_name = TRUE,
  .popup_new_cities = TRUE,
  .popup_actor_arrival = TRUE,
  .keyboardless_goto = TRUE,
  .enable_cursor_changes = TRUE,
  .separate_unit_selection = FALSE,
  .unit_selection_clears_orders = TRUE,
  .highlight_our_names = FT_COLOR("#000000", "#FFFF00"),

  .voteinfo_bar_use = TRUE,
  .voteinfo_bar_always_show = FALSE,
  .voteinfo_bar_hide_when_not_player = FALSE,
  .voteinfo_bar_new_at_front = FALSE,

  .autoaccept_tileset_suggestion = FALSE,
  .autoaccept_soundset_suggestion = FALSE,
  .autoaccept_musicset_suggestion = FALSE,

  .sound_enable_effects = TRUE,
  .sound_enable_menu_music = TRUE,
  .sound_enable_game_music = TRUE,

/* This option is currently set by the client - not by the user. */
  .update_city_text_in_refresh_tile = TRUE,

  .draw_city_outlines = TRUE,
  .draw_city_output = FALSE,
  .draw_map_grid = FALSE,
  .draw_city_names = TRUE,
  .draw_city_growth = TRUE,
  .draw_city_productions = TRUE,
  .draw_city_buycost = FALSE,
  .draw_city_trade_routes = FALSE,
  .draw_terrain = TRUE,
  .draw_coastline = FALSE,
  .draw_roads_rails = TRUE,
  .draw_irrigation = TRUE,
  .draw_mines = TRUE,
  .draw_fortress_airbase = TRUE,
  .draw_specials = TRUE,
  .draw_huts = TRUE,
  .draw_pollution = TRUE,
  .draw_cities = TRUE,
  .draw_units = TRUE,
  .draw_focus_unit = FALSE,
  .draw_fog_of_war = TRUE,
  .draw_borders = TRUE,
  .draw_native = FALSE,
  .draw_full_citybar = TRUE,
  .draw_unit_shields = TRUE,
  .player_dlg_show_dead_players = TRUE,
  .reqtree_show_icons = TRUE,
  .reqtree_curved_lines = FALSE,

/* options for map images */
/*  .mapimg_format, */
  .mapimg_zoom = 2,
/* See the definition of MAPIMG_LAYER in mapimg.h. */
  .mapimg_layer = {
    FALSE, /* a - MAPIMG_LAYER_AREA */
    TRUE,  /* b - MAPIMG_LAYER_BORDERS */
    TRUE,  /* c - MAPIMG_LAYER_CITIES */
    TRUE,  /* f - MAPIMG_LAYER_FOGOFWAR */
    TRUE,  /* k - MAPIMG_LAYER_KNOWLEDGE */
    TRUE,  /* t - MAPIMG_LAYER_TERRAIN */
    TRUE   /* u - MAPIMG_LAYER_UNITS */
  },
/*  .mapimg_filename, */

  .zoom_set = FALSE,
  .zoom_default_level = 1.0,

/* gui-gtk-2.0 client specific options. */
  .gui_gtk2_default_theme_name = FC_GTK2_DEFAULT_THEME_NAME,
  .gui_gtk2_fullscreen = FALSE,
  .gui_gtk2_map_scrollbars = FALSE,
  .gui_gtk2_dialogs_on_top = TRUE,
  .gui_gtk2_show_task_icons = TRUE,
  .gui_gtk2_enable_tabs = TRUE,
  .gui_gtk2_better_fog = TRUE,
  .gui_gtk2_show_chat_message_time = FALSE,
  .gui_gtk2_new_messages_go_to_top = FALSE,
  .gui_gtk2_show_message_window_buttons = TRUE,
  .gui_gtk2_metaserver_tab_first = FALSE,
  .gui_gtk2_allied_chat_only = FALSE,
  .gui_gtk2_message_chat_location = GUI_GTK_MSGCHAT_MERGED,
  .gui_gtk2_small_display_layout = FALSE,
  .gui_gtk2_mouse_over_map_focus = FALSE,
  .gui_gtk2_chatline_autocompletion = TRUE,
  .gui_gtk2_citydlg_xsize = GUI_GTK2_CITYDLG_DEFAULT_XSIZE,
  .gui_gtk2_citydlg_ysize = GUI_GTK2_CITYDLG_DEFAULT_YSIZE,
  .gui_gtk2_popup_tech_help = GUI_POPUP_TECH_HELP_RULESET,
  .gui_gtk2_font_city_label = "Monospace 8",
  .gui_gtk2_font_notify_label = "Monospace Bold 9",
  .gui_gtk2_font_spaceship_label = "Monospace 8",
  .gui_gtk2_font_help_label = "Sans Bold 10",
  .gui_gtk2_font_help_link = "Sans 9",
  .gui_gtk2_font_help_text = "Monospace 8",
  .gui_gtk2_font_chatline = "Monospace 8",
  .gui_gtk2_font_beta_label = "Sans Italic 10",
  .gui_gtk2_font_small = "Sans 9",
  .gui_gtk2_font_comment_label = "Sans Italic 9",
  .gui_gtk2_font_city_names = "Sans Bold 10",
  .gui_gtk2_font_city_productions = "Serif 10",
  .gui_gtk2_font_reqtree_text = "Serif 10",

/* gui-gtk-3.0 client specific options. */
  .gui_gtk3_default_theme_name = FC_GTK3_DEFAULT_THEME_NAME,
  .gui_gtk3_fullscreen = FALSE,
  .gui_gtk3_map_scrollbars = FALSE,
  .gui_gtk3_dialogs_on_top = TRUE,
  .gui_gtk3_show_task_icons = TRUE,
  .gui_gtk3_enable_tabs = TRUE,
  .gui_gtk3_show_chat_message_time = FALSE,
  .gui_gtk3_new_messages_go_to_top = FALSE,
  .gui_gtk3_show_message_window_buttons = TRUE,
  .gui_gtk3_metaserver_tab_first = FALSE,
  .gui_gtk3_allied_chat_only = FALSE,
  .gui_gtk3_message_chat_location = GUI_GTK_MSGCHAT_MERGED,
  .gui_gtk3_small_display_layout = FALSE,
  .gui_gtk3_mouse_over_map_focus = FALSE,
  .gui_gtk3_chatline_autocompletion = TRUE,
  .gui_gtk3_citydlg_xsize = GUI_GTK3_CITYDLG_DEFAULT_XSIZE,
  .gui_gtk3_citydlg_ysize = GUI_GTK3_CITYDLG_DEFAULT_YSIZE,
  .gui_gtk3_popup_tech_help = GUI_POPUP_TECH_HELP_RULESET,
  .gui_gtk3_governor_range_min = -20,
  .gui_gtk3_governor_range_max = 20,
  .gui_gtk3_font_city_label = "Monospace 8",
  .gui_gtk3_font_notify_label = "Monospace Bold 9",
  .gui_gtk3_font_spaceship_label = "Monospace 8",
  .gui_gtk3_font_help_label = "Sans Bold 10",
  .gui_gtk3_font_help_link = "Sans 9",
  .gui_gtk3_font_help_text = "Monospace 8",
  .gui_gtk3_font_chatline = "Monospace 8",
  .gui_gtk3_font_beta_label = "Sans Italic 10",
  .gui_gtk3_font_small = "Sans 9",
  .gui_gtk3_font_comment_label = "Sans Italic 9",
  .gui_gtk3_font_city_names = "Sans Bold 10",
  .gui_gtk3_font_city_productions = "Serif 10",
  .gui_gtk3_font_reqtree_text = "Serif 10",

/* gui-gtk-3.22 client specific options. */
  .gui_gtk3_22_default_theme_name = FC_GTK3_DEFAULT_THEME_NAME,
  .gui_gtk3_22_fullscreen = FALSE,
  .gui_gtk3_22_map_scrollbars = FALSE,
  .gui_gtk3_22_dialogs_on_top = TRUE,
  .gui_gtk3_22_show_task_icons = TRUE,
  .gui_gtk3_22_enable_tabs = TRUE,
  .gui_gtk3_22_show_chat_message_time = FALSE,
  .gui_gtk3_22_new_messages_go_to_top = FALSE,
  .gui_gtk3_22_show_message_window_buttons = TRUE,
  .gui_gtk3_22_metaserver_tab_first = FALSE,
  .gui_gtk3_22_allied_chat_only = FALSE,
  .gui_gtk3_22_message_chat_location = GUI_GTK_MSGCHAT_MERGED,
  .gui_gtk3_22_small_display_layout = FALSE,
  .gui_gtk3_22_mouse_over_map_focus = FALSE,
  .gui_gtk3_22_chatline_autocompletion = TRUE,
  .gui_gtk3_22_citydlg_xsize = GUI_GTK3_CITYDLG_DEFAULT_XSIZE,
  .gui_gtk3_22_citydlg_ysize = GUI_GTK3_CITYDLG_DEFAULT_YSIZE,
  .gui_gtk3_22_popup_tech_help = GUI_POPUP_TECH_HELP_RULESET,
  .gui_gtk3_22_governor_range_min = -20,
  .gui_gtk3_22_governor_range_max = 20,
  .gui_gtk3_22_font_city_label = "Monospace 8",
  .gui_gtk3_22_font_notify_label = "Monospace Bold 9",
  .gui_gtk3_22_font_spaceship_label = "Monospace 8",
  .gui_gtk3_22_font_help_label = "Sans Bold 10",
  .gui_gtk3_22_font_help_link = "Sans 9",
  .gui_gtk3_22_font_help_text = "Monospace 8",
  .gui_gtk3_22_font_chatline = "Monospace 8",
  .gui_gtk3_22_font_beta_label = "Sans Italic 10",
  .gui_gtk3_22_font_small = "Sans 9",
  .gui_gtk3_22_font_comment_label = "Sans Italic 9",
  .gui_gtk3_22_font_city_names = "Sans Bold 10",
  .gui_gtk3_22_font_city_productions = "Serif 10",
  .gui_gtk3_22_font_reqtree_text = "Serif 10",

/* gui-sdl client specific options. */
  .gui_sdl_default_theme_name = FC_SDL_DEFAULT_THEME_NAME,
  .gui_sdl_fullscreen = FALSE,
  .gui_sdl_screen = VIDEO_MODE(640, 480),
  .gui_sdl_do_cursor_animation = TRUE,
  .gui_sdl_use_color_cursors = TRUE,

/* gui-sdl2 client specific options. */
  .gui_sdl2_default_theme_name = FC_SDL2_DEFAULT_THEME_NAME,
  .gui_sdl2_fullscreen = FALSE,
  .gui_sdl2_screen = VIDEO_MODE(640, 480),
  .gui_sdl2_swrenderer = FALSE,
  .gui_sdl2_do_cursor_animation = TRUE,
  .gui_sdl2_use_color_cursors = TRUE,

/* gui-qt client specific options. */
  .gui_qt_fullscreen = FALSE,
  .gui_qt_show_preview = TRUE,
  .gui_qt_sidebar_left = TRUE,
  .gui_qt_default_theme_name = FC_QT_DEFAULT_THEME_NAME,
  .gui_qt_font_city_label = "Monospace,8,-1,5,50,0,0,0,0,0",
  .gui_qt_font_default = "Sans Serif,10,-1,5,75,0,0,0,0,0",
  .gui_qt_font_notify_label = "Monospace,8,-1,5,75,0,0,0,0,0",
  .gui_qt_font_spaceship_label = "Monospace,8,-1,5,50,0,0,0,0,0",
  .gui_qt_font_help_label = "Sans Serif,9,-1,5,50,0,0,0,0,0",
  .gui_qt_font_help_link = "Sans Serif,9,-1,5,50,0,0,0,0,0",
  .gui_qt_font_help_text = "Monospace,8,-1,5,50,0,0,0,0,0",
  .gui_qt_font_help_title = "Sans Serif,10,-1,5,75,0,0,0,0,0",
  .gui_qt_font_chatline = "Monospace,8,-1,5,50,0,0,0,0,0",
  .gui_qt_font_beta_label = "Sans Serif,10,-1,5,50,1,0,0,0,0",
  .gui_qt_font_small = "Sans Serif,9,-1,5,50,0,0,0,0,0",
  .gui_qt_font_comment_label = "Sans Serif,9,-1,5,50,1,0,0,0,0",
  .gui_qt_font_city_names = "Sans Serif,10,-1,5,75,0,0,0,0,0",
  .gui_qt_font_city_productions = "Sans Serif,10,-1,5,50,1,0,0,0,0",
  .gui_qt_font_reqtree_text = "Sans Serif,10,-1,5,50,1,0,0,0,0",
  .gui_qt_show_titlebar = TRUE,
  .gui_qt_wakeup_text = "Wake up %1"
};

/* Set to TRUE after the first call to options_init(), to avoid the usage
 * of non-initialized datas when calling the changed callback. */
static bool options_fully_initialized = FALSE;

static const struct strvec *get_mapimg_format_list(const struct option *poption);

/****************************************************************************
  Option set structure.
****************************************************************************/
struct option_set {
  struct option * (*option_by_number) (int);
  struct option * (*option_first) (void);

  int (*category_number) (void);
  const char * (*category_name) (int);
};

/****************************************************************************
  Returns the option corresponding of the number in this option set.
****************************************************************************/
struct option *optset_option_by_number(const struct option_set *poptset,
                                       int id)
{
  fc_assert_ret_val(NULL != poptset, NULL);

  return poptset->option_by_number(id);
}

/****************************************************************************
  Returns the option corresponding of the name in this option set.
****************************************************************************/
struct option *optset_option_by_name(const struct option_set *poptset,
                                     const char *name)
{
  fc_assert_ret_val(NULL != poptset, NULL);

  options_iterate(poptset, poption) {
    if (0 == strcmp(option_name(poption), name)) {
      return poption;
    }
  } options_iterate_end;
  return NULL;
}

/****************************************************************************
  Returns the first option of this option set.
****************************************************************************/
struct option *optset_option_first(const struct option_set *poptset)
{
  fc_assert_ret_val(NULL != poptset, NULL);

  return poptset->option_first();
}

/****************************************************************************
  Returns the number of categories of this option set.
****************************************************************************/
int optset_category_number(const struct option_set *poptset)
{
  fc_assert_ret_val(NULL != poptset, 0);

  return poptset->category_number();
}

/****************************************************************************
  Returns the name (translated) of the category of this option set.
****************************************************************************/
const char *optset_category_name(const struct option_set *poptset,
                                 int category)
{
  fc_assert_ret_val(NULL != poptset, NULL);

  return poptset->category_name(category);
}


/****************************************************************************
  The base class for options.
****************************************************************************/
struct option {
  /* A link to the option set. */
  const struct option_set *poptset;
  /* Type of the option. */
  enum option_type type;

  /* Common accessors. */
  const struct option_common_vtable {
    int (*number) (const struct option *);
    const char * (*name) (const struct option *);
    const char * (*description) (const struct option *);
    const char * (*help_text) (const struct option *);
    int (*category) (const struct option *);
    bool (*is_changeable) (const struct option *);
    struct option * (*next) (const struct option *);
  } *common_vtable;
  /* Specific typed accessors. */
  union {
    /* Specific boolean accessors (OT_BOOLEAN == type). */
    const struct option_bool_vtable {
      bool (*get) (const struct option *);
      bool (*def) (const struct option *);
      bool (*set) (struct option *, bool);
    } *bool_vtable;
    /* Specific integer accessors (OT_INTEGER == type). */
    const struct option_int_vtable {
      int (*get) (const struct option *);
      int (*def) (const struct option *);
      int (*minimum) (const struct option *);
      int (*maximum) (const struct option *);
      bool (*set) (struct option *, int);
    } *int_vtable;
    /* Specific string accessors (OT_STRING == type). */
    const struct option_str_vtable {
      const char * (*get) (const struct option *);
      const char * (*def) (const struct option *);
      const struct strvec * (*values) (const struct option *);
      bool (*set) (struct option *, const char *);
    } *str_vtable;
    /* Specific enum accessors (OT_ENUM == type). */
    const struct option_enum_vtable {
      int (*get) (const struct option *);
      int (*def) (const struct option *);
      const struct strvec * (*values) (const struct option *);
      bool (*set) (struct option *, int);
      int (*cmp) (const char *, const char *);
    } *enum_vtable;
    /* Specific bitwise accessors (OT_BITWISE == type). */
    const struct option_bitwise_vtable {
      unsigned (*get) (const struct option *);
      unsigned (*def) (const struct option *);
      const struct strvec * (*values) (const struct option *);
      bool (*set) (struct option *, unsigned);
    } *bitwise_vtable;
    /* Specific font accessors (OT_FONT == type). */
    const struct option_font_vtable {
      const char * (*get) (const struct option *);
      const char * (*def) (const struct option *);
      const char * (*target) (const struct option *);
      bool (*set) (struct option *, const char *);
    } *font_vtable;
    /* Specific color accessors (OT_COLOR == type). */
    const struct option_color_vtable {
      struct ft_color (*get) (const struct option *);
      struct ft_color (*def) (const struct option *);
      bool (*set) (struct option *, struct ft_color);
    } *color_vtable;
    /* Specific video mode accessors (OT_VIDEO_MODE == type). */
    const struct option_video_mode_vtable {
      struct video_mode (*get) (const struct option *);
      struct video_mode (*def) (const struct option *);
      bool (*set) (struct option *, struct video_mode);
    } *video_mode_vtable;
  };

  /* Called after the value changed. */
  void (*changed_callback) (struct option *option);

  int callback_data;

  /* Volatile. */
  void *gui_data;
};

#define OPTION(poption) ((struct option *) (poption))

#define OPTION_INIT(optset, spec_type, spec_table_var, common_table,        \
                    spec_table, changed_cb, cb_data) {                      \
  .poptset = optset,                                                        \
  .type = spec_type,                                                        \
  .common_vtable = &common_table,                                           \
  INIT_BRACE_BEGIN                                                          \
    .spec_table_var = &spec_table                                           \
  INIT_BRACE_END,                                                           \
  .changed_callback = changed_cb,                                           \
  .callback_data = cb_data,                                                 \
  .gui_data = NULL                                                          \
}
#define OPTION_BOOL_INIT(optset, common_table, bool_table, changed_cb)      \
  OPTION_INIT(optset, OT_BOOLEAN, bool_vtable, common_table, bool_table,    \
              changed_cb, 0)
#define OPTION_INT_INIT(optset, common_table, int_table, changed_cb)        \
  OPTION_INIT(optset, OT_INTEGER, int_vtable, common_table, int_table,      \
              changed_cb, 0)
#define OPTION_STR_INIT(optset, common_table, str_table, changed_cb, cb_data) \
  OPTION_INIT(optset, OT_STRING, str_vtable, common_table, str_table,       \
              changed_cb, cb_data)
#define OPTION_ENUM_INIT(optset, common_table, enum_table, changed_cb)      \
  OPTION_INIT(optset, OT_ENUM, enum_vtable, common_table, enum_table,       \
              changed_cb, 0)
#define OPTION_BITWISE_INIT(optset, common_table, bitwise_table,            \
                            changed_cb)                                     \
  OPTION_INIT(optset, OT_BITWISE, bitwise_vtable, common_table,             \
              bitwise_table, changed_cb, 0)
#define OPTION_FONT_INIT(optset, common_table, font_table, changed_cb)      \
  OPTION_INIT(optset, OT_FONT, font_vtable, common_table, font_table,       \
              changed_cb, 0)
#define OPTION_COLOR_INIT(optset, common_table, color_table, changed_cb)    \
  OPTION_INIT(optset, OT_COLOR, color_vtable, common_table, color_table,    \
              changed_cb, 0)
#define OPTION_VIDEO_MODE_INIT(optset, common_table, video_mode_table,      \
                               changed_cb)                                  \
  OPTION_INIT(optset, OT_VIDEO_MODE, video_mode_vtable, common_table,       \
              video_mode_table, changed_cb, 0)


/****************************************************************************
  Returns the option set owner of this option.
****************************************************************************/
const struct option_set *option_optset(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);

  return poption->poptset;
}

/****************************************************************************
  Returns the number of the option.
****************************************************************************/
int option_number(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, -1);

  return poption->common_vtable->number(poption);
}

/****************************************************************************
  Returns the name of the option.
****************************************************************************/
const char *option_name(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);

  return poption->common_vtable->name(poption);
}

/****************************************************************************
  Returns the description (translated) of the option.
****************************************************************************/
const char *option_description(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);

  return poption->common_vtable->description(poption);
}

/****************************************************************************
  Returns the help text (translated) of the option.
****************************************************************************/
const char *option_help_text(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);

  return poption->common_vtable->help_text(poption);
}

/****************************************************************************
  Returns the type of the option.
****************************************************************************/
enum option_type option_type(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, -1);

  return poption->type;
}

/****************************************************************************
  Returns the category of the option.
****************************************************************************/
int option_category(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, -1);

  return poption->common_vtable->category(poption);
}

/****************************************************************************
  Returns the name (tranlated) of the category of the option.
****************************************************************************/
const char *option_category_name(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);

  return optset_category_name(poption->poptset,
                              poption->common_vtable->category(poption));
}

/****************************************************************************
  Returns TRUE if this option can be modified.
****************************************************************************/
bool option_is_changeable(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, FALSE);

  return poption->common_vtable->is_changeable(poption);
}

/****************************************************************************
  Returns the next option or NULL if this is the last.
****************************************************************************/
struct option *option_next(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);

  return poption->common_vtable->next(poption);
}

/****************************************************************************
  Set the option to its default value.  Returns TRUE if the option changed.
****************************************************************************/
bool option_reset(struct option *poption)
{
  fc_assert_ret_val(NULL != poption, FALSE);

  switch (option_type(poption)) {
  case OT_BOOLEAN:
    return option_bool_set(poption, option_bool_def(poption));
  case OT_INTEGER:
    return option_int_set(poption, option_int_def(poption));
  case OT_STRING:
    return option_str_set(poption, option_str_def(poption));
  case OT_ENUM:
    return option_enum_set_int(poption, option_enum_def_int(poption));
  case OT_BITWISE:
    return option_bitwise_set(poption, option_bitwise_def(poption));
  case OT_FONT:
    return option_font_set(poption, option_font_def(poption));
  case OT_COLOR:
    return option_color_set(poption, option_color_def(poption));
  case OT_VIDEO_MODE:
    return option_video_mode_set(poption, option_video_mode_def(poption));
  }
  return FALSE;
}

/****************************************************************************
  Set the function to call every time this option changes.  Can be NULL.
****************************************************************************/
void option_set_changed_callback(struct option *poption,
                                 void (*callback) (struct option *))
{
  fc_assert_ret(NULL != poption);

  poption->changed_callback = callback;
}

/****************************************************************************
  Force to use the option changed callback.
****************************************************************************/
void option_changed(struct option *poption)
{
  fc_assert_ret(NULL != poption);

  if (!options_fully_initialized) {
    /* Prevent to use non-initialized datas. */
    return;
  }

  if (poption->changed_callback) {
    poption->changed_callback(poption);
  }

  option_gui_update(poption);
}

/****************************************************************************
  Set the gui data for this option.
****************************************************************************/
void option_set_gui_data(struct option *poption, void *data)
{
  fc_assert_ret(NULL != poption);

  poption->gui_data = data;
}

/****************************************************************************
  Returns the gui data of this option.
****************************************************************************/
void *option_get_gui_data(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);

  return poption->gui_data;
}

/****************************************************************************
  Returns the callback data of this option.
****************************************************************************/
int option_get_cb_data(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, 0);

  return poption->callback_data;
}

/****************************************************************************
  Returns the current value of this boolean option.
****************************************************************************/
bool option_bool_get(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_BOOLEAN == poption->type, FALSE);

  return poption->bool_vtable->get(poption);
}

/****************************************************************************
  Returns the default value of this boolean option.
****************************************************************************/
bool option_bool_def(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_BOOLEAN == poption->type, FALSE);

  return poption->bool_vtable->def(poption);
}

/****************************************************************************
  Sets the value of this boolean option. Returns TRUE if the value changed.
****************************************************************************/
bool option_bool_set(struct option *poption, bool val)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_BOOLEAN == poption->type, FALSE);

  if (poption->bool_vtable->set(poption, val)) {
    option_changed(poption);
    return TRUE;
  }
  return FALSE;
}

/****************************************************************************
  Returns the current value of this integer option.
****************************************************************************/
int option_int_get(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, 0);
  fc_assert_ret_val(OT_INTEGER == poption->type, 0);

  return poption->int_vtable->get(poption);
}

/****************************************************************************
  Returns the default value of this integer option.
****************************************************************************/
int option_int_def(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, 0);
  fc_assert_ret_val(OT_INTEGER == poption->type, 0);

  return poption->int_vtable->def(poption);
}

/****************************************************************************
  Returns the minimal value of this integer option.
****************************************************************************/
int option_int_min(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, 0);
  fc_assert_ret_val(OT_INTEGER == poption->type, 0);

  return poption->int_vtable->minimum(poption);
}

/****************************************************************************
  Returns the maximal value of this integer option.
****************************************************************************/
int option_int_max(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, 0);
  fc_assert_ret_val(OT_INTEGER == poption->type, 0);

  return poption->int_vtable->maximum(poption);
}

/****************************************************************************
  Sets the value of this integer option. Returns TRUE if the value changed.
****************************************************************************/
bool option_int_set(struct option *poption, int val)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_INTEGER == poption->type, FALSE);

  if (poption->int_vtable->set(poption, val)) {
    option_changed(poption);
    return TRUE;
  }
  return FALSE;
}

/****************************************************************************
  Returns the current value of this string option.
****************************************************************************/
const char *option_str_get(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_STRING == poption->type, NULL);

  return poption->str_vtable->get(poption);
}

/****************************************************************************
  Returns the default value of this string option.
****************************************************************************/
const char *option_str_def(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_STRING == poption->type, NULL);

  return poption->str_vtable->def(poption);
}

/****************************************************************************
  Returns the possible string values of this string option.
****************************************************************************/
const struct strvec *option_str_values(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_STRING == poption->type, NULL);

  return poption->str_vtable->values(poption);
}

/****************************************************************************
  Sets the value of this string option. Returns TRUE if the value changed.
****************************************************************************/
bool option_str_set(struct option *poption, const char *str)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_STRING == poption->type, FALSE);
  fc_assert_ret_val(NULL != str, FALSE);

  if (poption->str_vtable->set(poption, str)) {
    option_changed(poption);
    return TRUE;
  }
  return FALSE;
}

/****************************************************************************
  Returns the value corresponding to the user-visible (translatable but not
  translated) string. Returns -1 if not matched.
****************************************************************************/
int option_enum_str_to_int(const struct option *poption, const char *str)
{
  const struct strvec *values;
  int val;

  fc_assert_ret_val(NULL != poption, -1);
  fc_assert_ret_val(OT_ENUM == poption->type, -1);
  values = poption->enum_vtable->values(poption);
  fc_assert_ret_val(NULL != values, -1);

  for (val = 0; val < strvec_size(values); val++) {
    if (0 == poption->enum_vtable->cmp(strvec_get(values, val), str)) {
      return val;
    }
  }
  return -1;
}

/****************************************************************************
  Returns the user-visible (translatable but not translated) string
  corresponding to the value. Returns NULL on error.
****************************************************************************/
const char *option_enum_int_to_str(const struct option *poption, int val)
{
  const struct strvec *values;

  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_ENUM == poption->type, NULL);
  values = poption->enum_vtable->values(poption);
  fc_assert_ret_val(NULL != values, NULL);

  return strvec_get(values, val);
}

/****************************************************************************
  Returns the current value of this enum option (as an integer).
****************************************************************************/
int option_enum_get_int(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, -1);
  fc_assert_ret_val(OT_ENUM == poption->type, -1);

  return poption->enum_vtable->get(poption);
}

/****************************************************************************
  Returns the current value of this enum option as a user-visible
  (translatable but not translated) string.
****************************************************************************/
const char *option_enum_get_str(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_ENUM == poption->type, NULL);

  return strvec_get(poption->enum_vtable->values(poption),
                    poption->enum_vtable->get(poption));
}

/****************************************************************************
  Returns the default value of this enum option (as an integer).
****************************************************************************/
int option_enum_def_int(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, -1);
  fc_assert_ret_val(OT_ENUM == poption->type, -1);

  return poption->enum_vtable->def(poption);
}

/****************************************************************************
  Returns the default value of this enum option as a user-visible
  (translatable but not translated) string.
****************************************************************************/
const char *option_enum_def_str(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_ENUM == poption->type, NULL);

  return strvec_get(poption->enum_vtable->values(poption),
                    poption->enum_vtable->def(poption));
}

/****************************************************************************
  Returns the possible string values of this enum option, as user-visible
  (translatable but not translated) strings.
****************************************************************************/
const struct strvec *option_enum_values(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_ENUM == poption->type, NULL);

  return poption->enum_vtable->values(poption);
}

/****************************************************************************
  Sets the value of this enum option. Returns TRUE if the value changed.
****************************************************************************/
bool option_enum_set_int(struct option *poption, int val)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_ENUM == poption->type, FALSE);

  if (poption->enum_vtable->set(poption, val)) {
    option_changed(poption);
    return TRUE;
  }
  return FALSE;
}

/****************************************************************************
  Sets the value of this enum option from a string, which is matched as a
  user-visible (translatable but not translated) string. Returns TRUE if the
  value changed.
****************************************************************************/
bool option_enum_set_str(struct option *poption, const char *str)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_ENUM == poption->type, FALSE);
  fc_assert_ret_val(NULL != str, FALSE);

  if (poption->enum_vtable->set(poption,
                                option_enum_str_to_int(poption, str))) {
    option_changed(poption);
    return TRUE;
  }
  return FALSE;
}

/****************************************************************************
  Returns the current value of this bitwise option.
****************************************************************************/
unsigned option_bitwise_get(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, 0);
  fc_assert_ret_val(OT_BITWISE == poption->type, 0);

  return poption->bitwise_vtable->get(poption);
}

/****************************************************************************
  Returns the default value of this bitwise option.
****************************************************************************/
unsigned option_bitwise_def(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, 0);
  fc_assert_ret_val(OT_BITWISE == poption->type, 0);

  return poption->bitwise_vtable->def(poption);
}

/****************************************************************************
  Returns the mask of this bitwise option.
****************************************************************************/
unsigned option_bitwise_mask(const struct option *poption)
{
  const struct strvec *values;

  fc_assert_ret_val(NULL != poption, 0);
  fc_assert_ret_val(OT_BITWISE == poption->type, 0);

  values = poption->bitwise_vtable->values(poption);
  fc_assert_ret_val(NULL != values, 0);

  return (1 << strvec_size(values)) - 1;
}

/****************************************************************************
  Returns a vector of strings describing every bit of this option, as
  user-visible (translatable but not translated) strings.
****************************************************************************/
const struct strvec *option_bitwise_values(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_BITWISE == poption->type, NULL);

  return poption->bitwise_vtable->values(poption);
}

/****************************************************************************
  Sets the value of this bitwise option. Returns TRUE if the value changed.
****************************************************************************/
bool option_bitwise_set(struct option *poption, unsigned val)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_BITWISE == poption->type, FALSE);

  if (0 != (val & ~option_bitwise_mask(poption))
      || !poption->bitwise_vtable->set(poption, val)) {
    return FALSE;
  }

  option_changed(poption);
  return TRUE;
}

/****************************************************************************
  Returns the current value of this font option.
****************************************************************************/
const char *option_font_get(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_FONT == poption->type, NULL);

  return poption->font_vtable->get(poption);
}

/****************************************************************************
  Returns the default value of this font option.
****************************************************************************/
const char *option_font_def(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_FONT == poption->type, NULL);

  return poption->font_vtable->def(poption);
}

/****************************************************************************
  Returns the target style name of this font option.
****************************************************************************/
const char *option_font_target(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, NULL);
  fc_assert_ret_val(OT_FONT == poption->type, NULL);

  return poption->font_vtable->target(poption);
}

/****************************************************************************
  Sets the value of this font option. Returns TRUE if the value changed.
****************************************************************************/
bool option_font_set(struct option *poption, const char *font)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_FONT == poption->type, FALSE);
  fc_assert_ret_val(NULL != font, FALSE);

  if (poption->font_vtable->set(poption, font)) {
    option_changed(poption);
    return TRUE;
  }
  return FALSE;
}

/****************************************************************************
  Returns the current value of this color option.
****************************************************************************/
struct ft_color option_color_get(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, ft_color_construct(NULL, NULL));
  fc_assert_ret_val(OT_COLOR == poption->type, ft_color_construct(NULL, NULL));

  return poption->color_vtable->get(poption);
}

/****************************************************************************
  Returns the default value of this color option.
****************************************************************************/
struct ft_color option_color_def(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, ft_color_construct(NULL, NULL));
  fc_assert_ret_val(OT_COLOR == poption->type, ft_color_construct(NULL, NULL));

  return poption->color_vtable->def(poption);
}

/****************************************************************************
  Sets the value of this color option. Returns TRUE if the value
  changed.
****************************************************************************/
bool option_color_set(struct option *poption, struct ft_color color)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_COLOR == poption->type, FALSE);

  if (poption->color_vtable->set(poption, color)) {
    option_changed(poption);
    return TRUE;
  }
  return FALSE;
}

/****************************************************************************
  Returns the current value of this video mode option.
****************************************************************************/
struct video_mode option_video_mode_get(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, video_mode_construct(-1, -1));
  fc_assert_ret_val(OT_VIDEO_MODE == poption->type,
                    video_mode_construct(-1, -1));

  return poption->video_mode_vtable->get(poption);
}

/****************************************************************************
  Returns the default value of this video mode option.
****************************************************************************/
struct video_mode option_video_mode_def(const struct option *poption)
{
  fc_assert_ret_val(NULL != poption, video_mode_construct(-1, -1));
  fc_assert_ret_val(OT_VIDEO_MODE == poption->type,
                    video_mode_construct(-1, -1));

  return poption->video_mode_vtable->def(poption);
}

/****************************************************************************
  Sets the value of this video mode option. Returns TRUE if the value
  changed.
****************************************************************************/
bool option_video_mode_set(struct option *poption, struct video_mode mode)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(OT_VIDEO_MODE == poption->type, FALSE);

  if (poption->video_mode_vtable->set(poption, mode)) {
    option_changed(poption);
    return TRUE;
  }
  return FALSE;
}


/****************************************************************************
  Client option set.
****************************************************************************/
static struct option *client_optset_option_by_number(int id);
static struct option *client_optset_option_first(void);
static int client_optset_category_number(void);
static const char *client_optset_category_name(int category);

static struct option_set client_optset_static = {
  .option_by_number = client_optset_option_by_number,
  .option_first = client_optset_option_first,
  .category_number = client_optset_category_number,
  .category_name = client_optset_category_name
};
const struct option_set *client_optset = &client_optset_static;

struct copt_val_name {
  const char *support;          /* Untranslated long support name, used
                                 * for saving. */
  const char *pretty;           /* Translated, used to display to the
                                 * users. */
};

/****************************************************************************
  Virtuals tables for the client options.
****************************************************************************/
static int client_option_number(const struct option *poption);
static const char *client_option_name(const struct option *poption);
static const char *client_option_description(const struct option *poption);
static const char *client_option_help_text(const struct option *poption);
static int client_option_category(const struct option *poption);
static bool client_option_is_changeable(const struct option *poption);
static struct option *client_option_next(const struct option *poption);

static const struct option_common_vtable client_option_common_vtable = {
  .number = client_option_number,
  .name = client_option_name,
  .description = client_option_description,
  .help_text = client_option_help_text,
  .category = client_option_category,
  .is_changeable = client_option_is_changeable,
  .next = client_option_next
};

static bool client_option_bool_get(const struct option *poption);
static bool client_option_bool_def(const struct option *poption);
static bool client_option_bool_set(struct option *poption, bool val);

static const struct option_bool_vtable client_option_bool_vtable = {
  .get = client_option_bool_get,
  .def = client_option_bool_def,
  .set = client_option_bool_set
};

static int client_option_int_get(const struct option *poption);
static int client_option_int_def(const struct option *poption);
static int client_option_int_min(const struct option *poption);
static int client_option_int_max(const struct option *poption);
static bool client_option_int_set(struct option *poption, int val);

static const struct option_int_vtable client_option_int_vtable = {
  .get = client_option_int_get,
  .def = client_option_int_def,
  .minimum = client_option_int_min,
  .maximum = client_option_int_max,
  .set = client_option_int_set
};

static const char *client_option_str_get(const struct option *poption);
static const char *client_option_str_def(const struct option *poption);
static const struct strvec *
    client_option_str_values(const struct option *poption);
static bool client_option_str_set(struct option *poption, const char *str);

static const struct option_str_vtable client_option_str_vtable = {
  .get = client_option_str_get,
  .def = client_option_str_def,
  .values = client_option_str_values,
  .set = client_option_str_set
};

static int client_option_enum_get(const struct option *poption);
static int client_option_enum_def(const struct option *poption);
static const struct strvec *
    client_option_enum_pretty_names(const struct option *poption);
static bool client_option_enum_set(struct option *poption, int val);

static const struct option_enum_vtable client_option_enum_vtable = {
  .get = client_option_enum_get,
  .def = client_option_enum_def,
  .values = client_option_enum_pretty_names,
  .set = client_option_enum_set,
  .cmp = fc_strcasecmp
};

#if 0 /* There's no bitwise options currently */
static unsigned client_option_bitwise_get(const struct option *poption);
static unsigned client_option_bitwise_def(const struct option *poption);
static const struct strvec *
    client_option_bitwise_pretty_names(const struct option *poption);
static bool client_option_bitwise_set(struct option *poption, unsigned val);

static const struct option_bitwise_vtable client_option_bitwise_vtable = {
  .get = client_option_bitwise_get,
  .def = client_option_bitwise_def,
  .values = client_option_bitwise_pretty_names,
  .set = client_option_bitwise_set
};
#endif /* 0 */

static const char *client_option_font_get(const struct option *poption);
static const char *client_option_font_def(const struct option *poption);
static const char *client_option_font_target(const struct option *poption);
static bool client_option_font_set(struct option *poption, const char *font);

static const struct option_font_vtable client_option_font_vtable = {
  .get = client_option_font_get,
  .def = client_option_font_def,
  .target = client_option_font_target,
  .set = client_option_font_set
};

static struct ft_color client_option_color_get(const struct option *poption);
static struct ft_color client_option_color_def(const struct option *poption);
static bool client_option_color_set(struct option *poption,
                                    struct ft_color color);

static const struct option_color_vtable client_option_color_vtable = {
  .get = client_option_color_get,
  .def = client_option_color_def,
  .set = client_option_color_set
};

static struct video_mode
client_option_video_mode_get(const struct option *poption);
static struct video_mode
client_option_video_mode_def(const struct option *poption);
static bool client_option_video_mode_set(struct option *poption,
                                         struct video_mode mode);

static const struct option_video_mode_vtable client_option_video_mode_vtable = {
  .get = client_option_video_mode_get,
  .def = client_option_video_mode_def,
  .set = client_option_video_mode_set
};

enum client_option_category {
  COC_GRAPHICS,
  COC_OVERVIEW,
  COC_SOUND,
  COC_INTERFACE,
  COC_MAPIMG,
  COC_NETWORK,
  COC_FONT,
  COC_MAX
};

/****************************************************************************
  Derived class client option, inherinting of base class option.
****************************************************************************/
struct client_option {
  struct option base_option;    /* Base structure, must be the first! */

  const char *name;             /* Short name - used as an identifier */
  const char *description;      /* One-line description */
  const char *help_text;        /* Paragraph-length help text */
  enum client_option_category category;
  enum gui_type specific;       /* GUI_STUB for common options. */

  union {
    /* OT_BOOLEAN type option. */
    struct {
      bool *const pvalue;
      const bool def;
    } boolean;
    /* OT_INTEGER type option. */
    struct {
      int *const pvalue;
      const int def, min, max;
    } integer;
    /* OT_STRING type option. */
    struct {
      char *const pvalue;
      const size_t size;
      const char *const def;
      /* 
       * A function to return a string vector of possible string values,
       * or NULL for none. 
       */
      const struct strvec *(*const val_accessor) (const struct option *);
    } string;
    /* OT_ENUM type option. */
    struct {
      int *const pvalue;
      const int def;
      struct strvec *support_names, *pretty_names; /* untranslated */
      const struct copt_val_name * (*const name_accessor) (int value);
    } enumerator;
    /* OT_BITWISE type option. */
    struct {
      unsigned *const pvalue;
      const unsigned def;
      struct strvec *support_names, *pretty_names; /* untranslated */
      const struct copt_val_name * (*const name_accessor) (int value);
    } bitwise;
    /* OT_FONT type option. */
    struct {
      char *const pvalue;
      const size_t size;
      const char *const def;
      const char *const target;
    } font;
    /* OT_COLOR type option. */
    struct {
      struct ft_color *const pvalue;
      const struct ft_color def;
    } color;
    /* OT_VIDEO_MODE type option. */
    struct {
      struct video_mode *const pvalue;
      const struct video_mode def;
    } video_mode;
  };
};

#define CLIENT_OPTION(poption) ((struct client_option *) (poption))

/*
 * Generate a client option of type OT_BOOLEAN.
 *
 * oname: The option data.  Note it is used as name to be loaded or saved.
 *        So, you shouldn't change the name of this variable in any case.
 * odesc: A short description of the client option.  Should be used with the
 *        N_() macro.
 * ohelp: The help text for the client option.  Should be used with the N_()
 *        macro.
 * ocat:  The client_option_class of this client option.
 * ospec: A gui_type enumerator which determin for what particular client
 *        gui this option is for. Sets to GUI_STUB for common options.
 * odef:  The default value of this client option (FALSE or TRUE).
 * ocb:   A callback function of type void (*)(struct option *) called when
 *        the option changed.
 */
#define GEN_BOOL_OPTION(oname, odesc, ohelp, ocat, ospec, odef, ocb)        \
{                                                                           \
  .base_option = OPTION_BOOL_INIT(&client_optset_static,                    \
                                  client_option_common_vtable,              \
                                  client_option_bool_vtable, ocb),          \
  .name = #oname,                                                           \
  .description = odesc,                                                     \
  .help_text = ohelp,                                                       \
  .category = ocat,                                                         \
  .specific = ospec,                                                        \
  INIT_BRACE_BEGIN                                                          \
    .boolean = {                                                            \
      .pvalue = &gui_options.oname,                                         \
      .def = odef,                                                          \
    }                                                                       \
  INIT_BRACE_END                                                            \
}

/*
 * Generate a client option of type OT_INTEGER.
 *
 * oname: The option data.  Note it is used as name to be loaded or saved.
 *        So, you shouldn't change the name of this variable in any case.
 * odesc: A short description of the client option.  Should be used with the
 *        N_() macro.
 * ohelp: The help text for the client option.  Should be used with the N_()
 *        macro.
 * ocat:  The client_option_class of this client option.
 * ospec: A gui_type enumerator which determin for what particular client
 *        gui this option is for. Sets to GUI_STUB for common options.
 * odef:  The default value of this client option.
 * omin:  The minimal value of this client option.
 * omax:  The maximal value of this client option.
 * ocb:   A callback function of type void (*)(struct option *) called when
 *        the option changed.
 */
#define GEN_INT_OPTION(oname, odesc, ohelp, ocat, ospec, odef, omin, omax, ocb) \
{                                                                           \
  .base_option = OPTION_INT_INIT(&client_optset_static,                     \
                                 client_option_common_vtable,               \
                                 client_option_int_vtable, ocb),            \
  .name = #oname,                                                           \
  .description = odesc,                                                     \
  .help_text = ohelp,                                                       \
  .category = ocat,                                                         \
  .specific = ospec,                                                        \
  INIT_BRACE_BEGIN                                                          \
    .integer = {                                                            \
      .pvalue = &gui_options.oname,                                         \
      .def = odef,                                                          \
      .min = omin,                                                          \
      .max = omax                                                           \
    }                                                                       \
  INIT_BRACE_END                                                            \
}

/*
 * Generate a client option of type OT_STRING.
 *
 * oname: The option data.  Note it is used as name to be loaded or saved.
 *        So, you shouldn't change the name of this variable in any case.
 *        Be sure to pass the array variable and not a pointer to it because
 *        the size is calculated with sizeof().
 * odesc: A short description of the client option.  Should be used with the
 *        N_() macro.
 * ohelp: The help text for the client option.  Should be used with the N_()
 *        macro.
 * ocat:  The client_option_class of this client option.
 * ospec: A gui_type enumerator which determines for what particular client
 *        gui this option is for. Set to GUI_STUB for common options.
 * odef:  The default string for this client option.
 * ocb:   A callback function of type void (*)(struct option *) called when
 *        the option changed.
 */
#define GEN_STR_OPTION(oname, odesc, ohelp, ocat, ospec, odef, ocb, cbd)    \
{                                                                           \
  .base_option = OPTION_STR_INIT(&client_optset_static,                     \
                                 client_option_common_vtable,               \
                                 client_option_str_vtable, ocb, cbd),       \
  .name = #oname,                                                           \
  .description = odesc,                                                     \
  .help_text = ohelp,                                                       \
  .category = ocat,                                                         \
  .specific = ospec,                                                        \
  INIT_BRACE_BEGIN                                                          \
    .string = {                                                             \
      .pvalue = gui_options.oname,                                          \
      .size = sizeof(gui_options.oname),                                    \
      .def = odef,                                                          \
      .val_accessor = NULL                                                  \
    }                                                                       \
  INIT_BRACE_END                                                            \
}

/*
 * Generate a client option of type OT_STRING with a string accessor
 * function.
 *
 * oname: The option data.  Note it is used as name to be loaded or saved.
 *        So, you shouldn't change the name of this variable in any case.
 *        Be sure to pass the array variable and not a pointer to it because
 *        the size is calculated with sizeof().
 * odesc: A short description of the client option.  Should be used with the
 *        N_() macro.
 * ohelp: The help text for the client option.  Should be used with the N_()
 *        macro.
 * ocat:  The client_option_class of this client option.
 * ospec: A gui_type enumerator which determin for what particular client
 *        gui this option is for. Sets to GUI_STUB for common options.
 * odef:  The default string for this client option.
 * oacc:  The string accessor where to find the allowed values of type
 *        'const struct strvec * (*) (void)'.
 * ocb:   A callback function of type void (*)(struct option *) called when
 *        the option changed.
 */
#define GEN_STR_LIST_OPTION(oname, odesc, ohelp, ocat, ospec, odef, oacc, ocb, cbd) \
{                                                                           \
  .base_option = OPTION_STR_INIT(&client_optset_static,                     \
                                 client_option_common_vtable,               \
                                 client_option_str_vtable, ocb, cbd),       \
  .name = #oname,                                                           \
  .description = odesc,                                                     \
  .help_text = ohelp,                                                       \
  .category = ocat,                                                         \
  .specific = ospec,                                                        \
  INIT_BRACE_BEGIN                                                          \
    .string = {                                                             \
      .pvalue = gui_options.oname,                                          \
      .size = sizeof(gui_options.oname),                                    \
      .def = odef,                                                          \
      .val_accessor = oacc                                                  \
    }                                                                       \
  INIT_BRACE_END                                                            \
}

/*
 * Generate a client option of type OT_ENUM.
 *
 * oname: The option data.  Note it is used as name to be loaded or saved.
 *        So, you shouldn't change the name of this variable in any case.
 * odesc: A short description of the client option.  Should be used with the
 *        N_() macro.
 * ohelp: The help text for the client option.  Should be used with the N_()
 *        macro.
 * ocat:  The client_option_class of this client option.
 * ospec: A gui_type enumerator which determin for what particular client
 *        gui this option is for. Sets to GUI_STUB for common options.
 * odef:  The default value for this client option.
 * oacc:  The name accessor of type 'const struct copt_val_name * (*) (int)'.
 * ocb:   A callback function of type void (*) (struct option *) called when
 *        the option changed.
 */
#define GEN_ENUM_OPTION(oname, odesc, ohelp, ocat, ospec, odef, oacc, ocb)  \
{                                                                           \
  .base_option = OPTION_ENUM_INIT(&client_optset_static,                    \
                                  client_option_common_vtable,              \
                                  client_option_enum_vtable, ocb),          \
  .name = #oname,                                                           \
  .description = odesc,                                                     \
  .help_text = ohelp,                                                       \
  .category = ocat,                                                         \
  .specific = ospec,                                                        \
  INIT_BRACE_BEGIN                                                          \
    .enumerator = {                                                         \
      .pvalue = (int *) &gui_options.oname,                                 \
      .def = odef,                                                          \
      .support_names = NULL, /* Set in options_init(). */                   \
      .pretty_names  = NULL,                                                \
      .name_accessor = oacc                                                 \
    }                                                                       \
  INIT_BRACE_END                                                            \
}

/*
 * Generate a client option of type OT_BITWISE.
 *
 * oname: The option data.  Note it is used as name to be loaded or saved.
 *        So, you shouldn't change the name of this variable in any case.
 * odesc: A short description of the client option.  Should be used with the
 *        N_() macro.
 * ohelp: The help text for the client option.  Should be used with the N_()
 *        macro.
 * ocat:  The client_option_class of this client option.
 * ospec: A gui_type enumerator which determin for what particular client
 *        gui this option is for. Sets to GUI_STUB for common options.
 * odef:  The default value for this client option.
 * oacc:  The name accessor of type 'const struct copt_val_name * (*) (int)'.
 * ocb:   A callback function of type void (*) (struct option *) called when
 *        the option changed.
 */
#define GEN_BITWISE_OPTION(oname, odesc, ohelp, ocat, ospec, odef, oacc,    \
                           ocb)                                             \
{                                                                           \
  .base_option = OPTION_BITWISE_INIT(&client_optset_static,                 \
                                     client_option_common_vtable,           \
                                     client_option_bitwise_vtable, ocb),    \
  .name = #oname,                                                           \
  .description = odesc,                                                     \
  .help_text = ohelp,                                                       \
  .category = ocat,                                                         \
  .specific = ospec,                                                        \
  INIT_BRACE_BEGIN                                                          \
    .bitwise = {                                                            \
      .pvalue = &gui_options.oname,                                         \
      .def = odef,                                                          \
      .support_names = NULL, /* Set in options_init(). */                   \
      .pretty_names  = NULL,                                                \
      .name_accessor = oacc                                                 \
    }                                                                       \
  INIT_BRACE_END                                                            \
}

/*
 * Generate a client option of type OT_FONT.
 *
 * oname: The option data.  Note it is used as name to be loaded or saved.
 *        So, you shouldn't change the name of this variable in any case.
 *        Be sure to pass the array variable and not a pointer to it because
 *        the size is calculated with sizeof().
 * otgt:  The target widget style.
 * odesc: A short description of the client option.  Should be used with the
 *        N_() macro.
 * ohelp: The help text for the client option.  Should be used with the N_()
 *        macro.
 * ocat:  The client_option_class of this client option.
 * ospec: A gui_type enumerator which determin for what particular client
 *        gui this option is for. Sets to GUI_STUB for common options.
 * odef:  The default string for this client option.
 * ocb:   A callback function of type void (*)(struct option *) called when
 *        the option changed.
 */
#define GEN_FONT_OPTION(oname, otgt, odesc, ohelp, ocat, ospec, odef, ocb)  \
{                                                                           \
  .base_option = OPTION_FONT_INIT(&client_optset_static,                    \
                                  client_option_common_vtable,              \
                                  client_option_font_vtable, ocb),          \
  .name = #oname,                                                           \
  .description = odesc,                                                     \
  .help_text = ohelp,                                                       \
  .category = ocat,                                                         \
  .specific = ospec,                                                        \
  INIT_BRACE_BEGIN                                                          \
    .font = {                                                               \
      .pvalue = gui_options.oname,                                          \
      .size = sizeof(gui_options.oname),                                    \
      .def = odef,                                                          \
      .target = otgt,                                                       \
    }                                                                       \
  INIT_BRACE_END                                                            \
}

/*
 * Generate a client option of type OT_COLOR.
 *
 * oname: The option data.  Note it is used as name to be loaded or saved.
 *        So, you shouldn't change the name of this variable in any case.
 * odesc: A short description of the client option.  Should be used with the
 *        N_() macro.
 * ohelp: The help text for the client option.  Should be used with the N_()
 *        macro.
 * ocat:  The client_option_class of this client option.
 * ospec: A gui_type enumerator which determin for what particular client
 *        gui this option is for. Sets to GUI_STUB for common options.
 * odef_fg, odef_bg:  The default values for this client option.
 * ocb:   A callback function of type void (*)(struct option *) called when
 *        the option changed.
 */
#define GEN_COLOR_OPTION(oname, odesc, ohelp, ocat, ospec, odef_fg,         \
                         odef_bg, ocb)                                      \
{                                                                           \
  .base_option = OPTION_COLOR_INIT(&client_optset_static,                   \
                                   client_option_common_vtable,             \
                                   client_option_color_vtable, ocb),        \
  .name = #oname,                                                           \
  .description = odesc,                                                     \
  .help_text = ohelp,                                                       \
  .category = ocat,                                                         \
  .specific = ospec,                                                        \
  INIT_BRACE_BEGIN                                                          \
    .color = {                                                              \
      .pvalue = &gui_options.oname,                                         \
      .def = FT_COLOR(odef_fg, odef_bg)                                     \
    }                                                                       \
  INIT_BRACE_END                                                            \
}

/*
 * Generate a client option of type OT_VIDEO_MODE.
 *
 * oname: The option data.  Note it is used as name to be loaded or saved.
 *        So, you shouldn't change the name of this variable in any case.
 * odesc: A short description of the client option.  Should be used with the
 *        N_() macro.
 * ohelp: The help text for the client option.  Should be used with the N_()
 *        macro.
 * ocat:  The client_option_class of this client option.
 * ospec: A gui_type enumerator which determin for what particular client
 *        gui this option is for. Sets to GUI_STUB for common options.
 * odef_width, odef_height:  The default values for this client option.
 * ocb:   A callback function of type void (*)(struct option *) called when
 *        the option changed.
 */
#define GEN_VIDEO_OPTION(oname, odesc, ohelp, ocat, ospec, odef_width,      \
                         odef_height, ocb)                                  \
{                                                                           \
  .base_option = OPTION_VIDEO_MODE_INIT(&client_optset_static,              \
                                        client_option_common_vtable,        \
                                        client_option_video_mode_vtable,    \
                                        ocb),                               \
  .name = #oname,                                                           \
  .description = odesc,                                                     \
  .help_text = ohelp,                                                       \
  .category = ocat,                                                         \
  .specific = ospec,                                                        \
  INIT_BRACE_BEGIN                                                          \
    .video_mode = {                                                         \
      .pvalue = &gui_options.oname,                                         \
      .def = VIDEO_MODE(odef_width, odef_height)                            \
    }                                                                       \
  INIT_BRACE_END                                                            \
}

/****************************************************************************
  Enumerator name accessors.
****************************************************************************/

/****************************************************************************
  GTK message/chat layout setting names accessor.
****************************************************************************/
static const struct copt_val_name
  *gui_gtk_message_chat_location_name(int value)
{
  /* Order must match enum GUI_GTK_MSGCHAT_* */
  static const struct copt_val_name names[] = {
    /* TRANS: enum value for 'gui_gtk2/gtk3_message_chat_location' */
    { "SPLIT",    N_("Split") },
    /* TRANS: enum value for 'gui_gtk2/gtk3_message_chat_location' */
    { "SEPARATE", N_("Separate") },
    /* TRANS: enum value for 'gui_gtk2/gtk3_message_chat_location' */
    { "MERGED",   N_("Merged") }
  };

  return (0 <= value && value < ARRAY_SIZE(names)
          ? names + value : NULL);
}

/****************************************************************************
  Popup tech help setting names accessor.
****************************************************************************/
static const struct copt_val_name
  *gui_popup_tech_help_name(int value)
{
  /* Order must match enum GUI_POPUP_TECH_HELP_* */
  static const struct copt_val_name names[] = {
    /* TRANS: enum value for 'gui_popup_tech_help' */
    { "ENABLED",   N_("Enabled") },
    /* TRANS: enum value for 'gui_popup_tech_help' */
    { "DISABLED",  N_("Disabled") },
    /* TRANS: enum value for 'gui_popup_tech_help' */
    { "RULESET",   N_("Ruleset") }
  };

  return (0 <= value && value < ARRAY_SIZE(names)
          ? names + value : NULL);
}

/* Some changed callbacks. */
static void reqtree_show_icons_callback(struct option *poption);
static void view_option_changed_callback(struct option *poption);
static void manual_turn_done_callback(struct option *poption);
static void voteinfo_bar_callback(struct option *poption);
static void font_changed_callback(struct option *poption);
static void mapimg_changed_callback(struct option *poption);
static void game_music_enable_callback(struct option *poption);
static void menu_music_enable_callback(struct option *poption);

static struct client_option client_options[] = {
  GEN_STR_OPTION(default_user_name,
                 N_("Login name"),
                 N_("This is the default login username that will be used "
                    "in the connection dialogs or with the -a command-line "
                    "parameter."),
                 COC_NETWORK, GUI_STUB, NULL, NULL, 0),
  GEN_BOOL_OPTION(use_prev_server, N_("Default to previously used server"),
                  N_("Automatically update \"Server\" and \"Server port\" "
                     "options to match your latest connection, so by "
                     "default you connect to the same server you used "
                     "on the previous run. You should enable "
                     "saving options on exit too, so that the automatic "
                     "updates to the options get saved too."),
                  COC_NETWORK, GUI_STUB, NULL, NULL),
  GEN_STR_OPTION(default_server_host,
                 N_("Server"),
                 N_("This is the default server hostname that will be used "
                    "in the connection dialogs or with the -a command-line "
                    "parameter."),
                 COC_NETWORK, GUI_STUB, "localhost", NULL, 0),
  GEN_INT_OPTION(default_server_port,
                 N_("Server port"),
                 N_("This is the default server port that will be used "
                    "in the connection dialogs or with the -a command-line "
                    "parameter."),
                 COC_NETWORK, GUI_STUB, DEFAULT_SOCK_PORT, 0, 65535, NULL),
  GEN_STR_OPTION(default_metaserver,
                 N_("Metaserver"),
                 N_("The metaserver is a host that the client contacts to "
                    "find out about games on the internet.  Don't change "
                    "this from its default value unless you know what "
                    "you're doing."),
                 COC_NETWORK, GUI_STUB, DEFAULT_METASERVER_OPTION, NULL, 0),
  GEN_BOOL_OPTION(heartbeat_enabled, N_("Send heartbeat messages to server"),
                  N_("Periodically send an empty heartbeat message to the "
                     "server to probe whether the connection is still up. "
                     "This can help to make it obvious when the server has "
                     "cut the connection due to a connectivity outage, if "
                     "the client would otherwise sit idle for a long period."),
                  COC_NETWORK, GUI_STUB, TRUE, NULL),
  GEN_STR_LIST_OPTION(default_sound_set_name,
                      N_("Soundset"),
                      N_("This is the soundset that will be used.  Changing "
                         "this is the same as using the -S command-line "
                         "parameter."),
                      COC_SOUND, GUI_STUB, "stdsounds", get_soundset_list, NULL, 0),
  GEN_STR_LIST_OPTION(default_music_set_name,
                      N_("Musicset"),
                      N_("This is the musicset that will be used.  Changing "
                         "this is the same as using the -m command-line "
                         "parameter."),
                      COC_SOUND, GUI_STUB, "stdmusic",
                      get_musicset_list, musicspec_reread_callback, 0),
  GEN_STR_LIST_OPTION(default_sound_plugin_name,
                      N_("Sound plugin"),
                      N_("If you have a problem with sound, try changing "
                         "the sound plugin.  The new plugin won't take "
                         "effect until you restart Freeciv.  Changing this "
                         "is the same as using the -P command-line option."),
                      COC_SOUND, GUI_STUB, NULL, get_soundplugin_list, NULL, 0),
  GEN_STR_OPTION(default_chat_logfile,
                 N_("The chat log file"),
                 N_("The name of the chat log file."),
                 COC_INTERFACE, GUI_STUB, GUI_DEFAULT_CHAT_LOGFILE, NULL, 0),
  /* gui_gtk2/3_default_theme_name and gui_sdl/2_default_theme_name are
   * different settings to avoid client crash after loading the
   * style for the other gui.  Keeps 4 different options! */
  GEN_STR_LIST_OPTION(gui_gtk2_default_theme_name, N_("Theme"),
                      N_("By changing this option you change the "
                         "active theme."),
                      COC_GRAPHICS, GUI_GTK2, FC_GTK2_DEFAULT_THEME_NAME,
                      get_themes_list, theme_reread_callback, 0),
  GEN_STR_LIST_OPTION(gui_gtk3_default_theme_name, N_("Theme"),
                      N_("By changing this option you change the "
                         "active theme."),
                      COC_GRAPHICS, GUI_GTK3, FC_GTK3_DEFAULT_THEME_NAME,
                      get_themes_list, theme_reread_callback, 0),
  GEN_STR_LIST_OPTION(gui_gtk3_22_default_theme_name, N_("Theme"),
                      N_("By changing this option you change the "
                         "active theme."),
                      COC_GRAPHICS, GUI_GTK3_22, FC_GTK3_22_DEFAULT_THEME_NAME,
                      get_themes_list, theme_reread_callback, 0),
  GEN_STR_LIST_OPTION(gui_sdl_default_theme_name, N_("Theme"),
                      N_("By changing this option you change the "
                         "active theme."),
                      COC_GRAPHICS, GUI_SDL, FC_SDL_DEFAULT_THEME_NAME,
                      get_themes_list, theme_reread_callback, 0),
  GEN_STR_LIST_OPTION(gui_sdl2_default_theme_name, N_("Theme"),
                      N_("By changing this option you change the "
                         "active theme."),
                      COC_GRAPHICS, GUI_SDL2, FC_SDL2_DEFAULT_THEME_NAME,
                      get_themes_list, theme_reread_callback, 0),
  GEN_STR_LIST_OPTION(gui_qt_default_theme_name, N_("Theme"),
                      N_("By changing this option you change the "
                         "active theme."),
                      COC_GRAPHICS, GUI_QT, FC_QT_DEFAULT_THEME_NAME,
                      get_themes_list, theme_reread_callback, 0),

  /* It's important to give empty string instead of NULL as as default
   * value. For NULL value it would default to assigning first value
   * from the tileset list returned by get_tileset_list() as default
   * tileset. We don't want default tileset assigned at all here, but
   * leave it to tilespec code that can handle tileset priority. */
  GEN_STR_LIST_OPTION(default_tileset_overhead_name, N_("Tileset (Overhead)"),
                      N_("Select the tileset used with Overhead maps. "
                         "This may change the currently active tileset, if "
                         "you are playing on such a map, in which "
                         "case this is the same as using the -t "
                         "command-line parameter."),
                      COC_GRAPHICS, GUI_STUB, "",
                      get_tileset_list, tilespec_reread_callback, 0),
  GEN_STR_LIST_OPTION(default_tileset_iso_name, N_("Tileset (Isometric)"),
                      N_("Select the tileset used with Isometric maps. "
                         "This may change the currently active tileset, if "
                         "you are playing on such a map, in which "
                         "case this is the same as using the -t "
                         "command-line parameter."),
                      COC_GRAPHICS, GUI_STUB, "",
                      get_tileset_list, tilespec_reread_callback, TF_ISO),
  GEN_STR_LIST_OPTION(default_tileset_hex_name, N_("Tileset (Hex)"),
                      N_("Select the tileset used with Hex maps. "
                         "This may change the currently active tileset, if "
                         "you are playing on such a map, in which "
                         "case this is the same as using the -t "
                         "command-line parameter."),
                      COC_GRAPHICS, GUI_STUB, "",
                      get_tileset_list, tilespec_reread_callback, TF_HEX),
  GEN_STR_LIST_OPTION(default_tileset_isohex_name, N_("Tileset (Iso-Hex)"),
                      N_("Select the tileset used with Iso-Hex maps. "
                         "This may change the currently active tileset, if "
                         "you are playing on such a map, in which "
                         "case this is the same as using the -t "
                         "command-line parameter."),
                      COC_GRAPHICS, GUI_STUB, "",
                      get_tileset_list, tilespec_reread_callback, TF_ISO | TF_HEX),

  GEN_BOOL_OPTION(draw_city_outlines, N_("Draw city outlines"),
                  N_("Setting this option will draw a line at the city "
                     "workable limit."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_city_output, N_("Draw city output"),
                  N_("Setting this option will draw city output for every "
                     "citizen."),
                  COC_GRAPHICS, GUI_STUB, FALSE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_map_grid, N_("Draw the map grid"),
                  N_("Setting this option will draw a grid over the map."),
                  COC_GRAPHICS, GUI_STUB, FALSE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_full_citybar, N_("Draw the city bar"),
                  N_("Setting this option will display a 'city bar' "
                     "containing useful information beneath each city. "
                     "Disabling this option will display only the city's "
                     "name and, optionally, production."),
                  COC_GRAPHICS, GUI_STUB,
                  TRUE, view_option_changed_callback),
  GEN_BOOL_OPTION(draw_city_names, N_("Draw the city names"),
                  N_("Setting this option will draw the names of the cities "
                     "on the map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_city_growth, N_("Draw the city growth"),
                  N_("Setting this option will draw in how many turns the "
                     "cities will grow or shrink."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_city_productions, N_("Draw the city productions"),
                  N_("Setting this option will draw what the cities are "
                     "currently building on the map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_city_buycost, N_("Draw the city buy costs"),
                  N_("Setting this option will draw how much gold is "
                     "needed to buy the production of the cities."),
                  COC_GRAPHICS, GUI_STUB, FALSE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_city_trade_routes, N_("Draw the city trade routes"),
                  N_("Setting this option will draw trade route lines "
                     "between cities which have trade routes."),
                  COC_GRAPHICS, GUI_STUB, FALSE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_terrain, N_("Draw the terrain"),
                  N_("Setting this option will draw the terrain."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_coastline, N_("Draw the coast line"),
                  N_("Setting this option will draw a line to separate the "
                     "land from the ocean."),
                  COC_GRAPHICS, GUI_STUB, FALSE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_roads_rails, N_("Draw the roads and the railroads"),
                  N_("Setting this option will draw the roads and the "
                     "railroads on the map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_irrigation, N_("Draw the irrigation"),
                  N_("Setting this option will draw the irrigation systems "
                     "on the map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_mines, N_("Draw the mines"),
                  N_("Setting this option will draw the mines on the map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_fortress_airbase, N_("Draw the bases"),
                  N_("Setting this option will draw the bases on the map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_specials, N_("Draw the resources"),
                  N_("Setting this option will draw the resources on the "
                     "map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_huts, N_("Draw the huts"),
                  N_("Setting this option will draw the huts on the "
                     "map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_pollution, N_("Draw the pollution/nuclear fallout"),
                  N_("Setting this option will draw pollution and "
                     "nuclear fallout on the map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_cities, N_("Draw the cities"),
                  N_("Setting this option will draw the cities on the map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_units, N_("Draw the units"),
                  N_("Setting this option will draw the units on the map."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(solid_color_behind_units,
                  N_("Solid unit background color"),
                  N_("Setting this option will cause units on the map "
                     "view to be drawn with a solid background color "
                     "instead of the flag backdrop."),
                  COC_GRAPHICS, GUI_STUB,
                  FALSE, view_option_changed_callback),
  GEN_BOOL_OPTION(draw_unit_shields, N_("Draw shield graphics for units"),
                  N_("Setting this option will draw a shield icon "
                     "as the flags on units.  If unset, the full flag will "
                     "be drawn."),
                  COC_GRAPHICS, GUI_STUB, TRUE, view_option_changed_callback),
  GEN_BOOL_OPTION(draw_focus_unit, N_("Draw the units in focus"),
                  N_("Setting this option will cause the currently focused "
                     "unit(s) to always be drawn, even if units are not "
                     "otherwise being drawn (for instance if 'Draw the units' "
                     "is unset)."),
                  COC_GRAPHICS, GUI_STUB, FALSE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_fog_of_war, N_("Draw the fog of war"),
                  N_("Setting this option will draw the fog of war."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_borders, N_("Draw the borders"),
                  N_("Setting this option will draw the national borders."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(draw_native, N_("Draw whether tiles are native to "
                                  "selected unit"),
                  N_("Setting this option will highlight tiles that the "
                     "currently selected unit cannot enter unaided due to "
                     "non-native terrain. (If multiple units are selected, "
                     "only tiles that all of them can enter are indicated.)"),
                  COC_GRAPHICS, GUI_STUB, FALSE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(player_dlg_show_dead_players,
                  N_("Show dead players in Nations report"),
                  N_("This option controls whether defeated nations are "
                     "shown on the Nations report page."),
                  COC_GRAPHICS, GUI_STUB, TRUE,
                  view_option_changed_callback),
  GEN_BOOL_OPTION(sound_bell_at_new_turn, N_("Sound bell at new turn"),
                  N_("Set this option to have a \"bell\" event be generated "
                     "at the start of a new turn.  You can control the "
                     "behavior of the \"bell\" event by editing the message "
                     "options."),
                  COC_SOUND, GUI_STUB, FALSE, NULL),
  GEN_INT_OPTION(smooth_move_unit_msec,
                 N_("Unit movement animation time (milliseconds)"),
                 N_("This option controls how long unit \"animation\" takes "
                    "when a unit moves on the map view.  Set it to 0 to "
                    "disable animation entirely."),
                 COC_GRAPHICS, GUI_STUB, 30, 0, 2000, NULL),
  GEN_INT_OPTION(smooth_center_slide_msec,
                 N_("Mapview recentering time (milliseconds)"),
                 N_("When the map view is recentered, it will slide "
                    "smoothly over the map to its new position.  This "
                    "option controls how long this slide lasts.  Set it to "
                    "0 to disable mapview sliding entirely."),
                 COC_GRAPHICS, GUI_STUB, 200, 0, 5000, NULL),
  GEN_INT_OPTION(smooth_combat_step_msec,
                 N_("Combat animation step time (milliseconds)"),
                 N_("This option controls the speed of combat animation "
                    "between units on the mapview.  Set it to 0 to disable "
                    "animation entirely."),
                 COC_GRAPHICS, GUI_STUB, 10, 0, 100, NULL),
  GEN_BOOL_OPTION(reqtree_show_icons,
                  N_("Show icons in the technology tree"),
                  N_("Setting this option will display icons "
                     "on the technology tree diagram. Turning "
                     "this option off makes the technology tree "
                     "more compact."),
                  COC_GRAPHICS, GUI_STUB, TRUE, reqtree_show_icons_callback),
  GEN_BOOL_OPTION(reqtree_curved_lines,
                  N_("Use curved lines in the technology tree"),
                  N_("Setting this option make the technology tree "
                     "diagram use curved lines to show technology "
                     "relations. Turning this option off causes "
                     "the lines to be drawn straight."),
                  COC_GRAPHICS, GUI_STUB, FALSE,
                  reqtree_show_icons_callback),
   GEN_COLOR_OPTION(highlight_our_names,
                    N_("Color to highlight your player/user name"),
                    N_("If set, your player and user name in the new chat "
                       "messages will be highlighted using this color as "
                       "background.  If not set, it will just not highlight "
                       "anything."),
                    COC_GRAPHICS, GUI_STUB, "#000000", "#FFFF00", NULL),
  GEN_BOOL_OPTION(ai_manual_turn_done, N_("Manual Turn Done in AI mode"),
                  N_("Disable this option if you do not want to "
                     "press the Turn Done button manually when watching "
                     "an AI player."),
                  COC_INTERFACE, GUI_STUB, TRUE, manual_turn_done_callback),
  GEN_BOOL_OPTION(auto_center_on_unit, N_("Auto center on units"),
                  N_("Set this option to have the active unit centered "
                     "automatically when the unit focus changes."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(auto_center_on_automated, N_("Show automated units"),
                  N_("Disable this option if you do not want to see "
                     "automated units autocentered and animated."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(auto_center_on_combat, N_("Auto center on combat"),
                  N_("Set this option to have any combat be centered "
                     "automatically.  Disabling this will speed up the time "
                     "between turns but may cause you to miss combat "
                     "entirely."),
                  COC_INTERFACE, GUI_STUB, FALSE, NULL),
  GEN_BOOL_OPTION(auto_center_each_turn, N_("Auto center on new turn"),
                  N_("Set this option to have the client automatically "
                     "recenter the map on a suitable location at the "
                     "start of each turn."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(wakeup_focus, N_("Focus on awakened units"),
                  N_("Set this option to have newly awoken units be "
                     "focused automatically."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(keyboardless_goto, N_("Keyboardless goto"),
                  N_("If this option is set then a goto may be initiated "
                     "by left-clicking and then holding down the mouse "
                     "button while dragging the mouse onto a different "
                     "tile."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(goto_into_unknown, N_("Allow goto into the unknown"),
                  N_("Setting this option will make the game consider "
                     "moving into unknown tiles.  If not, then goto routes "
                     "will detour around or be blocked by unknown tiles."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(center_when_popup_city, N_("Center map when popup city"),
                  N_("Setting this option makes the mapview center on a "
                     "city when its city dialog is popped up."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(concise_city_production, N_("Concise city production"),
                  N_("Set this option to make the city production (as shown "
                     "in the city dialog) to be more compact."),
                  COC_INTERFACE, GUI_STUB, FALSE, NULL),
  GEN_BOOL_OPTION(auto_turn_done, N_("End turn when done moving"),
                  N_("Setting this option makes your turn end automatically "
                     "when all your units are done moving."),
                  COC_INTERFACE, GUI_STUB, FALSE, NULL),
  GEN_BOOL_OPTION(ask_city_name, N_("Prompt for city names"),
                  N_("Disabling this option will make the names of newly "
                     "founded cities be chosen automatically by the server."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(popup_new_cities, N_("Pop up city dialog for new cities"),
                  N_("Setting this option will pop up a newly-founded "
                     "city's city dialog automatically."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(popup_actor_arrival, N_("Pop up caravan and spy actions"),
                  N_("If this option is enabled, when a unit arrives at "
                     "a city where it can perform an action like "
                     "establishing a trade route, helping build a wonder, or "
                     "establishing an embassy, a window will pop up asking "
                     "which action should be performed. "
                     "Disabling this option means you will have to do the "
                     "action manually by pressing either 'r' (for a trade "
                     "route), 'b' (for building a wonder) or 'd' (for a "
                     "spy action) when the unit is in the city."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(enable_cursor_changes, N_("Enable cursor changing"),
                  N_("This option controls whether the client should "
                     "try to change the mouse cursor depending on what "
                     "is being pointed at, as well as to indicate "
                     "changes in the client or server state."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(separate_unit_selection, N_("Select cities before units"),
                  N_("If this option is enabled, when both cities and "
                     "units are present in the selection rectangle, only "
                     "cities will be selected. See the help on Controls."),
                  COC_INTERFACE, GUI_STUB, FALSE, NULL),
  GEN_BOOL_OPTION(unit_selection_clears_orders,
                  N_("Clear unit orders on selection"),
                  N_("Enabling this option will cause unit orders to be "
                     "cleared as soon as one or more units are selected. If "
                     "this option is disabled, busy units will not stop "
                     "their current activity when selected. Giving them "
                     "new orders will clear their current ones; pressing "
                     "<space> once will clear their orders and leave them "
                     "selected, and pressing <space> a second time will "
                     "dismiss them."),
                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(voteinfo_bar_use, N_("Enable vote bar"),
                  N_("If this option is turned on, the vote bar will be "
                     "displayed to show vote information."),
                  COC_GRAPHICS, GUI_STUB, TRUE, voteinfo_bar_callback),
  GEN_BOOL_OPTION(voteinfo_bar_always_show,
                  N_("Always display the vote bar"),
                  N_("If this option is turned on, the vote bar will never "
                     "be hidden, even if there is no running vote."),
                  COC_GRAPHICS, GUI_STUB, FALSE, voteinfo_bar_callback),
  GEN_BOOL_OPTION(voteinfo_bar_hide_when_not_player,
                  N_("Do not show vote bar if not a player"),
                  N_("If this option is enabled, the client won't show the "
                     "vote bar if you are not a player."),
                  COC_GRAPHICS, GUI_STUB, FALSE, voteinfo_bar_callback),
  GEN_BOOL_OPTION(voteinfo_bar_new_at_front, N_("Set new votes at front"),
                  N_("If this option is enabled, then new votes will go "
                     "to the front of the vote list."),
                  COC_GRAPHICS, GUI_STUB, FALSE, voteinfo_bar_callback),
  GEN_BOOL_OPTION(autoaccept_tileset_suggestion,
                  N_("Autoaccept tileset suggestions"),
                  N_("If this option is enabled, any tileset suggested by "
                     "the ruleset is automatically used; otherwise you "
                     "are prompted to change tileset."),
                  COC_GRAPHICS, GUI_STUB, FALSE, NULL),

  GEN_BOOL_OPTION(sound_enable_effects,
                  N_("Enable sound effects"),
                  N_("Play sound effects, assuming there's suitable "
                     "sound plugin and soundset with the sounds."),
                  COC_SOUND, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(sound_enable_game_music,
                  N_("Enable in-game music"),
                  N_("Play music during the game, assuming there's suitable "
                     "sound plugin and musicset with in-game tracks."),
                  COC_SOUND, GUI_STUB, TRUE, game_music_enable_callback),
 GEN_BOOL_OPTION(sound_enable_menu_music,
                  N_("Enable menu music"),
                  N_("Play music while not in actual game, "
                     "assuming there's suitable "
                     "sound plugin and musicset with menu music tracks."),
                  COC_SOUND, GUI_STUB, TRUE, menu_music_enable_callback),
  GEN_BOOL_OPTION(autoaccept_soundset_suggestion,
                  N_("Autoaccept soundset suggestions"),
                  N_("If this option is enabled, any soundset suggested by "
                     "the ruleset is automatically used."),
                  COC_SOUND, GUI_STUB, FALSE, NULL),
  GEN_BOOL_OPTION(autoaccept_musicset_suggestion,
                  N_("Autoaccept musicset suggestions"),
                  N_("If this option is enabled, any musicset suggested by "
                     "the ruleset is automatically used."),
                  COC_SOUND, GUI_STUB, FALSE, NULL),

  GEN_BOOL_OPTION(overview.layers[OLAYER_BACKGROUND],
                  N_("Background layer"),
                  N_("The background layer of the overview shows just "
                     "ocean and land."),
                  COC_OVERVIEW, GUI_STUB, TRUE, NULL),
  GEN_BOOL_OPTION(overview.layers[OLAYER_RELIEF],
                  N_("Terrain relief map layer"),
                  N_("The relief layer shows all terrains on the map."),
                  COC_OVERVIEW, GUI_STUB, FALSE, overview_redraw_callback),
  GEN_BOOL_OPTION(overview.layers[OLAYER_BORDERS],
                  N_("Borders layer"),
                  N_("The borders layer of the overview shows which tiles "
                     "are owned by each player."),
                  COC_OVERVIEW, GUI_STUB, FALSE, overview_redraw_callback),
  GEN_BOOL_OPTION(overview.layers[OLAYER_BORDERS_ON_OCEAN],
                  N_("Borders layer on ocean tiles"),
                  N_("The borders layer of the overview are drawn on "
                     "ocean tiles as well (this may look ugly with many "
                     "islands). This option is only of interest if you "
                     "have set the option \"Borders layer\" already."),
                  COC_OVERVIEW, GUI_STUB, TRUE, overview_redraw_callback),
  GEN_BOOL_OPTION(overview.layers[OLAYER_UNITS],
                  N_("Units layer"),
                  N_("Enabling this will draw units on the overview."),
                  COC_OVERVIEW, GUI_STUB, TRUE, overview_redraw_callback),
  GEN_BOOL_OPTION(overview.layers[OLAYER_CITIES],
                  N_("Cities layer"),
                  N_("Enabling this will draw cities on the overview."),
                  COC_OVERVIEW, GUI_STUB, TRUE, overview_redraw_callback),
  GEN_BOOL_OPTION(overview.fog,
                  N_("Overview fog of war"),
                  N_("Enabling this will show fog of war on the "
                     "overview."),
                  COC_OVERVIEW, GUI_STUB, TRUE, overview_redraw_callback),

  /* options for map images */
  GEN_STR_LIST_OPTION(mapimg_format,
                      N_("Image format"),
                      N_("The image toolkit and file format used for "
                         "map images."),
                      COC_MAPIMG, GUI_STUB, NULL, get_mapimg_format_list,
                      NULL, 0),
  GEN_INT_OPTION(mapimg_zoom,
                 N_("Zoom factor for map images"),
                 N_("The magnification used for map images."),
                 COC_MAPIMG, GUI_STUB, 2, 1, 5, mapimg_changed_callback),
  GEN_BOOL_OPTION(mapimg_layer[MAPIMG_LAYER_AREA],
                  N_("Show area within borders"),
                  N_("If set, the territory of each nation is shown "
                     "on the saved image."),
                  COC_MAPIMG, GUI_STUB, FALSE, mapimg_changed_callback),
  GEN_BOOL_OPTION(mapimg_layer[MAPIMG_LAYER_BORDERS],
                  N_("Show borders"),
                  N_("If set, the border of each nation is shown on the "
                     "saved image."),
                  COC_MAPIMG, GUI_STUB, TRUE, mapimg_changed_callback),
  GEN_BOOL_OPTION(mapimg_layer[MAPIMG_LAYER_CITIES],
                  N_("Show cities"),
                  N_("If set, cities are shown on the saved image."),
                  COC_MAPIMG, GUI_STUB, TRUE, mapimg_changed_callback),
  GEN_BOOL_OPTION(mapimg_layer[MAPIMG_LAYER_FOGOFWAR],
                  N_("Show fog of war"),
                  N_("If set, the extent of fog of war is shown on the "
                     "saved image."),
                  COC_MAPIMG, GUI_STUB, TRUE, mapimg_changed_callback),
  GEN_BOOL_OPTION(mapimg_layer[MAPIMG_LAYER_TERRAIN],
                  N_("Show full terrain"),
                  N_("If set, terrain relief is shown with different colors "
                     "in the saved image; otherwise, only land and water are "
                     "distinguished."),
                  COC_MAPIMG, GUI_STUB, TRUE, mapimg_changed_callback),
  GEN_BOOL_OPTION(mapimg_layer[MAPIMG_LAYER_UNITS],
                  N_("Show units"),
                  N_("If set, units are shown in the saved image."),
                  COC_MAPIMG, GUI_STUB, TRUE, mapimg_changed_callback),
  GEN_STR_OPTION(mapimg_filename,
                 N_("Map image file name"),
                 N_("The base part of the filename for saved map images. "
                    "A string identifying the game turn and map options will "
                    "be appended."),
                 COC_MAPIMG, GUI_STUB, GUI_DEFAULT_MAPIMG_FILENAME, NULL, 0),

  /* gui-gtk-2.0 client specific options. */
  GEN_BOOL_OPTION(gui_gtk2_fullscreen, N_("Fullscreen"),
                  N_("If this option is set the client will use the "
                     "whole screen area for drawing."),
                  COC_INTERFACE, GUI_GTK2, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_map_scrollbars, N_("Show map scrollbars"),
                  N_("Disable this option to hide the scrollbars on the "
                     "map view."),
                  COC_INTERFACE, GUI_GTK2, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_dialogs_on_top, N_("Keep dialogs on top"),
                  N_("If this option is set then dialog windows will always "
                     "remain in front of the main Freeciv window. "
                     "Disabling this has no effect in fullscreen mode."),
                  COC_INTERFACE, GUI_GTK2, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_show_task_icons, N_("Show worklist task icons"),
                  N_("Disabling this will turn off the unit and building "
                     "icons in the worklist dialog and the production "
                     "tab of the city dialog."),
                  COC_GRAPHICS, GUI_GTK2, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_enable_tabs, N_("Enable status report tabs"),
                  N_("If this option is enabled then report dialogs will "
                     "be shown as separate tabs rather than in popup "
                     "dialogs."),
                  COC_INTERFACE, GUI_GTK2, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_better_fog,
                  N_("Better fog-of-war drawing"),
                  N_("If this is enabled then a better method is used "
                     "for drawing fog-of-war.  It is not any slower but "
                     "will consume about twice as much memory."),
                  COC_GRAPHICS, GUI_GTK2,
                  TRUE, view_option_changed_callback),
  GEN_BOOL_OPTION(gui_gtk2_show_chat_message_time,
                  N_("Show time for each chat message"),
                  N_("If this option is enabled then all chat messages "
                     "will be prefixed by a time string of the form "
                     "[hour:minute:second]."),
                  COC_INTERFACE, GUI_GTK2, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_new_messages_go_to_top,
                  N_("New message events go to top of list"),
                  N_("If this option is enabled, new events in the "
                     "message window will appear at the top of the list, "
                     "rather than being appended at the bottom."),
                  COC_INTERFACE, GUI_GTK2, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_show_message_window_buttons,
                  N_("Show extra message window buttons"),
                  N_("If this option is enabled, there will be two "
                     "buttons displayed in the message window for "
                     "inspecting a city and going to a location. If this "
                     "option is disabled, these buttons will not appear "
                     "(you can still double-click with the left mouse "
                     "button or right-click on a row to inspect or goto "
                     "respectively). This option will only take effect "
                     "once the message window is closed and reopened."),
                  COC_INTERFACE, GUI_GTK2, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_metaserver_tab_first,
                  N_("Metaserver tab first in network page"),
                  N_("If this option is enabled, the metaserver tab will "
                     "be the first notebook tab in the network page. This "
                     "option requires a restart in order to take effect."),
                  COC_NETWORK, GUI_GTK2, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_allied_chat_only,
                  N_("Plain chat messages are sent to allies only"),
                  N_("If this option is enabled, then plain messages "
                     "typed into the chat entry while the game is "
                     "running will only be sent to your allies. "
                     "Otherwise plain messages will be sent as "
                     "public chat messages. To send a public chat "
                     "message with this option enabled, prefix the "
                     "message with a single colon ':'. This option "
                     "can also be set using a toggle button beside "
                     "the chat entry (only visible in multiplayer "
                     "games)."),
                  COC_INTERFACE, GUI_GTK2, FALSE, NULL),
  GEN_ENUM_OPTION(gui_gtk2_message_chat_location,
                  N_("Messages and Chat reports location"),
                  /* TRANS: The strings used in the UI for 'Split' etc are
                   * tagged 'gui_gtk2/gtk3_message_chat_location' */
                  N_("Controls where the Messages and Chat reports "
                     "appear relative to the main view containing the map.\n"
                     "'Split' allows all three to be seen simultaneously, "
                     "which is best for multiplayer, but requires a large "
                     "window to be usable.\n"
                     "'Separate' puts Messages and Chat in a notebook "
                     "separate from the main view, so that one of them "
                     "can always be seen alongside the main view.\n"
                     "'Merged' makes the Messages and Chat reports into "
                     "tabs alongside the map and other reports; this "
                     "allows a larger map view on small screens.\n"
                     "This option requires a restart in order to take "
                     "effect."), COC_INTERFACE, GUI_GTK2,
                  GUI_GTK_MSGCHAT_MERGED /* Ignored! See options_load(). */,
                  gui_gtk_message_chat_location_name, NULL),
  GEN_BOOL_OPTION(gui_gtk2_small_display_layout,
                  N_("Arrange widgets for small displays"),
                  N_("If this option is enabled, widgets in the main "
                     "window will be arranged so that they take up the "
                     "least amount of total screen space. Specifically, "
                     "the left panel containing the overview, player "
                     "status, and the unit information box will be "
                     "extended over the entire left side of the window. "
                     "This option requires a restart in order to take "
                     "effect."), COC_INTERFACE, GUI_GTK2, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_mouse_over_map_focus,
                  N_("Mouse over the map widget selects it automatically"),
                  N_("If this option is enabled, then the map will be "
                     "focused when the mouse hovers over it."),
                  COC_INTERFACE, GUI_GTK2, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk2_chatline_autocompletion,
                  N_("Player or user name autocompletion"),
                  N_("If this option is turned on, the tabulation key "
                     "will be used in the chatline to complete the word you "
                     "are typing with the name of a player or a user."),
                  COC_INTERFACE, GUI_GTK2, TRUE, NULL),
  GEN_INT_OPTION(gui_gtk2_citydlg_xsize,
                 N_("Width of the city dialog"),
                 N_("This value is only used if the width of the city "
                    "dialog is saved."),
                 COC_INTERFACE, GUI_GTK2, GUI_GTK2_CITYDLG_DEFAULT_XSIZE,
                 GUI_GTK2_CITYDLG_MIN_XSIZE, GUI_GTK2_CITYDLG_MAX_XSIZE,
                 NULL),
  GEN_INT_OPTION(gui_gtk2_citydlg_ysize,
                 N_("Height of the city dialog"),
                 N_("This value is only used if the height of the city "
                    "dialog is saved."),
                 COC_INTERFACE, GUI_GTK2, GUI_GTK2_CITYDLG_DEFAULT_YSIZE,
                 GUI_GTK2_CITYDLG_MIN_YSIZE, GUI_GTK2_CITYDLG_MAX_YSIZE,
                 NULL),
  GEN_ENUM_OPTION(gui_gtk2_popup_tech_help,
                  N_("Popup tech help when gained"),
                  N_("Controls if tech help should be opened when "
                     "new tech has been gained.\n"
                     "'Ruleset' means that behavior suggested by "
                     "current ruleset is used."), COC_INTERFACE, GUI_GTK2,
                  GUI_POPUP_TECH_HELP_RULESET,
                  gui_popup_tech_help_name, NULL),
  GEN_FONT_OPTION(gui_gtk2_font_city_label, "city_label",
                  N_("City Label"),
                  N_("This font is used to display the city labels on city "
                     "dialogs."),
                  COC_FONT, GUI_GTK2,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk2_font_notify_label, "notify_label",
                  N_("Notify Label"),
                  N_("This font is used to display server reports such "
                     "as the demographic report or historian publications."),
                  COC_FONT, GUI_GTK2,
                  "Monospace Bold 9", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk2_font_spaceship_label, "spaceship_label",
                  N_("Spaceship Label"),
                  N_("This font is used to display the spaceship widgets."),
                  COC_FONT, GUI_GTK2,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk2_font_help_label, "help_label",
                  N_("Help Label"),
                  N_("This font is used to display the help headers in the "
                     "help window."),
                  COC_FONT, GUI_GTK2,
                  "Sans Bold 10", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk2_font_help_link, "help_link",
                  N_("Help Link"),
                  N_("This font is used to display the help links in the "
                     "help window."),
                  COC_FONT, GUI_GTK2,
                  "Sans 9", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk2_font_help_text, "help_text",
                  N_("Help Text"),
                  N_("This font is used to display the help body text in "
                     "the help window."),
                  COC_FONT, GUI_GTK2,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk2_font_chatline, "chatline",
                  N_("Chatline Area"),
                  N_("This font is used to display the text in the "
                     "chatline area."),
                  COC_FONT, GUI_GTK2,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk2_font_beta_label, "beta_label",
                  N_("Beta Label"),
                  N_("This font is used to display the beta label."),
                  COC_FONT, GUI_GTK2,
                  "Sans Italic 10", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk2_font_small, "small_font",
                  N_("Small Font"),
                  N_("This font is used for any small font request.  For "
                     "example, it is used for display the building lists "
                     "in the city dialog, the Economy report or the Units "
                     "report."),
                  COC_FONT, GUI_GTK2,
                  "Sans 9", NULL),
  GEN_FONT_OPTION(gui_gtk2_font_comment_label, "comment_label",
                  N_("Comment Label"),
                  N_("This font is used to display comment labels, such as "
                     "in the governor page of the city dialogs."),
                  COC_FONT, GUI_GTK2,
                  "Sans Italic 9", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk2_font_city_names, "city_names",
                  N_("City Names"),
                  N_("This font is used to the display the city names "
                     "on the map."),
                  COC_FONT, GUI_GTK2,
                  "Sans Bold 10", NULL),
  GEN_FONT_OPTION(gui_gtk2_font_city_productions, "city_productions",
                  N_("City Productions"),
                  N_("This font is used to display the city production "
                     "on the map."),
                  COC_FONT, GUI_GTK2,
                  "Serif 10", NULL),
  GEN_FONT_OPTION(gui_gtk2_font_reqtree_text, "reqtree_text",
                  N_("Requirement Tree"),
                  N_("This font is used to the display the requirement tree "
                     "in the Research report."),
                  COC_FONT, GUI_GTK2,
                  "Serif 10", NULL),

  /* gui-gtk-3.0 client specific options. */
  GEN_BOOL_OPTION(gui_gtk3_fullscreen, N_("Fullscreen"),
                  N_("If this option is set the client will use the "
                     "whole screen area for drawing."),
                  COC_INTERFACE, GUI_GTK3, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_map_scrollbars, N_("Show map scrollbars"),
                  N_("Disable this option to hide the scrollbars on the "
                     "map view."),
                  COC_INTERFACE, GUI_GTK3, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_dialogs_on_top, N_("Keep dialogs on top"),
                  N_("If this option is set then dialog windows will always "
                     "remain in front of the main Freeciv window. "
                     "Disabling this has no effect in fullscreen mode."),
                  COC_INTERFACE, GUI_GTK3, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_show_task_icons, N_("Show worklist task icons"),
                  N_("Disabling this will turn off the unit and building "
                     "icons in the worklist dialog and the production "
                     "tab of the city dialog."),
                  COC_GRAPHICS, GUI_GTK3, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_enable_tabs, N_("Enable status report tabs"),
                  N_("If this option is enabled then report dialogs will "
                     "be shown as separate tabs rather than in popup "
                     "dialogs."),
                  COC_INTERFACE, GUI_GTK3, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_show_chat_message_time,
                  N_("Show time for each chat message"),
                  N_("If this option is enabled then all chat messages "
                     "will be prefixed by a time string of the form "
                     "[hour:minute:second]."),
                  COC_INTERFACE, GUI_GTK3, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_new_messages_go_to_top,
                  N_("New message events go to top of list"),
                  N_("If this option is enabled, new events in the "
                     "message window will appear at the top of the list, "
                     "rather than being appended at the bottom."),
                  COC_INTERFACE, GUI_GTK3, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_show_message_window_buttons,
                  N_("Show extra message window buttons"),
                  N_("If this option is enabled, there will be two "
                     "buttons displayed in the message window for "
                     "inspecting a city and going to a location. If this "
                     "option is disabled, these buttons will not appear "
                     "(you can still double-click with the left mouse "
                     "button or right-click on a row to inspect or goto "
                     "respectively). This option will only take effect "
                     "once the message window is closed and reopened."),
                  COC_INTERFACE, GUI_GTK3, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_metaserver_tab_first,
                  N_("Metaserver tab first in network page"),
                  N_("If this option is enabled, the metaserver tab will "
                     "be the first notebook tab in the network page. This "
                     "option requires a restart in order to take effect."),
                  COC_NETWORK, GUI_GTK3, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_allied_chat_only,
                  N_("Plain chat messages are sent to allies only"),
                  N_("If this option is enabled, then plain messages "
                     "typed into the chat entry while the game is "
                     "running will only be sent to your allies. "
                     "Otherwise plain messages will be sent as "
                     "public chat messages. To send a public chat "
                     "message with this option enabled, prefix the "
                     "message with a single colon ':'. This option "
                     "can also be set using a toggle button beside "
                     "the chat entry (only visible in multiplayer "
                     "games)."),
                  COC_INTERFACE, GUI_GTK3, FALSE, NULL),
  GEN_ENUM_OPTION(gui_gtk3_message_chat_location,
                  N_("Messages and Chat reports location"),
                  /* TRANS: The strings used in the UI for 'Split' etc are
                   * tagged 'gui_gtk2/gtk3_message_chat_location' */
                  N_("Controls where the Messages and Chat reports "
                     "appear relative to the main view containing the map.\n"
                     "'Split' allows all three to be seen simultaneously, "
                     "which is best for multiplayer, but requires a large "
                     "window to be usable.\n"
                     "'Separate' puts Messages and Chat in a notebook "
                     "separate from the main view, so that one of them "
                     "can always be seen alongside the main view.\n"
                     "'Merged' makes the Messages and Chat reports into "
                     "tabs alongside the map and other reports; this "
                     "allows a larger map view on small screens.\n"
                     "This option requires a restart in order to take "
                     "effect."), COC_INTERFACE, GUI_GTK3,
                  GUI_GTK_MSGCHAT_MERGED /* Ignored! See options_load(). */,
                  gui_gtk_message_chat_location_name, NULL),
  GEN_BOOL_OPTION(gui_gtk3_small_display_layout,
                  N_("Arrange widgets for small displays"),
                  N_("If this option is enabled, widgets in the main "
                     "window will be arranged so that they take up the "
                     "least amount of total screen space. Specifically, "
                     "the left panel containing the overview, player "
                     "status, and the unit information box will be "
                     "extended over the entire left side of the window. "
                     "This option requires a restart in order to take "
                     "effect."), COC_INTERFACE, GUI_GTK3, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_mouse_over_map_focus,
                  N_("Mouse over the map widget selects it automatically"),
                  N_("If this option is enabled, then the map will be "
                     "focused when the mouse hovers over it."),
                  COC_INTERFACE, GUI_GTK3, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_chatline_autocompletion,
                  N_("Player or user name autocompletion"),
                  N_("If this option is turned on, the tabulation key "
                     "will be used in the chatline to complete the word you "
                     "are typing with the name of a player or a user."),
                  COC_INTERFACE, GUI_GTK3, TRUE, NULL),
  GEN_INT_OPTION(gui_gtk3_citydlg_xsize,
                 N_("Width of the city dialog"),
                 N_("This value is only used if the width of the city "
                    "dialog is saved."),
                 COC_INTERFACE, GUI_GTK3, GUI_GTK3_CITYDLG_DEFAULT_XSIZE,
                 GUI_GTK3_CITYDLG_MIN_XSIZE, GUI_GTK3_CITYDLG_MAX_XSIZE,
                 NULL),
  GEN_INT_OPTION(gui_gtk3_citydlg_ysize,
                 N_("Height of the city dialog"),
                 N_("This value is only used if the height of the city "
                    "dialog is saved."),
                 COC_INTERFACE, GUI_GTK3, GUI_GTK3_CITYDLG_DEFAULT_YSIZE,
                 GUI_GTK3_CITYDLG_MIN_YSIZE, GUI_GTK3_CITYDLG_MAX_YSIZE,
                 NULL),
  GEN_ENUM_OPTION(gui_gtk3_popup_tech_help,
                  N_("Popup tech help when gained"),
                  N_("Controls if tech help should be opened when "
                     "new tech has been gained.\n"
                     "'Ruleset' means that behavior suggested by "
                     "current ruleset is used."), COC_INTERFACE, GUI_GTK3,
                  GUI_POPUP_TECH_HELP_RULESET,
                  gui_popup_tech_help_name, NULL),
  GEN_INT_OPTION(gui_gtk3_governor_range_min,
                 N_("Minimum surplus for a governor"),
                 N_("The lower limit of the range for requesting surpluses "
                    "from the governor."),
                 COC_INTERFACE, GUI_GTK3, GUI_GTK3_GOV_RANGE_MIN_DEFAULT,
                 GUI_GTK3_GOV_RANGE_MIN_MIN, GUI_GTK3_GOV_RANGE_MIN_MAX,
                 NULL),
  GEN_INT_OPTION(gui_gtk3_governor_range_max,
                 N_("Maximum surplus for a governor"),
                 N_("The higher limit of the range for requesting surpluses "
                    "from the governor."),
                 COC_INTERFACE, GUI_GTK3, GUI_GTK3_GOV_RANGE_MAX_DEFAULT,
                 GUI_GTK3_GOV_RANGE_MAX_MIN, GUI_GTK3_GOV_RANGE_MAX_MAX,
                 NULL),
  GEN_FONT_OPTION(gui_gtk3_font_city_label, "city_label",
                  N_("City Label"),
                  N_("This font is used to display the city labels on city "
                     "dialogs."),
                  COC_FONT, GUI_GTK3,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_font_notify_label, "notify_label",
                  N_("Notify Label"),
                  N_("This font is used to display server reports such "
                     "as the demographic report or historian publications."),
                  COC_FONT, GUI_GTK3,
                  "Monospace Bold 9", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_font_spaceship_label, "spaceship_label",
                  N_("Spaceship Label"),
                  N_("This font is used to display the spaceship widgets."),
                  COC_FONT, GUI_GTK3,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_font_help_label, "help_label",
                  N_("Help Label"),
                  N_("This font is used to display the help headers in the "
                     "help window."),
                  COC_FONT, GUI_GTK3,
                  "Sans Bold 10", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_font_help_link, "help_link",
                  N_("Help Link"),
                  N_("This font is used to display the help links in the "
                     "help window."),
                  COC_FONT, GUI_GTK3,
                  "Sans 9", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_font_help_text, "help_text",
                  N_("Help Text"),
                  N_("This font is used to display the help body text in "
                     "the help window."),
                  COC_FONT, GUI_GTK3,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_font_chatline, "chatline",
                  N_("Chatline Area"),
                  N_("This font is used to display the text in the "
                     "chatline area."),
                  COC_FONT, GUI_GTK3,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_font_beta_label, "beta_label",
                  N_("Beta Label"),
                  N_("This font is used to display the beta label."),
                  COC_FONT, GUI_GTK3,
                  "Sans Italic 10", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_font_small, "small_font",
                  N_("Small Font"),
                  N_("This font is used for any small font request.  For "
                     "example, it is used for display the building lists "
                     "in the city dialog, the Economy report or the Units "
                     "report."),
                  COC_FONT, GUI_GTK3,
                  "Sans 9", NULL),
  GEN_FONT_OPTION(gui_gtk3_font_comment_label, "comment_label",
                  N_("Comment Label"),
                  N_("This font is used to display comment labels, such as "
                     "in the governor page of the city dialogs."),
                  COC_FONT, GUI_GTK3,
                  "Sans Italic 9", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_font_city_names, "city_names",
                  N_("City Names"),
                  N_("This font is used to the display the city names "
                     "on the map."),
                  COC_FONT, GUI_GTK3,
                  "Sans Bold 10", NULL),
  GEN_FONT_OPTION(gui_gtk3_font_city_productions, "city_productions",
                  N_("City Productions"),
                  N_("This font is used to display the city production "
                     "on the map."),
                  COC_FONT, GUI_GTK3,
                  "Serif 10", NULL),
  GEN_FONT_OPTION(gui_gtk3_font_reqtree_text, "reqtree_text",
                  N_("Requirement Tree"),
                  N_("This font is used to the display the requirement tree "
                     "in the Research report."),
                  COC_FONT, GUI_GTK3,
                  "Serif 10", NULL),

  /* gui-gtk-3.22 client specific options. */
  GEN_BOOL_OPTION(gui_gtk3_22_fullscreen, N_("Fullscreen"),
                  N_("If this option is set the client will use the "
                     "whole screen area for drawing."),
                  COC_INTERFACE, GUI_GTK3_22, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_map_scrollbars, N_("Show map scrollbars"),
                  N_("Disable this option to hide the scrollbars on the "
                     "map view."),
                  COC_INTERFACE, GUI_GTK3_22, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_dialogs_on_top, N_("Keep dialogs on top"),
                  N_("If this option is set then dialog windows will always "
                     "remain in front of the main Freeciv window. "
                     "Disabling this has no effect in fullscreen mode."),
                  COC_INTERFACE, GUI_GTK3_22, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_show_task_icons, N_("Show worklist task icons"),
                  N_("Disabling this will turn off the unit and building "
                     "icons in the worklist dialog and the production "
                     "tab of the city dialog."),
                  COC_GRAPHICS, GUI_GTK3_22, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_enable_tabs, N_("Enable status report tabs"),
                  N_("If this option is enabled then report dialogs will "
                     "be shown as separate tabs rather than in popup "
                     "dialogs."),
                  COC_INTERFACE, GUI_GTK3_22, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_show_chat_message_time,
                  N_("Show time for each chat message"),
                  N_("If this option is enabled then all chat messages "
                     "will be prefixed by a time string of the form "
                     "[hour:minute:second]."),
                  COC_INTERFACE, GUI_GTK3_22, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_new_messages_go_to_top,
                  N_("New message events go to top of list"),
                  N_("If this option is enabled, new events in the "
                     "message window will appear at the top of the list, "
                     "rather than being appended at the bottom."),
                  COC_INTERFACE, GUI_GTK3_22, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_show_message_window_buttons,
                  N_("Show extra message window buttons"),
                  N_("If this option is enabled, there will be two "
                     "buttons displayed in the message window for "
                     "inspecting a city and going to a location. If this "
                     "option is disabled, these buttons will not appear "
                     "(you can still double-click with the left mouse "
                     "button or right-click on a row to inspect or goto "
                     "respectively). This option will only take effect "
                     "once the message window is closed and reopened."),
                  COC_INTERFACE, GUI_GTK3_22, TRUE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_metaserver_tab_first,
                  N_("Metaserver tab first in network page"),
                  N_("If this option is enabled, the metaserver tab will "
                     "be the first notebook tab in the network page. This "
                     "option requires a restart in order to take effect."),
                  COC_NETWORK, GUI_GTK3_22, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_allied_chat_only,
                  N_("Plain chat messages are sent to allies only"),
                  N_("If this option is enabled, then plain messages "
                     "typed into the chat entry while the game is "
                     "running will only be sent to your allies. "
                     "Otherwise plain messages will be sent as "
                     "public chat messages. To send a public chat "
                     "message with this option enabled, prefix the "
                     "message with a single colon ':'. This option "
                     "can also be set using a toggle button beside "
                     "the chat entry (only visible in multiplayer "
                     "games)."),
                  COC_INTERFACE, GUI_GTK3_22, FALSE, NULL),
  GEN_ENUM_OPTION(gui_gtk3_22_message_chat_location,
                  N_("Messages and Chat reports location"),
                  /* TRANS: The strings used in the UI for 'Split' etc are
                   * tagged 'gui_gtk2/gtk3_message_chat_location' */
                  N_("Controls where the Messages and Chat reports "
                     "appear relative to the main view containing the map.\n"
                     "'Split' allows all three to be seen simultaneously, "
                     "which is best for multiplayer, but requires a large "
                     "window to be usable.\n"
                     "'Separate' puts Messages and Chat in a notebook "
                     "separate from the main view, so that one of them "
                     "can always be seen alongside the main view.\n"
                     "'Merged' makes the Messages and Chat reports into "
                     "tabs alongside the map and other reports; this "
                     "allows a larger map view on small screens.\n"
                     "This option requires a restart in order to take "
                     "effect."), COC_INTERFACE, GUI_GTK3_22,
                  GUI_GTK_MSGCHAT_MERGED /* Ignored! See options_load(). */,
                  gui_gtk_message_chat_location_name, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_small_display_layout,
                  N_("Arrange widgets for small displays"),
                  N_("If this option is enabled, widgets in the main "
                     "window will be arranged so that they take up the "
                     "least amount of total screen space. Specifically, "
                     "the left panel containing the overview, player "
                     "status, and the unit information box will be "
                     "extended over the entire left side of the window. "
                     "This option requires a restart in order to take "
                     "effect."), COC_INTERFACE, GUI_GTK3_22, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_mouse_over_map_focus,
                  N_("Mouse over the map widget selects it automatically"),
                  N_("If this option is enabled, then the map will be "
                     "focused when the mouse hovers over it."),
                  COC_INTERFACE, GUI_GTK3_22, FALSE, NULL),
  GEN_BOOL_OPTION(gui_gtk3_22_chatline_autocompletion,
                  N_("Player or user name autocompletion"),
                  N_("If this option is turned on, the tabulation key "
                     "will be used in the chatline to complete the word you "
                     "are typing with the name of a player or a user."),
                  COC_INTERFACE, GUI_GTK3_22, TRUE, NULL),
  GEN_INT_OPTION(gui_gtk3_22_citydlg_xsize,
                 N_("Width of the city dialog"),
                 N_("This value is only used if the width of the city "
                    "dialog is saved."),
                 COC_INTERFACE, GUI_GTK3_22, GUI_GTK3_22_CITYDLG_DEFAULT_XSIZE,
                 GUI_GTK3_22_CITYDLG_MIN_XSIZE, GUI_GTK3_22_CITYDLG_MAX_XSIZE,
                 NULL),
  GEN_INT_OPTION(gui_gtk3_22_citydlg_ysize,
                 N_("Height of the city dialog"),
                 N_("This value is only used if the height of the city "
                    "dialog is saved."),
                 COC_INTERFACE, GUI_GTK3_22, GUI_GTK3_22_CITYDLG_DEFAULT_YSIZE,
                 GUI_GTK3_22_CITYDLG_MIN_YSIZE, GUI_GTK3_22_CITYDLG_MAX_YSIZE,
                 NULL),
  GEN_ENUM_OPTION(gui_gtk3_22_popup_tech_help,
                  N_("Popup tech help when gained"),
                  N_("Controls if tech help should be opened when "
                     "new tech has been gained.\n"
                     "'Ruleset' means that behavior suggested by "
                     "current ruleset is used."), COC_INTERFACE, GUI_GTK3_22,
                  GUI_POPUP_TECH_HELP_RULESET,
                  gui_popup_tech_help_name, NULL),
  GEN_INT_OPTION(gui_gtk3_22_governor_range_min,
                 N_("Minimum surplus for a governor"),
                 N_("The lower limit of the range for requesting surpluses "
                    "from the governor."),
                 COC_INTERFACE, GUI_GTK3_22, GUI_GTK3_22_GOV_RANGE_MIN_DEFAULT,
                 GUI_GTK3_22_GOV_RANGE_MIN_MIN, GUI_GTK3_22_GOV_RANGE_MIN_MAX,
                 NULL),
  GEN_INT_OPTION(gui_gtk3_22_governor_range_max,
                 N_("Maximum surplus for a governor"),
                 N_("The higher limit of the range for requesting surpluses "
                    "from the governor."),
                 COC_INTERFACE, GUI_GTK3_22, GUI_GTK3_22_GOV_RANGE_MAX_DEFAULT,
                 GUI_GTK3_22_GOV_RANGE_MAX_MIN, GUI_GTK3_22_GOV_RANGE_MAX_MAX,
                 NULL),
  GEN_FONT_OPTION(gui_gtk3_22_font_city_label, "city_label",
                  N_("City Label"),
                  N_("This font is used to display the city labels on city "
                     "dialogs."),
                  COC_FONT, GUI_GTK3_22,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_22_font_notify_label, "notify_label",
                  N_("Notify Label"),
                  N_("This font is used to display server reports such "
                     "as the demographic report or historian publications."),
                  COC_FONT, GUI_GTK3_22,
                  "Monospace Bold 9", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_22_font_spaceship_label, "spaceship_label",
                  N_("Spaceship Label"),
                  N_("This font is used to display the spaceship widgets."),
                  COC_FONT, GUI_GTK3_22,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_22_font_help_label, "help_label",
                  N_("Help Label"),
                  N_("This font is used to display the help headers in the "
                     "help window."),
                  COC_FONT, GUI_GTK3_22,
                  "Sans Bold 10", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_22_font_help_link, "help_link",
                  N_("Help Link"),
                  N_("This font is used to display the help links in the "
                     "help window."),
                  COC_FONT, GUI_GTK3_22,
                  "Sans 9", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_22_font_help_text, "help_text",
                  N_("Help Text"),
                  N_("This font is used to display the help body text in "
                     "the help window."),
                  COC_FONT, GUI_GTK3_22,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_22_font_chatline, "chatline",
                  N_("Chatline Area"),
                  N_("This font is used to display the text in the "
                     "chatline area."),
                  COC_FONT, GUI_GTK3_22,
                  "Monospace 8", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_22_font_beta_label, "beta_label",
                  N_("Beta Label"),
                  N_("This font is used to display the beta label."),
                  COC_FONT, GUI_GTK3_22,
                  "Sans Italic 10", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_22_font_small, "small_font",
                  N_("Small Font"),
                  N_("This font is used for any small font request.  For "
                     "example, it is used for display the building lists "
                     "in the city dialog, the Economy report or the Units "
                     "report."),
                  COC_FONT, GUI_GTK3_22,
                  "Sans 9", NULL),
  GEN_FONT_OPTION(gui_gtk3_22_font_comment_label, "comment_label",
                  N_("Comment Label"),
                  N_("This font is used to display comment labels, such as "
                     "in the governor page of the city dialogs."),
                  COC_FONT, GUI_GTK3_22,
                  "Sans Italic 9", font_changed_callback),
  GEN_FONT_OPTION(gui_gtk3_22_font_city_names, "city_names",
                  N_("City Names"),
                  N_("This font is used to the display the city names "
                     "on the map."),
                  COC_FONT, GUI_GTK3_22,
                  "Sans Bold 10", NULL),
  GEN_FONT_OPTION(gui_gtk3_22_font_city_productions, "city_productions",
                  N_("City Productions"),
                  N_("This font is used to display the city production "
                     "on the map."),
                  COC_FONT, GUI_GTK3_22,
                  "Serif 10", NULL),
  GEN_FONT_OPTION(gui_gtk3_22_font_reqtree_text, "reqtree_text",
                  N_("Requirement Tree"),
                  N_("This font is used to the display the requirement tree "
                     "in the Research report."),
                  COC_FONT, GUI_GTK3_22,
                  "Serif 10", NULL),

  /* gui-sdl client specific options. */
  GEN_BOOL_OPTION(gui_sdl_fullscreen, N_("Fullscreen"),
                  N_("If this option is set the client will use the "
                     "whole screen area for drawing."),
                  COC_INTERFACE, GUI_SDL, FALSE, NULL),
  GEN_VIDEO_OPTION(gui_sdl_screen, N_("Screen resolution"),
                   N_("This option controls the resolution of the "
                      "selected screen."),
                   COC_INTERFACE, GUI_SDL, 640, 480, NULL),
  GEN_BOOL_OPTION(gui_sdl_do_cursor_animation, N_("Do cursor animation"),
                  N_("If this option is disabled, the cursor will "
                     "always be displayed as static."),
                  COC_INTERFACE, GUI_SDL, TRUE, NULL),
  GEN_BOOL_OPTION(gui_sdl_use_color_cursors, N_("Use color cursors"),
                  N_("If this option is disabled, the cursor will "
                     "always be displayed in black and white."),
                  COC_INTERFACE, GUI_SDL, TRUE, NULL),

  /* gui-sdl2 client specific options. */
  GEN_BOOL_OPTION(gui_sdl2_fullscreen, N_("Fullscreen"),
                  N_("If this option is set the client will use the "
                     "whole screen area for drawing."),
                  COC_INTERFACE, GUI_SDL2, FALSE, NULL),
  GEN_VIDEO_OPTION(gui_sdl2_screen, N_("Screen resolution"),
                   N_("This option controls the resolution of the "
                      "selected screen."),
                   COC_INTERFACE, GUI_SDL2, 640, 480, NULL),
  GEN_BOOL_OPTION(gui_sdl2_swrenderer, N_("Use software rendering"),
                  N_("Usually hardware rendering is used when possible. "
                     "With this option set, software rendering is always used."),
                  COC_GRAPHICS, GUI_SDL2, FALSE, NULL),
  GEN_BOOL_OPTION(gui_sdl2_do_cursor_animation, N_("Do cursor animation"),
                  N_("If this option is disabled, the cursor will "
                     "always be displayed as static."),
                  COC_INTERFACE, GUI_SDL2, TRUE, NULL),
  GEN_BOOL_OPTION(gui_sdl2_use_color_cursors, N_("Use color cursors"),
                  N_("If this option is disabled, the cursor will "
                     "always be displayed in black and white."),
                  COC_INTERFACE, GUI_SDL2, TRUE, NULL),

  /* gui-qt client specific options. */
  GEN_BOOL_OPTION(gui_qt_fullscreen, N_("Fullscreen"),
                  N_("If this option is set the client will use the "
                     "whole screen area for drawing."),
                  COC_INTERFACE, GUI_QT, FALSE, NULL),
  GEN_BOOL_OPTION(gui_qt_show_titlebar, N_("Show titlebar"),
                  N_("If this option is set the client will show a titlebar. "
                     "If disabled, then no titlebar will be shown, and "
                     "minimize/maximize/etc buttons will be placed on the "
                     "menu bar."),
                  COC_INTERFACE, GUI_QT, TRUE, NULL),
  GEN_FONT_OPTION(gui_qt_font_city_label, "city_label",
                  N_("City Label"),
                  N_("This font is used to display the city labels on city "
                     "dialogs."),
                  COC_FONT, GUI_QT,
                  "Monospace,8,-1,5,50,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_default, "default_font",
                  N_("Default font"),
                  N_("This is default font"),
                  COC_FONT, GUI_QT,
                  "Sans Serif,10,-1,5,75,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_notify_label, "notify_label",
                  N_("Notify Label"),
                  N_("This font is used to display server reports such "
                     "as the demographic report or historian publications."),
                  COC_FONT, GUI_QT,
                  "Monospace,9,-1,5,75,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_spaceship_label, "spaceship_label",
                  N_("Spaceship Label"),
                  N_("This font is used to display the spaceship widgets."),
                  COC_FONT, GUI_QT,
                  "Monospace,8,-1,5,50,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_help_label, "help_label",
                  N_("Help Label"),
                  N_("This font is used to display the help labels in the "
                     "help window."),
                  COC_FONT, GUI_QT,
                  "Sans Serif,9,-1,5,50,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_help_link, "help_link",
                  N_("Help Link"),
                  N_("This font is used to display the help links in the "
                     "help window."),
                  COC_FONT, GUI_QT,
                  "Sans Serif,9,-1,5,50,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_help_text, "help_text",
                  N_("Help Text"),
                  N_("This font is used to display the help body text in "
                     "the help window."),
                  COC_FONT, GUI_QT,
                  "Monospace,8,-1,5,50,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_help_title, "help_title",
                  N_("Help Title"),
                  N_("This font is used to display the help title in "
                     "the help window."),
                  COC_FONT, GUI_QT,
                  "Sans Serif,10,-1,5,75,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_chatline, "chatline",
                  N_("Chatline Area"),
                  N_("This font is used to display the text in the "
                     "chatline area."),
                  COC_FONT, GUI_QT,
                  "Monospace,8,-1,5,50,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_beta_label, "beta_label",
                  N_("Beta Label"),
                  N_("This font is used to display the beta label."),
                  COC_FONT, GUI_QT,
                  "Sans Serif,10,-1,5,50,1,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_small, "small_font",
                  N_("Small Font"),
                  N_("This font is used for any small font request.  For "
                     "example, it is used for display the building lists "
                     "in the city dialog, the Economy report or the Units "
                     "report."),
                  COC_FONT, GUI_QT,
                  "Sans Serif,9,-1,5,50,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_comment_label, "comment_label",
                  N_("Comment Label"),
                  N_("This font is used to display comment labels, such as "
                     "in the governor page of the city dialogs."),
                  COC_FONT, GUI_QT,
                  "Sans Serif,9,-1,5,50,1,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_city_names, "city_names",
                  N_("City Names"),
                  N_("This font is used to the display the city names "
                     "on the map."),
                  COC_FONT, GUI_QT,
                  "Sans Serif,10,-1,5,75,0,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_city_productions, "city_productions",
                  N_("City Productions"),
                  N_("This font is used to display the city production "
                     "on the map."),
                  COC_FONT, GUI_QT,
                  "Sans Serif,10,-1,5,50,1,0,0,0,0", font_changed_callback),
  GEN_FONT_OPTION(gui_qt_font_reqtree_text, "reqtree_text",
                  N_("Requirement Tree"),
                  N_("This font is used to the display the requirement tree "
                     "in the Research report."),
                  COC_FONT, GUI_QT,
                  "Sans Serif,10,-1,5,50,1,0,0,0,0", font_changed_callback),
  GEN_BOOL_OPTION(gui_qt_show_preview, N_("Show savegame information"),
                  N_("If this option is set the client will show "
                     "information and map preview of current savegame."),
                  COC_GRAPHICS, GUI_QT, TRUE, NULL),
  GEN_BOOL_OPTION(gui_qt_sidebar_left, N_("Sidebar position"),
                  N_("If this option is set, the sidebar will be to the left "
                     "of the map, otherwise to the right."),
                  COC_INTERFACE, GUI_QT, TRUE, NULL),
  GEN_STR_OPTION(gui_qt_wakeup_text,
                 N_("Wake up sequence"),
                 N_("String which will trigger sound in pregame page; "
                    "%1 stands for username."),
                 COC_INTERFACE, GUI_QT, "Wake up %1", NULL, 0)

};
static const int client_options_num = ARRAY_SIZE(client_options);

/* Iteration loop, including invalid options for the current gui type. */
#define client_options_iterate_all(poption)                                 \
{                                                                           \
  const struct client_option *const poption##_max =                         \
      client_options + client_options_num;                                  \
  struct client_option *client_##poption = client_options;                  \
  struct option *poption;                                                   \
  for (; client_##poption < poption##_max; client_##poption++) {            \
    poption = OPTION(client_##poption);

#define client_options_iterate_all_end                                      \
  }                                                                         \
}


/****************************************************************************
  Returns the next valid option pointer for the current gui type.
****************************************************************************/
static struct client_option *
    client_option_next_valid(struct client_option *poption)
{
  const struct client_option *const max = 
    client_options + client_options_num;
  const enum gui_type our_type = get_gui_type();

  while (poption < max
         && poption->specific != GUI_STUB
         && poption->specific != our_type) {
    poption++;
  }

  return (poption < max ? poption : NULL);
}

/****************************************************************************
  Returns the option corresponding to this id.
****************************************************************************/
static struct option *client_optset_option_by_number(int id)
{
  if (0 > id || id > client_options_num)  {
    return NULL;
  }
  return OPTION(client_options + id);
}

/****************************************************************************
  Returns the first valid option pointer for the current gui type.
****************************************************************************/
static struct option *client_optset_option_first(void)
{
  return OPTION(client_option_next_valid(client_options));
}

/****************************************************************************
  Returns the number of client option categories.
****************************************************************************/
static int client_optset_category_number(void)
{
  return COC_MAX;
}

/****************************************************************************
  Returns the name (translated) of the option class.
****************************************************************************/
static const char *client_optset_category_name(int category)
{
  switch (category) {
  case COC_GRAPHICS:
    return _("Graphics");
  case COC_OVERVIEW:
    /* TRANS: Options section for overview map (mini-map) */
    return Q_("?map:Overview");
  case COC_SOUND:
    return _("Sound");
  case COC_INTERFACE:
    return _("Interface");
  case COC_MAPIMG:
    return _("Map Image");
  case COC_NETWORK:
    return _("Network");
  case COC_FONT:
    return _("Font");
  case COC_MAX:
    break;
  }

  log_error("%s: invalid option category number %d.",
            __FUNCTION__, category);
  return NULL;
}

/***************************************************************************
  Returns the number of this client option.
****************************************************************************/
static int client_option_number(const struct option *poption)
{
  return CLIENT_OPTION(poption) - client_options;
}

/****************************************************************************
  Returns the name of this client option.
****************************************************************************/
static const char *client_option_name(const struct option *poption)
{
  return CLIENT_OPTION(poption)->name;
}

/****************************************************************************
  Returns the description of this client option.
****************************************************************************/
static const char *client_option_description(const struct option *poption)
{
  return _(CLIENT_OPTION(poption)->description);
}

/****************************************************************************
  Returns the help text for this client option.
****************************************************************************/
static const char *client_option_help_text(const struct option *poption)
{
  return _(CLIENT_OPTION(poption)->help_text);
}

/****************************************************************************
  Returns the category of this client option.
****************************************************************************/
static int client_option_category(const struct option *poption)
{
  return CLIENT_OPTION(poption)->category;
}

/****************************************************************************
  Returns TRUE if this client option can be modified.
****************************************************************************/
static bool client_option_is_changeable(const struct option *poption)
{
  return TRUE;
}

/****************************************************************************
  Returns the next valid option pointer for the current gui type.
****************************************************************************/
static struct option *client_option_next(const struct option *poption)
{
  return OPTION(client_option_next_valid(CLIENT_OPTION(poption) + 1));
}

/****************************************************************************
  Returns the value of this client option of type OT_BOOLEAN.
****************************************************************************/
static bool client_option_bool_get(const struct option *poption)
{
  return *(CLIENT_OPTION(poption)->boolean.pvalue);
}

/****************************************************************************
  Returns the default value of this client option of type OT_BOOLEAN.
****************************************************************************/
static bool client_option_bool_def(const struct option *poption)
{
  return CLIENT_OPTION(poption)->boolean.def;
}

/****************************************************************************
  Set the value of this client option of type OT_BOOLEAN.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool client_option_bool_set(struct option *poption, bool val)
{
  struct client_option *pcoption = CLIENT_OPTION(poption);

  if (*pcoption->boolean.pvalue == val) {
    return FALSE;
  }

  *pcoption->boolean.pvalue = val;
  return TRUE;
}

/****************************************************************************
  Returns the value of this client option of type OT_INTEGER.
****************************************************************************/
static int client_option_int_get(const struct option *poption)
{
  return *(CLIENT_OPTION(poption)->integer.pvalue);
}

/****************************************************************************
  Returns the default value of this client option of type OT_INTEGER.
****************************************************************************/
static int client_option_int_def(const struct option *poption)
{
  return CLIENT_OPTION(poption)->integer.def;
}

/****************************************************************************
  Returns the minimal value for this client option of type OT_INTEGER.
****************************************************************************/
static int client_option_int_min(const struct option *poption)
{
  return CLIENT_OPTION(poption)->integer.min;
}

/****************************************************************************
  Returns the maximal value for this client option of type OT_INTEGER.
****************************************************************************/
static int client_option_int_max(const struct option *poption)
{
  return CLIENT_OPTION(poption)->integer.max;
}

/****************************************************************************
  Set the value of this client option of type OT_INTEGER.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool client_option_int_set(struct option *poption, int val)
{
  struct client_option *pcoption = CLIENT_OPTION(poption);

  if (val < pcoption->integer.min
      || val > pcoption->integer.max
      || *pcoption->integer.pvalue == val) {
    return FALSE;
  }

  *pcoption->integer.pvalue = val;
  return TRUE;
}

/****************************************************************************
  Returns the value of this client option of type OT_STRING.
****************************************************************************/
static const char *client_option_str_get(const struct option *poption)
{
  return CLIENT_OPTION(poption)->string.pvalue;
}

/****************************************************************************
  Returns the default value of this client option of type OT_STRING.
****************************************************************************/
static const char *client_option_str_def(const struct option *poption)
{
  return CLIENT_OPTION(poption)->string.def;
}

/****************************************************************************
  Returns the possible string values of this client option of type
  OT_STRING.
****************************************************************************/
static const struct strvec *
    client_option_str_values(const struct option *poption)
{
  return (CLIENT_OPTION(poption)->string.val_accessor
          ? CLIENT_OPTION(poption)->string.val_accessor(poption) : NULL);
}

/****************************************************************************
  Set the value of this client option of type OT_STRING.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool client_option_str_set(struct option *poption, const char *str)
{
  struct client_option *pcoption = CLIENT_OPTION(poption);

  if (strlen(str) >= pcoption->string.size
      || 0 == strcmp(pcoption->string.pvalue, str)) {
    return FALSE;
  }

  fc_strlcpy(pcoption->string.pvalue, str, pcoption->string.size);
  return TRUE;
}

/****************************************************************************
  Returns the current value of this client option of type OT_ENUM.
****************************************************************************/
static int client_option_enum_get(const struct option *poption)
{
  return *(CLIENT_OPTION(poption)->enumerator.pvalue);
}

/****************************************************************************
  Returns the default value of this client option of type OT_ENUM.
****************************************************************************/
static int client_option_enum_def(const struct option *poption)
{
  return CLIENT_OPTION(poption)->enumerator.def;
}

/****************************************************************************
  Returns the possible values of this client option of type OT_ENUM, as
  user-visible (translatable but not translated) strings.
****************************************************************************/
static const struct strvec *
    client_option_enum_pretty_names(const struct option *poption)
{
  return CLIENT_OPTION(poption)->enumerator.pretty_names;
}

/****************************************************************************
  Set the value of this client option of type OT_ENUM.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool client_option_enum_set(struct option *poption, int val)
{
  struct client_option *pcoption = CLIENT_OPTION(poption);

  if (*pcoption->enumerator.pvalue == val
      || 0 > val
      || val >= strvec_size(pcoption->enumerator.support_names)) {
    return FALSE;
  }

  *pcoption->enumerator.pvalue = val;
  return TRUE;
}

/****************************************************************************
  Returns the "support" name of the value for this client option of type
  OT_ENUM (a string suitable for saving in a file).
  The prototype must match the 'secfile_enum_name_data_fn_t' type.
****************************************************************************/
static const char *client_option_enum_secfile_str(secfile_data_t data,
                                                  int val)
{
  const struct strvec *names = CLIENT_OPTION(data)->enumerator.support_names;

  return (0 <= val && val < strvec_size(names)
          ? strvec_get(names, val) : NULL);
}

#if 0 /* There's no bitwise options currently */
/****************************************************************************
  Returns the current value of this client option of type OT_BITWISE.
****************************************************************************/
static unsigned client_option_bitwise_get(const struct option *poption)
{
  return *(CLIENT_OPTION(poption)->bitwise.pvalue);
}

/****************************************************************************
  Returns the default value of this client option of type OT_BITWISE.
****************************************************************************/
static unsigned client_option_bitwise_def(const struct option *poption)
{
  return CLIENT_OPTION(poption)->bitwise.def;
}

/****************************************************************************
  Returns the possible values of this client option of type OT_BITWISE, as
  user-visible (translatable but not translated) strings.
****************************************************************************/
static const struct strvec *
    client_option_bitwise_pretty_names(const struct option *poption)
{
  return CLIENT_OPTION(poption)->bitwise.pretty_names;
}

/****************************************************************************
  Set the value of this client option of type OT_BITWISE.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool client_option_bitwise_set(struct option *poption, unsigned val)
{
  struct client_option *pcoption = CLIENT_OPTION(poption);

  if (*pcoption->bitwise.pvalue == val) {
    return FALSE;
  }

  *pcoption->bitwise.pvalue = val;
  return TRUE;
}
#endif /* 0 */

/****************************************************************************
  Returns the "support" name of a single value for this client option of type
  OT_BITWISE (a string suitable for saving in a file).
  The prototype must match the 'secfile_enum_name_data_fn_t' type.
****************************************************************************/
static const char *client_option_bitwise_secfile_str(secfile_data_t data,
                                                     int val)
{
  const struct strvec *names = CLIENT_OPTION(data)->bitwise.support_names;

  return (0 <= val && val < strvec_size(names)
          ? strvec_get(names, val) : NULL);
}

/****************************************************************************
  Returns the value of this client option of type OT_FONT.
****************************************************************************/
static const char *client_option_font_get(const struct option *poption)
{
  return CLIENT_OPTION(poption)->font.pvalue;
}

/****************************************************************************
  Returns the default value of this client option of type OT_FONT.
****************************************************************************/
static const char *client_option_font_def(const struct option *poption)
{
  return CLIENT_OPTION(poption)->font.def;
}

/****************************************************************************
  Returns the target style name of this client option of type OT_FONT.
****************************************************************************/
static const char *client_option_font_target(const struct option *poption)
{
  return CLIENT_OPTION(poption)->font.target;
}

/****************************************************************************
  Set the value of this client option of type OT_FONT.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool client_option_font_set(struct option *poption, const char *font)
{
  struct client_option *pcoption = CLIENT_OPTION(poption);

  if (strlen(font) >= pcoption->font.size
      || 0 == strcmp(pcoption->font.pvalue, font)) {
    return FALSE;
  }

  fc_strlcpy(pcoption->font.pvalue, font, pcoption->font.size);
  return TRUE;
}

/****************************************************************************
  Returns the value of this client option of type OT_COLOR.
****************************************************************************/
static struct ft_color client_option_color_get(const struct option *poption)
{
  return *CLIENT_OPTION(poption)->color.pvalue;
}

/****************************************************************************
  Returns the default value of this client option of type OT_COLOR.
****************************************************************************/
static struct ft_color client_option_color_def(const struct option *poption)
{
  return CLIENT_OPTION(poption)->color.def;
}

/****************************************************************************
  Set the value of this client option of type OT_COLOR.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool client_option_color_set(struct option *poption,
                                    struct ft_color color)
{
  struct ft_color *pcolor = CLIENT_OPTION(poption)->color.pvalue;
  bool changed = FALSE;

#define color_set(color_tgt, color)                                         \
  if (NULL == color_tgt) {                                                  \
    if (NULL != color) {                                                    \
      color_tgt = fc_strdup(color);                                         \
      changed = TRUE;                                                       \
    }                                                                       \
  } else {                                                                  \
    if (NULL == color) {                                                    \
      free((void *) color_tgt);                                             \
      color_tgt = NULL;                                                     \
      changed = TRUE;                                                       \
    } else if (0 != strcmp(color_tgt, color)) {                             \
      free((void *) color_tgt);                                             \
      color_tgt = fc_strdup(color);                                         \
      changed = TRUE;                                                       \
    }                                                                       \
  }

  color_set(pcolor->foreground, color.foreground);
  color_set(pcolor->background, color.background);

#undef color_set

  return changed;
}

/****************************************************************************
  Returns the value of this client option of type OT_VIDEO_MODE.
****************************************************************************/
static struct video_mode
client_option_video_mode_get(const struct option *poption)
{
  return *CLIENT_OPTION(poption)->video_mode.pvalue;
}

/****************************************************************************
  Returns the default value of this client option of type OT_VIDEO_MODE.
****************************************************************************/
static struct video_mode
client_option_video_mode_def(const struct option *poption)
{
  return CLIENT_OPTION(poption)->video_mode.def;
}

/****************************************************************************
  Set the value of this client option of type OT_VIDEO_MODE.  Returns TRUE
  if the value changed.
****************************************************************************/
static bool client_option_video_mode_set(struct option *poption,
                                         struct video_mode mode)
{
  struct client_option *pcoption = CLIENT_OPTION(poption);

  if (0 == memcmp(&mode, pcoption->video_mode.pvalue,
                  sizeof(struct video_mode))) {
    return FALSE;
  }

  *pcoption->video_mode.pvalue = mode;
  return TRUE;
}

/****************************************************************************
  Load the option from a file.  Returns TRUE if the option changed.
****************************************************************************/
static bool client_option_load(struct option *poption,
                               struct section_file *sf)
{
  fc_assert_ret_val(NULL != poption, FALSE);
  fc_assert_ret_val(NULL != sf, FALSE);

  switch (option_type(poption)) {
  case OT_BOOLEAN:
    {
      bool value;

      return (secfile_lookup_bool(sf, &value, "client.%s",
                                  option_name(poption))
              && option_bool_set(poption, value));
    }
  case OT_INTEGER:
    {
      int value;

      return (secfile_lookup_int(sf, &value, "client.%s",
                                 option_name(poption))
              && option_int_set(poption, value));
    }
  case OT_STRING:
    {
      const char *string;

      return ((string = secfile_lookup_str(sf, "client.%s",
                                           option_name(poption)))
              && option_str_set(poption, string));
    }
  case OT_ENUM:
    {
      int value;

      return (secfile_lookup_enum_data(sf, &value, FALSE,
                                       client_option_enum_secfile_str,
                                       poption, "client.%s",
                                       option_name(poption))
              && option_enum_set_int(poption, value));
    }
  case OT_BITWISE:
    {
      int value;

      return (secfile_lookup_enum_data(sf, &value, TRUE,
                                       client_option_bitwise_secfile_str,
                                       poption, "client.%s",
                                       option_name(poption))
              && option_bitwise_set(poption, value));
    }
  case OT_FONT:
    {
      const char *string;

      return ((string = secfile_lookup_str(sf, "client.%s",
                                           option_name(poption)))
              && option_font_set(poption, string));
    }
  case OT_COLOR:
    {
      struct ft_color color;

      return ((color.foreground =
                   secfile_lookup_str(sf, "client.%s.foreground",
                                      option_name(poption)))
              && (color.background =
                      secfile_lookup_str(sf, "client.%s.background",
                                         option_name(poption)))
              && option_color_set(poption, color));
    }
  case OT_VIDEO_MODE:
    {
      struct video_mode mode;

      return (secfile_lookup_int(sf, &mode.width, "client.%s.width",
                                 option_name(poption))
              && secfile_lookup_int(sf, &mode.height, "client.%s.height",
                                    option_name(poption))
              && option_video_mode_set(poption, mode));
    }
  }
  return FALSE;
}

/****************************************************************************
  Save the option to a file.
****************************************************************************/
static void client_option_save(struct option *poption,
                               struct section_file *sf)
{
  fc_assert_ret(NULL != poption);
  fc_assert_ret(NULL != sf);

  switch (option_type(poption)) {
  case OT_BOOLEAN:
    secfile_insert_bool(sf, option_bool_get(poption),
                        "client.%s", option_name(poption));
    break;
  case OT_INTEGER:
    secfile_insert_int(sf, option_int_get(poption),
                       "client.%s", option_name(poption));
    break;
  case OT_STRING:
    secfile_insert_str(sf, option_str_get(poption),
                       "client.%s", option_name(poption));
    break;
  case OT_ENUM:
    secfile_insert_enum_data(sf, option_enum_get_int(poption), FALSE,
                             client_option_enum_secfile_str, poption,
                             "client.%s", option_name(poption));
    break;
  case OT_BITWISE:
    secfile_insert_enum_data(sf, option_bitwise_get(poption), TRUE,
                             client_option_bitwise_secfile_str, poption,
                             "client.%s", option_name(poption));
    break;
  case OT_FONT:
    secfile_insert_str(sf, option_font_get(poption),
                       "client.%s", option_name(poption));
    break;
  case OT_COLOR:
    {
      struct ft_color color = option_color_get(poption);

      secfile_insert_str(sf, color.foreground, "client.%s.foreground",
                         option_name(poption));
      secfile_insert_str(sf, color.background, "client.%s.background",
                         option_name(poption));
    }
    break;
  case OT_VIDEO_MODE:
    {
      struct video_mode mode = option_video_mode_get(poption);

      secfile_insert_int(sf, mode.width, "client.%s.width",
                         option_name(poption));
      secfile_insert_int(sf, mode.height, "client.%s.height",
                         option_name(poption));
    }
    break;
  }
}


/****************************************************************************
  Server options variables.
****************************************************************************/
static char **server_options_categories = NULL;
static struct server_option *server_options = NULL;

static int server_options_categories_num = 0;
static int server_options_num = 0;


/****************************************************************************
  Server option set.
****************************************************************************/
static struct option *server_optset_option_by_number(int id);
static struct option *server_optset_option_first(void);
static int server_optset_category_number(void);
static const char *server_optset_category_name(int category);

static struct option_set server_optset_static = {
  .option_by_number = server_optset_option_by_number,
  .option_first = server_optset_option_first,
  .category_number = server_optset_category_number,
  .category_name = server_optset_category_name
};
const struct option_set *server_optset = &server_optset_static;


/****************************************************************************
  Virtuals tables for the client options.
****************************************************************************/
static int server_option_number(const struct option *poption);
static const char *server_option_name(const struct option *poption);
static const char *server_option_description(const struct option *poption);
static const char *server_option_help_text(const struct option *poption);
static int server_option_category(const struct option *poption);
static bool server_option_is_changeable(const struct option *poption);
static struct option *server_option_next(const struct option *poption);

static const struct option_common_vtable server_option_common_vtable = {
  .number = server_option_number,
  .name = server_option_name,
  .description = server_option_description,
  .help_text = server_option_help_text,
  .category = server_option_category,
  .is_changeable = server_option_is_changeable,
  .next = server_option_next
};

static bool server_option_bool_get(const struct option *poption);
static bool server_option_bool_def(const struct option *poption);
static bool server_option_bool_set(struct option *poption, bool val);

static const struct option_bool_vtable server_option_bool_vtable = {
  .get = server_option_bool_get,
  .def = server_option_bool_def,
  .set = server_option_bool_set
};

static int server_option_int_get(const struct option *poption);
static int server_option_int_def(const struct option *poption);
static int server_option_int_min(const struct option *poption);
static int server_option_int_max(const struct option *poption);
static bool server_option_int_set(struct option *poption, int val);

static const struct option_int_vtable server_option_int_vtable = {
  .get = server_option_int_get,
  .def = server_option_int_def,
  .minimum = server_option_int_min,
  .maximum = server_option_int_max,
  .set = server_option_int_set
};

static const char *server_option_str_get(const struct option *poption);
static const char *server_option_str_def(const struct option *poption);
static const struct strvec *
    server_option_str_values(const struct option *poption);
static bool server_option_str_set(struct option *poption, const char *str);

static const struct option_str_vtable server_option_str_vtable = {
  .get = server_option_str_get,
  .def = server_option_str_def,
  .values = server_option_str_values,
  .set = server_option_str_set
};

static int server_option_enum_get(const struct option *poption);
static int server_option_enum_def(const struct option *poption);
static const struct strvec *
    server_option_enum_pretty(const struct option *poption);
static bool server_option_enum_set(struct option *poption, int val);

static const struct option_enum_vtable server_option_enum_vtable = {
  .get = server_option_enum_get,
  .def = server_option_enum_def,
  .values = server_option_enum_pretty,
  .set = server_option_enum_set,
  .cmp = strcmp
};

static unsigned server_option_bitwise_get(const struct option *poption);
static unsigned server_option_bitwise_def(const struct option *poption);
static const struct strvec *
    server_option_bitwise_pretty(const struct option *poption);
static bool server_option_bitwise_set(struct option *poption, unsigned val);

static const struct option_bitwise_vtable server_option_bitwise_vtable = {
  .get = server_option_bitwise_get,
  .def = server_option_bitwise_def,
  .values = server_option_bitwise_pretty,
  .set = server_option_bitwise_set
};

/****************************************************************************
  Derived class server option, inheriting from base class option.
****************************************************************************/
struct server_option {
  struct option base_option;    /* Base structure, must be the first! */

  char *name;                   /* Short name - used as an identifier */
  char *description;            /* One-line description */
  char *help_text;              /* Paragraph-length help text */
  unsigned char category;
  bool desired_sent;
  bool is_changeable;
  bool is_visible;

  union {
    /* OT_BOOLEAN type option. */
    struct {
      bool value;
      bool def;
    } boolean;
    /* OT_INTEGER type option. */
    struct {
      int value;
      int def, min, max;
    } integer;
    /* OT_STRING type option. */
    struct {
      char *value;
      char *def;
    } string;
    /* OT_ENUM type option. */
    struct {
      int value;
      int def;
      struct strvec *support_names;
      struct strvec *pretty_names; /* untranslated */
    } enumerator;
    /* OT_BITWISE type option. */
    struct {
      unsigned value;
      unsigned def;
      struct strvec *support_names;
      struct strvec *pretty_names; /* untranslated */
    } bitwise;
  };
};

#define SERVER_OPTION(poption) ((struct server_option *) (poption))

static void desired_settable_option_send(struct option *poption);


/****************************************************************************
  Initialize the server options (not received yet).
****************************************************************************/
void server_options_init(void)
{
  fc_assert(NULL == server_options_categories);
  fc_assert(NULL == server_options);
  fc_assert(0 == server_options_categories_num);
  fc_assert(0 == server_options_num);
}

/****************************************************************************
  Free one server option.
****************************************************************************/
static void server_option_free(struct server_option *poption)
{
  switch (poption->base_option.type) {
  case OT_STRING:
    if (NULL != poption->string.value) {
      FC_FREE(poption->string.value);
    }
    if (NULL != poption->string.def) {
      FC_FREE(poption->string.def);
    }
    break;

  case OT_ENUM:
    if (NULL != poption->enumerator.support_names) {
      strvec_destroy(poption->enumerator.support_names);
      poption->enumerator.support_names = NULL;
    }
    if (NULL != poption->enumerator.pretty_names) {
      strvec_destroy(poption->enumerator.pretty_names);
      poption->enumerator.pretty_names = NULL;
    }
    break;

  case OT_BITWISE:
    if (NULL != poption->bitwise.support_names) {
      strvec_destroy(poption->bitwise.support_names);
      poption->bitwise.support_names = NULL;
    }
    if (NULL != poption->bitwise.pretty_names) {
      strvec_destroy(poption->bitwise.pretty_names);
      poption->bitwise.pretty_names = NULL;
    }
    break;

  case OT_BOOLEAN:
  case OT_INTEGER:
  case OT_FONT:
  case OT_COLOR:
  case OT_VIDEO_MODE:
    break;
  }

  if (NULL != poption->name) {
    FC_FREE(poption->name);
  }
  if (NULL != poption->description) {
    FC_FREE(poption->description);
  }
  if (NULL != poption->help_text) {
    FC_FREE(poption->help_text);
  }
}

/****************************************************************************
  Free the server options, if already received.
****************************************************************************/
void server_options_free(void)
{
  int i;

  /* Don't keep this dialog open. */
  option_dialog_popdown(server_optset);

  /* Free the options themselves. */
  if (NULL != server_options) {
    for (i = 0; i < server_options_num; i++) {
      server_option_free(server_options + i);
    }
    FC_FREE(server_options);
    server_options_num = 0;
  }

  /* Free the categories. */
  if (NULL != server_options_categories) {
    for (i = 0; i < server_options_categories_num; i++) {
      if (NULL != server_options_categories[i]) {
        FC_FREE(server_options_categories[i]);
      }
    }
    FC_FREE(server_options_categories);
    server_options_categories_num = 0;
  }
}

/****************************************************************************
  Allocate the server options and categories.
****************************************************************************/
void handle_server_setting_control
    (const struct packet_server_setting_control *packet)
{
  int i;

  /* This packet should be received only once. */
  fc_assert_ret(NULL == server_options_categories);
  fc_assert_ret(NULL == server_options);
  fc_assert_ret(0 == server_options_categories_num);
  fc_assert_ret(0 == server_options_num);

  /* Allocate server option categories. */
  if (0 < packet->categories_num) {
    server_options_categories_num = packet->categories_num;
    server_options_categories =
        fc_calloc(server_options_categories_num,
                  sizeof(*server_options_categories));

    for (i = 0; i < server_options_categories_num; i++) {
      /* NB: Translate now. */
      server_options_categories[i] = fc_strdup(_(packet->category_names[i]));
    }
  }

  /* Allocate server options. */
  if (0 < packet->settings_num) {
    server_options_num = packet->settings_num;
    server_options = fc_calloc(server_options_num, sizeof(*server_options));
  }
}

/****************************************************************************
  Receive a server setting info packet.
****************************************************************************/
void handle_server_setting_const
    (const struct packet_server_setting_const *packet)
{
  struct option *poption = server_optset_option_by_number(packet->id);
  struct server_option *psoption = SERVER_OPTION(poption);

  fc_assert_ret(NULL != poption);

  fc_assert(NULL == psoption->name);
  psoption->name = fc_strdup(packet->name);
  fc_assert(NULL == psoption->description);
  /* NB: Translate now. */
  psoption->description = fc_strdup(_(packet->short_help));
  fc_assert(NULL == psoption->help_text);
  /* NB: Translate now. */
  psoption->help_text = fc_strdup(_(packet->extra_help));
  psoption->category = packet->category;
}

/****************************************************************************
  Common part of handle_server_setting_*() functions. See below.
****************************************************************************/
#define handle_server_setting_common(psoption, packet)                      \
  psoption->is_changeable = packet->is_changeable;                          \
  if (psoption->is_visible != packet->is_visible) {                         \
    if (psoption->is_visible) {                                             \
      need_gui_remove = TRUE;                                               \
    } else if (packet->is_visible) {                                        \
      need_gui_add = TRUE;                                                  \
    }                                                                       \
    psoption->is_visible = packet->is_visible;                              \
  }                                                                         \
                                                                            \
  if (!psoption->desired_sent                                               \
      && psoption->is_visible                                               \
      && psoption->is_changeable                                            \
      && is_server_running()                                                \
      && packet->initial_setting) {                                         \
    /* Only send our private settings if we are running                     \
     * on a forked local server, i.e. started by the                        \
     * client with the "Start New Game" button.                             \
     * Do now override settings that are already saved to savegame          \
     * and now loaded. */                                                   \
    desired_settable_option_send(OPTION(poption));                          \
    psoption->desired_sent = TRUE;                                          \
  }                                                                         \
                                                                            \
  /* Update the GUI. */                                                     \
  if (need_gui_remove) {                                                    \
    option_gui_remove(poption);                                             \
  } else if (need_gui_add) {                                                \
    option_gui_add(poption);                                                \
  } else {                                                                  \
    option_gui_update(poption);                                             \
  }

/****************************************************************************
  Receive a boolean server setting info packet.
****************************************************************************/
void handle_server_setting_bool
    (const struct packet_server_setting_bool *packet)
{
  struct option *poption = server_optset_option_by_number(packet->id);
  struct server_option *psoption = SERVER_OPTION(poption);
  bool need_gui_remove = FALSE;
  bool need_gui_add = FALSE;

  fc_assert_ret(NULL != poption);

  if (NULL == poption->common_vtable) {
    /* Not initialized yet. */
    poption->poptset = server_optset;
    poption->common_vtable = &server_option_common_vtable;
    poption->type = OT_BOOLEAN;
    poption->bool_vtable = &server_option_bool_vtable;
  }
  fc_assert_ret_msg(OT_BOOLEAN == poption->type,
                    "Server setting \"%s\" (nb %d) has type %s (%d), "
                    "expected %s (%d)",
                    option_name(poption), option_number(poption),
                    option_type_name(poption->type), poption->type,
                    option_type_name(OT_BOOLEAN), OT_BOOLEAN);

  if (packet->is_visible) {
    psoption->boolean.value = packet->val;
    psoption->boolean.def = packet->default_val;
  }

  handle_server_setting_common(psoption, packet);
}

/****************************************************************************
  Receive a integer server setting info packet.
****************************************************************************/
void handle_server_setting_int
    (const struct packet_server_setting_int *packet)
{
  struct option *poption = server_optset_option_by_number(packet->id);
  struct server_option *psoption = SERVER_OPTION(poption);
  bool need_gui_remove = FALSE;
  bool need_gui_add = FALSE;

  fc_assert_ret(NULL != poption);

  if (NULL == poption->common_vtable) {
    /* Not initialized yet. */
    poption->poptset = server_optset;
    poption->common_vtable = &server_option_common_vtable;
    poption->type = OT_INTEGER;
    poption->int_vtable = &server_option_int_vtable;
  }
  fc_assert_ret_msg(OT_INTEGER == poption->type,
                    "Server setting \"%s\" (nb %d) has type %s (%d), "
                    "expected %s (%d)",
                    option_name(poption), option_number(poption),
                    option_type_name(poption->type), poption->type,
                    option_type_name(OT_INTEGER), OT_INTEGER);

  if (packet->is_visible) {
    psoption->integer.value = packet->val;
    psoption->integer.def = packet->default_val;
    psoption->integer.min = packet->min_val;
    psoption->integer.max = packet->max_val;
  }

  /* Backward compatibility hack: early 2.6 beta servers didn't send this
   * in the GAME_INFO packet, so for their benefit, scrape it from the
   * option packet. Elsewhere we take care to preserve it. */
  if (!has_capability("techloss_forgiveness", client.conn.capability)
      && strcmp(option_name(poption), "techlossforgiveness") == 0) {
    game.info.techloss_forgiveness = packet->val;
  }

  handle_server_setting_common(psoption, packet);
}

/****************************************************************************
  Receive a string server setting info packet.
****************************************************************************/
void handle_server_setting_str
    (const struct packet_server_setting_str *packet)
{
  struct option *poption = server_optset_option_by_number(packet->id);
  struct server_option *psoption = SERVER_OPTION(poption);
  bool need_gui_remove = FALSE;
  bool need_gui_add = FALSE;

  fc_assert_ret(NULL != poption);

  if (NULL == poption->common_vtable) {
    /* Not initialized yet. */
    poption->poptset = server_optset;
    poption->common_vtable = &server_option_common_vtable;
    poption->type = OT_STRING;
    poption->str_vtable = &server_option_str_vtable;
  }
  fc_assert_ret_msg(OT_STRING == poption->type,
                    "Server setting \"%s\" (nb %d) has type %s (%d), "
                    "expected %s (%d)",
                    option_name(poption), option_number(poption),
                    option_type_name(poption->type), poption->type,
                    option_type_name(OT_STRING), OT_STRING);

  if (packet->is_visible) {
    if (NULL == psoption->string.value) {
      psoption->string.value = fc_strdup(packet->val);
    } else if (0 != strcmp(packet->val, psoption->string.value)) {
      free(psoption->string.value);
      psoption->string.value = fc_strdup(packet->val);
    }
    if (NULL == psoption->string.def) {
      psoption->string.def = fc_strdup(packet->default_val);
    } else if (0 != strcmp(packet->default_val, psoption->string.def)) {
      free(psoption->string.def);
      psoption->string.def = fc_strdup(packet->default_val);
    }
  }

  handle_server_setting_common(psoption, packet);
}

/****************************************************************************
  Receive an enumerator server setting info packet.
****************************************************************************/
void handle_server_setting_enum
    (const struct packet_server_setting_enum *packet)
{
  struct option *poption = server_optset_option_by_number(packet->id);
  struct server_option *psoption = SERVER_OPTION(poption);
  bool need_gui_remove = FALSE;
  bool need_gui_add = FALSE;

  fc_assert_ret(NULL != poption);

  if (NULL == poption->common_vtable) {
    /* Not initialized yet. */
    poption->poptset = server_optset;
    poption->common_vtable = &server_option_common_vtable;
    poption->type = OT_ENUM;
    poption->enum_vtable = &server_option_enum_vtable;
  }
  fc_assert_ret_msg(OT_ENUM == poption->type,
                    "Server setting \"%s\" (nb %d) has type %s (%d), "
                    "expected %s (%d)",
                    option_name(poption), option_number(poption),
                    option_type_name(poption->type), poption->type,
                    option_type_name(OT_ENUM), OT_ENUM);

  if (packet->is_visible) {
    int i;

    psoption->enumerator.value = packet->val;
    psoption->enumerator.def = packet->default_val;

    if (NULL == psoption->enumerator.support_names) {
      /* First time we get this packet. */
      fc_assert(NULL == psoption->enumerator.pretty_names);
      psoption->enumerator.support_names = strvec_new();
      strvec_reserve(psoption->enumerator.support_names, packet->values_num);
      psoption->enumerator.pretty_names = strvec_new();
      strvec_reserve(psoption->enumerator.pretty_names, packet->values_num);
      for (i = 0; i < packet->values_num; i++) {
        strvec_set(psoption->enumerator.support_names, i,
                   packet->support_names[i]);
        /* Store untranslated string from server. */
        strvec_set(psoption->enumerator.pretty_names, i,
                   packet->pretty_names[i]);
      }
    } else if (strvec_size(psoption->enumerator.support_names)
               != packet->values_num) {
      fc_assert(strvec_size(psoption->enumerator.support_names)
                == strvec_size(psoption->enumerator.pretty_names));
      /* The number of values have changed, we need to reset the list
       * of possible values. */
      strvec_reserve(psoption->enumerator.support_names, packet->values_num);
      strvec_reserve(psoption->enumerator.pretty_names, packet->values_num);
      for (i = 0; i < packet->values_num; i++) {
        strvec_set(psoption->enumerator.support_names, i,
                   packet->support_names[i]);
        /* Store untranslated string from server. */
        strvec_set(psoption->enumerator.pretty_names, i,
                   packet->pretty_names[i]);
      }
      need_gui_remove = TRUE;
      need_gui_add = TRUE;
    } else {
      /* Check if a value changed, then we need to reset the list
       * of possible values. */
      const char *str;

      for (i = 0; i < packet->values_num; i++) {
        str = strvec_get(psoption->enumerator.pretty_names, i);
        if (NULL == str || 0 != strcmp(str, packet->pretty_names[i])) {
          /* Store untranslated string from server. */
          strvec_set(psoption->enumerator.pretty_names, i,
                     packet->pretty_names[i]);
          need_gui_remove = TRUE;
          need_gui_add = TRUE;
        }
        /* Support names are not visible, we don't need to check if it
         * has changed. */
        strvec_set(psoption->enumerator.support_names, i,
                   packet->support_names[i]);
      }
    }
  }

  handle_server_setting_common(psoption, packet);
}

/****************************************************************************
  Receive a bitwise server setting info packet.
****************************************************************************/
void handle_server_setting_bitwise
    (const struct packet_server_setting_bitwise *packet)
{
  struct option *poption = server_optset_option_by_number(packet->id);
  struct server_option *psoption = SERVER_OPTION(poption);
  bool need_gui_remove = FALSE;
  bool need_gui_add = FALSE;

  fc_assert_ret(NULL != poption);

  if (NULL == poption->common_vtable) {
    /* Not initialized yet. */
    poption->poptset = server_optset;
    poption->common_vtable = &server_option_common_vtable;
    poption->type = OT_BITWISE;
    poption->bitwise_vtable = &server_option_bitwise_vtable;
  }
  fc_assert_ret_msg(OT_BITWISE == poption->type,
                    "Server setting \"%s\" (nb %d) has type %s (%d), "
                    "expected %s (%d)",
                    option_name(poption), option_number(poption),
                    option_type_name(poption->type), poption->type,
                    option_type_name(OT_BITWISE), OT_BITWISE);

  if (packet->is_visible) {
    int i;

    psoption->bitwise.value = packet->val;
    psoption->bitwise.def = packet->default_val;

    if (NULL == psoption->bitwise.support_names) {
      /* First time we get this packet. */
      fc_assert(NULL == psoption->bitwise.pretty_names);
      psoption->bitwise.support_names = strvec_new();
      strvec_reserve(psoption->bitwise.support_names, packet->bits_num);
      psoption->bitwise.pretty_names = strvec_new();
      strvec_reserve(psoption->bitwise.pretty_names, packet->bits_num);
      for (i = 0; i < packet->bits_num; i++) {
        strvec_set(psoption->bitwise.support_names, i,
                   packet->support_names[i]);
        /* Store untranslated string from server. */
        strvec_set(psoption->bitwise.pretty_names, i,
                   packet->pretty_names[i]);
      }
    } else if (strvec_size(psoption->bitwise.support_names)
               != packet->bits_num) {
      fc_assert(strvec_size(psoption->bitwise.support_names)
                == strvec_size(psoption->bitwise.pretty_names));
      /* The number of values have changed, we need to reset the list
       * of possible values. */
      strvec_reserve(psoption->bitwise.support_names, packet->bits_num);
      strvec_reserve(psoption->bitwise.pretty_names, packet->bits_num);
      for (i = 0; i < packet->bits_num; i++) {
        strvec_set(psoption->bitwise.support_names, i,
                   packet->support_names[i]);
        /* Store untranslated string from server. */
        strvec_set(psoption->bitwise.pretty_names, i,
                   packet->pretty_names[i]);
      }
      need_gui_remove = TRUE;
      need_gui_add = TRUE;
    } else {
      /* Check if a value changed, then we need to reset the list
       * of possible values. */
      const char *str;

      for (i = 0; i < packet->bits_num; i++) {
        str = strvec_get(psoption->bitwise.pretty_names, i);
        if (NULL == str || 0 != strcmp(str, packet->pretty_names[i])) {
          /* Store untranslated string from server. */
          strvec_set(psoption->bitwise.pretty_names, i,
                     packet->pretty_names[i]);
          need_gui_remove = TRUE;
          need_gui_add = TRUE;
        }
        /* Support names are not visible, we don't need to check if it
         * has changed. */
        strvec_set(psoption->bitwise.support_names, i,
                   packet->support_names[i]);
      }
    }
  }

  handle_server_setting_common(psoption, packet);
}

/****************************************************************************
  Returns the next valid option pointer for the current gui type.
****************************************************************************/
static struct server_option *
    server_option_next_valid(struct server_option *poption)
{
  const struct server_option *const max = 
    server_options + server_options_num;

  while (NULL != poption && poption < max && !poption->is_visible) {
    poption++;
  }

  return (poption < max ? poption : NULL);
}

/****************************************************************************
  Returns the server option associated to the number
****************************************************************************/
struct option *server_optset_option_by_number(int id)
{
  if (0 > id || id > server_options_num)  {
    return NULL;
  }
  return OPTION(server_options + id);
}

/****************************************************************************
  Returns the first valid (visible) option pointer.
****************************************************************************/
struct option *server_optset_option_first(void)
{
  return OPTION(server_option_next_valid(server_options));
}

/****************************************************************************
  Returns the number of server option categories.
****************************************************************************/
int server_optset_category_number(void)
{
  return server_options_categories_num;
}

/****************************************************************************
  Returns the name (translated) of the server option category.
****************************************************************************/
const char *server_optset_category_name(int category)
{
  if (0 > category || category >= server_options_categories_num) {
    return NULL;
  }

  return server_options_categories[category];
}

/***************************************************************************
  Returns the number of this server option.
****************************************************************************/
static int server_option_number(const struct option *poption)
{
  return SERVER_OPTION(poption) - server_options;
}

/****************************************************************************
  Returns the name of this server option.
****************************************************************************/
static const char *server_option_name(const struct option *poption)
{
  return SERVER_OPTION(poption)->name;
}

/****************************************************************************
  Returns the (translated) description of this server option.
****************************************************************************/
static const char *server_option_description(const struct option *poption)
{
  return SERVER_OPTION(poption)->description;
}

/****************************************************************************
  Returns the (translated) help text for this server option.
****************************************************************************/
static const char *server_option_help_text(const struct option *poption)
{
  return SERVER_OPTION(poption)->help_text;
}

/****************************************************************************
  Returns the category of this server option.
****************************************************************************/
static int server_option_category(const struct option *poption)
{
  return SERVER_OPTION(poption)->category;
}

/****************************************************************************
  Returns TRUE if this client option can be modified.
****************************************************************************/
static bool server_option_is_changeable(const struct option *poption)
{
  return SERVER_OPTION(poption)->is_changeable;
}

/****************************************************************************
  Returns the next valid (visible) option pointer.
****************************************************************************/
static struct option *server_option_next(const struct option *poption)
{
  return OPTION(server_option_next_valid(SERVER_OPTION(poption) + 1));
}

/****************************************************************************
  Returns the value of this server option of type OT_BOOLEAN.
****************************************************************************/
static bool server_option_bool_get(const struct option *poption)
{
  return SERVER_OPTION(poption)->boolean.value;
}

/****************************************************************************
  Returns the default value of this server option of type OT_BOOLEAN.
****************************************************************************/
static bool server_option_bool_def(const struct option *poption)
{
  return SERVER_OPTION(poption)->boolean.def;
}

/****************************************************************************
  Set the value of this server option of type OT_BOOLEAN.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool server_option_bool_set(struct option *poption, bool val)
{
  struct server_option *psoption = SERVER_OPTION(poption);

  if (psoption->boolean.value == val) {
    return FALSE;
  }

  send_chat_printf("/set %s %s", psoption->name,
                   val ? "enabled" : "disabled");
  return TRUE;
}

/****************************************************************************
  Returns the value of this server option of type OT_INTEGER.
****************************************************************************/
static int server_option_int_get(const struct option *poption)
{
  return SERVER_OPTION(poption)->integer.value;
}

/****************************************************************************
  Returns the default value of this server option of type OT_INTEGER.
****************************************************************************/
static int server_option_int_def(const struct option *poption)
{
  return SERVER_OPTION(poption)->integer.def;
}

/****************************************************************************
  Returns the minimal value for this server option of type OT_INTEGER.
****************************************************************************/
static int server_option_int_min(const struct option *poption)
{
  return SERVER_OPTION(poption)->integer.min;
}

/****************************************************************************
  Returns the maximal value for this server option of type OT_INTEGER.
****************************************************************************/
static int server_option_int_max(const struct option *poption)
{
  return SERVER_OPTION(poption)->integer.max;
}

/****************************************************************************
  Set the value of this server option of type OT_INTEGER.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool server_option_int_set(struct option *poption, int val)
{
  struct server_option *psoption = SERVER_OPTION(poption);

  if (val < psoption->integer.min
      || val > psoption->integer.max
      || psoption->integer.value == val) {
    return FALSE;
  }

  send_chat_printf("/set %s %d", psoption->name, val);
  return TRUE;
}

/****************************************************************************
  Returns the value of this server option of type OT_STRING.
****************************************************************************/
static const char *server_option_str_get(const struct option *poption)
{
  return SERVER_OPTION(poption)->string.value;
}

/****************************************************************************
  Returns the default value of this server option of type OT_STRING.
****************************************************************************/
static const char *server_option_str_def(const struct option *poption)
{
  return SERVER_OPTION(poption)->string.def;
}

/****************************************************************************
  Returns the possible string values of this server option of type
  OT_STRING.
****************************************************************************/
static const struct strvec *
    server_option_str_values(const struct option *poption)
{
  return NULL;
}

/****************************************************************************
  Set the value of this server option of type OT_STRING.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool server_option_str_set(struct option *poption, const char *str)
{
  struct server_option *psoption = SERVER_OPTION(poption);

  if (0 == strcmp(psoption->string.value, str)) {
    return FALSE;
  }

  send_chat_printf("/set %s \"%s\"", psoption->name, str);
  return TRUE;
}

/****************************************************************************
  Returns the current value of this server option of type OT_ENUM.
****************************************************************************/
static int server_option_enum_get(const struct option *poption)
{
  return SERVER_OPTION(poption)->enumerator.value;
}

/****************************************************************************
  Returns the default value of this server option of type OT_ENUM.
****************************************************************************/
static int server_option_enum_def(const struct option *poption)
{
  return SERVER_OPTION(poption)->enumerator.def;
}

/****************************************************************************
  Returns the user-visible, translatable (but untranslated) "pretty" names
  of this server option of type OT_ENUM.
****************************************************************************/
static const struct strvec *
    server_option_enum_pretty(const struct option *poption)
{
  return SERVER_OPTION(poption)->enumerator.pretty_names;
}

/****************************************************************************
  Set the value of this server option of type OT_ENUM.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool server_option_enum_set(struct option *poption, int val)
{
  struct server_option *psoption = SERVER_OPTION(poption);
  const char *name;

  if (val == psoption->enumerator.value
      || !(name = strvec_get(psoption->enumerator.support_names, val))) {
    return FALSE;
  }

  send_chat_printf("/set %s \"%s\"", psoption->name, name);
  return TRUE;
}

/****************************************************************************
  Returns the long support names of the values of the server option of type
  OT_ENUM.
****************************************************************************/
static void server_option_enum_support_name(const struct option *poption,
                                            const char **pvalue,
                                            const char **pdefault)
{
  const struct server_option *psoption = SERVER_OPTION(poption);
  const struct strvec *values = psoption->enumerator.support_names;

  if (NULL != pvalue) {
    *pvalue = strvec_get(values, psoption->enumerator.value);
  }
  if (NULL != pdefault) {
    *pdefault = strvec_get(values, psoption->enumerator.def);
  }
}

/****************************************************************************
  Returns the current value of this server option of type OT_BITWISE.
****************************************************************************/
static unsigned server_option_bitwise_get(const struct option *poption)
{
  return SERVER_OPTION(poption)->bitwise.value;
}

/****************************************************************************
  Returns the default value of this server option of type OT_BITWISE.
****************************************************************************/
static unsigned server_option_bitwise_def(const struct option *poption)
{
  return SERVER_OPTION(poption)->bitwise.def;
}

/****************************************************************************
  Returns the user-visible, translatable (but untranslated) "pretty" names
  of this server option of type OT_BITWISE.
****************************************************************************/
static const struct strvec *
    server_option_bitwise_pretty(const struct option *poption)
{
  return SERVER_OPTION(poption)->bitwise.pretty_names;
}

/****************************************************************************
  Compute the long support names of a value.
****************************************************************************/
static void server_option_bitwise_support_base(const struct strvec *values,
                                               unsigned val,
                                               char *buf, size_t buf_len)
{
  int bit;

  buf[0] = '\0';
  for (bit = 0; bit < strvec_size(values); bit++) {
    if ((1 << bit) & val) {
      if ('\0' != buf[0]) {
        fc_strlcat(buf, "|", buf_len);
      }
      fc_strlcat(buf, strvec_get(values, bit), buf_len);
    }
  }
}

/****************************************************************************
  Set the value of this server option of type OT_BITWISE.  Returns TRUE if
  the value changed.
****************************************************************************/
static bool server_option_bitwise_set(struct option *poption, unsigned val)
{
  struct server_option *psoption = SERVER_OPTION(poption);
  char name[MAX_LEN_MSG];

  if (val == psoption->bitwise.value) {
    return FALSE;
  }

  server_option_bitwise_support_base(psoption->bitwise.support_names, val,
                                     name, sizeof(name));
  send_chat_printf("/set %s \"%s\"", psoption->name, name);
  return TRUE;
}

/****************************************************************************
  Compute the long support names of the values of the server option of type
  OT_BITWISE.
****************************************************************************/
static void server_option_bitwise_support_name(const struct option *poption,
                                               char *val_buf, size_t val_len,
                                               char *def_buf, size_t def_len)
{
  const struct server_option *psoption = SERVER_OPTION(poption);
  const struct strvec *values = psoption->bitwise.support_names;

  if (NULL != val_buf && 0 < val_len) {
    server_option_bitwise_support_base(values, psoption->bitwise.value,
                                       val_buf, val_len);
  }
  if (NULL != def_buf && 0 < def_len) {
    server_option_bitwise_support_base(values, psoption->bitwise.def,
                                       def_buf, def_len);
  }
}


/** Message Options: **/

int messages_where[E_COUNT];


/****************************************************************
  These could be a static table initialisation, except
  its easier to do it this way.
*****************************************************************/
static void message_options_init(void)
{
  int none[] = {
    E_IMP_BUY, E_IMP_SOLD, E_UNIT_BUY,
    E_UNIT_LOST_ATT, E_UNIT_WIN_ATT, E_GAME_START,
    E_CITY_BUILD, E_NEXT_YEAR,
    E_CITY_PRODUCTION_CHANGED,
    E_CITY_MAY_SOON_GROW, E_WORKLIST, E_AI_DEBUG
  };
  int out_only[] = {
    E_NATION_SELECTED, E_CHAT_MSG, E_CHAT_ERROR, E_CONNECTION,
    E_LOG_ERROR, E_SETTING, E_VOTE_NEW, E_VOTE_RESOLVED, E_VOTE_ABORTED
  };
  int all[] = {
    E_LOG_FATAL, E_SCRIPT, E_DEPRECATION_WARNING, E_MESSAGE_WALL
  };
  int i;

  for (i = 0; i <= event_type_max(); i++) {
    /* Include possible undefined values. */
    messages_where[i] = MW_MESSAGES;
  }
  for (i = 0; i < ARRAY_SIZE(none); i++) {
    messages_where[none[i]] = 0;
  }
  for (i = 0; i < ARRAY_SIZE(out_only); i++) {
    messages_where[out_only[i]] = MW_OUTPUT;
  }
  for (i = 0; i < ARRAY_SIZE(all); i++) {
    messages_where[all[i]] = MW_MESSAGES | MW_POPUP;
  }

  events_init();
}

/****************************************************************
  Free resources allocated for message options system
*****************************************************************/
static void message_options_free(void)
{
  events_free();
}

/****************************************************************
  Load the message options; use the function defined by
  specnum.h (see also events.h).
*****************************************************************/
static void message_options_load(struct section_file *file,
                                 const char *prefix)
{
  enum event_type event;
  int i, num_events;
  const char *p;

  if (!secfile_lookup_int(file, &num_events, "messages.count")) {
    /* version < 2.2 */
    /* Order of the events in 2.1. */
    const enum event_type old_events[] = {
      E_CITY_CANTBUILD, E_CITY_LOST, E_CITY_LOVE, E_CITY_DISORDER,
      E_CITY_FAMINE, E_CITY_FAMINE_FEARED, E_CITY_GROWTH,
      E_CITY_MAY_SOON_GROW, E_CITY_AQUEDUCT, E_CITY_AQ_BUILDING,
      E_CITY_NORMAL, E_CITY_NUKED, E_CITY_CMA_RELEASE, E_CITY_GRAN_THROTTLE,
      E_CITY_TRANSFER, E_CITY_BUILD, E_CITY_PRODUCTION_CHANGED,
      E_WORKLIST, E_UPRISING, E_CIVIL_WAR, E_ANARCHY, E_FIRST_CONTACT,
      E_NEW_GOVERNMENT, E_LOW_ON_FUNDS, E_POLLUTION, E_REVOLT_DONE,
      E_REVOLT_START, E_SPACESHIP, E_MY_DIPLOMAT_BRIBE,
      E_DIPLOMATIC_INCIDENT, E_MY_DIPLOMAT_ESCAPE, E_MY_DIPLOMAT_EMBASSY,
      E_MY_DIPLOMAT_FAILED, E_MY_DIPLOMAT_INCITE, E_MY_DIPLOMAT_POISON,
      E_MY_DIPLOMAT_SABOTAGE, E_MY_DIPLOMAT_THEFT, E_ENEMY_DIPLOMAT_BRIBE,
      E_ENEMY_DIPLOMAT_EMBASSY, E_ENEMY_DIPLOMAT_FAILED,
      E_ENEMY_DIPLOMAT_INCITE, E_ENEMY_DIPLOMAT_POISON,
      E_ENEMY_DIPLOMAT_SABOTAGE, E_ENEMY_DIPLOMAT_THEFT,
      E_CARAVAN_ACTION, E_SCRIPT, E_BROADCAST_REPORT, E_GAME_END,
      E_GAME_START, E_NATION_SELECTED, E_DESTROYED, E_REPORT, E_TURN_BELL,
      E_NEXT_YEAR, E_GLOBAL_ECO, E_NUKE, E_HUT_BARB, E_HUT_CITY, E_HUT_GOLD,
      E_HUT_BARB_KILLED, E_HUT_MERC, E_HUT_SETTLER, E_HUT_TECH,
      E_HUT_BARB_CITY_NEAR, E_IMP_BUY, E_IMP_BUILD, E_IMP_AUCTIONED,
      E_IMP_AUTO, E_IMP_SOLD, E_TECH_GAIN, E_TECH_LEARNED, E_TREATY_ALLIANCE,
      E_TREATY_BROKEN, E_TREATY_CEASEFIRE, E_TREATY_PEACE,
      E_TREATY_SHARED_VISION, E_UNIT_LOST_ATT, E_UNIT_WIN_ATT, E_UNIT_BUY,
      E_UNIT_BUILT, E_UNIT_LOST_DEF, E_UNIT_WIN, E_UNIT_BECAME_VET,
      E_UNIT_UPGRADED, E_UNIT_RELOCATED, E_UNIT_ORDERS, E_WONDER_BUILD,
      E_WONDER_OBSOLETE, E_WONDER_STARTED, E_WONDER_STOPPED,
      E_WONDER_WILL_BE_BUILT, E_DIPLOMACY, E_TREATY_EMBASSY,
      E_BAD_COMMAND, E_SETTING, E_CHAT_MSG, E_MESSAGE_WALL, E_CHAT_ERROR,
      E_CONNECTION, E_AI_DEBUG
    };
    const size_t old_events_num = ARRAY_SIZE(old_events);

    for (i = 0; i < old_events_num; i++) {
      messages_where[old_events[i]] =
        secfile_lookup_int_default(file, messages_where[old_events[i]],
                                   "%s.message_where_%02d", prefix, i);
    }
    return;
  }

  for (i = 0; i < num_events; i++) {
    p = secfile_lookup_str(file, "messages.event%d.name", i);
    if (NULL == p) {
      log_error("Corruption in file %s: %s",
                secfile_name(file), secfile_error());
      continue;
    }
    event = event_type_by_name(p, strcmp);
    if (!event_type_is_valid(event)) {
      log_error("Event not supported: %s", p);
      continue;
    }

    if (!secfile_lookup_int(file, &messages_where[event],
                            "messages.event%d.where", i)) {
      log_error("Corruption in file %s: %s",
                secfile_name(file), secfile_error());
    }
  }
}

/****************************************************************
  Save the message options; use the function defined by
  specnum.h (see also events.h).
*****************************************************************/
static void message_options_save(struct section_file *file,
                                 const char *prefix)
{
  enum event_type event;
  int i = 0;

  for (event = event_type_begin(); event != event_type_end();
       event = event_type_next(event)) {
    secfile_insert_str(file, event_type_name(event),
                       "messages.event%d.name", i);
    secfile_insert_int(file, messages_where[i],
                       "messages.event%d.where", i);
    i++;
  }

  secfile_insert_int(file, i, "messages.count");
}


/****************************************************************
 Does heavy lifting for looking up a preset.
*****************************************************************/
static void load_cma_preset(struct section_file *file, int i)
{
  struct cm_parameter parameter;
  const char *name =
    secfile_lookup_str_default(file, "preset",
                               "cma.preset%d.name", i);

  output_type_iterate(o) {
    parameter.minimal_surplus[o] =
        secfile_lookup_int_default(file, 0, "cma.preset%d.minsurp%d", i, o);
    parameter.factor[o] =
        secfile_lookup_int_default(file, 0, "cma.preset%d.factor%d", i, o);
  } output_type_iterate_end;
  parameter.require_happy =
      secfile_lookup_bool_default(file, FALSE, "cma.preset%d.reqhappy", i);
  parameter.happy_factor =
      secfile_lookup_int_default(file, 0, "cma.preset%d.happyfactor", i);
  parameter.allow_disorder = FALSE;
  parameter.allow_specialists = TRUE;

  cmafec_preset_add(name, &parameter);
}

/****************************************************************
 Does heavy lifting for inserting a preset.
*****************************************************************/
static void save_cma_preset(struct section_file *file, int i)
{
  const struct cm_parameter *const pparam = cmafec_preset_get_parameter(i);
  char *name = cmafec_preset_get_descr(i);

  secfile_insert_str(file, name, "cma.preset%d.name", i);

  output_type_iterate(o) {
    secfile_insert_int(file, pparam->minimal_surplus[o],
                       "cma.preset%d.minsurp%d", i, o);
    secfile_insert_int(file, pparam->factor[o],
                       "cma.preset%d.factor%d", i, o);
  } output_type_iterate_end;
  secfile_insert_bool(file, pparam->require_happy,
                      "cma.preset%d.reqhappy", i);
  secfile_insert_int(file, pparam->happy_factor,
                     "cma.preset%d.happyfactor", i);
}

/****************************************************************
 Insert all cma presets.
*****************************************************************/
static void save_cma_presets(struct section_file *file)
{
  int i;

  secfile_insert_int_comment(file, cmafec_preset_num(),
                             _("If you add a preset by hand,"
                               " also update \"number_of_presets\""),
                             "cma.number_of_presets");
  for (i = 0; i < cmafec_preset_num(); i++) {
    save_cma_preset(file, i);
  }
}

/* Old rc file name. */
#define OLD_OPTION_FILE_NAME ".civclientrc"
/* New rc file name. */
#define MID_OPTION_FILE_NAME ".freeciv-client-rc-%d.%d"
#define NEW_OPTION_FILE_NAME "freeciv-client-rc-%d.%d"
#if MINOR_VERSION >= 90
#define MAJOR_NEW_OPTION_FILE_NAME (MAJOR_VERSION + 1)
#define MINOR_NEW_OPTION_FILE_NAME 0
#else /* MINOR_VERSION < 90 */
#define MAJOR_NEW_OPTION_FILE_NAME MAJOR_VERSION
#if IS_DEVEL_VERSION && ! IS_FREEZE_VERSION
#define MINOR_NEW_OPTION_FILE_NAME (MINOR_VERSION + 1)
#else
#define MINOR_NEW_OPTION_FILE_NAME MINOR_VERSION
#endif /* IS_DEVEL_VERSION */
#endif /* MINOR_VERSION >= 90 */
/* The first version the new option name appeared (2.6). */
#define FIRST_MAJOR_NEW_OPTION_FILE_NAME 2
#define FIRST_MINOR_NEW_OPTION_FILE_NAME 6
/* The first version the mid option name appeared (2.2). */
#define FIRST_MAJOR_MID_OPTION_FILE_NAME 2
#define FIRST_MINOR_MID_OPTION_FILE_NAME 2
/* The first version the new boolean values appeared (2.3). */
#define FIRST_MAJOR_NEW_BOOLEAN 2
#define FIRST_MINOR_NEW_BOOLEAN 3
/****************************************************************
  Returns pointer to static memory containing name of the current
  option file.  Usually used for saving.
  Ie, based on FREECIV_OPT env var, and home dir. (or a
  OPTION_FILE_NAME define defined in fc_config.h)
  Or NULL if problem.
*****************************************************************/
static const char *get_current_option_file_name(void)
{
  static char name_buffer[256];
  const char *name;

  name = getenv("FREECIV_OPT");

  if (name) {
    sz_strlcpy(name_buffer, name);
  } else {
#ifdef OPTION_FILE_NAME
    fc_strlcpy(name_buffer, OPTION_FILE_NAME, sizeof(name_buffer));
#else
    name = user_home_dir();
    if (!name) {
      log_error(_("Cannot find your home directory"));
      return NULL;
    }
    fc_snprintf(name_buffer, sizeof(name_buffer),
                "%s" DIR_SEPARATOR ".freeciv" DIR_SEPARATOR NEW_OPTION_FILE_NAME,
                name, MAJOR_NEW_OPTION_FILE_NAME, MINOR_NEW_OPTION_FILE_NAME);
#endif /* OPTION_FILE_NAME */
  }
  log_verbose("settings file is %s", name_buffer);
  return name_buffer;
}

/****************************************************************************
  Check the last option file we saved. Usually used to load. Ie, based on
  FREECIV_OPT env var, and home dir. (or a OPTION_FILE_NAME define defined
  in fc_config.h), or NULL if not found.

  Set in allow_digital_boolean if we should look for old boolean values
  (saved as 0 and 1), so if the rc file version is older than 2.3.0.
****************************************************************************/
static const char *get_last_option_file_name(bool *allow_digital_boolean)
{
  static char name_buffer[256];
  const char *name;
  static int last_minors[] = {
    0,  /* There was no 0.x releases */
    14, /* 1.14 */
    6   /* 2.6 */
  };

  FC_STATIC_ASSERT(MAJOR_VERSION < sizeof(last_minors) / sizeof(int), missing_last_minor);

  *allow_digital_boolean = FALSE;
  name = getenv("FREECIV_OPT");
  if (name) {
    sz_strlcpy(name_buffer, name);
  } else {
#ifdef OPTION_FILE_NAME
    fc_strlcpy(name_buffer, OPTION_FILE_NAME, sizeof(name_buffer));
#else
    int major, minor;
    struct stat buf;

    name = user_home_dir();
    if (!name) {
      log_error(_("Cannot find your home directory"));
      return NULL;
    }
    for (major = MAJOR_NEW_OPTION_FILE_NAME,
         minor = MINOR_NEW_OPTION_FILE_NAME;
         major >= FIRST_MAJOR_NEW_OPTION_FILE_NAME; major--) {
      for (; (major == FIRST_MAJOR_NEW_OPTION_FILE_NAME
              ? minor >= FIRST_MINOR_NEW_OPTION_FILE_NAME 
              : minor >= 0); minor--) {
        fc_snprintf(name_buffer, sizeof(name_buffer),
                    "%s" DIR_SEPARATOR ".freeciv" DIR_SEPARATOR NEW_OPTION_FILE_NAME,
                    name, major, minor);
        if (0 == fc_stat(name_buffer, &buf)) {
          if (MAJOR_NEW_OPTION_FILE_NAME != major
              || MINOR_NEW_OPTION_FILE_NAME != minor) {
            log_normal(_("Didn't find '%s' option file, "
                         "loading from '%s' instead."),
                       get_current_option_file_name() + strlen(name) + 1,
                       name_buffer + strlen(name) + 1);
          }

          return name_buffer;
        }
      }
      minor = last_minors[major - 1];
    }

    /* minor having max value of FIRST_MINOR_NEW_OPTION_FILE_NAME
     * works since MID versioning scheme was used within major version 2
     * only (2.2 - 2.6) so the last minor is bigger than any earlier minor. */
    for (major = FIRST_MAJOR_MID_OPTION_FILE_NAME,
         minor = FIRST_MINOR_NEW_OPTION_FILE_NAME ;
         minor >= FIRST_MINOR_MID_OPTION_FILE_NAME ;
         minor--) {
      fc_snprintf(name_buffer, sizeof(name_buffer),
                  "%s" DIR_SEPARATOR MID_OPTION_FILE_NAME, name, major, minor);
      if (0 == fc_stat(name_buffer, &buf)) {
        log_normal(_("Didn't find '%s' option file, "
                     "loading from '%s' instead."),
                   get_current_option_file_name() + strlen(name) + 1,
                   name_buffer + strlen(name) + 1);

        if (FIRST_MINOR_NEW_BOOLEAN > minor) {
          *allow_digital_boolean = TRUE;
        }
        return name_buffer;
      }
    }

    /* Try with the old one. */
    fc_snprintf(name_buffer, sizeof(name_buffer),
                "%s" DIR_SEPARATOR OLD_OPTION_FILE_NAME, name);
    if (0 == fc_stat(name_buffer, &buf)) {
      log_normal(_("Didn't find '%s' option file, "
                   "loading from '%s' instead."),
                 get_current_option_file_name() + strlen(name) + 1,
                 OLD_OPTION_FILE_NAME);
      *allow_digital_boolean = TRUE;
      return name_buffer;
    } else {
      return NULL;
    }
#endif /* OPTION_FILE_NAME */
  }
  log_verbose("settings file is %s", name_buffer);
  return name_buffer;
}
#undef OLD_OPTION_FILE_NAME
#undef MID_OPTION_FILE_NAME
#undef NEW_OPTION_FILE_NAME
#undef FIRST_MAJOR_NEW_OPTION_FILE_NAME
#undef FIRST_MINOR_NEW_OPTION_FILE_NAME
#undef FIRST_MAJOR_MID_OPTION_FILE_NAME
#undef FIRST_MINOR_MID_OPTION_FILE_NAME
#undef FIRST_MINOR_NEW_BOOLEAN


/****************************************************************************
  Desired settable options.
****************************************************************************/
#define SPECHASH_TAG settable_options
#define SPECHASH_ASTR_KEY_TYPE
#define SPECHASH_ASTR_DATA_TYPE
#include "spechash.h"
#define settable_options_hash_iterate(hash, name, value)                    \
  TYPED_HASH_ITERATE(const char *, const char *, hash, name, value)
#define settable_options_hash_iterate_end HASH_ITERATE_END

static struct settable_options_hash *settable_options_hash = NULL;

/**************************************************************************
  Load the server options.
**************************************************************************/
static void settable_options_load(struct section_file *sf)
{
  char buf[64];
  const struct section *psection;
  const struct entry_list *entries;
  const char *string;
  bool bval;
  int ival;

  fc_assert_ret(NULL != settable_options_hash);

  settable_options_hash_clear(settable_options_hash);

  psection = secfile_section_by_name(sf, "server");
  if (NULL == psection) {
    /* Does not exist! */
    return;
  }

  entries = section_entries(psection);
  entry_list_iterate(entries, pentry) {
    string = NULL;
    switch (entry_type(pentry)) {
    case ENTRY_BOOL:
      if (entry_bool_get(pentry, &bval)) {
        fc_strlcpy(buf, bval ? "enabled" : "disabled", sizeof(buf));
        string = buf;
      }
      break;

    case ENTRY_INT:
      if (entry_int_get(pentry, &ival)) {
        fc_snprintf(buf, sizeof(buf), "%d", ival);
        string = buf;
      }
      break;

    case ENTRY_STR:
      (void) entry_str_get(pentry, &string);
      break;

    case ENTRY_FLOAT:
    case ENTRY_FILEREFERENCE:
      /* Not supported yet */
      break;
    case ENTRY_ILLEGAL:
      fc_assert(entry_type(pentry) != ENTRY_ILLEGAL);
      break;
    }

    if (NULL == string) {
      log_error("Entry type variant of \"%s.%s\" is not supported.",
                section_name(psection), entry_name(pentry));
      continue;
    }

    settable_options_hash_insert(settable_options_hash, entry_name(pentry),
                                 string);
  } entry_list_iterate_end;
}

/****************************************************************
  Save the desired server options.
*****************************************************************/
static void settable_options_save(struct section_file *sf)
{
  fc_assert_ret(NULL != settable_options_hash);

  settable_options_hash_iterate(settable_options_hash, name, value) {
    if (!fc_strcasecmp(name, "gameseed") || !fc_strcasecmp(name, "mapseed")) {
      /* Do not save mapseed or gameseed. */
      continue;
    }
    if (!fc_strcasecmp(name, "topology")) {
      /* client_start_server() sets topology based on tileset. Don't store
       * its choice. The tileset is already stored. Storing topology leads
       * to all sort of breakage:
       * - it breaks ruleset default topology.
       * - it interacts badly with tileset ruleset change, ruleset tileset
       *   change and topology tileset change.
       * - its value is probably based on what tileset was loaded when
       *   client_start_server() decided to set topology, not on player
       *   choice.
       */
      continue;
    }
    secfile_insert_str(sf, value, "server.%s", name);
  } settable_options_hash_iterate_end;
}

/****************************************************************************
  Update the desired settable options hash table from the current
  setting configuration.
****************************************************************************/
void desired_settable_options_update(void)
{
  char val_buf[1024], def_buf[1024];
  const char *value, *def_val;

  fc_assert_ret(NULL != settable_options_hash);

  options_iterate(server_optset, poption) {
    value = NULL;
    def_val = NULL;
    switch (option_type(poption)) {
    case OT_BOOLEAN:
      fc_strlcpy(val_buf, option_bool_get(poption) ? "enabled" : "disabled",
                 sizeof(val_buf));
      value = val_buf;
      fc_strlcpy(def_buf, option_bool_def(poption) ? "enabled" : "disabled",
                 sizeof(def_buf));
      def_val = def_buf;
      break;
    case OT_INTEGER:
      fc_snprintf(val_buf, sizeof(val_buf), "%d", option_int_get(poption));
      value = val_buf;
      fc_snprintf(def_buf, sizeof(def_buf), "%d", option_int_def(poption));
      def_val = def_buf;
      break;
    case OT_STRING:
      value = option_str_get(poption);
      def_val = option_str_def(poption);
      break;
    case OT_ENUM:
      server_option_enum_support_name(poption, &value, &def_val);
      break;
    case OT_BITWISE:
      server_option_bitwise_support_name(poption, val_buf, sizeof(val_buf),
                                         def_buf, sizeof(def_buf));
      value = val_buf;
      def_val = def_buf;
      break;
    case OT_FONT:
    case OT_COLOR:
    case OT_VIDEO_MODE:
      break;
    }

    if (NULL == value || NULL == def_val) {
      log_error("Option type %s (%d) not supported for '%s'.",
                option_type_name(option_type(poption)), option_type(poption),
                option_name(poption));
      continue;
    }

    if (0 == strcmp(value, def_val)) {
      /* Not set, using default... */
      settable_options_hash_remove(settable_options_hash,
                                   option_name(poption));
    } else {
      /* Really desired. */
      settable_options_hash_replace(settable_options_hash,
                                    option_name(poption), value);
    }
  } options_iterate_end;
}

/****************************************************************
  Update a desired settable option in the hash table from a value
  which can be different of the current configuration.
*****************************************************************/
void desired_settable_option_update(const char *op_name,
                                    const char *op_value,
                                    bool allow_replace)
{
  fc_assert_ret(NULL != settable_options_hash);

  if (allow_replace) {
    settable_options_hash_replace(settable_options_hash, op_name, op_value);
  } else {
    settable_options_hash_insert(settable_options_hash, op_name, op_value);
  }
}

/****************************************************************************
  Convert old integer to new values (Freeciv 2.2.x to Freeciv 2.3.x).
  Very ugly hack. TODO: Remove this later.
****************************************************************************/
static bool settable_option_upgrade_value(const struct option *poption,
                                          int old_value,
                                          char *buf, size_t buf_len)
{
  const char *name = option_name(poption);

#define SETTING_CASE(ARG_name, ...)                                         \
  if (0 == strcmp(ARG_name, name)) {                                        \
    static const char *values[] = { __VA_ARGS__ };                          \
    if (0 <= old_value && old_value < ARRAY_SIZE(values)                    \
        && NULL != values[old_value]) {                                     \
      fc_strlcpy(buf, values[old_value], buf_len);                          \
      return TRUE;                                                          \
    } else {                                                                \
      return FALSE;                                                         \
    }                                                                       \
  }

  SETTING_CASE("topology", "", "WRAPX", "WRAPY", "WRAPX|WRAPY", "ISO",
               "WRAPX|ISO", "WRAPY|ISO", "WRAPX|WRAPY|ISO", "HEX",
               "WRAPX|HEX", "WRAPY|HEX", "WRAPX|WRAPY|HEX", "ISO|HEX",
               "WRAPX|ISO|HEX", "WRAPY|ISO|HEX", "WRAPX|WRAPY|ISO|HEX");
  SETTING_CASE("generator", NULL, "RANDOM", "FRACTAL", "ISLAND");
  SETTING_CASE("startpos", "DEFAULT", "SINGLE", "2or3", "ALL", "VARIABLE");
  SETTING_CASE("borders", "DISABLED", "ENABLED", "SEE_INSIDE", "EXPAND");
  SETTING_CASE("diplomacy", "ALL", "HUMAN", "AI", "TEAM", "DISABLED");
  SETTING_CASE("citynames", "NO_RESTRICTIONS", "PLAYER_UNIQUE",
               "GLOBAL_UNIQUE", "NO_STEALING");
  SETTING_CASE("barbarians", "DISABLED", "HUTS_ONLY", "NORMAL", "FREQUENT",
               "HORDES");
  SETTING_CASE("phasemode", "ALL", "PLAYER", "TEAM");
  SETTING_CASE("compresstype", "PLAIN", "LIBZ", "BZIP2");

#undef SETTING_CASE
  return FALSE;
}

/****************************************************************************
  Send the desired server options to the server.
****************************************************************************/
static void desired_settable_option_send(struct option *poption)
{
  char *desired;
  int value;

  fc_assert_ret(NULL != settable_options_hash);

  if (!settable_options_hash_lookup(settable_options_hash,
                                    option_name(poption), &desired)) {
    /* No change explicitly  desired. */
    return;
  }

  switch (option_type(poption)) {
  case OT_BOOLEAN:
    if ((0 == fc_strcasecmp("enabled", desired)
         || (str_to_int(desired, &value) && 1 == value))
        && !option_bool_get(poption)) {
      send_chat_printf("/set %s enabled", option_name(poption));
    } else if ((0 == fc_strcasecmp("disabled", desired)
                || (str_to_int(desired, &value) && 0 == value))
               && option_bool_get(poption)) {
      send_chat_printf("/set %s disabled", option_name(poption));
    }
    return;
  case OT_INTEGER:
    if (str_to_int(desired, &value) && value != option_int_get(poption)) {
      send_chat_printf("/set %s %d", option_name(poption), value);
    }
    return;
  case OT_STRING:
    if (0 != strcmp(desired, option_str_get(poption))) {
      send_chat_printf("/set %s \"%s\"", option_name(poption), desired);
    }
    return;
  case OT_ENUM:
    {
      char desired_buf[256];
      const char *value_str;

      /* Handle old values. */
      if (str_to_int(desired, &value)
          && settable_option_upgrade_value(poption, value, desired_buf,
                                           sizeof(desired_buf))) {
        desired = desired_buf;
      }

      server_option_enum_support_name(poption, &value_str, NULL);
      if (0 != strcmp(desired, value_str)) {
        send_chat_printf("/set %s \"%s\"", option_name(poption), desired);
      }
    }
    return;
  case OT_BITWISE:
    {
      char desired_buf[256], value_buf[256];

      /* Handle old values. */
      if (str_to_int(desired, &value)
          && settable_option_upgrade_value(poption, value, desired_buf,
                                           sizeof(desired_buf))) {
        desired = desired_buf;
      }

      server_option_bitwise_support_name(poption, value_buf,
                                         sizeof(value_buf), NULL, 0);
      if (0 != strcmp(desired, value_buf)) {
        send_chat_printf("/set %s \"%s\"", option_name(poption), desired);
      }
    }
    return;
  case OT_FONT:
  case OT_COLOR:
  case OT_VIDEO_MODE:
    break;
  }

  log_error("Option type %s (%d) not supported for '%s'.",
            option_type_name(option_type(poption)), option_type(poption),
            option_name(poption));
}


/****************************************************************************
  City and player report dialog options.
****************************************************************************/
#define SPECHASH_TAG dialog_options
#define SPECHASH_ASTR_KEY_TYPE
#define SPECHASH_IDATA_TYPE bool
#define SPECHASH_UDATA_TO_IDATA FC_INT_TO_PTR
#define SPECHASH_IDATA_TO_UDATA FC_PTR_TO_INT
#include "spechash.h"
#define dialog_options_hash_iterate(hash, column, visible)                  \
  TYPED_HASH_ITERATE(const char *, intptr_t, hash, column, visible)
#define dialog_options_hash_iterate_end HASH_ITERATE_END

static struct dialog_options_hash *dialog_options_hash = NULL;

/****************************************************************************
  Load the city and player report dialog options.
****************************************************************************/
static void options_dialogs_load(struct section_file *sf)
{
  const struct entry_list *entries;
  const char *prefixes[] = { "player_dlg_", "city_report_", NULL };
  const char **prefix;
  bool visible;

  fc_assert_ret(NULL != dialog_options_hash);

  entries = section_entries(secfile_section_by_name(sf, "client"));

  if (NULL != entries) {
    entry_list_iterate(entries, pentry) {
      for (prefix = prefixes; NULL != *prefix; prefix++) {
        if (0 == strncmp(*prefix, entry_name(pentry), strlen(*prefix))
            && secfile_lookup_bool(sf, &visible, "client.%s",
                                   entry_name(pentry))) {
          dialog_options_hash_replace(dialog_options_hash,
                                      entry_name(pentry), visible);
          break;
        }
      }
    } entry_list_iterate_end;
  }
}

/****************************************************************************
  Save the city and player report dialog options.
****************************************************************************/
static void options_dialogs_save(struct section_file *sf)
{
  fc_assert_ret(NULL != dialog_options_hash);

  options_dialogs_update();
  dialog_options_hash_iterate(dialog_options_hash, column, visible) {
    secfile_insert_bool(sf, visible, "client.%s", column);
  } dialog_options_hash_iterate_end;
}

/****************************************************************
  This set the city and player report dialog options to the
  current ones.  It's called when the client goes to
  C_S_DISCONNECTED state.
*****************************************************************/
void options_dialogs_update(void)
{
  char buf[64];
  int i;

  fc_assert_ret(NULL != dialog_options_hash);

  /* Player report dialog options. */
  for (i = 1; i < num_player_dlg_columns; i++) {
    fc_snprintf(buf, sizeof(buf), "player_dlg_%s",
                player_dlg_columns[i].tagname);
    dialog_options_hash_replace(dialog_options_hash, buf,
                                player_dlg_columns[i].show);
  }

  /* City report dialog options. */
  for (i = 0; i < num_city_report_spec(); i++) {
    fc_snprintf(buf, sizeof(buf), "city_report_%s",
                city_report_spec_tagname(i));
    dialog_options_hash_replace(dialog_options_hash, buf,
                                *city_report_spec_show_ptr(i));
  }
}

/****************************************************************
  This set the city and player report dialog options.  It's called
  when the client goes to C_S_RUNNING state.
*****************************************************************/
void options_dialogs_set(void)
{
  char buf[64];
  bool visible;
  int i;

  fc_assert_ret(NULL != dialog_options_hash);

  /* Player report dialog options. */
  for (i = 1; i < num_player_dlg_columns; i++) {
    fc_snprintf(buf, sizeof(buf), "player_dlg_%s",
                player_dlg_columns[i].tagname);
    if (dialog_options_hash_lookup(dialog_options_hash, buf, &visible)) {
      player_dlg_columns[i].show = visible;
    }
  }

  /* City report dialog options. */
  for (i = 0; i < num_city_report_spec(); i++) {
    fc_snprintf(buf, sizeof(buf), "city_report_%s",
                city_report_spec_tagname(i));
    if (dialog_options_hash_lookup(dialog_options_hash, buf, &visible)) {
      *city_report_spec_show_ptr(i) = visible;
    }
  }
}


/****************************************************************
  Load from the rc file any options that are not ruleset specific.
  It is called after ui_init(), yet before ui_main().
  Unfortunately, this means that some clients cannot display.
  Instead, use log_*().
*****************************************************************/
void options_load(void)
{
  struct section_file *sf;
  bool allow_digital_boolean;
  int i, num;
  const char *name;
  const char *const prefix = "client";
  const char *str;

  name = get_last_option_file_name(&allow_digital_boolean);
  if (!name) {
    log_normal(_("Didn't find the option file. Creating a new one."));
    options_fully_initialized = TRUE;
    create_default_cma_presets();
    gui_options.first_boot = TRUE;
    return;
  }
  if (!(sf = secfile_load(name, TRUE))) {
    log_debug("Error loading option file '%s':\n%s", name, secfile_error());
    /* try to create the rc file */
    sf = secfile_new(TRUE);
    secfile_insert_str(sf, VERSION_STRING, "client.version");

    create_default_cma_presets();
    gui_options.first_boot = TRUE;
    save_cma_presets(sf);

    /* FIXME: need better messages */
    if (!secfile_save(sf, name, 0, FZ_PLAIN)) {
      log_error(_("Save failed, cannot write to file %s"), name);
    } else {
      log_normal(_("Saved settings to file %s"), name);
    }
    secfile_destroy(sf);
    options_fully_initialized = TRUE;
    return;
  }
  secfile_allow_digital_boolean(sf, allow_digital_boolean);

  /* a "secret" option for the lazy. TODO: make this saveable */
  sz_strlcpy(password,
             secfile_lookup_str_default(sf, "", "%s.password", prefix));

  gui_options.save_options_on_exit =
    secfile_lookup_bool_default(sf, gui_options.save_options_on_exit,
                                "%s.save_options_on_exit", prefix);
  gui_options.migrate_fullscreen =
    secfile_lookup_bool_default(sf, gui_options.migrate_fullscreen,
                                "%s.fullscreen_mode", prefix);

  /* Settings migrations */
  gui_options.gui_gtk3_22_migrated_from_gtk3 =
    secfile_lookup_bool_default(sf, gui_options.gui_gtk3_22_migrated_from_gtk3,
                                "%s.migration_gtk3_22_from_gtk3", prefix);
  gui_options.gui_gtk3_migrated_from_gtk2 =
    secfile_lookup_bool_default(sf, gui_options.gui_gtk3_migrated_from_gtk2,
                                "%s.migration_gtk3_from_gtk2", prefix);
  gui_options.gui_sdl2_migrated_from_sdl =
    secfile_lookup_bool_default(sf, gui_options.gui_sdl2_migrated_from_sdl,
                                "%s.migration_sdl2_from_sdl", prefix);
  gui_options.gui_gtk2_migrated_from_2_5 =
    secfile_lookup_bool_default(sf, gui_options.gui_gtk2_migrated_from_2_5,
                                "%s.migration_gtk2_from_2_5", prefix);
  gui_options.gui_gtk3_migrated_from_2_5 =
    secfile_lookup_bool_default(sf, gui_options.gui_gtk3_migrated_from_2_5,
                                "%s.migration_gtk3_from_2_5", prefix);
  gui_options.gui_qt_migrated_from_2_5 =
    secfile_lookup_bool_default(sf, gui_options.gui_qt_migrated_from_2_5,
                                "%s.migration_qt_from_2_5", prefix);

  /* These are not gui-enabled yet */
  gui_options.zoom_set =
    secfile_lookup_bool_default(sf, FALSE, "%s.zoom_set", prefix);
  gui_options.zoom_default_level =
    secfile_lookup_float_default(sf, 1.0,
                                 "%s.zoom_default_level", prefix);

  str = secfile_lookup_str_default(sf, NULL, "client.default_tileset_name");
  if (str != NULL) {
    sz_strlcpy(gui_options.default_tileset_name, str);
  }

  /* Backwards compatibility for removed options replaced by entirely "new"
   * options. The equivalent "new" option will override these, if set. */

  /* Removed in 2.3 */
  /* Note: this overrides the previously specified default for
   * gui_gtk2_message_chat_location */
  /* gtk3 client never had the old form of this option. The overridden
   * gui_gtk2_ value will be propagated to gui_gtk3_ later by
   * migrate_options_from_gtk2() if necessary. */
  if (secfile_lookup_bool_default(sf, FALSE,
                                  "%s.gui_gtk2_merge_notebooks", prefix)) {
    gui_options.gui_gtk2_message_chat_location = GUI_GTK_MSGCHAT_MERGED;
  } else if (secfile_lookup_bool_default(sf, FALSE,
                                         "%s.gui_gtk2_split_bottom_notebook",
                                         prefix)) {
    gui_options.gui_gtk2_message_chat_location = GUI_GTK_MSGCHAT_SPLIT;
  } else {
    gui_options.gui_gtk2_message_chat_location = GUI_GTK_MSGCHAT_SEPARATE;
  }

  /* Renamed in 2.6 */
  gui_options.popup_actor_arrival = secfile_lookup_bool_default(sf, TRUE,
      "%s.popup_caravan_arrival", prefix);

  /* Load all the regular options */
  client_options_iterate_all(poption) {
    client_option_load(poption, sf);
  } client_options_iterate_all_end;

  /* More backwards compatibility, for removed options that had been
   * folded into then-existing options. Here, the backwards-compatibility
   * behaviour overrides the "destination" option. */

  /* Removed in 2.4 */
  if (!secfile_lookup_bool_default(sf, TRUE,
                                   "%s.do_combat_animation", prefix)) {
    gui_options.smooth_combat_step_msec = 0;
  }

  message_options_load(sf, prefix);
  options_dialogs_load(sf);

  /* Load cma presets. If cma.number_of_presets doesn't exist, don't load 
   * any, the order here should be reversed to keep the order the same */
  if (secfile_lookup_int(sf, &num, "cma.number_of_presets")) {
    for (i = num - 1; i >= 0; i--) {
      load_cma_preset(sf, i);
    }
  } else {
    create_default_cma_presets();
  }

  settable_options_load(sf);
  global_worklists_load(sf);

  secfile_destroy(sf);
  options_fully_initialized = TRUE;
}

/**************************************************************************
  Write messages from option saving to the output window.
**************************************************************************/
static void option_save_output_window_callback(enum log_level lvl,
                                               const char *msg, ...)
{
  va_list args;

  va_start(args, msg);
  output_window_vprintf(ftc_client, msg, args);
  va_end(args);
}

/**************************************************************************
  Save all options.
**************************************************************************/
void options_save(option_save_log_callback log_cb)
{
  struct section_file *sf;
  const char *name = get_current_option_file_name();
  char dir_name[2048];
  int i;

  if (log_cb == NULL) {
    /* Default callback */
    log_cb = option_save_output_window_callback;
  }

  if (!name) {
    log_cb(LOG_ERROR, _("Save failed, cannot find a filename."));
    return;
  }

  sf = secfile_new(TRUE);
  secfile_insert_str(sf, VERSION_STRING, "client.version");

  secfile_insert_bool(sf, gui_options.save_options_on_exit,
                      "client.save_options_on_exit");
  secfile_insert_bool_comment(sf, gui_options.migrate_fullscreen,
                              "deprecated", "client.fullscreen_mode");

  /* Migrations */
  secfile_insert_bool(sf, gui_options.gui_gtk3_22_migrated_from_gtk3,
                      "client.migration_gtk3_22_from_gtk3");
  secfile_insert_bool(sf, gui_options.gui_gtk3_migrated_from_gtk2,
                      "client.migration_gtk3_from_gtk2");
  secfile_insert_bool(sf, gui_options.gui_sdl2_migrated_from_sdl,
                      "client.migration_sdl2_from_sdl");
  secfile_insert_bool(sf, gui_options.gui_gtk2_migrated_from_2_5,
                      "client.migration_gtk2_from_2_5");
  secfile_insert_bool(sf, gui_options.gui_gtk3_migrated_from_2_5,
                      "client.migration_gtk3_from_2_5");
  secfile_insert_bool(sf, gui_options.gui_qt_migrated_from_2_5,
                      "client.migration_qt_from_2_5");

  /* gui-enabled options */
  client_options_iterate_all(poption) {
    client_option_save(poption, sf);
  } client_options_iterate_all_end;

  /* These are not gui-enabled yet. */
  secfile_insert_bool(sf, gui_options.zoom_set, "client.zoom_set");
  secfile_insert_float(sf, gui_options.zoom_default_level,
                         "client.zoom_default_level");

  if (gui_options.default_tileset_name[0] != '\0') {
    secfile_insert_str(sf, gui_options.default_tileset_name,
                       "client.default_tileset_name");
  }

  message_options_save(sf, "client");
  options_dialogs_save(sf);

  /* server settings */
  save_cma_presets(sf);
  settable_options_save(sf);

  /* insert global worklists */
  global_worklists_save(sf);

  /* Directory name */
  sz_strlcpy(dir_name, name);
  for (i = strlen(dir_name) - 1 ; dir_name[i] != DIR_SEPARATOR_CHAR && i >= 0; i--) {
    /* Nothing */
  }
  if (i > 0) {
    dir_name[i] = '\0';
    make_dir(dir_name);
  }

  /* save to disk */
  if (!secfile_save(sf, name, 0, FZ_PLAIN)) {
    log_cb(LOG_ERROR, _("Save failed, cannot write to file %s"), name);
  } else {
    log_cb(LOG_VERBOSE, _("Saved settings to file %s"), name);
  }
  secfile_destroy(sf);
}


/**************************************************************************
  Initialize lists of names for a client option.
**************************************************************************/
static void options_init_names(const struct copt_val_name *(*acc)(int),
                               struct strvec **support, struct strvec **pretty)
{
  int val;
  const struct copt_val_name *name;
  fc_assert_ret(NULL != acc);
  *support = strvec_new();
  *pretty = strvec_new();
  for (val=0; (name = acc(val)); val++) {
    strvec_append(*support, name->support);
    strvec_append(*pretty, name->pretty);
  }
}

/**************************************************************************
  Initialize the option module.
**************************************************************************/
void options_init(void)
{
  message_options_init();
  options_extra_init();
  global_worklists_init();

  settable_options_hash = settable_options_hash_new();
  dialog_options_hash = dialog_options_hash_new();

  client_options_iterate_all(poption) {
    struct client_option *pcoption = CLIENT_OPTION(poption);

    switch (option_type(poption)) {
    case OT_INTEGER:
      if (option_int_def(poption) < option_int_min(poption)
          || option_int_def(poption) > option_int_max(poption)) {
        int new_default = MAX(MIN(option_int_def(poption),
                                  option_int_max(poption)),
                              option_int_min(poption));

        log_error("option %s has default value of %d, which is "
                  "out of its range [%d; %d], changing to %d.",
                  option_name(poption), option_int_def(poption),
                  option_int_min(poption), option_int_max(poption),
                  new_default);
        *((int *) &(pcoption->integer.def)) = new_default;
      }
      break;

    case OT_STRING:
      if (gui_options.default_user_name == option_str_get(poption)) {
        /* Hack to get a default value. */
        *((const char **) &(pcoption->string.def)) =
            fc_strdup(gui_options.default_user_name);
      }

      if (NULL == option_str_def(poption)) {
        const struct strvec *values = option_str_values(poption);

        if (NULL == values || strvec_size(values) == 0) {
          log_error("Invalid NULL default string for option %s.",
                    option_name(poption));
        } else {
          *((const char **) &(pcoption->string.def)) =
              strvec_get(values, 0);
        }
      }
      break;

    case OT_ENUM:
      fc_assert(NULL == pcoption->enumerator.support_names);
      fc_assert(NULL == pcoption->enumerator.pretty_names);
      options_init_names(pcoption->enumerator.name_accessor,
                         &pcoption->enumerator.support_names,
                         &pcoption->enumerator.pretty_names);
      fc_assert(NULL != pcoption->enumerator.support_names);
      fc_assert(NULL != pcoption->enumerator.pretty_names);
      break;

    case OT_BITWISE:
      fc_assert(NULL == pcoption->bitwise.support_names);
      fc_assert(NULL == pcoption->bitwise.pretty_names);
      options_init_names(pcoption->bitwise.name_accessor,
                         &pcoption->bitwise.support_names,
                         &pcoption->bitwise.pretty_names);
      fc_assert(NULL != pcoption->bitwise.support_names);
      fc_assert(NULL != pcoption->bitwise.pretty_names);
      break;

    case OT_COLOR:
      {
        /* Duplicate the string pointers. */
        struct ft_color *pcolor = pcoption->color.pvalue;

        if (NULL != pcolor->foreground) {
          pcolor->foreground = fc_strdup(pcolor->foreground);
        }
        if (NULL != pcolor->background) {
          pcolor->background = fc_strdup(pcolor->background);
        }
      }

    case OT_BOOLEAN:
    case OT_FONT:
    case OT_VIDEO_MODE:
      break;
    }

    /* Set to default. */
    option_reset(poption);
  } client_options_iterate_all_end;
}

/**************************************************************************
  Free the option module.
**************************************************************************/
void options_free(void)
{
  client_options_iterate_all(poption) {
    struct client_option *pcoption = CLIENT_OPTION(poption);

    switch (option_type(poption)) {
    case OT_ENUM:
      fc_assert_action(NULL != pcoption->enumerator.support_names, break);
      strvec_destroy(pcoption->enumerator.support_names);
      pcoption->enumerator.support_names = NULL;
      fc_assert_action(NULL != pcoption->enumerator.pretty_names, break);
      strvec_destroy(pcoption->enumerator.pretty_names);
      pcoption->enumerator.pretty_names = NULL;
      break;

    case OT_BITWISE:
      fc_assert_action(NULL != pcoption->bitwise.support_names, break);
      strvec_destroy(pcoption->bitwise.support_names);
      pcoption->bitwise.support_names = NULL;
      fc_assert_action(NULL != pcoption->bitwise.pretty_names, break);
      strvec_destroy(pcoption->bitwise.pretty_names);
      pcoption->bitwise.pretty_names = NULL;
      break;

    case OT_BOOLEAN:
    case OT_INTEGER:
    case OT_STRING:
    case OT_FONT:
    case OT_COLOR:
    case OT_VIDEO_MODE:
      break;
    }
  } client_options_iterate_all_end;

  if (NULL != settable_options_hash) {
    settable_options_hash_destroy(settable_options_hash);
    settable_options_hash = NULL;
  }

  if (NULL != dialog_options_hash) {
    dialog_options_hash_destroy(dialog_options_hash);
    dialog_options_hash = NULL;
  }

  message_options_free();
  global_worklists_free();
}

/****************************************************************************
  Callback when the reqtree show icons option is changed. The tree is
  recalculated.
****************************************************************************/
static void reqtree_show_icons_callback(struct option *poption)
{
  science_report_dialog_redraw();
}

/****************************************************************************
  Callback for when any view option is changed.
****************************************************************************/
static void view_option_changed_callback(struct option *poption)
{
  menus_init();
  update_map_canvas_visible();
}

/****************************************************************************
  Callback for when ai_manual_turn_done is changed.
****************************************************************************/
static void manual_turn_done_callback(struct option *poption)
{
  update_turn_done_button_state();
  if (!gui_options.ai_manual_turn_done && client.conn.playing->ai_controlled) {
    if (can_end_turn()) {
      user_ended_turn();
    }
  }
}

/****************************************************************************
  Callback for when any voteinfo bar option is changed.
****************************************************************************/
static void voteinfo_bar_callback(struct option *poption)
{
  voteinfo_gui_update();
}

/****************************************************************************
  Callback for font options.
****************************************************************************/
static void font_changed_callback(struct option *poption)
{
  fc_assert_ret(OT_FONT == option_type(OPTION(poption)));
  gui_update_font(option_font_target(poption), option_font_get(poption));
}

/****************************************************************************
  Callback for mapimg options.
****************************************************************************/
static void mapimg_changed_callback(struct option *poption)
{
  if (!mapimg_client_define()) {
    bool success;

    log_normal("Error setting the value for %s (%s). Restoring the default "
               "value.", option_name(poption), mapimg_error());

    /* Reset the value to the default value. */
    success = option_reset(poption);
    fc_assert_msg(success == TRUE,
                  "Failed to reset the option \"%s\".",
                  option_name(poption));
    success = mapimg_client_define();
    fc_assert_msg(success == TRUE,
                  "Failed to restore mapimg definition for option \"%s\".",
                  option_name(poption));
  }
}

/****************************************************************************
  Callback for music enabling option.
****************************************************************************/
static void game_music_enable_callback(struct option *poption)
{
  if (client_state() == C_S_RUNNING) {
    if (gui_options.sound_enable_game_music) {
      start_style_music();
    } else {
      stop_style_music();
    }
  }
}

/****************************************************************************
  Callback for music enabling option.
****************************************************************************/
static void menu_music_enable_callback(struct option *poption)
{
  if (client_state() != C_S_RUNNING) {
    if (gui_options.sound_enable_menu_music) {
      start_menu_music("music_menu", NULL);
    } else {
      stop_menu_music();
    }
  }
}

/****************************************************************************
  Convert a video mode to string. Returns TRUE on success.
****************************************************************************/
bool video_mode_to_string(char *buf, size_t buf_len, struct video_mode *mode)
{
  return (2 < fc_snprintf(buf, buf_len, "%dx%d", mode->width, mode->height));
}

/****************************************************************************
  Convert a string to video mode. Returns TRUE on success.
****************************************************************************/
bool string_to_video_mode(const char *buf, struct video_mode *mode)
{
  return (2 == sscanf(buf, "%dx%d", &mode->width, &mode->height));
}

/****************************************************************************
  Option framework wrapper for mapimg_get_format_list()
****************************************************************************/
static const struct strvec *get_mapimg_format_list(const struct option *poption)
{
  return mapimg_get_format_list();
}

/****************************************************************************
  What is the user defined tileset for the given topology
****************************************************************************/
const char *tileset_name_for_topology(int topology_id)
{
  const char *tsn = NULL;
  
  switch (topology_id & (TF_ISO | TF_HEX)) {
  case 0:
    tsn = gui_options.default_tileset_overhead_name;
    break;
  case TF_ISO:
    tsn = gui_options.default_tileset_iso_name;
    break;
  case TF_HEX:
    tsn = gui_options.default_tileset_hex_name;
    break;
  case TF_ISO | TF_HEX:
    tsn = gui_options.default_tileset_isohex_name;
    break;
  }

  if (tsn == NULL) {
    tsn = gui_options.default_tileset_name;
  }

  return tsn;
}

/****************************************************************************
  Set given tileset as the default for suitable topology
****************************************************************************/
void option_set_default_ts(struct tileset *t)
{
  const char *optname = "<not set>";
  struct option *opt;

  switch (tileset_topo_index(t)) {
  case TS_TOPO_OVERHEAD:
    /* Overhead */
    optname = "default_tileset_overhead_name";
    break;
  case TS_TOPO_ISO:
    /* Iso */
    optname = "default_tileset_iso_name";
    break;
  case TS_TOPO_HEX:
    /* Hex */
    optname = "default_tileset_hex_name";
    break;
  case TS_TOPO_ISOHEX:
    /* Isohex */
    optname = "default_tileset_isohex_name";
    break;
  }

  opt = optset_option_by_name(client_optset, optname);

  if (opt == NULL) {
    log_error("Unknown option name \"%s\" in option_set_default_ts()", optname);
    return;
  }

  /* Do not call option_str_set() since we don't want option changed callback
   * to reload this tileset. */
  opt->str_vtable->set(opt, tileset_basename(t));
  option_gui_update(opt);
}

/****************************************************************************
  Does topology-specific tileset option lack value?
****************************************************************************/
static bool is_ts_option_unset(const char *optname)
{
  struct option *opt;
  const char *val;

  opt = optset_option_by_name(client_optset, optname);

  if (opt == NULL) {
    return TRUE;
  }

  val = opt->str_vtable->get(opt);

  if (val == NULL || val[0] == '\0') {
    return TRUE;
  }

  return FALSE;
}

/****************************************************************************
  Fill default tilesets for topology-specific settings.
****************************************************************************/
void fill_topo_ts_default(void)
{
  if (is_ts_option_unset("default_tileset_overhead_name")) {
    log_debug("Setting tileset for overhead topology.");
    tilespec_try_read(NULL, FALSE, 0, FALSE);
  }
  if (is_ts_option_unset("default_tileset_iso_name")) {
    log_debug("Setting tileset for iso topology.");
    tilespec_try_read(NULL, FALSE, TF_ISO, FALSE);
  }
  if (is_ts_option_unset("default_tileset_hex_name")) {
    log_debug("Setting tileset for hex topology.");
    tilespec_try_read(NULL, FALSE, TF_HEX, FALSE);
  }
  if (is_ts_option_unset("default_tileset_isohex_name")) {
    log_debug("Setting tileset for isohex topology.");
    tilespec_try_read(NULL, FALSE, TF_ISO | TF_HEX, FALSE);
  }
}