df_ls_structure 0.3.0-rc.1

A language server for Dwarf Fortress RAW files
Documentation
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
use df_ls_core::{Choose, Clamp, DFChar, Reference, ReferenceTo, Referenceable};
use df_ls_diagnostics::DiagnosticsInfo;
use df_ls_syntax_analysis::{Token, TokenDeserialize, TryFromArgumentGroup};
use serde::{Deserialize, Serialize};

use crate::{MusicSkillEnum, SkillEnum};

#[allow(clippy::large_enum_variant)]
#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
pub enum ItemToken {
    #[token_de(token = "ITEM_AMMO")]
    AmmoToken(AmmoToken),
    #[token_de(token = "ITEM_ARMOR")]
    ArmorToken(ArmorToken),
    #[token_de(token = "ITEM_FOOD")]
    FoodToken(FoodToken),
    #[token_de(token = "ITEM_GLOVES")]
    GlovesToken(GlovesToken),
    #[token_de(token = "ITEM_HELM")]
    HelmToken(HelmToken),
    #[token_de(token = "ITEM_INSTRUMENT")]
    InstrumentToken(InstrumentToken),
    #[token_de(token = "ITEM_PANTS")]
    PantsToken(PantsToken),
    #[token_de(token = "ITEM_SHIELD")]
    ShieldToken(ShieldToken),
    #[token_de(token = "ITEM_SHOES")]
    ShoesToken(ShoesToken),
    #[token_de(token = "ITEM_SIEGEAMMO")]
    SiegeAmmoToken(SiegeAmmoToken),
    #[token_de(token = "ITEM_TOOL")]
    ToolToken(ToolToken),
    #[token_de(token = "ITEM_TOY")]
    ToyToken(ToyToken),
    #[token_de(token = "ITEM_TRAPCOMP")]
    TrapCompToken(TrapCompToken),
    #[token_de(token = "ITEM_WEAPON")]
    WeaponToken(WeaponToken),
}
impl Default for ItemToken {
    fn default() -> Self {
        Self::AmmoToken(AmmoToken::default())
    }
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct AmmoToken {
    /// Argument 1 of `[ITEM_AMMO:...]`
    #[token_de(token = "ITEM_AMMO", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// This ammo can be fired from a weapon that is set to fire the same ammo type.
    /// Defaults to `BOLT`.
    #[token_de(token = "CLASS")]
    pub class: Option<Reference>,
    /// How large the ammunition is.
    #[token_de(token = "SIZE")] // Required token
    pub size: Option<u32>,
    /// The attack used by this ammo when used as a melee weapon.
    #[token_de(token = "ATTACK")]
    pub attack: Option<ItemAttack>, // TODO: test ingame if WeaponAttack could be used instead here
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct ArmorToken {
    /// Argument 1 of `[ITEM_ARMOR:...]`
    #[token_de(token = "ITEM_ARMOR", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// Length of the sleeves, counted in `[LIMB]` body parts towards the hands. A value of 0 only
    /// protects both halves of the torso, 1 extends over the upper arms and so on. Regardless of
    /// the value, body armor can never extend to cover the hands or head.
    ///
    /// Currently bugged, high values of `UBSTEP` will result in the item protecting
    /// facial features, fingers, and toes, while leaving those parts that it cannot protect
    /// unprotected (but still counting them as steps).
    /// [Bug:1821](http://www.bay12games.com/dwarves/mantisbt/view.php?id=1821)
    #[token_de(token = "UBSTEP")]
    pub ubstep: Option<Choose<u8, MaxEnum>>,
    // region: Shared by garments/shields/trapcomp/weapons; are all required ======================
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// How much material is needed to make the item. Most important with bars. The number of bars
    /// required to make the item is the value divided by three.
    #[token_de(token = "MATERIAL_SIZE")]
    pub material_size: Option<u32>,
    // endregion ==================================================================================
    // region: Shared by all garments =============================================================
    /// Adjective preceding the material name (e.g. "large copper dagger").
    #[token_de(token = "ADJECTIVE")]
    pub adjective: Option<String>,
    /// Metal versions of this item count as one `ARMORLEVEL` higher and thus won't be worn by
    /// random peasants. This tag will not work unless `ARMORLEVEL` is explicitly declared: if you
    /// leave out `ARMORLEVEL`, even metal armor will default to level 0.
    #[token_de(token = "METAL_ARMOR_LEVELS")]
    pub metal_armor_levels: Option<()>,
    /// Metal versions of this item will have "chain" added between the material and item name.
    #[token_de(token = "CHAIN_METAL_TEXT")]
    pub chain_metal_text: Option<()>,
    /// Clothiers can make this item from all kinds of cloth. If paired with `[LEATHER]`, the item
    /// has an equal chance of being either in randomly generated outfits. Further uses of this tag
    /// are unknown.
    #[token_de(token = "SOFT")]
    pub soft: Option<()>,
    /// Default state in the absence of a `[SOFT]` token. Actual effects unknown.
    #[token_de(token = "HARD")]
    pub hard: Option<()>,
    /// Item can be made from metal. Overrides `[SOFT]` and `[LEATHER]` in randomly generated
    /// outfits, if the `ARMORLEVEL` permits. Civilizations with `[WOOD_ARMOR]` will make this
    /// item out of wood instead.
    #[token_de(token = "METAL")]
    pub metal: Option<()>,
    /// Craftsmen can make this item from bones. Randomly generated outfits don't include bone
    /// armor.
    #[token_de(token = "BARRED")]
    pub barred: Option<()>,
    /// Craftsmen can make this item from shells. Randomly generated outfits don't include shell
    /// armor.
    #[token_de(token = "SCALED")]
    pub scaled: Option<()>,
    /// Leatherworkers can make this item from leather. If paired with `[SOFT]`, this item has an
    /// equal chance of being either in randomly generated outfits.
    #[token_de(token = "LEATHER")]
    pub leather: Option<()>,
    /// Only one shaped piece of clothing can be worn on a single body slot at a time.
    #[token_de(token = "SHAPED")]
    pub shaped: Option<()>,
    /// Increases the `*_STRAIN_AT_YIELD` properties of the armor's material to 50000, if lower.
    /// This makes the garment flex and give way instead of shattering under force. Strong materials
    /// that resist cutting will blunt edged attacks into bone-crushing hits instead.
    #[token_de(token = "STRUCTURAL_ELASTICITY_CHAIN_ALL")]
    pub structural_elasticity_chain_all: Option<()>,
    /// Increases the `*_STRAIN_AT_YIELD` properties of the armor's material to 50000, but only if
    /// the garment is made from metal.
    #[token_de(token = "STRUCTURAL_ELASTICITY_CHAIN_METAL")]
    pub structural_elasticity_chain_metal: Option<()>,
    /// Reduces the armor material's `SHEAR_YIELD` to 20000, `SHEAR_FRACTURE` to 30000 and increases
    /// the `*_STRAIN_AT_YIELD` properties to 50000, but only if the garment is made from cloth.
    /// This makes the item very weak against edged attacks, even if the thread material is
    /// normally very strong.
    #[token_de(token = "STRUCTURAL_ELASTICITY_WOVEN_THREAD")]
    pub structural_elasticity_woven_thread: Option<()>,
    /// The item's bulkiness when worn. Aside from the layer limitations, it's a big contributor to
    /// the thickness and weight (and therefore price) of the garment. See
    /// [Armor](https://dwarffortresswiki.org/index.php/Armor) for more on item sizes and
    /// layering. Defaults to 10.
    #[token_de(token = "LAYER_SIZE")]
    pub layer_size: Option<u32>,
    /// The maximum amount of garments that can fit underneath this garment. See
    /// [Armor](https://dwarffortresswiki.org/index.php/Armor) for more on item sizes and
    /// layering. Defaults to 10.
    #[token_de(token = "LAYER_PERMIT")]
    pub layer_permit: Option<u32>,
    /// Where the item goes in relation to other clothes. Socks cannot be worn on top of boots!
    ///
    /// The `LAYER_PERMIT` of the highest layer is used on a given section of the body - you can fit
    /// a lot of shirts and other undergarments underneath a robe, but not if you wear a leather
    /// jerkin on top of it, and you can still wear a cloak over the whole ensemble. Defaults to
    /// `UNDER`.
    #[token_de(token = "LAYER")]
    pub layer: Option<LayerEnum>,
    /// How often the garment gets in the way of a contaminant or an attack. Armor with a 5%
    /// coverage value, for example, will be near useless because 95% of attacks will bypass it
    /// completely. Temperature effects and armor thickness are also influenced. Defaults to 100.
    #[token_de(token = "COVERAGE")]
    pub coverage: Option<u8>,
    /// The garment's general purpose. Defaults to 1 for shields, 0 for everything else. Class 0
    /// items are claimed and used by civilians as ordinary clothing and are subject to wear.
    #[token_de(token = "ARMORLEVEL")]
    pub armorlevel: Option<u8>, // shared by all garments, and shields
    // endregion ==================================================================================
    // region: Shared by ARMOR and PANTS ==========================================================
    /// Changes the plural form of this item to "`phrase of` item". Primarily pertains to the stock
    /// screens.
    ///
    /// Example, "suits of" platemail, "pairs of" trousers, etc.
    #[token_de(token = "PREPLURAL")]
    pub preplural: Option<String>,
    /// If the item has no material associated with it (e.g. stockpile menus and trade
    /// negotiations), this will be displayed in its place. Used for leather armor in vanilla.
    #[token_de(token = "MATERIAL_PLACEHOLDER")]
    pub material_placeholder: Option<String>,
    /// Length of the legs/hem, counted in `[LIMB]` body parts towards the feet. A value of 0 only
    /// covers the lower body, 1 extends over the upper legs and so on. Regardless of the value,
    /// body armor or pants can never extend to cover the feet.
    #[token_de(token = "LBSTEP")]
    pub lbstep: Option<Choose<u8, MaxEnum>>,
    // endregion ==================================================================================
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct FoodToken {
    /// Argument 1 of `[ITEM_FOOD:...]`
    #[token_de(token = "ITEM_FOOD", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<String>,
    /// Specifies the number of ingredients that are used in this type of prepared meal:
    /// - 2 for Easy. (default)
    /// - 3 for Fine.
    /// - 4 for Lavish.
    #[token_de(token = "LEVEL")]
    pub level: Option<Clamp<u8, 2, 4>>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct GlovesToken {
    /// Argument 1 of `[ITEM_GLOVES:...]`
    #[token_de(token = "ITEM_GLOVES", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// Length of gloves or footwear, counted in `[LIMB]` body parts towards the torso. A value of 1
    /// lets gloves cover the lower arms, a value of 2 stretches a boot all the way over the upper
    /// leg and so on.
    ///
    /// Regardless of the value, none of these items can ever extend to cover the upper or lower
    /// body. Shields also have this token, but it only seems to affect weight.
    #[token_de(token = "UPSTEP")]
    pub upstep: Option<Choose<u8, MaxEnum>>, // shared by glove, shield, shoes
    // region: Shared by garments/shields/trapcomp/weapons; are all required ======================
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// How much material is needed to make the item. Most important with bars. The number of bars
    /// required to make the item is the value divided by three.
    #[token_de(token = "MATERIAL_SIZE")]
    pub material_size: Option<u32>,
    // endregion ==================================================================================
    // region: Shared by all garments =============================================================
    /// Adjective preceding the material name (e.g. "large copper dagger").
    #[token_de(token = "ADJECTIVE")]
    pub adjective: Option<String>,
    /// Metal versions of this item count as one `ARMORLEVEL` higher and thus won't be worn by
    /// random peasants. This tag will not work unless `ARMORLEVEL` is explicitly declared: if you
    /// leave out `ARMORLEVEL`, even metal armor will default to level 0.
    #[token_de(token = "METAL_ARMOR_LEVELS")]
    pub metal_armor_levels: Option<()>,
    /// Metal versions of this item will have "chain" added between the material and item name.
    #[token_de(token = "CHAIN_METAL_TEXT")]
    pub chain_metal_text: Option<()>,
    /// Clothiers can make this item from all kinds of cloth. If paired with `[LEATHER]`, the item
    /// has an equal chance of being either in randomly generated outfits. Further uses of this tag
    /// are unknown.
    #[token_de(token = "SOFT")]
    pub soft: Option<()>,
    /// Default state in the absence of a `[SOFT]` token. Actual effects unknown.
    #[token_de(token = "HARD")]
    pub hard: Option<()>,
    /// Item can be made from metal. Overrides `[SOFT]` and `[LEATHER]` in randomly generated
    /// outfits, if the `ARMORLEVEL` permits. Civilizations with `[WOOD_ARMOR]` will make this
    /// item out of wood instead.
    #[token_de(token = "METAL")]
    pub metal: Option<()>,
    /// Craftsmen can make this item from bones. Randomly generated outfits don't include bone
    /// armor.
    #[token_de(token = "BARRED")]
    pub barred: Option<()>,
    /// Craftsmen can make this item from shells. Randomly generated outfits don't include shell
    /// armor.
    #[token_de(token = "SCALED")]
    pub scaled: Option<()>,
    /// Leatherworkers can make this item from leather. If paired with `[SOFT]`, this item has an
    /// equal chance of being either in randomly generated outfits.
    #[token_de(token = "LEATHER")]
    pub leather: Option<()>,
    /// Only one shaped piece of clothing can be worn on a single body slot at a time.
    #[token_de(token = "SHAPED")]
    pub shaped: Option<()>,
    /// Increases the `*_STRAIN_AT_YIELD` properties of the armor's material to 50000, if lower.
    /// This makes the garment flex and give way instead of shattering under force. Strong materials
    /// that resist cutting will blunt edged attacks into bone-crushing hits instead.
    #[token_de(token = "STRUCTURAL_ELASTICITY_CHAIN_ALL")]
    pub structural_elasticity_chain_all: Option<()>,
    /// Increases the `*_STRAIN_AT_YIELD` properties of the armor's material to 50000, but only if
    /// the garment is made from metal.
    #[token_de(token = "STRUCTURAL_ELASTICITY_CHAIN_METAL")]
    pub structural_elasticity_chain_metal: Option<()>,
    /// Reduces the armor material's `SHEAR_YIELD` to 20000, `SHEAR_FRACTURE` to 30000 and increases
    /// the `*_STRAIN_AT_YIELD` properties to 50000, but only if the garment is made from cloth.
    /// This makes the item very weak against edged attacks, even if the thread material is
    /// normally very strong.
    #[token_de(token = "STRUCTURAL_ELASTICITY_WOVEN_THREAD")]
    pub structural_elasticity_woven_thread: Option<()>,
    /// The item's bulkiness when worn. Aside from the layer limitations, it's a big contributor to
    /// the thickness and weight (and therefore price) of the garment. See
    /// [Armor](https://dwarffortresswiki.org/index.php/Armor) for more on item sizes and
    /// layering. Defaults to 10.
    #[token_de(token = "LAYER_SIZE")]
    pub layer_size: Option<u32>,
    /// The maximum amount of garments that can fit underneath this garment. See
    /// [Armor](https://dwarffortresswiki.org/index.php/Armor) for more on item sizes and
    /// layering. Defaults to 10.
    #[token_de(token = "LAYER_PERMIT")]
    pub layer_permit: Option<u32>,
    /// Where the item goes in relation to other clothes. Socks cannot be worn on top of boots!
    ///
    /// The `LAYER_PERMIT` of the highest layer is used on a given section of the body - you can fit
    /// a lot of shirts and other undergarments underneath a robe, but not if you wear a leather
    /// jerkin on top of it, and you can still wear a cloak over the whole ensemble. Defaults to
    /// `UNDER`.
    #[token_de(token = "LAYER")]
    pub layer: Option<LayerEnum>,
    /// How often the garment gets in the way of a contaminant or an attack. Armor with a 5%
    /// coverage value, for example, will be near useless because 95% of attacks will bypass it
    /// completely. Temperature effects and armor thickness are also influenced. Defaults to 100.
    #[token_de(token = "COVERAGE")]
    pub coverage: Option<u8>,
    /// The garment's general purpose. Defaults to 1 for shields, 0 for everything else. Class 0
    /// items are claimed and used by civilians as ordinary clothing and are subject to wear.
    #[token_de(token = "ARMORLEVEL")] // shared by all garments, and shields
    pub armorlevel: Option<u8>,
    // endregion ==================================================================================
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct HelmToken {
    /// Argument 1 of `[ITEM_HELM:...]`
    #[token_de(token = "ITEM_HELM", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    // region: Shared by garments/shields/trapcomp/weapons; are all required ======================
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// How much material is needed to make the item. Most important with bars. The number of bars
    /// required to make the item is the value divided by three.
    #[token_de(token = "MATERIAL_SIZE")]
    pub material_size: Option<u32>,
    // endregion ==================================================================================
    // region: Shared by all garments =============================================================
    /// Adjective preceding the material name (e.g. "large copper dagger").
    #[token_de(token = "ADJECTIVE")]
    pub adjective: Option<String>,
    /// Metal versions of this item count as one `ARMORLEVEL` higher and thus won't be worn by
    /// random peasants. This tag will not work unless `ARMORLEVEL` is explicitly declared: if you
    /// leave out `ARMORLEVEL`, even metal armor will default to level 0.
    #[token_de(token = "METAL_ARMOR_LEVELS")]
    pub metal_armor_levels: Option<()>,
    /// Metal versions of this item will have "chain" added between the material and item name.
    #[token_de(token = "CHAIN_METAL_TEXT")]
    pub chain_metal_text: Option<()>,
    /// Clothiers can make this item from all kinds of cloth. If paired with `[LEATHER]`, the item
    /// has an equal chance of being either in randomly generated outfits. Further uses of this tag
    /// are unknown.
    #[token_de(token = "SOFT")]
    pub soft: Option<()>,
    /// Default state in the absence of a `[SOFT]` token. Actual effects unknown.
    #[token_de(token = "HARD")]
    pub hard: Option<()>,
    /// Item can be made from metal. Overrides `[SOFT]` and `[LEATHER]` in randomly generated
    /// outfits, if the `ARMORLEVEL` permits. Civilizations with `[WOOD_ARMOR]` will make this
    /// item out of wood instead.
    #[token_de(token = "METAL")]
    pub metal: Option<()>,
    /// Craftsmen can make this item from bones. Randomly generated outfits don't include bone
    /// armor.
    #[token_de(token = "BARRED")]
    pub barred: Option<()>,
    /// Craftsmen can make this item from shells. Randomly generated outfits don't include shell
    /// armor.
    #[token_de(token = "SCALED")]
    pub scaled: Option<()>,
    /// Leatherworkers can make this item from leather. If paired with `[SOFT]`, this item has an
    /// equal chance of being either in randomly generated outfits.
    #[token_de(token = "LEATHER")]
    pub leather: Option<()>,
    /// Only one shaped piece of clothing can be worn on a single body slot at a time.
    #[token_de(token = "SHAPED")]
    pub shaped: Option<()>,
    /// Increases the `*_STRAIN_AT_YIELD` properties of the armor's material to 50000, if lower.
    /// This makes the garment flex and give way instead of shattering under force. Strong materials
    /// that resist cutting will blunt edged attacks into bone-crushing hits instead.
    #[token_de(token = "STRUCTURAL_ELASTICITY_CHAIN_ALL")]
    pub structural_elasticity_chain_all: Option<()>,
    /// Increases the `*_STRAIN_AT_YIELD` properties of the armor's material to 50000, but only if
    /// the garment is made from metal.
    #[token_de(token = "STRUCTURAL_ELASTICITY_CHAIN_METAL")]
    pub structural_elasticity_chain_metal: Option<()>,
    /// Reduces the armor material's `SHEAR_YIELD` to 20000, `SHEAR_FRACTURE` to 30000 and increases
    /// the `*_STRAIN_AT_YIELD` properties to 50000, but only if the garment is made from cloth.
    /// This makes the item very weak against edged attacks, even if the thread material is
    /// normally very strong.
    #[token_de(token = "STRUCTURAL_ELASTICITY_WOVEN_THREAD")]
    pub structural_elasticity_woven_thread: Option<()>,
    /// The item's bulkiness when worn. Aside from the layer limitations, it's a big contributor to
    /// the thickness and weight (and therefore price) of the garment. See
    /// [Armor](https://dwarffortresswiki.org/index.php/Armor) for more on item sizes and
    /// layering. Defaults to 10.
    #[token_de(token = "LAYER_SIZE")]
    pub layer_size: Option<u32>,
    /// The maximum amount of garments that can fit underneath this garment. See
    /// [Armor](https://dwarffortresswiki.org/index.php/Armor) for more on item sizes and
    /// layering. Defaults to 10.
    #[token_de(token = "LAYER_PERMIT")]
    pub layer_permit: Option<u32>,
    /// Where the item goes in relation to other clothes. Socks cannot be worn on top of boots!
    ///
    /// The `LAYER_PERMIT` of the highest layer is used on a given section of the body - you can fit
    /// a lot of shirts and other undergarments underneath a robe, but not if you wear a leather
    /// jerkin on top of it, and you can still wear a cloak over the whole ensemble. Defaults to
    /// `UNDER`.
    #[token_de(token = "LAYER")]
    pub layer: Option<LayerEnum>,
    /// How often the garment gets in the way of a contaminant or an attack. Armor with a 5%
    /// coverage value, for example, will be near useless because 95% of attacks will bypass it
    /// completely. Temperature effects and armor thickness are also influenced. Defaults to 100.
    #[token_de(token = "COVERAGE")]
    pub coverage: Option<u8>,
    /// The garment's general purpose. Defaults to 1 for shields, 0 for everything else. Class 0
    /// items are claimed and used by civilians as ordinary clothing and are subject to wear.
    #[token_de(token = "ARMORLEVEL")] // shared by all garments, and shields
    pub armorlevel: Option<u8>,
    // endregion ==================================================================================
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct InstrumentToken {
    /// Argument 1 of `[ITEM_INSTRUMENT:...]`
    #[token_de(token = "ITEM_INSTRUMENT", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    // region: Unique to instruments ==============================================================
    /// Makes the instrument stationary.
    #[token_de(token = "PLACED_AS_BUILDING")]
    pub placed_as_building: Option<()>,
    /// Sets a piece as the central part of the instrument.
    #[token_de(token = "DOMINANT_MATERIAL_PIECE")]
    pub dominant_material_piece: Option<Reference>,
    /// Defines an instrument piece. The 1st argument is the identifier that can be used in other
    /// raw tags to refer to this instrument piece. The 2nd is the tool which is required
    /// (and consumed) during the construction process to create this instrument piece.
    ///
    /// If an instrument does not have any pieces, `SELF` can be used for any argument which needs
    /// to be an instrument piece.
    #[token_de(token = "INSTRUMENT_PIECE")]
    pub instrument_piece: Vec<(
        Reference,
        ReferenceTo<ToolToken>,
        String,
        String,
        NameTypeEnum,
    )>,
    /// The instrument's volume range, in millibels (100 mB = 1 dB).
    #[token_de(token = "VOLUME_mB")]
    pub volume_mb: Option<(u32, u32)>,
    /// Defines how a musician can produce sound when using this instrument. Can be used multiple
    /// times.
    #[token_de(token = "SOUND_PRODUCTION")]
    pub sound_production: Vec<(SoundProductionEnum, Reference, Option<Reference>)>,
    /// Defines how the pitch can be varied by the musician. Can be used multiple times.
    #[token_de(token = "PITCH_CHOICE")]
    pub pitch_choice: Vec<(PitchMethodEnum, Reference, Option<Reference>)>,
    /// Defines how the instrument may be tuned. Can be used multiple times.
    #[token_de(token = "TUNING")]
    pub tuning: Vec<(TuningMethodEnum, Reference)>,
    /// Pitch is `min`:`max` in cents with middle C at zero. There are 1200 cents in an octave.
    ///
    /// The game verbally differentiates values from -4200 to 4200, but you can go outside
    /// that if you like.  The in-game generated instruments will range from roughly C0 to C8
    /// (-4800 to 4800), sometimes beyond for really unusual ones.
    ///
    /// You can also use `[INDEFINITE_PITCH]` instead.
    #[token_de(token = "PITCH_RANGE")]
    pub pitch_range: Option<(i32, i32)>,
    /// You can add as many timbre words as you want. The generated timbres have a series of
    /// checks for conflicts, but they don't apply to the raws, so how you use them is up to you.
    #[token_de(token = "TIMBRE")]
    pub timbre: Option<(TimbreEnum, Vec<TimbreEnum>)>,
    /// The pitch range overrides the global pitch for a register, but the register timbres are
    /// added to the global ones. You can add as many timbre words as you want.
    ///
    /// Pitch is `min`:`max` in cents with middle C at zero. There are 1200 cents in an octave.
    ///
    /// The game verbally differentiates values from -4200 to 4200, but you can go outside
    /// that if you like.  The in-game generated instruments will range from roughly C0 to C8
    /// (-4800 to 4800), sometimes beyond for really unusual ones.
    ///
    /// You can also use `[INDEFINITE_PITCH]` instead.
    #[token_de(token = "REGISTER")]
    pub register: Vec<(i32, i32, TimbreEnum, Vec<TimbreEnum>)>,
    /// The skill used for playing this instrument.
    #[token_de(token = "MUSIC_SKILL")]
    pub music_skill: Option<MusicSkillEnum>,
    /// Can be used instead of either `REGISTER` or `PITCH_RANGE`.
    #[token_de(token = "INDEFINITE_PITCH")]
    pub indefinite_pitch: Option<()>,
    // endregion ==================================================================================

    // TODO: prune the following list/region of shared tokens, these aren't all actually shared.
    // The following 3 links may be useful for figuring out which are truly shared:
    // - https://github.com/DFHack/df-structures/blob/master/df.items.xml
    // - https://github.com/DFHack/df-structures/blob/master/df.item-raws.xml
    // - https://github.com/DFHack/df-structures/blob/master/df.item-vectors.xml
    // Also, the descriptions for most of them are almost definitely inapplicable for instruments.
    // region: Shared by tools and instruments ====================================================
    /// Volume of tool in mL or cubic centimeters. Required.
    #[token_de(token = "SIZE")]
    pub size: Option<u32>,
    /// Name of the tool. Required.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// Defines the item value of the tool. Required.
    #[token_de(token = "VALUE")]
    pub value: Option<u32>,
    /// Defines the tile used to represent the tool. Required.
    #[token_de(token = "TILE")]
    pub tile: Option<DFChar>,
    /// Permits the tool to be made from any bone.
    #[token_de(token = "BONE_MAT")]
    pub bone_mat: Option<()>,
    /// Permits the tool to be made from any ceramic material.
    #[token_de(token = "CERAMIC_MAT")]
    pub ceramic_mat: Option<()>,
    /// Allows a string to describe the tool when viewed. The text box can accommodate up to 325
    /// characters until it cuts off, but the spacing of actual sentences puts the realistic limit
    /// closer to 300.
    #[token_de(token = "DESCRIPTION")]
    pub description: Option<String>,
    /// Permits the tool to be made from any glass.
    #[token_de(token = "GLASS_MAT")]
    pub glass_mat: Option<()>,
    /// Permits the tool to be made from anything with the `[ITEMS_HARD]` token, such as wood, stone
    /// or metal.
    #[token_de(token = "HARD_MAT")]
    pub hard_mat: Option<()>,
    /// Permits the tool to be made from any leather.
    #[token_de(token = "LEATHER_MAT")]
    pub leather_mat: Option<()>,
    /// Permits the tool to be made from anything with the `[IS_METAL]` token.
    #[token_de(token = "METAL_MAT")]
    pub metal_mat: Option<()>,
    /// Permits the tool to be made from any metal with the `[ITEMS_WEAPON]` token.
    #[token_de(token = "METAL_WEAPON_MAT")]
    pub metal_weapon_mat: Option<()>,
    /// Permits the tool to be made from any "sheet" material, such as papyrus, paper, and
    /// parchment. May be connected to the `PAPER_SLURRY`/`PAPER_PLANT` reaction classes,
    /// but this is not verified.
    #[token_de(token = "SHEET_MAT")]
    pub sheet_mat: Option<()>,
    /// Permits the tool to be made from any shell.
    #[token_de(token = "SHELL_MAT")]
    pub shell_mat: Option<()>,
    /// Permits the tool to be made from any silk.
    #[token_de(token = "SILK_MAT")]
    pub silk_mat: Option<()>,
    /// Permits the tool to be made from any material with the `[ITEMS_SOFT]` token, such as leather
    /// or textiles.
    #[token_de(token = "SOFT_MAT")]
    pub soft_mat: Option<()>,
    /// Permits the tool to be made from any stone. Presumably connected to the `[IS_STONE]` token.
    #[token_de(token = "STONE_MAT")]
    pub stone_mat: Option<()>,
    /// Permits the tool to be made from any plant fiber, such as pig tails.
    #[token_de(token = "THREAD_PLANT_MAT")]
    pub thread_plant_mat: Option<()>,
    /// Permits the tool to be made from any wood.
    #[token_de(token = "WOOD_MAT")]
    pub wood_mat: Option<()>,
    /// According to Toady, "Won't be used in world gen libraries (to differentiate scrolls from
    /// quires). Also put it on bindings, rollers, instr. pieces for completeness/future use".
    /// Used on scroll rollers, book bindings, and quires.
    #[token_de(token = "INCOMPLETE_ITEM")]
    pub incomplete_item: Option<()>,
    /// Items that appear in the wild come standard with this kind of improvement. Used on scrolls:
    /// `[DEFAULT_IMPROVEMENT:SPECIFIC:ROLLERS:HARD_MAT]`
    ///
    /// Currently bugged, the effect is also applied to everything made in-game. This causes
    /// scrolls to have two sets of rollers, for example.
    #[token_de(token = "DEFAULT_IMPROVEMENT")]
    pub default_improvement: Option<ImprovementTypeWithMatFlagTokenArg>,
    /// Prevents the tool from being improved. Used on honeycombs, scroll rollers, book bindings,
    /// and quires.
    #[token_de(token = "UNIMPROVABLE")]
    pub unimprovable: Option<()>,
    /// **This token's purpose is unknown, and it may be an alias of another token; if you know
    /// what it does, please open an issue on the issue tracker.**
    #[token_de(token = "NO_DEFAULT_IMPROVEMENTS")]
    pub no_default_improvements: Option<()>,
    /// The background of the tile will be colored, instead of the foreground.
    #[token_de(token = "INVERTED_TILE")]
    pub inverted_tile: Option<()>,
    /// According to Toady, "only custom reactions are used to make this item". Found on scrolls and
    /// quires.
    #[token_de(token = "NO_DEFAULT_JOB")]
    pub no_default_job: Option<()>,
    /// Defines the task performed using the tool.
    #[token_de(token = "TOOL_USE")]
    pub tool_use: Vec<ToolUseEnum>,
    /// Allows item to be stored in a furniture stockpile.
    #[token_de(token = "FURNITURE")]
    pub furniture: Option<()>,
    // TODO: ref is shape category
    #[token_de(token = "SHAPE_CATEGORY")]
    pub shape_category: Option<Reference>,
    /// Used on dice.
    #[token_de(token = "USES_FACE_IMAGE_SET")]
    pub uses_face_image_set: Option<()>,
    /// Adjective preceding the material name (e.g. "large copper dagger")
    #[token_de(token = "ADJECTIVE")]
    pub adjective: Option<String>,
    /// How much the item can contain. Defaults to 0.
    #[token_de(token = "CONTAINER_CAPACITY")]
    pub container_capacity: Option<u32>,
    /// Required for weapons.
    #[token_de(token = "SHOOT_FORCE")]
    pub shoot_force: Option<u32>,
    /// Required for weapons.
    #[token_de(token = "SHOOT_MAXVEL")]
    pub shoot_maxvel: Option<u32>,
    /// The skill to determine effectiveness in melee with this tool. Required for weapons.
    #[token_de(token = "SKILL")]
    pub skill: Option<SkillEnum>,
    /// Makes this tool a ranged weapon that uses the specified ammo. The specified skill
    /// determines accuracy in ranged combat.
    #[token_de(token = "RANGED")]
    pub ranged: Option<(SkillEnum, ReferenceTo<AmmoToken>)>,
    /// Creatures under this size (in cm^3) must use the tool two-handed. Required for weapons.
    #[token_de(token = "TWO_HANDED")]
    pub two_handed: Option<u32>,
    /// Minimum body size (in cm^3) to use the tool at all (multigrasp required until `TWO_HANDED`
    /// value). Required for weapons.
    #[token_de(token = "MINIMUM_SIZE")]
    pub minimum_size: Option<u32>,
    /// Number of bar units needed for forging, as well as the amount gained from melting. Required
    /// for weapons.
    #[token_de(token = "MATERIAL_SIZE")]
    pub material_size: Option<u32>,
    /// You can have many `ATTACK` tags and one will be randomly selected for each attack, with
    /// `EDGE` attacks 100 times more common than `BLUNT` attacks. Required for weapons.
    #[token_de(token = "ATTACK")]
    pub attack: Vec<WeaponAttack>,
    // endregion ==================================================================================
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum NameTypeEnum {
    #[token_de(token = "STANDARD")]
    Standard,
    #[token_de(token = "ALWAYS_PLURAL")]
    AlwaysPlural,
    #[token_de(token = "ALWAYS_SINGULAR")]
    AlwaysSingular,
}
impl Default for NameTypeEnum {
    fn default() -> Self {
        Self::Standard
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum PitchMethodEnum {
    #[token_de(token = "MEMBRANE_POSITION")]
    MembranePosition,
    #[token_de(token = "SUBPART_CHOICE")]
    SubpartChoice,
    #[token_de(token = "KEYBOARD")]
    Keyboard,
    /// Requires two `INSTRUMENT_PIECE` tokens, first for "string" second for "neck"
    /// -- or whatever is being pressed against what.
    #[token_de(token = "STOPPING_FRET")]
    StoppingFret,
    /// Requires two `INSTRUMENT_PIECE` tokens.
    #[token_de(token = "STOPPING_AGAINST_BODY")]
    StoppingAgainstBody,
    #[token_de(token = "STOPPING_HOLE")]
    StoppingHole,
    #[token_de(token = "STOPPING_HOLE_KEY")]
    StoppingHoleKey,
    #[token_de(token = "SLIDE")]
    Slide,
    #[token_de(token = "HARMONIC_SERIES")]
    HarmonicSeries,
    #[token_de(token = "VALVE_ROUTES_AIR")]
    ValveRoutesAir,
    #[token_de(token = "BP_IN_BELL")]
    BpInBell,
    /// Requires two `INSTRUMENT_PIECE` tokens, first is what is being changed e.g. "strings",
    /// second is "body" which has the pedalboard -- or whatever piece is being stepped on.
    #[token_de(token = "FOOT_PEDALS")]
    FootPedals,
}
impl Default for PitchMethodEnum {
    fn default() -> Self {
        Self::MembranePosition
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum TuningMethodEnum {
    #[token_de(token = "PEGS")]
    Pegs,
    #[token_de(token = "ADJUSTABLE_BRIDGES")]
    AdjustableBridhes,
    #[token_de(token = "CROOKS")]
    Crooks,
    #[token_de(token = "TIGHTENING")]
    Tightening,
    #[token_de(token = "LEVERS")]
    Levers,
}
impl Default for TuningMethodEnum {
    fn default() -> Self {
        Self::Pegs
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum SoundProductionEnum {
    #[token_de(token = "PLUCKED_BY_BP")]
    PluckedByBp,
    /// Requires two `INSTRUMENT_PIECE` tokens: actor, then target.
    #[token_de(token = "PLUCKED")]
    Plucked,
    /// Requires two `INSTRUMENT_PIECE` tokens: actor, then target.
    #[token_de(token = "BOWED")]
    Bowed,
    #[token_de(token = "STRUCK_BY_BP")]
    StruckByBp,
    /// Requires two `INSTRUMENT_PIECE` tokens: actor, then target.
    #[token_de(token = "STRUCK")]
    Struck,
    #[token_de(token = "VIBRATE_BP_AGAINST_OPENING")]
    VibrateBpAgainstOpening,
    #[token_de(token = "BLOW_AGAINST_FIPPLE")]
    BlowAgainstFipple,
    #[token_de(token = "BLOW_OVER_OPENING_SIDE")]
    BlowOverOpeningSide,
    #[token_de(token = "BLOW_OVER_OPENING_END")]
    BlowOverOpeningEnd,
    #[token_de(token = "BLOW_OVER_SINGLE_REED")]
    BlowOverSingleReed,
    #[token_de(token = "BLOW_OVER_DOUBLE_REED")]
    BlowOverDoubleReed,
    #[token_de(token = "BLOW_OVER_FREE_REED")]
    BlowOverFreeReed,
    #[token_de(token = "STRUCK_TOGETHER")]
    StruckTogether,
    #[token_de(token = "SHAKEN")]
    Shaken,
    /// Requires two `INSTRUMENT_PIECE` tokens: actor, then target.
    #[token_de(token = "SCRAPED")]
    Scraped,
    /// Requires two `INSTRUMENT_PIECE` tokens: actor, then target.
    #[token_de(token = "FRICTION")]
    Friction,
    #[token_de(token = "RESONATOR")]
    Resonator,
    /// Requires two `INSTRUMENT_PIECE` tokens: actor, then target.
    #[token_de(token = "BAG_OVER_REED")]
    BagOverReed,
    /// Requires two `INSTRUMENT_PIECE` tokens: actor, then target.
    #[token_de(token = "AIR_OVER_REED")]
    AirOverReed,
    /// Requires two `INSTRUMENT_PIECE` tokens: actor, then target.
    #[token_de(token = "AIR_OVER_FREE_REED")]
    AirOverFreeReed,
    /// Requires two `INSTRUMENT_PIECE` tokens: actor, then target.
    #[token_de(token = "AIR_AGAINST_FIPPLE")]
    AirAgainstFipple,
}
impl Default for SoundProductionEnum {
    fn default() -> Self {
        Self::PluckedByBp
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum TimbreEnum {
    #[token_de(token = "CLEAR")]
    Clear,
    #[token_de(token = "NOISY")]
    Noisy,
    #[token_de(token = "FULL")]
    Full,
    #[token_de(token = "THIN")]
    Thin,
    #[token_de(token = "ROUND")]
    Round,
    #[token_de(token = "SHARP")]
    Sharp,
    #[token_de(token = "SMOOTH")]
    Smooth,
    #[token_de(token = "CHOPPY")]
    Choppy,
    #[token_de(token = "STEADY")]
    Steady,
    #[token_de(token = "EVOLVING")]
    Evolving,
    #[token_de(token = "STRONG")]
    Strong,
    #[token_de(token = "DELICATE")]
    Delicate,
    #[token_de(token = "BRIGHT")]
    Bright,
    #[token_de(token = "GRACEFUL")]
    Graceful,
    #[token_de(token = "SPARSE")]
    Sparse,
    #[token_de(token = "BREATHY")]
    Breathy,
    #[token_de(token = "STRAINED")]
    Strained,
    #[token_de(token = "BROAD")]
    Broad,
    #[token_de(token = "LIGHT")]
    Light,
    #[token_de(token = "MELLOW")]
    Mellow,
    #[token_de(token = "WOBBLING")]
    Wobbling,
    #[token_de(token = "FOCUSED")]
    Focused,
    #[token_de(token = "EVEN")]
    Even,
    #[token_de(token = "FLUID")]
    Fluid,
    #[token_de(token = "VIBRATING")]
    Vibrating,
    #[token_de(token = "QUAVERING")]
    Quavering,
    #[token_de(token = "EERIE")]
    Eerie,
    #[token_de(token = "FRAGILE")]
    Fragile,
    #[token_de(token = "BRITTLE")]
    Brittle,
    #[token_de(token = "PURE")]
    Pure,
    #[token_de(token = "PIERCING")]
    Piercing,
    #[token_de(token = "STRIDENT")]
    Strident,
    #[token_de(token = "WAVERING")]
    Wavering,
    #[token_de(token = "HARSH")]
    Harsh,
    #[token_de(token = "REEDY")]
    Reedy,
    #[token_de(token = "NASAL")]
    Nasal,
    #[token_de(token = "BUZZY")]
    Buzzy,
    #[token_de(token = "ROUGH")]
    Rough,
    #[token_de(token = "WARM")]
    Warm,
    #[token_de(token = "RUGGED")]
    Rugged,
    #[token_de(token = "HEAVY")]
    Heavy,
    #[token_de(token = "FLAT")]
    Flat,
    #[token_de(token = "DARK")]
    Dark,
    #[token_de(token = "CRISP")]
    Crisp,
    #[token_de(token = "SONOROUS")]
    Sonorous,
    #[token_de(token = "WATERY")]
    Watery,
    #[token_de(token = "GENTLE")]
    Gentle,
    #[token_de(token = "SLICING")]
    Slicing,
    #[token_de(token = "LIQUID")]
    Liquid,
    #[token_de(token = "RAUCOUS")]
    Raucous,
    #[token_de(token = "BREEZY")]
    Breezy,
    #[token_de(token = "RASPY")]
    Raspy,
    #[token_de(token = "WISPY")]
    Wispy,
    #[token_de(token = "SHRILL")]
    Shrill,
    #[token_de(token = "MUDDY")]
    Muddy,
    #[token_de(token = "RICH")]
    Rich,
    #[token_de(token = "DULL")]
    Dull,
    #[token_de(token = "FLOATING")]
    Floating,
    #[token_de(token = "RINGING")]
    Ringing,
    #[token_de(token = "RESONANT")]
    Resonant,
    #[token_de(token = "SWEET")]
    Sweet,
    #[token_de(token = "RIPPLING")]
    Rippling,
    #[token_de(token = "SPARKLING")]
    Sparkling,
}
impl Default for TimbreEnum {
    fn default() -> Self {
        Self::Clear
    }
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct PantsToken {
    /// Argument 1 of `[ITEM_PANTS:...]`
    #[token_de(token = "ITEM_PANTS", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    // region: Shared by garments/shields/trapcomp/weapons; are all required ======================
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// How much material is needed to make the item. Most important with bars. The number of bars
    /// required to make the item is the value divided by three.
    #[token_de(token = "MATERIAL_SIZE")]
    pub material_size: Option<u32>,
    // endregion ==================================================================================
    // region: Shared by all garments =============================================================
    /// Adjective preceding the material name (e.g. "large copper dagger").
    #[token_de(token = "ADJECTIVE")]
    pub adjective: Option<String>,
    /// Metal versions of this item count as one `ARMORLEVEL` higher and thus won't be worn by
    /// random peasants. This tag will not work unless `ARMORLEVEL` is explicitly declared: if you
    /// leave out `ARMORLEVEL`, even metal armor will default to level 0.
    #[token_de(token = "METAL_ARMOR_LEVELS")]
    pub metal_armor_levels: Option<()>,
    /// Metal versions of this item will have "chain" added between the material and item name.
    #[token_de(token = "CHAIN_METAL_TEXT")]
    pub chain_metal_text: Option<()>,
    /// Clothiers can make this item from all kinds of cloth. If paired with `[LEATHER]`, the item
    /// has an equal chance of being either in randomly generated outfits. Further uses of this tag
    /// are unknown.
    #[token_de(token = "SOFT")]
    pub soft: Option<()>,
    /// Default state in the absence of a `[SOFT]` token. Actual effects unknown.
    #[token_de(token = "HARD")]
    pub hard: Option<()>,
    /// Item can be made from metal. Overrides `[SOFT]` and `[LEATHER]` in randomly generated
    /// outfits, if the `ARMORLEVEL` permits. Civilizations with `[WOOD_ARMOR]` will make this
    /// item out of wood instead.
    #[token_de(token = "METAL")]
    pub metal: Option<()>,
    /// Craftsmen can make this item from bones. Randomly generated outfits don't include bone
    /// armor.
    #[token_de(token = "BARRED")]
    pub barred: Option<()>,
    /// Craftsmen can make this item from shells. Randomly generated outfits don't include shell
    /// armor.
    #[token_de(token = "SCALED")]
    pub scaled: Option<()>,
    /// Leatherworkers can make this item from leather. If paired with `[SOFT]`, this item has an
    /// equal chance of being either in randomly generated outfits.
    #[token_de(token = "LEATHER")]
    pub leather: Option<()>,
    /// Only one shaped piece of clothing can be worn on a single body slot at a time.
    #[token_de(token = "SHAPED")]
    pub shaped: Option<()>,
    /// Increases the `*_STRAIN_AT_YIELD` properties of the armor's material to 50000, if lower.
    /// This makes the garment flex and give way instead of shattering under force. Strong materials
    /// that resist cutting will blunt edged attacks into bone-crushing hits instead.
    #[token_de(token = "STRUCTURAL_ELASTICITY_CHAIN_ALL")]
    pub structural_elasticity_chain_all: Option<()>,
    /// Increases the `*_STRAIN_AT_YIELD` properties of the armor's material to 50000, but only if
    /// the garment is made from metal.
    #[token_de(token = "STRUCTURAL_ELASTICITY_CHAIN_METAL")]
    pub structural_elasticity_chain_metal: Option<()>,
    /// Reduces the armor material's `SHEAR_YIELD` to 20000, `SHEAR_FRACTURE` to 30000 and increases
    /// the `*_STRAIN_AT_YIELD` properties to 50000, but only if the garment is made from cloth.
    /// This makes the item very weak against edged attacks, even if the thread material is
    /// normally very strong.
    #[token_de(token = "STRUCTURAL_ELASTICITY_WOVEN_THREAD")]
    pub structural_elasticity_woven_thread: Option<()>,
    /// The item's bulkiness when worn. Aside from the layer limitations, it's a big contributor to
    /// the thickness and weight (and therefore price) of the garment. See
    /// [Armor](https://dwarffortresswiki.org/index.php/Armor) for more on item sizes and
    /// layering. Defaults to 10.
    #[token_de(token = "LAYER_SIZE")]
    pub layer_size: Option<u32>,
    /// The maximum amount of garments that can fit underneath this garment. See
    /// [Armor](https://dwarffortresswiki.org/index.php/Armor) for more on item sizes and
    /// layering. Defaults to 10.
    #[token_de(token = "LAYER_PERMIT")]
    pub layer_permit: Option<u32>,
    /// Where the item goes in relation to other clothes. Socks cannot be worn on top of boots!
    ///
    /// The `LAYER_PERMIT` of the highest layer is used on a given section of the body - you can fit
    /// a lot of shirts and other undergarments underneath a robe, but not if you wear a leather
    /// jerkin on top of it, and you can still wear a cloak over the whole ensemble. Defaults to
    /// `UNDER`.
    #[token_de(token = "LAYER")]
    pub layer: Option<LayerEnum>,
    /// How often the garment gets in the way of a contaminant or an attack. Armor with a 5%
    /// coverage value, for example, will be near useless because 95% of attacks will bypass it
    /// completely. Temperature effects and armor thickness are also influenced. Defaults to 100.
    #[token_de(token = "COVERAGE")]
    pub coverage: Option<u8>,
    /// The garment's general purpose. Defaults to 1 for shields, 0 for everything else. Class 0
    /// items are claimed and used by civilians as ordinary clothing and are subject to wear.
    #[token_de(token = "ARMORLEVEL")] // shared by all garments, and shields
    pub armorlevel: Option<u8>,
    // endregion ==================================================================================
    // region: Shared by ARMOR and PANTS ==========================================================
    /// Changes the plural form of this item to "`phrase of` item". Primarily pertains to the stock
    /// screens.
    ///
    /// Example, "suits of" platemail, "pairs of" trousers, etc.
    #[token_de(token = "PREPLURAL")]
    pub preplural: Option<String>,
    /// If the item has no material associated with it (e.g. stockpile menus and trade
    /// negotiations), this will be displayed in its place. Used for leather armor in vanilla.
    #[token_de(token = "MATERIAL_PLACEHOLDER")]
    pub material_placeholder: Option<String>,
    /// Length of the legs/hem, counted in `[LIMB]` body parts towards the feet. A value of 0 only
    /// covers the lower body, 1 extends over the upper legs and so on. Regardless of the value,
    /// body armor or pants can never extend to cover the feet.
    #[token_de(token = "LBSTEP")]
    pub lbstep: Option<Choose<u8, MaxEnum>>,
    // endregion ==================================================================================
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct ShieldToken {
    /// Argument 1 of `[ITEM_SHIELD:...]`
    #[token_de(token = "ITEM_SHIELD", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// Affects the block chance of the shield. Defaults to 10.
    #[token_de(token = "BLOCKCHANCE")]
    pub blockchance: Option<Clamp<u8, 0, 100>>,
    /// Length of gloves or footwear, counted in `[LIMB]` body parts towards the torso. A value of 1
    /// lets gloves cover the lower arms, a value of 2 stretches a boot all the way over the upper
    /// leg and so on.
    ///
    /// Regardless of the value, none of these items can ever extend to cover the upper or lower
    /// body. Shields also have this token, but it only seems to affect weight.
    #[token_de(token = "UPSTEP")]
    pub upstep: Option<Choose<u8, MaxEnum>>, // shared by glove, shield, shoes
    /// The garment's general purpose. Defaults to 1 for shields, 0 for everything else. Class 0
    /// items are claimed and used by civilians as ordinary clothing and are subject to wear.
    #[token_de(token = "ARMORLEVEL")]
    pub armorlevel: Option<u8>, // shared by all garments, and shields
    // region: Shared by garments/shields/trapcomp/weapons; are all required ======================
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// How much material is needed to make the item. Most important with bars. The number of bars
    /// required to make the item is the value divided by three.
    #[token_de(token = "MATERIAL_SIZE")]
    pub material_size: Option<u32>,
    // endregion ==================================================================================
    /// Adjective preceding the material name (e.g. "large copper dagger").
    #[token_de(token = "ADJECTIVE")]
    pub adjective: Option<String>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct ShoesToken {
    /// Argument 1 of `[ITEM_SHOES:...]`
    #[token_de(token = "ITEM_SHOES", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// Length of gloves or footwear, counted in `[LIMB]` body parts towards the torso. A value of 1
    /// lets gloves cover the lower arms, a value of 2 stretches a boot all the way over the upper
    /// leg and so on.
    ///
    /// Regardless of the value, none of these items can ever extend to cover the upper or lower
    /// body. Shields also have this token, but it only seems to affect weight.
    #[token_de(token = "UPSTEP")]
    pub upstep: Option<Choose<u8, MaxEnum>>, // shared by glove, shield, shoes
    // region: Shared by garments/shields/trapcomp/weapons; are all required ======================
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// How much material is needed to make the item. Most important with bars. The number of bars
    /// required to make the item is the value divided by three.
    #[token_de(token = "MATERIAL_SIZE")]
    pub material_size: Option<u32>,
    // endregion ==================================================================================
    // region: Shared by all garments =============================================================
    /// Adjective preceding the material name (e.g. "large copper dagger").
    #[token_de(token = "ADJECTIVE")]
    pub adjective: Option<String>,
    /// Metal versions of this item count as one `ARMORLEVEL` higher and thus won't be worn by
    /// random peasants. This tag will not work unless `ARMORLEVEL` is explicitly declared: if you
    /// leave out `ARMORLEVEL`, even metal armor will default to level 0.
    #[token_de(token = "METAL_ARMOR_LEVELS")]
    pub metal_armor_levels: Option<()>,
    /// Metal versions of this item will have "chain" added between the material and item name.
    #[token_de(token = "CHAIN_METAL_TEXT")]
    pub chain_metal_text: Option<()>,
    /// Clothiers can make this item from all kinds of cloth. If paired with `[LEATHER]`, the item
    /// has an equal chance of being either in randomly generated outfits. Further uses of this tag
    /// are unknown.
    #[token_de(token = "SOFT")]
    pub soft: Option<()>,
    /// Default state in the absence of a `[SOFT]` token. Actual effects unknown.
    #[token_de(token = "HARD")]
    pub hard: Option<()>,
    /// Item can be made from metal. Overrides `[SOFT]` and `[LEATHER]` in randomly generated
    /// outfits, if the `ARMORLEVEL` permits. Civilizations with `[WOOD_ARMOR]` will make this
    /// item out of wood instead.
    #[token_de(token = "METAL")]
    pub metal: Option<()>,
    /// Craftsmen can make this item from bones. Randomly generated outfits don't include bone
    /// armor.
    #[token_de(token = "BARRED")]
    pub barred: Option<()>,
    /// Craftsmen can make this item from shells. Randomly generated outfits don't include shell
    /// armor.
    #[token_de(token = "SCALED")]
    pub scaled: Option<()>,
    /// Leatherworkers can make this item from leather. If paired with `[SOFT]`, this item has an
    /// equal chance of being either in randomly generated outfits.
    #[token_de(token = "LEATHER")]
    pub leather: Option<()>,
    /// Only one shaped piece of clothing can be worn on a single body slot at a time.
    #[token_de(token = "SHAPED")]
    pub shaped: Option<()>,
    /// Increases the `*_STRAIN_AT_YIELD` properties of the armor's material to 50000, if lower.
    /// This makes the garment flex and give way instead of shattering under force. Strong materials
    /// that resist cutting will blunt edged attacks into bone-crushing hits instead.
    #[token_de(token = "STRUCTURAL_ELASTICITY_CHAIN_ALL")]
    pub structural_elasticity_chain_all: Option<()>,
    /// Increases the `*_STRAIN_AT_YIELD` properties of the armor's material to 50000, but only if
    /// the garment is made from metal.
    #[token_de(token = "STRUCTURAL_ELASTICITY_CHAIN_METAL")]
    pub structural_elasticity_chain_metal: Option<()>,
    /// Reduces the armor material's `SHEAR_YIELD` to 20000, `SHEAR_FRACTURE` to 30000 and increases
    /// the `*_STRAIN_AT_YIELD` properties to 50000, but only if the garment is made from cloth.
    /// This makes the item very weak against edged attacks, even if the thread material is
    /// normally very strong.
    #[token_de(token = "STRUCTURAL_ELASTICITY_WOVEN_THREAD")]
    pub structural_elasticity_woven_thread: Option<()>,
    /// The item's bulkiness when worn. Aside from the layer limitations, it's a big contributor to
    /// the thickness and weight (and therefore price) of the garment. See
    /// [Armor](https://dwarffortresswiki.org/index.php/Armor) for more on item sizes and
    /// layering. Defaults to 10.
    #[token_de(token = "LAYER_SIZE")]
    pub layer_size: Option<u32>,
    /// The maximum amount of garments that can fit underneath this garment. See
    /// [Armor](https://dwarffortresswiki.org/index.php/Armor) for more on item sizes and
    /// layering. Defaults to 10.
    #[token_de(token = "LAYER_PERMIT")]
    pub layer_permit: Option<u32>,
    /// Where the item goes in relation to other clothes. Socks cannot be worn on top of boots!
    ///
    /// The `LAYER_PERMIT` of the highest layer is used on a given section of the body - you can fit
    /// a lot of shirts and other undergarments underneath a robe, but not if you wear a leather
    /// jerkin on top of it, and you can still wear a cloak over the whole ensemble. Defaults to
    /// `UNDER`.
    #[token_de(token = "LAYER")]
    pub layer: Option<LayerEnum>,
    /// How often the garment gets in the way of a contaminant or an attack. Armor with a 5%
    /// coverage value, for example, will be near useless because 95% of attacks will bypass it
    /// completely. Temperature effects and armor thickness are also influenced. Defaults to 100.
    #[token_de(token = "COVERAGE")]
    pub coverage: Option<u8>,
    /// The garment's general purpose. Defaults to 1 for shields, 0 for everything else. Class 0
    /// items are claimed and used by civilians as ordinary clothing and are subject to wear.
    #[token_de(token = "ARMORLEVEL")] // shared by all garments, and shields
    pub armorlevel: Option<u8>,
    // endregion ==================================================================================
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum LayerEnum {
    #[token_de(token = "UNDER")]
    Under,
    #[token_de(token = "OVER")]
    Over,
    #[token_de(token = "ARMOR")]
    Armor,
    #[token_de(token = "COVER")]
    Cover,
}
impl Default for LayerEnum {
    fn default() -> Self {
        Self::Under
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum MaxEnum {
    #[token_de(token = "MAX")]
    Max,
}
impl Default for MaxEnum {
    fn default() -> Self {
        Self::Max
    }
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct SiegeAmmoToken {
    /// Argument 1 of `[ITEM_SIEGEAMMO:...]`
    #[token_de(token = "ITEM_SIEGEAMMO", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// Specifies what type of siege engine uses this ammunition. Currently, only `BALLISTA` is
    /// permitted.
    #[token_de(token = "CLASS")]
    pub class: Option<SiegeAmmoClassEnum>,
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum SiegeAmmoClassEnum {
    #[token_de(token = "BALLISTA")]
    Ballista,
}
impl Default for SiegeAmmoClassEnum {
    fn default() -> Self {
        Self::Ballista
    }
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct ToolToken {
    /// Argument 1 of `[ITEM_TOOL:...]`
    #[token_de(token = "ITEM_TOOL", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// Volume of tool in mL or cubic centimeters. Required.
    #[token_de(token = "SIZE")]
    pub size: Option<u32>,
    /// Name of the tool. Required.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// Defines the item value of the tool. Required.
    #[token_de(token = "VALUE")]
    pub value: Option<u32>,
    /// Defines the tile used to represent the tool. Required.
    #[token_de(token = "TILE")]
    pub tile: Option<DFChar>,
    /// Permits the tool to be made from any bone.
    #[token_de(token = "BONE_MAT")]
    pub bone_mat: Option<()>,
    /// Permits the tool to be made from any ceramic material.
    #[token_de(token = "CERAMIC_MAT")]
    pub ceramic_mat: Option<()>,
    /// Allows a string to describe the tool when viewed. The text box can accommodate up to 325
    /// characters until it cuts off, but the spacing of actual sentences puts the realistic limit
    /// closer to 300.
    #[token_de(token = "DESCRIPTION")]
    pub description: Option<String>,
    /// Permits the tool to be made from any glass.
    #[token_de(token = "GLASS_MAT")]
    pub glass_mat: Option<()>,
    /// Permits the tool to be made from anything with the `[ITEMS_HARD]` token, such as wood, stone
    /// or metal.
    #[token_de(token = "HARD_MAT")]
    pub hard_mat: Option<()>,
    /// Permits the tool to be made from any leather.
    #[token_de(token = "LEATHER_MAT")]
    pub leather_mat: Option<()>,
    /// Permits the tool to be made from anything with the `[IS_METAL]` token.
    #[token_de(token = "METAL_MAT")]
    pub metal_mat: Option<()>,
    /// Permits the tool to be made from any metal with the `[ITEMS_WEAPON]` token.
    #[token_de(token = "METAL_WEAPON_MAT")]
    pub metal_weapon_mat: Option<()>,
    /// Permits the tool to be made from any "sheet" material, such as papyrus, paper, and
    /// parchment. May be connected to the `PAPER_SLURRY`/`PAPER_PLANT` reaction classes,
    /// but this is not verified.
    #[token_de(token = "SHEET_MAT")]
    pub sheet_mat: Option<()>,
    /// Permits the tool to be made from any shell.
    #[token_de(token = "SHELL_MAT")]
    pub shell_mat: Option<()>,
    /// Permits the tool to be made from any silk.
    #[token_de(token = "SILK_MAT")]
    pub silk_mat: Option<()>,
    /// Permits the tool to be made from any material with the `[ITEMS_SOFT]` token, such as leather
    /// or textiles.
    #[token_de(token = "SOFT_MAT")]
    pub soft_mat: Option<()>,
    /// Permits the tool to be made from any stone. Presumably connected to the `[IS_STONE]` token.
    #[token_de(token = "STONE_MAT")]
    pub stone_mat: Option<()>,
    /// Permits the tool to be made from any plant fiber, such as pig tails.
    #[token_de(token = "THREAD_PLANT_MAT")]
    pub thread_plant_mat: Option<()>,
    /// Permits the tool to be made from any wood.
    #[token_de(token = "WOOD_MAT")]
    pub wood_mat: Option<()>,
    /// According to Toady, "Won't be used in world gen libraries (to differentiate scrolls from
    /// quires). Also put it on bindings, rollers, instr. pieces for completeness/future use".
    /// Used on scroll rollers, book bindings, and quires.
    #[token_de(token = "INCOMPLETE_ITEM")]
    pub incomplete_item: Option<()>,
    /// Items that appear in the wild come standard with this kind of improvement. Used on scrolls:
    /// `[DEFAULT_IMPROVEMENT:SPECIFIC:ROLLERS:HARD_MAT]`
    ///
    /// Currently bugged, the effect is also applied to everything made in-game. This causes
    /// scrolls to have two sets of rollers, for example.
    #[token_de(token = "DEFAULT_IMPROVEMENT")]
    pub default_improvement: Option<ImprovementTypeWithMatFlagTokenArg>,
    /// Prevents the tool from being improved. Used on honeycombs, scroll rollers, book bindings,
    /// and quires.
    #[token_de(token = "UNIMPROVABLE")]
    pub unimprovable: Option<()>,
    /// **This token's purpose is unknown, and it may be an alias of another token; if you know
    /// what it does, please open an issue on the issue tracker.**
    #[token_de(token = "NO_DEFAULT_IMPROVEMENTS")]
    pub no_default_improvements: Option<()>,
    /// The background of the tile will be colored, instead of the foreground.
    #[token_de(token = "INVERTED_TILE")]
    pub inverted_tile: Option<()>,
    /// According to Toady, "only custom reactions are used to make this item". Found on scrolls and
    /// quires.
    #[token_de(token = "NO_DEFAULT_JOB")]
    pub no_default_job: Option<()>,
    /// Defines the task performed using the tool.
    #[token_de(token = "TOOL_USE")]
    pub tool_use: Vec<ToolUseEnum>,
    /// Allows item to be stored in a furniture stockpile.
    #[token_de(token = "FURNITURE")]
    pub furniture: Option<()>,
    // TODO: ref is shape category
    #[token_de(token = "SHAPE_CATEGORY")]
    pub shape_category: Option<Reference>,
    /// Used on dice.
    #[token_de(token = "USES_FACE_IMAGE_SET")]
    pub uses_face_image_set: Option<()>,
    /// Adjective preceding the material name (e.g. "large copper dagger")
    #[token_de(token = "ADJECTIVE")]
    pub adjective: Option<String>,
    /// How much the item can contain. Defaults to 0.
    #[token_de(token = "CONTAINER_CAPACITY")]
    pub container_capacity: Option<u32>,
    /// Required for weapons.
    #[token_de(token = "SHOOT_FORCE")]
    pub shoot_force: Option<u32>,
    /// Required for weapons.
    #[token_de(token = "SHOOT_MAXVEL")]
    pub shoot_maxvel: Option<u32>,
    /// The skill to determine effectiveness in melee with this tool. Required for weapons.
    #[token_de(token = "SKILL")]
    pub skill: Option<SkillEnum>,
    /// Makes this tool a ranged weapon that uses the specified ammo. The specified skill
    /// determines accuracy in ranged combat.
    #[token_de(token = "RANGED")]
    pub ranged: Option<(SkillEnum, ReferenceTo<AmmoToken>)>,
    /// Creatures under this size (in cm^3) must use the tool two-handed. Required for weapons.
    #[token_de(token = "TWO_HANDED")]
    pub two_handed: Option<u32>,
    /// Minimum body size (in cm^3) to use the tool at all (multigrasp required until `TWO_HANDED`
    /// value). Required for weapons.
    #[token_de(token = "MINIMUM_SIZE")]
    pub minimum_size: Option<u32>,
    /// Number of bar units needed for forging, as well as the amount gained from melting. Required
    /// for weapons.
    #[token_de(token = "MATERIAL_SIZE")]
    pub material_size: Option<u32>,
    /// You can have many `ATTACK` tags and one will be randomly selected for each attack, with
    /// `EDGE` attacks 100 times more common than `BLUNT` attacks. Required for weapons.
    #[token_de(token = "ATTACK")]
    pub attack: Vec<WeaponAttack>,
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum ToolUseEnum {
    /// Cauldron adventure mode decoration / weapon
    #[token_de(token = "LIQUID_COOKING")]
    LiquidCooking,
    /// Ladle, an adventure mode decoration/weapon.
    #[token_de(token = "LIQUID_SCOOP")]
    LiquidScoop,
    /// Mortar, an adventure mode decoration/weapon.
    #[token_de(token = "GRIND_POWDER_RECEPTACLE")]
    GrindPowderReceptacle,
    /// Pestle, an adventure mode decoration/weapon.
    #[token_de(token = "GRIND_POWDER_GRINDER")]
    GrindPowderGrinder,
    /// Carving knife, an adventure mode decoration/weapon.
    #[token_de(token = "MEAT_CARVING")]
    MeatCarving,
    /// Boning knife, an adventure mode decoration/weapon.
    #[token_de(token = "MEAT_BONING")]
    MeatBoning,
    /// Slicing knife, an adventure mode decoration/weapon.
    #[token_de(token = "MEAT_SLICING")]
    MeatSlicing,
    /// Meat cleaver, an adventure mode decoration/weapon.
    #[token_de(token = "MEAT_CLEAVING")]
    MeatCleaving,
    /// Carving fork, an adventure mode decoration/weapon.
    #[token_de(token = "HOLD_MEAT_FOR_CARVING")]
    HoldMeatForCarving,
    /// Bowl, an adventure mode decoration/weapon.
    #[token_de(token = "MEAL_CONTAINER")]
    MealContainer,
    /// Nest box for your birds to lay eggs.
    #[token_de(token = "NEST_BOX")]
    NestBox,
    /// Jug; can store honey or oil.
    #[token_de(token = "LIQUID_CONTAINER")]
    LiquidContainer,
    /// Large pot; can store beer.
    #[token_de(token = "FOOD_STORAGE")]
    FoodStorage,
    /// Hive; can make honey.
    #[token_de(token = "HIVE")]
    Hive,
    /// Pouch, an adventure mode coin purse.
    #[token_de(token = "SMALL_OBJECT_STORAGE")]
    SmallObjectStorage,
    /// Minecart; item hauling/weapon.
    #[token_de(token = "TRACK_CART")]
    TrackCart,
    /// Wheelbarrow; allows hauling items faster.
    #[token_de(token = "HEAVY_OBJECT_HAULING")]
    HeavyObjectHauling,
    /// Stepladder, allows gathering fruit from trees.
    #[token_de(token = "STAND_AND_WORK_ABOVE")]
    StandAndWorkAbove,
    /// Scroll rollers.
    #[token_de(token = "ROLL_UP_SHEET")]
    RollUpSheet,
    /// Book binding.
    #[token_de(token = "PROTECT_FOLDED_SHEETS")]
    ProtectFoldedSheets,
    /// Scroll & quire.
    #[token_de(token = "CONTAIN_WRITING")]
    ContainWriting,
    /// Bookcase.
    #[token_de(token = "BOOKCASE")]
    Bookcase,
    /// Pedestal & display case for museums.
    #[token_de(token = "DISPLAY_OBJECT")]
    DisplayObject,
    /// Altar for (eventually) offering sacrifices.
    #[token_de(token = "PLACE_OFFERING")]
    PlaceOffering,
    /// Dice.
    #[token_de(token = "DIVINATION")]
    Divination,
    /// Dice.
    #[token_de(token = "GAMES_OF_CHANCE")]
    GamesOfChance,
}
impl Default for ToolUseEnum {
    fn default() -> Self {
        Self::LiquidCooking
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub enum ImprovementTypeWithMatFlagTokenArg {
    // TODO: token should be marked as deprecated/unused/ignored by the game, see #83
    // #[token_de(token = "ART_IMAGE")]
    // ArtImage,
    // #[token_de(token = "COVERED")]
    Covered(ImprovementMaterialFlagEnum),
    // #[token_de(token = "RINGS_HANGING")]
    RingsHanging(ImprovementMaterialFlagEnum),
    // #[token_de(token = "BANDS")]
    Bands(ImprovementMaterialFlagEnum),
    // #[token_de(token = "SPIKES")]
    Spikes(ImprovementMaterialFlagEnum),
    // #[token_de(token = "SPECIFIC", alias = "ITEMSPECIFIC")]
    Specific((ItemSpecificEnum, ImprovementMaterialFlagEnum)),
    // TODO: token should be marked as deprecated/unused/ignored by the game, see #83
    // #[token_de(token = "THREAD")]
    // Thread,
    // TODO: token should be marked as deprecated/unused/ignored by the game, see #83
    // #[token_de(token = "CLOTH")]
    // Cloth,
    // TODO: token should be marked as deprecated/unused/ignored by the game, see #83
    // #[token_de(token = "SEWN_IMAGE")]
    // SewnImage,
    // #[token_de(token = "PAGES")]
    Pages(ImprovementMaterialFlagEnum),
    // TODO: token should be marked as deprecated/unused/ignored by the game, see #83
    // #[token_de(token = "ILLUSTRATION")]
    // Illustration,
    // #[token_de(token = "INSTRUMENT_PIECE")]
    InstrumentPiece((Reference, ImprovementMaterialFlagEnum)), // Ref to INSTRUMENT PIECE, distinct from ITEM_INSTRUMENT
    // #[token_de(token = "WRITING")]
    Writing(ImprovementMaterialFlagEnum),
    // TODO: token should be marked as deprecated/unused/ignored by the game, see #83
    // #[token_de(token = "IMAGE_SET")]
    // ImageSet,
}
impl Default for ImprovementTypeWithMatFlagTokenArg {
    fn default() -> Self {
        Self::Covered(ImprovementMaterialFlagEnum::default())
    }
}

// Deserialize a token with following pattern: `[REF:improvement_type_token_arg:...]`
df_ls_syntax_analysis::token_deserialize_unary_token!(ImprovementTypeWithMatFlagTokenArg);

impl TryFromArgumentGroup for ImprovementTypeWithMatFlagTokenArg {
    fn try_from_argument_group(
        token: &mut Token,
        source: &str,
        diagnostics: &mut DiagnosticsInfo,
        add_diagnostics_on_err: bool,
    ) -> Result<Self, ()> {
        // Safe first argument (is not token_name) for error case
        let arg0 = match token.get_current_arg() {
            Ok(arg) => Ok(arg.clone()),
            Err(err) => Err(err),
        };
        let reference_arg0 =
            Reference::try_from_argument_group(token, source, diagnostics, add_diagnostics_on_err)?;
        let bp_criteria = match reference_arg0.0.as_ref() {
            "COVERED" => {
                let covered = ImprovementMaterialFlagEnum::try_from_argument_group(
                    token,
                    source,
                    diagnostics,
                    add_diagnostics_on_err,
                )?;
                ImprovementTypeWithMatFlagTokenArg::Covered(covered)
            }
            "RINGS_HANGING" => {
                let rings_hanging = ImprovementMaterialFlagEnum::try_from_argument_group(
                    token,
                    source,
                    diagnostics,
                    add_diagnostics_on_err,
                )?;
                ImprovementTypeWithMatFlagTokenArg::RingsHanging(rings_hanging)
            }
            "BANDS" => {
                let bands = ImprovementMaterialFlagEnum::try_from_argument_group(
                    token,
                    source,
                    diagnostics,
                    add_diagnostics_on_err,
                )?;
                ImprovementTypeWithMatFlagTokenArg::Bands(bands)
            }
            "SPIKES" => {
                let spikes = ImprovementMaterialFlagEnum::try_from_argument_group(
                    token,
                    source,
                    diagnostics,
                    add_diagnostics_on_err,
                )?;
                ImprovementTypeWithMatFlagTokenArg::Spikes(spikes)
            }
            // TODO: add alias warning
            "SPECIFIC" | "ITEMSPECIFIC" => {
                let specific =
                    <(ItemSpecificEnum, ImprovementMaterialFlagEnum)>::try_from_argument_group(
                        token,
                        source,
                        diagnostics,
                        add_diagnostics_on_err,
                    )?;
                ImprovementTypeWithMatFlagTokenArg::Specific(specific)
            }
            "PAGES" => {
                let pages = ImprovementMaterialFlagEnum::try_from_argument_group(
                    token,
                    source,
                    diagnostics,
                    add_diagnostics_on_err,
                )?;
                ImprovementTypeWithMatFlagTokenArg::Pages(pages)
            }
            "INSTRUMENT_PIECE" => {
                let instrument_piece =
                    <(Reference, ImprovementMaterialFlagEnum)>::try_from_argument_group(
                        token,
                        source,
                        diagnostics,
                        add_diagnostics_on_err,
                    )?;
                ImprovementTypeWithMatFlagTokenArg::InstrumentPiece(instrument_piece)
            }
            "WRITING" => {
                let writing = ImprovementMaterialFlagEnum::try_from_argument_group(
                    token,
                    source,
                    diagnostics,
                    add_diagnostics_on_err,
                )?;
                ImprovementTypeWithMatFlagTokenArg::Writing(writing)
            }
            _ => {
                Self::diagnostics_wrong_enum_type(
                    &arg0?,
                    vec![
                        "COVERED",
                        "RINGS_HANGING",
                        "BANDS",
                        "SPIKES",
                        "SPECIFIC",
                        "ITEMSPECIFIC",
                        "PAGES",
                        "INSTRUMENT_PIECE",
                        "WRITING",
                    ],
                    source,
                    diagnostics,
                    add_diagnostics_on_err,
                );
                return Err(());
            }
        };
        Ok(bp_criteria)
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum ItemSpecificEnum {
    #[token_de(token = "ROLLERS")]
    Rollers,
    #[token_de(token = "HANDLE")]
    Handle,
}
impl Default for ItemSpecificEnum {
    fn default() -> Self {
        Self::Rollers
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum ImprovementMaterialFlagEnum {
    /// Permits the improvement to be made from any bone.
    #[token_de(token = "BONE_MAT")]
    BoneMat,
    /// Permits the improvement to be made from any ceramic material.
    #[token_de(token = "CERAMIC_MAT")]
    CeramicMat,
    /// Permits the improvement to be made from any glass.
    #[token_de(token = "GLASS_MAT")]
    GlassMat,
    /// Permits the improvement to be made from anything with the `[ITEMS_HARD]` token, such as wood, stone
    /// or metal.
    #[token_de(token = "HARD_MAT")]
    HardMat,
    /// Permits the improvement to be made from any leather.
    #[token_de(token = "LEATHER_MAT")]
    LeatherMat,
    /// Permits the improvement to be made from anything with the `[IS_METAL]` token.
    #[token_de(token = "METAL_MAT")]
    MetalMat,
    /// Permits the improvement to be made from any metal with the `[ITEMS_WEAPON]` token.
    #[token_de(token = "METAL_WEAPON_MAT")]
    MetalWeaponMat,
    /// Permits the improvement to be made from any "sheet" material, such as papyrus, paper, and
    /// parchment. May be connected to the `PAPER_SLURRY`/`PAPER_PLANT` reaction classes,
    /// but this is not verified.
    #[token_de(token = "SHEET_MAT")]
    SheetMat,
    /// Permits the improvement to be made from any shell.
    #[token_de(token = "SHELL_MAT")]
    ShellMat,
    /// Permits the improvement to be made from any silk.
    #[token_de(token = "SILK_MAT")]
    SilkMat,
    /// Permits the improvement to be made from any material with the `[ITEMS_SOFT]` token, such as leather
    /// or textiles.
    #[token_de(token = "SOFT_MAT")]
    SoftMat,
    /// Permits the improvement to be made from any stone. Presumably connected to the `[IS_STONE]` token.
    #[token_de(token = "STONE_MAT")]
    StoneMat,
    /// Permits the improvement to be made from any plant fiber, such as pig tails.
    #[token_de(token = "THREAD_PLANT_MAT")]
    ThreadPlantMat,
    /// Permits the improvement to be made from any wood.
    #[token_de(token = "WOOD_MAT")]
    WoodMat,
}
impl Default for ImprovementMaterialFlagEnum {
    fn default() -> Self {
        Self::BoneMat
    }
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct ToyToken {
    /// Argument 1 of `[ITEM_TOY:...]`
    #[token_de(token = "ITEM_TOY", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// Presumably prevents the item from being made from cloth, silk, or leather, present on
    /// everything but puzzleboxes and drums. Appears to work backwards for strange moods.
    #[token_de(token = "HARD_MAT")]
    pub hard_mat: Option<()>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct TrapCompToken {
    /// Argument 1 of `[ITEM_TRAPCOMP:...]`
    #[token_de(token = "ITEM_TRAPCOMP", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// What this item will be called in-game.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>,
    /// How much material is needed to make the item. Is most important with bars.
    /// The number of bars needed is the value divided by three.
    #[token_de(token = "MATERIAL_SIZE")]
    pub material_size: Option<u32>, // TODO: required
    /// Appears before the name of the weapon's material. For example: "menacing steel spike".
    #[token_de(token = "ADJECTIVE")]
    pub adjective: Option<String>,
    /// How large the item is. Defaults to 100.
    #[token_de(token = "SIZE")]
    pub size: Option<u32>,
    /// Number of times it hits. Defaults to 1
    #[token_de(token = "HITS")]
    pub hits: Option<u32>,
    /// Weapon may be installed in a screw pump.
    #[token_de(token = "IS_SCREW")]
    pub is_screw: Option<()>,
    /// Weapon may be installed in a spike trap.
    #[token_de(token = "IS_SPIKE")]
    pub is_spike: Option<()>,
    /// Weapon may be made out of wood.
    #[token_de(token = "WOOD")]
    pub wood: Option<()>,
    /// Weapon may be made out of metal.
    #[token_de(token = "METAL")]
    pub metal: Option<()>,
    /// Sets the attack characteristics of the weapon
    #[token_de(token = "ATTACK")]
    pub attack: Option<ItemAttack>,
}

#[derive(
    Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq, Referenceable,
)]
pub struct WeaponToken {
    /// Argument 1 of `[ITEM_WEAPON:...]`
    #[token_de(token = "ITEM_WEAPON", on_duplicate_to_parent, primary_token)]
    #[referenceable(self_reference)]
    pub reference: Option<ReferenceTo<Self>>,
    /// Name of the weapon.
    #[token_de(token = "NAME")]
    pub name: Option<(String, String)>, // TODO: required
    /// Number of bar units needed for forging, as well as the amount gained from melting.
    #[token_de(token = "MATERIAL_SIZE")]
    pub material_size: Option<u32>, // TODO: Required
    /// Adjective of the weapon, e.g. the "large" in "large copper dagger".
    #[token_de(token = "ADJECTIVE")]
    pub adjective: Option<String>,
    /// Volume of weapon in mL or cubic cm. Defaults to 100.
    #[token_de(token = "SIZE")]
    pub size: Option<u32>,
    /// The amount of force used when firing projectiles - velocity is presumably determined by the
    /// projectile's mass. Defaults to 0.
    #[token_de(token = "SHOOT_FORCE")]
    pub shoot_force: Option<u32>,
    /// The maximum speed a fired projectile can have.
    #[token_de(token = "SHOOT_MAXVEL")]
    pub shoot_maxvel: Option<u32>,
    /// The skill to determine effectiveness in melee with this weapon. Defaults to `MACE`.
    ///
    /// Skill of `AXE` will allow it to be used to chop down trees. Skill of `MINER` will allow
    /// it to be used for mining.
    ///
    /// Outsider adventurers (or regular ones with no points in offensive skills) will receive a
    /// weapon with the `SPEAR` skill, selected at random if multiple ones have been modded in.
    /// All adventurers will also start with a weapon using the `DAGGER` skill, again selected at
    /// random if multiple such weapons exist.
    #[token_de(token = "SKILL")]
    pub skill: Option<SkillEnum>,
    /// Makes this a ranged weapon that uses the specified ammo. The specified skill determines
    /// accuracy in ranged combat.
    #[token_de(token = "RANGED")]
    pub ranged: Option<(SkillEnum, Reference)>, // `TODO` reference is ammo class
    /// Creatures under this size (in cm^3) must use the weapon two-handed. Defaults to 50000.
    #[token_de(token = "TWO_HANDED")]
    pub two_handed: Option<u32>,
    /// Minimum body size (in cm^3) to use the weapon at all (multigrasp required until `TWO_HANDED`
    /// value). Defaults to 40000.
    #[token_de(token = "MINIMUM_SIZE")]
    pub minimum_size: Option<u32>,
    /// Allows the weapon to be made at a craftsdwarf's workshop from a sharp (`[MAX_EDGE:10000]` or
    /// higher) stone (i.e. obsidian) plus a wood log.
    #[token_de(token = "CAN_STONE")]
    pub can_stone: Option<()>,
    /// Restricts this weapon to being made of wood.
    #[token_de(token = "TRAINING")]
    pub training: Option<()>,
    /// List of attacks this weapon can have.
    #[token_de(token = "ATTACK")]
    pub attack: Vec<WeaponAttack>,
}

// region: Attack definitions

/// Specifies the attack characteristics of this item.
/// - attack type: `BLUNT` or `EDGE`
/// - contact_area: value
/// - penetration_size: value
/// - verb2nd: string
/// - verb3rd: string
/// - noun: string or `NO_SUB`
/// - velocity_multiplier: value
#[derive(Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq)]
pub struct ItemAttack {
    /// Arguments of the `ATTACK` token
    #[token_de(token = "ATTACK")]
    pub attack: Option<(
        AttackTypeEnum,
        u32,
        u32,
        String,
        String,
        Choose<NoSubEnum, String>,
        u32,
    )>,
    /// Determines the length of time to prepare this attack and until one can perform this attack
    /// again. Values appear to be calculated in adventure mode ticks.
    #[token_de(token = "ATTACK_PREPARE_AND_RECOVER")]
    pub attack_prepare_and_recover: Option<(u32, u32)>,
}

/// Defines an attack on this weapon.
/// You can have many `ATTACK` tags and one will be randomly selected for each attack, with `EDGE`
/// attacks used 100 times more often than `BLUNT` attacks.
///
/// Contact area is usually high for slashing and low for bludgeoning, piercing, and poking.
/// Penetration value tends to be low for slashing and high for stabbing. Penetration is ignored if
/// attack is `BLUNT`.
/// - attack type: `BLUNT` or `EDGE`
/// - contact_area: value
/// - penetration_size: value
/// - verb2nd: string
/// - verb3rd: string
/// - noun: string or `NO_SUB`
/// - velocity_multiplier: value
#[derive(Serialize, Deserialize, Clone, Debug, Default, TokenDeserialize, PartialEq, Eq)]
pub struct WeaponAttack {
    /// Arguments of the `ATTACK` token
    #[token_de(token = "ATTACK", on_duplicate_to_parent, primary_token)]
    pub attack: Option<(
        AttackTypeEnum,
        u32,
        u32,
        String,
        String,
        Choose<NoSubEnum, String>,
        u32,
    )>,
    /// Determines the length of time to prepare this attack and until one can perform this attack
    /// again. Values appear to be calculated in adventure mode ticks.
    #[token_de(token = "ATTACK_PREPARE_AND_RECOVER")]
    pub attack_prepare_and_recover: Option<(u32, u32)>,
    /// Multiple strikes with this attack cannot be performed effectively.
    #[token_de(token = "ATTACK_FLAG_BAD_MULTIATTACK")]
    pub attack_flag_bad_multiattack: Option<()>,
    /// Multiple strikes with this attack can be performed with no penalty.
    #[token_de(token = "ATTACK_FLAG_INDEPENDENT_MULTIATTACK")]
    pub attack_flag_independent_multiattack: Option<()>,
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum AttackTypeEnum {
    #[token_de(token = "EDGE")]
    Edge,
    #[token_de(token = "BLUNT")]
    Blunt,
}
impl Default for AttackTypeEnum {
    fn default() -> Self {
        Self::Edge
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, TokenDeserialize, PartialEq, Eq)]
#[token_de(enum_value)]
pub enum NoSubEnum {
    #[token_de(token = "NO_SUB")]
    NoSub,
}
impl Default for NoSubEnum {
    fn default() -> Self {
        Self::NoSub
    }
}
// endregion