summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/describe.cc
blob: 43c23017cf335c7c45dd79d4aac9e1bf294aef44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
/*
 *  File:       describe.cc
 *  Summary:    Functions used to print information about various game objects.
 *  Written by: Linley Henzell
 */

#include "AppHdr.h"

#include "describe.h"
#include "database.h"

#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <numeric>

#include "externs.h"
#include "options.h"
#include "species.h"

#include "abl-show.h"
#include "artefact.h"
#include "cio.h"
#include "debug.h"
#include "decks.h"
#include "fight.h"
#include "food.h"
#include "ghost.h"
#include "godabil.h"
#include "goditem.h"
#include "invent.h"
#include "itemname.h"
#include "itemprop.h"
#include "items.h"
#include "jobs.h"
#include "macro.h"
#include "menu.h"
#include "message.h"
#include "mon-stuff.h"
#include "mon-util.h"
#include "newgame.h"
#include "output.h"
#include "player.h"
#include "random.h"
#include "religion.h"
#include "rng.h"
#include "skills2.h"
#include "spl-book.h"
#include "stuff.h"
#include "env.h"
#include "spl-cast.h"
#include "spl-util.h"
#include "transform.h"
#include "tutorial.h"
#include "xom.h"

#define LONG_DESC_KEY "long_desc_key"
#define QUOTE_KEY "quote_key"

// ========================================================================
//      Internal Functions
// ========================================================================

//---------------------------------------------------------------
//
// append_value
//
// Appends a value to the string. If plussed == 1, will add a + to
// positive values (itoa always adds - to -ve ones).
//
//---------------------------------------------------------------
static void _append_value( std::string & description, int valu, bool plussed )
{
    if (valu >= 0 && plussed == 1)
        description += "+";

    char value_str[80];

    itoa( valu, value_str, 10 );

    description += value_str;
}

int count_desc_lines(const std::string _desc, const int width)
{
    std::string desc = get_linebreak_string(_desc, width);

    int count = 0;
    for (int i = 0, size = desc.size(); i < size; ++i)
    {
        const char ch = desc[i];

        if (ch == '\n' || ch == '$')
            count++;
    }

    return count;
}

//---------------------------------------------------------------
//
// print_description
//
// Takes a descrip string filled up with stuff from other functions,
// and displays it with minor formatting to avoid cut-offs in mid
// word and such. The character $ is interpreted as a CR.
//
//---------------------------------------------------------------

void print_description(const std::string &body)
{
    describe_info inf;
    inf.body << body;
    print_description(inf);
}

class default_desc_proc
{
public:
    int width() { return get_number_of_cols() - 1; }
    int height() { return get_number_of_lines(); }
    void print(const std::string &str) { cprintf("%s", str.c_str()); }
    void nextline() { cgotoxy(1, wherey() + 1); }
};

void print_description(const describe_info &inf)
{
    clrscr();
    textcolor(LIGHTGREY);

    default_desc_proc proc;
    process_description<default_desc_proc>(proc, inf);
}

const char* jewellery_base_ability_string(int subtype)
{
    switch (subtype)
    {
    case RING_REGENERATION:      return "Regen";
    case RING_SUSTAIN_ABILITIES: return "SustAb";
    case RING_SUSTENANCE:        return "Hunger-";
    case RING_WIZARDRY:          return "Wiz";
    case RING_FIRE:              return "Fire";
    case RING_ICE:               return "Ice";
    case RING_TELEPORT_CONTROL:  return "cTele";
    case AMU_CLARITY:            return "Clar";
    case AMU_WARDING:            return "Ward";
    case AMU_RESIST_CORROSION:   return "rCorr";
    case AMU_THE_GOURMAND:       return "Gourm";
    case AMU_CONSERVATION:       return "Cons";
    case AMU_CONTROLLED_FLIGHT:  return "cFly";
    case AMU_RESIST_MUTATION:    return "rMut";
    case AMU_GUARDIAN_SPIRIT:    return "Spirit";
    case AMU_FAITH:              return "Faith";
    case AMU_STASIS:             return "Stasis";
    }
    return "";
}


#define known_proprt(prop) (proprt[(prop)] && known[(prop)])

struct property_annotators
{
    const char* name;
    artefact_prop_type prop;
    int spell_out;              // 0: "+3", 1: "+++", 2: value doesn't matter
};

static std::vector<std::string> _randart_propnames( const item_def& item )
{
    artefact_properties_t  proprt;
    artefact_known_props_t known;
    artefact_desc_properties( item, proprt, known, true );

    std::vector<std::string> propnames;

    // list the following in rough order of importance
    const property_annotators propanns[] = {

        // (Generally) negative attributes
        // These come first, so they don't get chopped off!
        { "-CAST",  ARTP_PREVENT_SPELLCASTING,  2 },
        { "-TELE",  ARTP_PREVENT_TELEPORTATION, 2 },
        { "MUT",    ARTP_MUTAGENIC,             2 }, // handled specially
        { "*Rage",  ARTP_ANGRY,                 2 },
        { "*TELE",  ARTP_CAUSE_TELEPORTATION,   2 },
        { "Hunger", ARTP_METABOLISM,            2 }, // handled specially
        { "Noisy",  ARTP_NOISES,                2 },

        // Evokable abilities come second
        { "+Blink", ARTP_BLINK,                 2 },
        { "+Rage",  ARTP_BERSERK,               2 },
        { "+Inv",   ARTP_INVISIBLE,             2 },
        { "+Lev",   ARTP_LEVITATE,              2 },

        // Resists, also really important
        { "rElec",  ARTP_ELECTRICITY,           2 },
        { "rPois",  ARTP_POISON,                2 },
        { "rF",     ARTP_FIRE,                  1 },
        { "rC",     ARTP_COLD,                  1 },
        { "rN",     ARTP_NEGATIVE_ENERGY,       1 },
        { "MR",     ARTP_MAGIC,                 2 },

        // Quantitative attributes
        { "AC",     ARTP_AC,                    0 },
        { "EV",     ARTP_EVASION,               0 },
        { "Str",    ARTP_STRENGTH,              0 },
        { "Dex",    ARTP_DEXTERITY,             0 },
        { "Int",    ARTP_INTELLIGENCE,          0 },
        { "Acc",    ARTP_ACCURACY,              0 },
        { "Dam",    ARTP_DAMAGE,                0 },

        // Qualitative attributes
        { "MP",     ARTP_MAGICAL_POWER,         0 },
        { "SInv",   ARTP_EYESIGHT,              2 },
        { "Stlth",  ARTP_STEALTH,               2 }, // handled specially
        { "Curse",  ARTP_CURSED,                2 },
    };

    // For randart jewellery, note the base jewellery type if it's not
    // covered by artefact_desc_properties()
    if (item.base_type == OBJ_JEWELLERY
        && item_ident(item, ISFLAG_KNOW_PROPERTIES))
    {
        const std::string type = jewellery_base_ability_string(item.sub_type);
        if (!type.empty())
            propnames.push_back(type);
    }
    else if (item_ident(item, ISFLAG_KNOW_TYPE))
    {
        std::string ego;
        if (item.base_type == OBJ_WEAPONS)
            ego = weapon_brand_name(item, true);
        else if (item.base_type == OBJ_ARMOUR)
            ego = armour_ego_name(item, true);
        if (!ego.empty())
        {
            // XXX: Ugly hack to remove the brackets...
            ego = ego.substr(2, ego.length() - 3);

            // ... and another one for adding a comma if needed.
            for (unsigned i = 0; i < ARRAYSZ(propanns); ++i)
                if (known_proprt(propanns[i].prop)
                    && propanns[i].prop != ARTP_BRAND)
                {
                    ego += ",";
                    break;
                }

            propnames.push_back(ego);
        }
    }

    for (unsigned i = 0; i < ARRAYSZ(propanns); ++i)
    {
        if (known_proprt(propanns[i].prop))
        {
            const int val = proprt[propanns[i].prop];

            // Don't show rF+/rC- for =Fire, or vice versa for =Ice.
            if (item.base_type == OBJ_JEWELLERY)
            {
                if (item.sub_type == RING_FIRE
                    && (propanns[i].prop == ARTP_FIRE && val == 1
                        || propanns[i].prop == ARTP_COLD && val == -1))
                {
                    continue;
                }
                if (item.sub_type == RING_ICE
                    && (propanns[i].prop == ARTP_COLD && val == 1
                        || propanns[i].prop == ARTP_FIRE && val == -1))
                {
                    continue;
                }
            }

            std::ostringstream work;
            switch (propanns[i].spell_out)
            {
            case 0: // e.g. AC+4
                work << std::showpos << propanns[i].name << val;
                break;
            case 1: // e.g. F++
            {
                int sval = std::min(std::abs(val), 3);
                work << propanns[i].name
                     << std::string(sval, (val > 0 ? '+' : '-'));
                break;
            }
            case 2: // e.g. rPois or SInv
                if (propanns[i].prop == ARTP_CURSED && val < 1)
                    continue;

                work << propanns[i].name;

                // these need special handling, so we don't give anything away
                if (propanns[i].prop == ARTP_METABOLISM && val > 2
                    || propanns[i].prop == ARTP_MUTAGENIC && val > 3
                    || propanns[i].prop == ARTP_STEALTH && val > 20)
                {
                    work << "+";
                }
                else if (propanns[i].prop == ARTP_STEALTH && val < 0)
                {
                    if (val < -20)
                        work << "--";
                    else
                        work << "-";
                }
                break;
            }
            propnames.push_back(work.str());
        }
    }

    return propnames;
}

// Remove randart auto-inscription.  Do it once for each property
// string, rather than the return value of artefact_auto_inscription(),
// in case more information about the randart has been learned since
// the last auto-inscription.
static void _trim_randart_inscrip( item_def& item )
{
    std::vector<std::string> propnames = _randart_propnames(item);

    for (unsigned int i = 0; i < propnames.size(); ++i)
    {
        item.inscription = replace_all(item.inscription, propnames[i]+",", "");
        item.inscription = replace_all(item.inscription, propnames[i],     "");
    }
    trim_string(item.inscription);
}

std::string artefact_auto_inscription( const item_def& item )
{
    if (item.base_type == OBJ_BOOKS)
        return ("");

    const std::vector<std::string> propnames = _randart_propnames(item);

    return (comma_separated_line(propnames.begin(), propnames.end(),
                                 " ", " "));
}

void add_autoinscription( item_def &item, std::string ainscrip)
{
    // Remove previous randart inscription.
    _trim_randart_inscrip(item);

    if (!item.inscription.empty())
    {
        if (ends_with(item.inscription, ","))
            item.inscription += " ";
        else
            item.inscription += ", ";
    }

    item.inscription += ainscrip;
}

struct property_descriptor
{
    artefact_prop_type property;
    const char* desc;           // If it contains %d, will be replaced by value.
    bool is_graded_resist;
};

static std::string _randart_descrip( const item_def &item )
{
    std::string description;

    artefact_properties_t  proprt;
    artefact_known_props_t known;
    artefact_desc_properties( item, proprt, known );

    const property_descriptor propdescs[] = {
        { ARTP_AC, "It affects your AC (%d).", false },
        { ARTP_EVASION, "It affects your evasion (%d).", false},
        { ARTP_STRENGTH, "It affects your strength (%d).", false},
        { ARTP_INTELLIGENCE, "It affects your intelligence (%d).", false},
        { ARTP_DEXTERITY, "It affects your dexterity (%d).", false},
        { ARTP_ACCURACY, "It affects your accuracy (%d).", false},
        { ARTP_DAMAGE, "It affects your damage-dealing abilities (%d).", false},
        { ARTP_FIRE, "fire", true},
        { ARTP_COLD, "cold", true},
        { ARTP_ELECTRICITY, "It insulates you from electricity.", false},
        { ARTP_POISON, "It protects you from poison.", false},
        { ARTP_NEGATIVE_ENERGY, "negative energy", true},
        { ARTP_MAGIC, "It increases your resistance to enchantments.", false},
        { ARTP_MAGICAL_POWER, "It affects your mana capacity (%d).", false},
        { ARTP_EYESIGHT, "It enhances your eyesight.", false},
        { ARTP_INVISIBLE, "It lets you turn invisible.", false},
        { ARTP_LEVITATE, "It lets you levitate.", false},
        { ARTP_BLINK, "It lets you blink.", false},
        { ARTP_BERSERK, "It lets you go berserk.", false},
        { ARTP_NOISES, "It makes noises.", false},
        { ARTP_PREVENT_SPELLCASTING, "It prevents spellcasting.", false},
        { ARTP_CAUSE_TELEPORTATION, "It causes teleportation.", false},
        { ARTP_PREVENT_TELEPORTATION, "It prevents most forms of teleportation.",
          false},
        { ARTP_ANGRY,  "It makes you angry.", false},
        { ARTP_CURSED, "It may recurse itself.", false}
    };

    for (unsigned i = 0; i < ARRAYSZ(propdescs); ++i)
    {
        if (known_proprt(propdescs[i].property))
        {
            // Only randarts with ARTP_CURSED > 0 may recurse themselves.
            if (propdescs[i].property == ARTP_CURSED
                && proprt[propdescs[i].property] < 1)
            {
                continue;
            }

            std::string sdesc = propdescs[i].desc;

            // FIXME Not the nicest hack.
            char buf[80];
            snprintf(buf, sizeof buf, "%+d", proprt[propdescs[i].property]);
            sdesc = replace_all(sdesc, "%d", buf);

            if (propdescs[i].is_graded_resist)
            {
                int idx = proprt[propdescs[i].property] + 3;
                idx = std::min(idx, 6);
                idx = std::max(idx, 0);

                const char* prefixes[] = {
                    "It makes you extremely vulnerable to ",
                    "It makes you very vulnerable to ",
                    "It makes you vulnerable to ",
                    "Buggy descriptor!",
                    "It protects you from ",
                    "It greatly protects you from ",
                    "It renders you almost immune to "
                };
                sdesc = prefixes[idx] + sdesc + '.';
            }

            description += '$';
            description += sdesc;
        }
    }

    // Some special cases which don't fit into the above.
    if (known_proprt( ARTP_METABOLISM ))
    {
        if (proprt[ ARTP_METABOLISM ] >= 3)
            description += "$It greatly speeds your metabolism.";
        else if (proprt[ ARTP_METABOLISM ])
            description += "$It speeds your metabolism. ";
    }

    if (known_proprt( ARTP_STEALTH ))
    {
        const int stval = proprt[ARTP_STEALTH];
        char buf[80];
        snprintf(buf, sizeof buf, "$It makes you %s%s stealthy.",
                 (stval < -20 || stval > 20) ? "much " : "",
                 (stval < 0) ? "less" : "more");
        description += buf;
    }

    if (known_proprt( ARTP_MUTAGENIC ))
    {
        if (proprt[ ARTP_MUTAGENIC ] > 3)
            description += "$It glows with mutagenic radiation.";
        else
            description += "$It emits mutagenic radiation.";
    }

    return description;
}
#undef known_proprt

static const char *trap_names[] =
{
    "dart", "arrow", "spear", "axe",
    "teleport", "alarm", "blade",
    "bolt", "net", "zot", "needle",
    "shaft"
};

const char *trap_name(trap_type trap)
{
    ASSERT(NUM_TRAPS == sizeof(trap_names) / sizeof(*trap_names));

    if (trap >= TRAP_DART && trap < NUM_TRAPS)
        return trap_names[trap];
    return (NULL);
}

int str_to_trap(const std::string &s)
{
    ASSERT(NUM_TRAPS == sizeof(trap_names) / sizeof(*trap_names));

    // allow a couple of synonyms
    if (s == "random" || s == "any")
        return (TRAP_RANDOM);
    else if (s == "suitable")
        return (TRAP_INDEPTH);
    else if (s == "nonteleport" || s == "noteleport"
             || s == "nontele" || s == "notele")
    {
        return (TRAP_NONTELEPORT);
    }

    for (int i = 0; i < NUM_TRAPS; ++i)
        if (trap_names[i] == s)
            return (i);

    return (-1);
}

//---------------------------------------------------------------
//
// describe_demon
//
// Describes the random demons you find in Pandemonium.
//
//---------------------------------------------------------------
static std::string _describe_demon(const monsters &mons)
{
    ASSERT(mons.ghost.get());

    const ghost_demon &ghost = *mons.ghost;

    const long seed =
        std::accumulate(ghost.name.begin(), ghost.name.end(), 0L) *
        ghost.name.length();

    rng_save_excursion exc;
    seed_rng( seed );

    const char* body_descs[] = {
        " huge, barrel-shaped ",
        " wispy, insubstantial ",
        " spindly ",
        " skeletal ",
        " horribly deformed ",
        " spiny ",
        " waif-like ",
        " scaly ",
        " sickeningly deformed ",
        " bruised and bleeding ",
        " sickly ",
        " mass of writhing tentacles for a ",
        " mass of ropey tendrils for a ",
        " tree trunk-like ",
        " hairy ",
        " furry ",
        " fuzzy ",
        "n obese ",
        " fat ",
        " slimy ",
        " wrinkled ",
        " metallic ",
        " glassy ",
        " crystalline ",
        " muscular ",
        "n icky ",
        " swollen ",
        " lumpy ",
        "n armoured ",
        " carapaced ",
        " slender "
    };

    const char* wing_names[] = {
        " with small insectoid wings",
        " with large insectoid wings",
        " with moth-like wings",
        " with butterfly wings",
        " with huge, bat-like wings",
        " with fleshy wings",
        " with small, bat-like wings",
        " with hairy wings",
        " with great feathered wings",
        " with shiny metal wings"
    };

    const char* lev_names[] = {
        " which hovers in mid-air",
        " with sacs of gas hanging from its back"
    };

    const char* nonfly_names[] = {
        " covered in tiny crawling spiders",
        " covered in tiny crawling insects",
        " and the head of a crocodile",
        " and the head of a hippopotamus",
        " and a cruel curved beak for a mouth",
        " and a straight sharp beak for a mouth",
        " and no head at all",
        " and a hideous tangle of tentacles for a mouth",
        " and an elephantine trunk",
        " and an evil-looking proboscis",
        " and dozens of eyes",
        " and two ugly heads",
        " and a long serpentine tail",
        " and a pair of huge tusks growing from its jaw",
        " and a single huge eye, in the centre of its forehead",
        " and spikes of black metal for teeth",
        " and a disc-shaped sucker for a head",
        " and huge, flapping ears",
        " and a huge, toothy maw in the centre of its chest",
        " and a giant snail shell on its back",
        " and a dozen heads",
        " and the head of a jackal",
        " and the head of a baboon",
        " and a huge, slobbery tongue",
        " which is covered in oozing lacerations",
        " and the head of a frog",
        " and the head of a yak",
        " and eyes out on stalks",
    };

    const char* misc_descs[] = {
        " It seethes with hatred of the living.",
        " Tiny orange flames dance around it.",
        " Tiny purple flames dance around it.",
        " It is surrounded by a weird haze.",
        " It glows with a malevolent light.",
        " It looks incredibly angry.",
        " It oozes with slime.",
        " It dribbles constantly.",
        " Mould grows all over it.",
        " It looks diseased.",
        " It looks as frightened of you as you are of it.",
        " It moves in a series of hideous convulsions.",
        " It moves with an unearthly grace.",
        " It hungers for your soul!",
        " It leaves a glistening oily trail.",
        " It shimmers before your eyes.",
        " It is surrounded by a brilliant glow.",
        " It radiates an aura of extreme power.",
    };

    std::ostringstream description;
    description << "A powerful demon, " << ghost.name << " has a"
                << RANDOM_ELEMENT(body_descs) << "body";

    switch (ghost.fly)
    {
    case FL_FLY:
        description << RANDOM_ELEMENT(wing_names);
        break;

    case FL_LEVITATE:
        description << RANDOM_ELEMENT(lev_names);
        break;

    case FL_NONE:  // does not fly
        if (!one_chance_in(4))
            description << RANDOM_ELEMENT(nonfly_names);
        break;
    }

    description << ".";

    if (x_chance_in_y(3, 40))
    {
        if (you.can_smell())
        {
            switch (random2(3))
            {
            case 0:
                description << " It stinks of brimstone.";
                break;
            case 1:
                description << " It is surrounded by a sickening stench.";
                break;
            case 2:
                description << " It smells like rotting flesh"
                            << (player_mutation_level(MUT_SAPROVOROUS) == 3 ?
                                " - yum!" : ".");
                break;
            }
        }
    }
    else if (coinflip())
        description << RANDOM_ELEMENT(misc_descs);

    return description.str();
}

void append_weapon_stats(std::string &description, const item_def &item)
{
    description += "$Accuracy rating: ";
    _append_value(description, property( item, PWPN_HIT ), true);
    description += "    ";

    description += "Damage rating: ";
    _append_value(description, property( item, PWPN_DAMAGE ), false);
    description += "   ";

    description += "Base attack delay: ";
    _append_value(description, property( item, PWPN_SPEED ) * 10, false);
   description += "%";
}

//---------------------------------------------------------------
//
// describe_weapon
//
//---------------------------------------------------------------
static std::string _describe_weapon(const item_def &item, bool verbose)
{
    std::string description;

    description.reserve(200);

    description = "";

    if (verbose)
        append_weapon_stats(description, item);

    int spec_ench = get_weapon_brand(item);

    if (!is_artefact(item) && !verbose)
        spec_ench = SPWPN_NORMAL;

    // special weapon descrip
    if (spec_ench != SPWPN_NORMAL && item_type_known(item))
    {
        description += "$$";

        switch (spec_ench)
        {
        case SPWPN_FLAMING:
            description += "It emits flame when wielded, causing extra "
                "injury to most foes and up to double damage against "
                "particularly susceptible opponents. Big, fiery blades "
                "are also staple armaments of hydra-hunters.";
            break;
        case SPWPN_FREEZING:
            description += "It has been specially enchanted to freeze "
                "those struck by it, causing extra injury to most foes "
                "and up to double damage against particularly "
                "susceptible opponents. It can also slow down "
                "cold-blooded creatures.";
            break;
        case SPWPN_HOLY_WRATH:
            description += "It has been blessed by the Shining One to "
                "cause great damage to the undead and demons.";
            break;
        case SPWPN_ELECTROCUTION:
            if (is_range_weapon(item))
                description += "It charges the ammunition it shoots with "
                    "electricity; occasionally upon a hit, such missiles "
                    "may discharge and cause terrible harm.";
            else
                description += "Occasionally, upon striking a foe, it will "
                    "discharge some electrical energy and cause terrible "
                    "harm.";
            break;
        case SPWPN_ORC_SLAYING:
            description += "It is especially effective against all of "
                "orcish descent.";
            break;
        case SPWPN_DRAGON_SLAYING:
            description += "This legendary weapon is deadly to all "
                "dragonkind. It also provides some protection from the "
                "breath attacks of dragons and other creatures.";
            break;
        case SPWPN_VENOM:
            if (is_range_weapon(item))
                description += "It poisons the ammo it fires.";
            else
                description += "It poisons the flesh of those it strikes.";
            break;
        case SPWPN_PROTECTION:
            description += "It protects the one who wields it against "
                "injury (+5 to AC).";
            break;
        case SPWPN_EVASION:
            description += "It affects your evasion (+5 to EV).";
            break;
        case SPWPN_DRAINING:
            description += "A truly terrible weapon, it drains the "
                "life of those it strikes.";
            break;
        case SPWPN_SPEED:
            description += "Attacks with this weapon take half as long "
                "as usual.";
            break;
        case SPWPN_VORPAL:
            if (is_range_weapon(item))
            {
                description += "Any ";
                description += ammo_name(item);
                description += " fired from it inflicts extra damage.";
            }
            else
            {
                description += "It inflicts extra damage upon your "
                    "enemies.";
            }
            break;
        case SPWPN_FLAME:
            description += "It turns projectiles fired from it into "
                "bolts of flame.";
            break;
        case SPWPN_FROST:
            description += "It turns projectiles fired from it into "
                "bolts of frost.";
            break;
        case SPWPN_CHAOS:
            if (is_range_weapon(item))
            {
                description += "Each time it fires, it turns the "
                    "launched projectile into a different, random type "
                    "of bolt.";
            }
            else
            {
                description += "Each time it hits an enemy it has a "
                    "different, random effect.";
            }
            break;
        case SPWPN_VAMPIRICISM:
            description += "It inflicts no extra harm, but heals its "
                "wielder somewhat when it strikes a living foe.";
            break;
        case SPWPN_PAIN:
            description += "In the hands of one skilled in necromantic "
                "magic, it inflicts extra damage on living creatures.";
            break;
        case SPWPN_DISTORTION:
            description += "It warps and distorts space around it. "
                "Unwielding it can cause banishment or high damage.";
            break;
        case SPWPN_REACHING:
            description += "It can be evoked to extend its reach.";
            break;
        case SPWPN_RETURNING:
            description += "A skilled user can throw it in such a way "
                "that it will return to its owner.";
            break;
        case SPWPN_PENETRATION:
            description += "Ammo fired by it will pass through the "
                "targets it hits, potentially hitting all targets in "
                "its path until it reaches maximum range.";
            break;
        case SPWPN_REAPING:
            if (is_range_weapon(item))
            {
                description += "If ammo fired by it kills a monster, "
                    "causing it to leave a corpse, the corpse will be "
                    "animated as a zombie friendly to the killer.";
            }
            else
            {
                description += "If a monster killed with it leaves a "
                    "corpse in good enough shape, the corpse will be "
                    "animated as a zombie friendly to the killer.";
            }
            break;
        }
    }

    if (is_artefact(item))
    {
        std::string rand_desc = _randart_descrip(item);
        if (!rand_desc.empty())
        {
            description += "$$";
            description += rand_desc;
        }

        // XXX: Can't happen, right?
        if (!item_ident(item, ISFLAG_KNOW_PROPERTIES)
            && item_type_known(item))
        {
            description += "$This weapon may have some hidden properties.";
        }
    }

    const bool launcher = is_range_weapon(item);
    if (verbose)
    {
        description += "$$This weapon falls into the";

        const skill_type skill =
            is_range_weapon(item)? range_skill(item) : weapon_skill(item);

        description +=
            make_stringf(" '%s' category. ",
                         skill == SK_FIGHTING ? "buggy" : skill_name(skill));

        if (!launcher)
        {
            switch (hands_reqd(item, you.body_size()))
            {
            case HANDS_ONE:
                description += "It is a one handed weapon";
                 break;
            case HANDS_HALF:
                description += "It can be used with one hand, or more "
                       "effectively with two (i.e. when not using a "
                       "shield)";
                break;
            case HANDS_TWO:
                description += "It is a two handed weapon";
                break;
            case HANDS_DOUBLE:
                description += "It is a buggy weapon";
                break;
            }

            const int str_weight = weapon_str_weight(item.base_type,
                                                     item.sub_type);

            if (str_weight >= 8)
                description += ", and it is best used by the strong";
            else if (str_weight > 5)
                description += ", and it is better for the strong";
            else if (str_weight <= 2)
                description += ", and it is best used by the dexterous";
            else if (str_weight < 5)
                description += ", and it is better for the dexterous";
            description += ".";
        }
        if (!you.could_wield(item, true))
            description += "$It is too large for you to wield.";
    }

    if (verbose)
    {
        if (is_demonic(item) && !launcher)
            description += "$Demonspawn are more deadly with it.";
        else if (get_equip_race(item) != ISFLAG_NO_RACE)
        {
            unsigned long race = get_equip_race(item);

            if (race == ISFLAG_DWARVEN)
                description += "$It is well-crafted and very durable.";

            description += "$";
            description += (race == ISFLAG_DWARVEN) ? "Dwarves" :
                           (race == ISFLAG_ELVEN)   ? "Elves"
                                                    : "Orcs";
            description += " are more deadly with it";

            if (launcher)
            {
                description += ", and it is most deadly when used with ";
                description += racial_description_string(item);
                description += "ammunition";
            }

            description += ".";
        }
    }

    if (!is_known_artefact(item))
    {
        if (item_ident(item, ISFLAG_KNOW_PLUSES)
            && item.plus >= MAX_WPN_ENCHANT && item.plus2 >= MAX_WPN_ENCHANT)
        {
            description += "$It is maximally enchanted.";
        }
        else
        {
            description += "$It can be maximally enchanted to +";
            _append_value(description, MAX_WPN_ENCHANT, false);
            description += ", +";
            _append_value(description, MAX_WPN_ENCHANT, false);
            description += ".";
        }
    }

    return (description);
}


//---------------------------------------------------------------
//
// describe_ammo
//
//---------------------------------------------------------------
static std::string _describe_ammo(const item_def &item)
{
    std::string description;

    description.reserve(64);

    if (item.sub_type == MI_THROWING_NET)
    {
        if (item.plus > 1 || item.plus < 0)
        {
            std::string how;

            if (item.plus > 1)
                how = "brand-new";
            else if (item.plus < 0)
            {
                if (item.plus > -3)
                    how = "a little worn";
                else if (item.plus > -5)
                    how = "slightly damaged";
                else if (item.plus > -7)
                    how = "damaged";
                else
                    how = "heavily frayed";
            }

            description += "It looks ";
            description += how;
            description += ".";
        }
    }

    bool can_launch       = has_launcher(item);
    bool can_throw        = is_throwable(&you, item, true);
    bool need_new_line    = true;
    bool always_destroyed = false;

    if (item.special && item_type_known(item))
    {
        description += "$$";
        std::string bolt_name;

        std::string threw_or_fired;
        if (can_throw)
        {
            threw_or_fired += "threw";
            if (can_launch)
                threw_or_fired += " or ";
        }
        if (can_launch)
            threw_or_fired += "fired";

        switch (item.special)
        {
        case SPMSL_FLAME:
            description += "It turns into a bolt of flame.";
            break;
        case SPMSL_FROST:
            description += "It turns into a bolt of frost.";
            break;
            break;
        case SPMSL_CHAOS:
            if (bolt_name.empty())
                bolt_name = "a random type";

            description += "When ";

            if (can_throw)
            {
                description += "thrown, ";
                if (can_launch)
                    description += "or ";
            }

            if (can_launch)
                description += "fired from an appropriate launcher, ";

            description += "it turns into a bolt of ";
            description += bolt_name;
            description += ".";
            always_destroyed = true;
            break;
        case SPMSL_POISONED:
            description += "It is coated with poison.";
            break;
        case SPMSL_CURARE:
            description += "It is tipped with asphyxiating poison.";
            break;
        case SPMSL_PARALYSIS:
            description += "It is tipped with a paralyzing poison.";
            break;
        case SPMSL_SLOW:
            description += "It is coated with a poison that causes slowness of the body.";
            break;
        case SPMSL_SLEEP:
            description += "It is coated with a fast-acting tranquilizer.";
            break;
        case SPMSL_CONFUSION:
            description += "It is tipped with a substance that causes confusion.";
            break;
        case SPMSL_SICKNESS:
            description += "It has been contaminated by something likely to cause disease.";
            break;
        case SPMSL_RAGE:
            description += "It is tipped with a substance that causes a mindless, berserk rage.";
            break;
       case SPMSL_RETURNING:
            description += "A skilled user can throw it in such a way "
                "that it will return to its owner.";
            break;
        case SPMSL_REAPING:
            description += "If it kills a monster, causing it to leave "
                "a corpse, the corpse will be animated as a zombie "
                "friendly to the one who " + threw_or_fired + " it.";
            break;
        case SPMSL_PENETRATION:
            description += "It will pass through any targets it hits, "
                "potentially hitting all targets in its path until it "
                "reaches maximum range.";
            break;
        case SPMSL_DISPERSAL:
            description += "Any target it hits will blink, with a "
                "tendency towards blinking further away from the one "
                "who " + threw_or_fired + " it.";
            always_destroyed = true;
            break;
        case SPMSL_EXPLODING:
            description += "It will explode into fragments upon "
                "hitting a target, hitting an obstruction, or reaching "
                "the end of its range.";
            always_destroyed = true;
            break;
        case SPMSL_STEEL:
            description += "Compared to normal ammo, it does 50% more "
                "damage, is destroyed upon impact only 1/10th of the "
                "time, and weighs three three times as much.";
            break;
        case SPMSL_SILVER:
            description += "Compared to normal ammo, it does twice as "
                "much damage to the undead, demons and chaotic beings, "
                "and weighs twice as much. With due care, it can still "
                "be handled by those folks.";
            break;
        }

        need_new_line = false;
    }

    if (get_equip_race(item) != ISFLAG_NO_RACE)
    {
        description += "$";

        if (need_new_line)
            description += "$";

        if (can_throw)
        {
            unsigned long race = get_equip_race(item);

            description += "It is more deadly when thrown by ";
            description += (race == ISFLAG_DWARVEN) ? "dwarves" :
                           (race == ISFLAG_ELVEN)   ? "elves"
                                                    : "orcs";
            description += (can_launch) ? ", and it" : ".";
            description += " ";
        }

        if (can_launch)
        {
            if (!can_throw)
                description += "It ";

            description += "is more effective in conjunction with ";
            description += racial_description_string(item);
            description += "launchers.";
        }
    }

    if (always_destroyed)
        description += "$It will always be destroyed upon impact.";
    else if (item.sub_type != MI_THROWING_NET)
        append_missile_info(description);

    if (item_ident(item, ISFLAG_KNOW_PLUSES) && item.plus >= MAX_WPN_ENCHANT)
        description += "$It is maximally enchanted.";
    else
    {
        description += "$It can be maximally enchanted to +";
        _append_value(description, MAX_WPN_ENCHANT, false);
        description += ".";
    }

    return (description);
}

void append_armour_stats(std::string &description, const item_def &item)
{
    description += "$Armour rating: ";
    _append_value(description, property( item, PARM_AC ), false);
    description += "       ";

    description += "Evasion modifier: ";
    _append_value(description, property( item, PARM_EVASION ), true);
}

void append_missile_info(std::string &description)
{
    description += "$All pieces of ammunition may get destroyed upon impact. "
                   "Enchantment reduces the chances of such loss.";
}

//---------------------------------------------------------------
//
// describe_armour
//
//---------------------------------------------------------------
static std::string _describe_armour( const item_def &item, bool verbose )
{
    std::string description;

    description.reserve(200);

    if (verbose
        && item.sub_type != ARM_SHIELD
        && item.sub_type != ARM_BUCKLER
        && item.sub_type != ARM_LARGE_SHIELD)
    {
        append_armour_stats(description, item);
    }

    const int ego = get_armour_ego_type( item );
    if (ego != SPARM_NORMAL && item_type_known(item) && verbose)
    {
        description += "$$";

        switch (ego)
        {
        case SPARM_RUNNING:
            description += "It allows its wearer to run at a great speed.";
            break;
        case SPARM_FIRE_RESISTANCE:
            description += "It protects its wearer from heat and fire.";
            break;
        case SPARM_COLD_RESISTANCE:
            description += "It protects its wearer from cold.";
            break;
        case SPARM_POISON_RESISTANCE:
            description += "It protects its wearer from poison.";
            break;
        case SPARM_SEE_INVISIBLE:
            description += "It allows its wearer to see invisible things.";
            break;
        case SPARM_DARKNESS:
            description += "When activated it hides its wearer from "
                "the sight of others, but also increases "
                "their metabolic rate by a large amount.";
            break;
        case SPARM_STRENGTH:
            description += "It increases the physical power of its wearer (+3 to strength).";
            break;
        case SPARM_DEXTERITY:
            description += "It increases the dexterity of its wearer (+3 to dexterity).";
            break;
        case SPARM_INTELLIGENCE:
            description += "It makes you more clever (+3 to intelligence).";
            break;
        case SPARM_PONDEROUSNESS:
            description += "It is very cumbersome (-2 to EV, slows movement).";
            break;
        case SPARM_LEVITATION:
            description += "It can be activated to allow its wearer to "
                "float above the ground and remain so indefinitely.";
            break;
        case SPARM_MAGIC_RESISTANCE:
            description += "It increases its wearer's resistance "
                "to enchantments.";
            break;
        case SPARM_PROTECTION:
            description += "It protects its wearer from harm (+3 to AC).";
            break;
        case SPARM_STEALTH:
            description += "It enhances the stealth of its wearer.";
            break;
        case SPARM_RESISTANCE:
            description += "It protects its wearer from the effects "
                "of both cold and heat.";
            break;

        // These two are only for robes.
        case SPARM_POSITIVE_ENERGY:
            description += "It protects its wearer from "
                "the effects of negative energy.";
            break;
        case SPARM_ARCHMAGI:
            description += "It greatly increases the power of its "
                "wearer's magical spells, but is only "
                "intended for those who have very little left to learn.";
            break;

        case SPARM_PRESERVATION:
            description += "It protects its wearer's possessions "
                "from damage and destruction.";
            break;

        case SPARM_REFLECTION:
            description += "It reflects blocked things back in the "
                "direction they came from.";
            break;

        case SPARM_SPIRIT_SHIELD:
            description += "It shields its wearer from harm at the cost "
                "of magical power.";
            break;

        // This is only for bracers (gloves).
        case SPARM_ARCHERY:
            description += "These improve your skills with ranged weaponry "
                "but interfere slightly with melee combat.";
            break;
        }
    }

    if (is_artefact( item ))
    {
        std::string rand_desc = _randart_descrip( item );
        if (!rand_desc.empty())
        {
            description += "$$";
            description += rand_desc;
        }

        // Can't happen, right? (XXX)
        if (!item_ident(item, ISFLAG_KNOW_PROPERTIES) && item_type_known(item))
            description += "$This armour may have some hidden properties.";
    }
    else if (get_equip_race( item ) != ISFLAG_NO_RACE)
    {
        // Randart armour can't be racial.
        description += "$";

        unsigned long race = get_equip_race(item);

        if (race == ISFLAG_DWARVEN)
            description += "$It is well-crafted and very durable.";
        else if (race == ISFLAG_ELVEN)
        {
            description += "$It is well-crafted and unobstructive";
            if (item.sub_type == ARM_CLOAK || item.sub_type == ARM_BOOTS)
                description += ", and helps its wearer avoid being noticed";
            description += ".";
        }

        description += "$It fits ";
        description += (race == ISFLAG_DWARVEN) ? "dwarves" :
                       (race == ISFLAG_ELVEN)   ? "elves"
                                                : "orcs";
        description += " well.";
    }

    if (verbose && get_armour_slot(item) == EQ_BODY_ARMOUR)
    {
        description += "$$";
        if (is_light_armour(item))
        {
            description += "This is a light armour. Wearing it will "
                "exercise Dodging and Stealth.";
        }
        else
        {
            description += "This is a heavy armour. Wearing it will "
                "exercise Armour.";
        }
    }

    if (!is_known_artefact(item))
    {
        const int max_ench = armour_max_enchant(item);
        if (armour_is_hide(item))
        {
            description += "$Enchanting it will turn it into a suit of "
                           "magical armour.";
        }
        else if (item.plus < max_ench || !item_ident(item, ISFLAG_KNOW_PLUSES))
        {
            description += "$It can be maximally enchanted to +";
            _append_value(description, max_ench, false);
            description += ".";
        }
        else
            description += "$It is maximally enchanted.";
    }

    return description;
}

//---------------------------------------------------------------
//
// describe_jewellery
//
//---------------------------------------------------------------
static std::string _describe_jewellery( const item_def &item, bool verbose)
{
    std::string description;

    description.reserve(200);

    if ((verbose || is_artefact( item ))
        && item_ident( item, ISFLAG_KNOW_PLUSES ))
    {
        // Explicit description of ring power (useful for randarts)
        // Note that for randarts we'll print out the pluses even
        // in the case that its zero, just to avoid confusion. -- bwr
        if (item.plus != 0
            || item.sub_type == RING_SLAYING && item.plus2 != 0
            || is_artefact( item ))
        {
            switch (item.sub_type)
            {
            case RING_PROTECTION:
                description += "$It affects your AC (";
                _append_value( description, item.plus, true );
                description += ").";
                break;

            case RING_EVASION:
                description += "$It affects your evasion (";
                _append_value( description, item.plus, true );
                description += ").";
                break;

            case RING_STRENGTH:
                description += "$It affects your strength (";
                _append_value( description, item.plus, true );
                description += ").";
                break;

            case RING_INTELLIGENCE:
                description += "$It affects your intelligence (";
                _append_value( description, item.plus, true );
                description += ").";
                break;

            case RING_DEXTERITY:
                description += "$It affects your dexterity (";
                _append_value( description, item.plus, true );
                description += ").";
                break;

            case RING_SLAYING:
                if (item.plus != 0)
                {
                    description += "$It affects your accuracy (";
                    _append_value( description, item.plus, true );
                    description += ").";
                }

                if (item.plus2 != 0)
                {
                    description += "$It affects your damage-dealing abilities (";
                    _append_value( description, item.plus2, true );
                    description += ").";
                }

                if (item.plus == 0 && item.plus2 == 0)
                {
                    description += "This buggy ring affects neither your "
                                   "accuracy nor your damage-dealing "
                                   "abilities.";
                }
                break;

            default:
                break;
            }
        }
    }

    // Artefact properties.
    if (is_artefact( item ))
    {
        std::string rand_desc = _randart_descrip( item );
        if (!rand_desc.empty())
        {
            description += "$";
            description += rand_desc;
        }
        if (!item_ident(item, ISFLAG_KNOW_PROPERTIES))
        {
            description += "$This ";
            description += (jewellery_is_amulet(item) ? "amulet" : "ring");
            description += " may have hidden properties.";
        }
    }

    return (description);
}                               // end describe_jewellery()

static bool _compare_card_names(card_type a, card_type b)
{
    return std::string(card_name(a)) < std::string(card_name(b));
}

//---------------------------------------------------------------
//
// describe_misc_item
//
//---------------------------------------------------------------
static std::string _describe_deck( const item_def &item )
{
    std::string description;

    description.reserve(100);

    description += "$";

    const std::vector<card_type> drawn_cards = get_drawn_cards(item);
    if (!drawn_cards.empty())
    {
        description += "Drawn card(s): ";
        for (unsigned int i = 0; i < drawn_cards.size(); ++i)
        {
            if (i != 0)
                description += ", ";
            description += card_name(drawn_cards[i]);
        }
        description += "$";
    }

    const int num_cards = cards_in_deck(item);
    int last_known_card = -1;
    if (top_card_is_known(item))
    {
        description += "Next card(s): ";
        for (int i = 0; i < num_cards; ++i)
        {
            unsigned char flags;
            const card_type card = get_card_and_flags(item, -i-1, flags);
            if (flags & CFLAG_MARKED)
            {
                if (i != 0)
                    description += ", ";
                description += card_name(card);
                last_known_card = i;
            }
            else
                break;
        }
        description += "$";
    }

    // Marked cards which we don't know straight off.
    std::vector<card_type> marked_cards;
    for (int i = last_known_card + 1; i < num_cards; ++i)
    {
        unsigned char flags;
        const card_type card = get_card_and_flags(item, -i-1, flags);
        if (flags & CFLAG_MARKED)
            marked_cards.push_back(card);
    }
    if (!marked_cards.empty())
    {
        std::sort(marked_cards.begin(), marked_cards.end(),
                  _compare_card_names);

        description += "Marked card(s): ";
        for (unsigned int i = 0; i < marked_cards.size(); ++i)
        {
            if (i != 0)
                description += ", ";
            description += card_name(marked_cards[i]);
        }
        description += "$";
    }

    // Seen cards in the deck.
    std::vector<card_type> seen_cards;
    for (int i = 0; i < num_cards; ++i)
    {
        unsigned char flags;
        const card_type card = get_card_and_flags(item, -i-1, flags);

        // This *might* leak a bit of information...oh well.
        if ((flags & CFLAG_SEEN) && !(flags & CFLAG_MARKED))
            seen_cards.push_back(card);
    }
    if (!seen_cards.empty())
    {
        std::sort(seen_cards.begin(), seen_cards.end(),
                  _compare_card_names);

        description += "Seen card(s): ";
        for (unsigned int i = 0; i < seen_cards.size(); ++i)
        {
            if (i != 0)
                description += ", ";
            description += card_name(seen_cards[i]);
        }
        description += "$";
    }

    return (description);
}

// Adds a list of all spells contained in a book or rod to its
// description string.
void append_spells(std::string &desc, const item_def &item)
{
    if (!item.has_spells())
        return;

    desc += "$$Spells                             Type                      Level$";

    for (int j = 0; j < SPELLBOOK_SIZE; ++j)
    {
        spell_type stype = which_spell_in_book(item, j);
        if (stype == SPELL_NO_SPELL)
            continue;

        std::string name = (is_memorised(stype) ? "*" : "");
                    name += spell_title(stype);
        desc += name;
        for (unsigned int i = 0; i < 35 - name.length(); ++i)
             desc += " ";

        std::string schools;
        if (item.base_type == OBJ_STAVES)
            schools = "Evocations";
        else
            schools = spell_schools_string(stype);

        desc += schools;
        for (unsigned int i = 36; i < 65 - schools.length(); ++i)
             desc += " ";

        char sval[3];
        itoa( spell_difficulty( stype ), sval, 10 );
        desc += sval;
        desc += "$";
    }
}

// ========================================================================
//      Public Functions
// ========================================================================

bool is_dumpable_artefact( const item_def &item, bool verbose)
{
    bool ret = false;

    if (is_known_artefact( item ))
    {
        ret = item_ident( item, ISFLAG_KNOW_PROPERTIES );
    }
    else if (verbose && item.base_type == OBJ_ARMOUR
             && item_type_known(item))
    {
        const int spec_ench = get_armour_ego_type( item );
        ret = (spec_ench >= SPARM_RUNNING && spec_ench <= SPARM_PRESERVATION);
    }
    else if (verbose && item.base_type == OBJ_JEWELLERY
             && item_type_known(item))
    {
        ret = true;
    }

    return (ret);
}


//---------------------------------------------------------------
//
// get_item_description
//
// Note that the string will include dollar signs which should
// be interpreted as carriage returns.
//
//---------------------------------------------------------------
std::string get_item_description( const item_def &item, bool verbose,
                                  bool dump, bool noquote )
{
    if (dump)
        noquote = true;

    std::ostringstream description;

    if (!dump)
        description << item.name(DESC_INVENTORY_EQUIP);

#if DEBUG_DIAGNOSTICS
    if (!dump)
    {
        description << std::setfill('0');
        description << "$$"
                    << "base: " << static_cast<int>(item.base_type)
                    << " sub: " << static_cast<int>(item.sub_type)
                    << " plus: " << item.plus << " plus2: " << item.plus2
                    << " special: " << item.special
                    << "$"
                    << "quant: " << item.quantity
                    << " colour: " << static_cast<int>(item.colour)
                    << " flags: " << std::hex << std::setw(8) << item.flags
                    << std::dec << "$"
                    << "x: " << item.pos.x << " y: " << item.pos.y
                    << " link: " << item.link
                    << " slot: " << item.slot
                    << " ident_type: "
                    << static_cast<int>(get_ident_type(item))
                    << " book_number: " << item.book_number();
    }
#endif

    if (verbose || (item.base_type != OBJ_WEAPONS
                    && item.base_type != OBJ_ARMOUR
                    && item.base_type != OBJ_BOOKS))
    {
        description << "$$";

        if (dump)
        {
            description << "["
                        << item.name(DESC_DBNAME, true, false, false)
                        << "]";
        }
        else if (is_unrandom_artefact(item)
                 && (unrandart_descrip(0, item)[0] != '\0'
                     || unrandart_descrip(1, item)[1] != '\0'))
        {
            const char *desc    = unrandart_descrip( 0, item );
            const char *desc_id = unrandart_descrip( 1, item );

            if (item_type_known(item) && desc_id[0] != '\0')
                description << desc_id << "$";
            else if (desc[0] != '\0')
                description << desc << "$";
        }
        else
        {
            std::string db_name = item.name(DESC_DBNAME, true, false, false);
            std::string db_desc = getLongDescription(db_name);
            if (!noquote && !is_known_artefact(item))
            {
                const unsigned int lineWidth = get_number_of_cols();
                const          int height    = get_number_of_lines();

                std::string quote = getQuoteString(db_name);

                if (count_desc_lines(db_desc, lineWidth)
                    + count_desc_lines(quote, lineWidth) <= height)
                {
                    if (!db_desc.empty())
                        db_desc += "$";
                    db_desc += quote;
                }
            }

            if (db_desc.empty())
            {
                if (item_type_known(item))
                {
                    description << "[ERROR: no desc for item name '" << db_name
                                << "']$";
                }
                else
                {
                    description << article_a(item.name(DESC_CAP_A, true,
                                                       false, false), false);
                    description << ".$";
                }
            }
            else
                description << db_desc;

            if (item.base_type == OBJ_WANDS
                || item.base_type == OBJ_MISSILES
                || item.base_type == OBJ_FOOD && item.sub_type == FOOD_CHUNK)
            {
                // Get rid of newline at end of description, so that
                // either the wand "no charges left" or the meat chunk
                // "unpleasant" description can follow on the same line.
                // Same for missiles' descriptions.
                description.seekp(description.tellp() - (std::streamoff)2);
                description << " ";
            }
        }
    }

    bool need_extra_line = true;
    std::string desc;
    switch (item.base_type)
    {
    // Weapons, armour, jewellery, books might be artefacts.
    case OBJ_WEAPONS:
        desc = _describe_weapon( item, verbose );
        if (desc.empty())
            need_extra_line = false;
        else
            description << desc;
        break;

    case OBJ_ARMOUR:
        desc = _describe_armour( item, verbose );
        if (desc.empty())
            need_extra_line = false;
        else
            description << desc;
        break;

    case OBJ_JEWELLERY:
        desc = _describe_jewellery( item, verbose );
        if (desc.empty())
            need_extra_line = false;
        else
            description << desc;
        break;

    case OBJ_BOOKS:
        if (!player_can_read_spellbook( item ))
        {
            description << "$This book is beyond your current level of "
                           "understanding.";
        }
        else if (!verbose
                 && (Options.dump_book_spells || is_random_artefact(item)))
        {
            append_spells( desc, item );
            if (desc.empty())
                need_extra_line = false;
            else
                description << desc;
        }
        break;

    case OBJ_MISSILES:
        description << _describe_ammo( item );
        break;

    case OBJ_WANDS:
        if (item_type_known(item))
        {
            const int max_charges = 3 * wand_charge_value(item.sub_type);
            if (item.plus < max_charges
                || !item_ident(item, ISFLAG_KNOW_PLUSES))
            {
                description << "$It can have at most " << max_charges
                            << " charges.";
            }
            else
                description << "$It is fully charged.";
        }

        if (item_ident( item, ISFLAG_KNOW_PLUSES ) && item.plus == 0
            || item.plus2 == ZAPCOUNT_EMPTY)
        {
            description << "$Unfortunately, it has no charges left.";
        }
        description << "$";
        break;

    case OBJ_CORPSES:
        if (item.sub_type == CORPSE_SKELETON)
            break;
        // intentional fall-through
    case OBJ_FOOD:
        if (item.base_type == OBJ_CORPSES || item.sub_type == FOOD_CHUNK)
        {
            if (food_is_rotten(item))
            {
                if (player_mutation_level(MUT_SAPROVOROUS) == 3)
                    description << "It looks nice and ripe.";
                else
                {
                    description << "In fact, it is rotting away before your "
                                   "eyes.";

                    if (!you.is_undead
                        && !player_mutation_level(MUT_SAPROVOROUS))
                    {
                        description << " Eating it is completely out of the "
                                       "question!";
                    }
                }
            }
            else if (player_mutation_level(MUT_SAPROVOROUS) < 3)
                description << "It looks rather unpleasant.";

            switch (mons_corpse_effect(item.plus))
            {
            case CE_POISONOUS:
                description << "$$This meat is poisonous.";
                break;
            case CE_MUTAGEN_RANDOM:
                if (you.species != SP_GHOUL)
                {
                    description << "$$Eating this meat will cause random "
                                   "mutations.";
                }
                break;
            case CE_HCL:
                if (you.species != SP_GHOUL)
                    description << "$$Eating this meat will cause rotting.";
                break;
            case CE_CONTAMINATED:
                if (player_mutation_level(MUT_SAPROVOROUS) < 3)
                {
                    description << "$$Meat like this may occasionally cause "
                                   "sickness.";
                }
                break;
            default:
                break;
            }

            if (god_hates_cannibalism(you.religion)
                   && is_player_same_species(item.plus)
                || you.religion == GOD_ZIN
                   && mons_class_intel(item.plus) >= I_NORMAL)
            {
                description << "$$" << god_name(you.religion) << " disapproves "
                               "of eating such meat.";
            }
            description << "$";
        }
        break;

    case OBJ_STAVES:
        if (item_is_rod( item ))
        {
            if (verbose)
            {
                description <<
                    "$It uses its own mana reservoir for casting spells, and "
                    "recharges automatically by channeling mana from its "
                    "wielder.";

                const int max_charges = MAX_ROD_CHARGE;
                if (item_ident(item, ISFLAG_KNOW_PLUSES))
                {
                    const int num_charges = item.plus2 / ROD_CHARGE_MULT;
                    if (max_charges > num_charges)
                    {
                        description << "$It can currently hold " << num_charges
                                    << " charges. It can be magically recharged "
                                    << "to contain up to " << max_charges
                                    << " charges.";
                    }
                    else
                        description << "$It is fully charged.";
                }
                else
                {
                    description << "$It can have at most " << max_charges
                                << " charges.";
                }
            }
            else if (Options.dump_book_spells)
            {
                append_spells( desc, item );
                if (desc.empty())
                    need_extra_line = false;
                else
                    description << desc;
            }
            std::string stats = "";
            append_weapon_stats(stats, item);
            description << stats;
            description << "$$It falls into the 'Maces & Flails' category.";
        }
        else
        {
            std::string stats = "";
            append_weapon_stats(stats, item);
            description << stats;
            description << "$$It falls into the 'Staves' category.";
        }
        break;

    case OBJ_MISCELLANY:
        if (is_deck(item))
            description << _describe_deck( item );
        break;

    case OBJ_POTIONS:
#ifdef DEBUG_BLOOD_POTIONS
        // List content of timer vector for blood potions.
        if (!dump && is_blood_potion(item))
        {
            item_def stack = static_cast<item_def>(item);
            CrawlHashTable &props = stack.props;
            ASSERT(props.exists("timer"));
            CrawlVector &timer = props["timer"].get_vector();
            ASSERT(!timer.empty());

            description << "$Quantity: " << stack.quantity
                        << "        Timer size: " << (int) timer.size();
            description << "$Timers:$";
            for (int i = 0; i < timer.size(); ++i)
                 description << (timer[i].get_long()) << "  ";
        }
#endif
        break;

    case OBJ_SCROLLS:
    case OBJ_ORBS:
    case OBJ_GOLD:
        // No extra processing needed for these item types.
        break;

    default:
        DEBUGSTR("Bad item class");
        description << "$This item should not exist. Mayday! Mayday!";
    }

    if (is_unrandom_artefact( item )
        && strlen(unrandart_descrip(2, item)) != 0)
    {
        description << "$$";
        description << unrandart_descrip(2, item);
    }

    if (!verbose && item_known_cursed( item ))
        description << "$It has a curse placed upon it.";
    else
    {
        if (verbose)
        {
            if (need_extra_line)
                description << "$";
            description << "$It";
            if (item_known_cursed( item ))
                description << " has a curse placed upon it, and it";

            const int mass = item_mass( item );
            description << " weighs around " << (mass / 10)
                        << "." << (mass % 10)
                        << " aum. "; // arbitrary unit of mass

            if (is_dumpable_artefact(item, false))
            {
                if (item.base_type == OBJ_ARMOUR
                    || item.base_type == OBJ_WEAPONS)
                {
                    description << "$$This ancient artefact cannot be changed "
                        "by magic or mundane means.";
                }
                else
                    description << "$$It is an ancient artefact.";
            }
        }
    }

    if (conduct_type ct = good_god_hates_item_handling(item))
    {
        description << "$$" << god_name(you.religion) << " opposes the use of "
                    << "such an ";

        if (ct == DID_NECROMANCY)
            description << "evil";
        else
            description << "unholy";

        description << " item.";
    }
    else if (god_hates_item_handling(item))
    {
        description << "$$" << god_name(you.religion) << " disapproves of the "
                    << "use of such an item.";
    }

    return description.str();
}

static std::string _get_feature_description_wide(int feat)
{
    return std::string();
}

void get_feature_desc(const coord_def &pos, describe_info &inf)
{
    const dungeon_feature_type feat = grd(pos);
    std::string desc      = feature_description(pos, false, DESC_CAP_A, false);
    std::string db_name   = grd(pos) == DNGN_ENTER_SHOP ? "A shop" : desc;
    std::string long_desc = getLongDescription(db_name);

    inf.body << desc << ".$$";

    // If we couldn't find a description in the database then see if
    // the feature's base name is different.
    if (long_desc.empty())
    {
        db_name   = feature_description(pos, false, DESC_CAP_A, false, true);
        long_desc = getLongDescription(db_name);
    }

    bool custom_desc = false;

    const std::string marker_desc =
        env.markers.property_at(pos, MAT_ANY, "feature_description_long");

    if (!marker_desc.empty())
    {
        long_desc   = marker_desc;
        custom_desc = true;
    }

    if (feat == DNGN_ENTER_PORTAL_VAULT && !custom_desc)
    {
        long_desc = "UNDESCRIBED PORTAL VAULT ENTRANCE.";
        custom_desc = true;
    }

    const CrawlHashTable &props = env.properties;
    if (!custom_desc && props.exists(LONG_DESC_KEY))
    {
        const CrawlHashTable &desc_table = props[LONG_DESC_KEY].get_table();

        // First try the modified name, then the base name.
        std::string key = raw_feature_description(feat);
        if (!desc_table.exists(key))
            key = raw_feature_description(feat, NUM_TRAPS, true);

        if (desc_table.exists(key))
        {
            long_desc   = desc_table[key].get_string();
            custom_desc = true;
        }

        std::string quote = getQuoteString(key);
        if (!quote.empty())
            db_name = key;
    }

    inf.body << long_desc;

    // For things which require logic
    if (!custom_desc)
        inf.body << _get_feature_description_wide(grd(pos));

    inf.quote = getQuoteString(db_name);

    // Quotes don't care about custom descriptions.
    if (props.exists(QUOTE_KEY))
    {
        const CrawlHashTable &quote_table = props[QUOTE_KEY].get_table();

        if (quote_table.exists(db_name))
            inf.quote = quote_table[db_name].get_string();
    }
}

void describe_feature_wide(const coord_def& pos)
{
    describe_info inf;
    get_feature_desc(pos, inf);
    print_description(inf);

    mouse_control mc(MOUSE_MODE_MORE);

    if (Tutorial.tutorial_left)
        tutorial_describe_pos(pos.x, pos.y);

    if (getch() == 0)
        getch();
}

void set_feature_desc_long(const std::string &raw_name,
                           const std::string &desc)
{
    ASSERT(!raw_name.empty());

    CrawlHashTable &props = env.properties;

    if (!props.exists(LONG_DESC_KEY))
        props[LONG_DESC_KEY].new_table();

    CrawlHashTable &desc_table = props[LONG_DESC_KEY].get_table();

    if (desc.empty())
        desc_table.erase(raw_name);
    else
        desc_table[raw_name] = desc;
}

void set_feature_quote(const std::string &raw_name,
                       const std::string &quote)
{
    ASSERT(!raw_name.empty());

    CrawlHashTable &props = env.properties;

    if (!props.exists(QUOTE_KEY))
        props[QUOTE_KEY].new_table();

    CrawlHashTable &quote_table = props[QUOTE_KEY].get_table();

    if (quote.empty())
        quote_table.erase(raw_name);
    else
        quote_table[raw_name] = quote;
}


void get_item_desc(const item_def &item, describe_info &inf, bool terse)
{
    // Don't use verbose descriptions if terse and the item contains spells,
    // so we can actually output these spells if space is scarce.
    const bool verbose = !terse || !item.has_spells();
    inf.body << get_item_description(item, verbose, false,
                                     Tutorial.tutorial_left);
}

// Returns true if spells can be shown to player.
static bool _show_item_description(const item_def &item)
{
    const unsigned int lineWidth = get_number_of_cols()  - 1;
    const          int height    = get_number_of_lines();

    std::string desc =
        get_item_description(item, true, false, Tutorial.tutorial_left);

    int num_lines = count_desc_lines(desc, lineWidth) + 1;

    // XXX: hack: Leave room for "Inscribe item?" and the blank line above
    // it by removing item quote.  This should really be taken care of
    // by putting the quotes into a separate DB and treating them as
    // a suffix that can be ignored by print_description().
    if (height - num_lines <= 2)
        desc = get_item_description(item, 1, false, true);

    print_description(desc);
    if (Tutorial.tutorial_left)
        tutorial_describe_item(item);

    if (item.has_spells())
    {
        if (item.base_type == OBJ_BOOKS && !player_can_read_spellbook( item ))
            return (false);

        formatted_string fs;
        item_def dup = item;
        spellbook_contents( dup, item.base_type == OBJ_BOOKS ? RBOOK_READ_SPELL
                                                             : RBOOK_USE_STAFF,
                            &fs );
        fs.display(2, -2);
        return (true);
    }

    return (false);
}

static bool _describe_spells(const item_def &item)
{
    int c = getch();
    if (c < 'a' || c > 'h')     //jmf: was 'g', but 8=h
    {
        mesclr( true );
        return (false);
    }

    const int spell_index = letter_to_index(c);

    spell_type nthing =
        which_spell_in_book(item, spell_index);
    if (nthing == SPELL_NO_SPELL)
        return (false);

    describe_spell( nthing, &item );
    return (true);
}

//---------------------------------------------------------------
//
// describe_item
//
// Describes all items in the game.
//
//---------------------------------------------------------------
void describe_item( item_def &item, bool allow_inscribe, bool shopping )
{
    if (!item.is_valid())
        return;

    while (true)
    {
        // Memorised spell while reading a spellbook.
        if (you.turn_is_over && !shopping)
            return;

        const bool spells_shown = _show_item_description(item);

        if (spells_shown)
        {
            cgotoxy(1, wherey());
            textcolor(LIGHTGREY);

            if (item.base_type == OBJ_BOOKS && in_inventory(item))
            {
                cprintf("Select a spell to read its description or to "
                        "memorise it.");
            }
            else
                cprintf("Select a spell to read its description.");

            if (_describe_spells(item))
                continue;
            return;
        }
        break;
    }

    // Don't ask if there aren't enough rows left
    if (allow_inscribe && wherey() <= get_number_of_lines() - 3)
    {
        cgotoxy(1, wherey() + 2);
        inscribe_item(item, false);
    }
    else if (getch() == 0)
        getch();
}

// There are currently two ways to inscribe an item:
// * using the inscribe command ('{') -> proper_prompt = true
// * from the inventory when viewing an item -> proper_prompt = false
//
// Thus, proper_prompt also controls whether a tutorial explanation can be
// shown, or whether the pre- and post-inscription item names need to be
// printed.
void inscribe_item(item_def &item, bool proper_prompt)
{
    if (proper_prompt)
        mpr(item.name(DESC_INVENTORY).c_str(), MSGCH_EQUIPMENT);

    const bool is_inscribed = !item.inscription.empty();
    std::string ainscrip;

    // Only allow autoinscription if we don't have all the text
    // already.
    bool need_autoinscribe = false;
    if (is_artefact(item))
    {
        ainscrip = artefact_auto_inscription(item);
        if (!ainscrip.empty()
            && (!is_inscribed
                || item.inscription.find(ainscrip) == std::string::npos))
        {
            need_autoinscribe = true;
        }
    }

    std::string prompt;
    int keyin;
    bool did_prompt = false;

    // Don't prompt for whether to inscribe in the first place if the
    // player is using '{' - unless autoinscribing or clearing an
    // existing inscription become an option.
    if (!proper_prompt || need_autoinscribe || is_inscribed)
    {
        if (!is_inscribed)
            prompt = "Press (i) to inscribe";
        else
            prompt = "Press (i) to add to or (r) to replace the inscription";

        if (need_autoinscribe || is_inscribed)
        {
            if (!need_autoinscribe || !is_inscribed)
                prompt += ", or ";
            else
                prompt += ", ";

            if (need_autoinscribe)
            {
                prompt += "(a) to autoinscribe";
                if (is_inscribed)
                    prompt += ", or ";
            }
            if (is_inscribed)
                prompt += "(c) to clear it";
        }
        prompt += ".";

        if (proper_prompt)
            mpr(prompt.c_str(), MSGCH_PROMPT);
        else
        {
            prompt = "<cyan>" + prompt + "</cyan>";
            formatted_string::parse_string(prompt).display();

            if (Tutorial.tutorial_left && wherey() <= get_number_of_lines() - 5)
                tutorial_inscription_info(need_autoinscribe, prompt);
        }
        did_prompt = true;
    }

    keyin = (did_prompt ? tolower(c_getch()) : 'i');
    switch (keyin)
    {
    case 'c':
        item.inscription.clear();
        break;
    case 'a':
        if (need_autoinscribe)
        {
            add_autoinscription(item, ainscrip);
            break;
        }
        // If autoinscription is impossible, prompt for an inscription instead.
    case 'i':
    case 'r':
    {
        if (!is_inscribed)
            prompt = "Inscribe with what? ";
        else if (keyin == 'i')
            prompt = "Add what to inscription? ";
        else
            prompt = "Replace inscription with what? ";

        if (proper_prompt)
            mpr(prompt.c_str(), MSGCH_PROMPT);
        else
        {
            prompt = EOL "<cyan>" + prompt + "</cyan>";
            formatted_string::parse_string(prompt).display();
        }

        char buf[79];
        if (!cancelable_get_line(buf, sizeof buf))
        {
            // Strip spaces from the end.
            for (int i = strlen(buf) - 1; i >= 0; --i)
            {
                if (isspace( buf[i] ))
                    buf[i] = 0;
                else
                    break;
            }

            if (strlen(buf) > 0)
            {
                if (is_inscribed && keyin == 'r')
                    item.inscription = std::string(buf);
                else
                {
                    if (is_inscribed)
                        item.inscription += ", ";

                    item.inscription += std::string(buf);
                }
            }
        }
        else if (proper_prompt)
        {
            canned_msg(MSG_OK);
            return;
        }
        break;
    }
    default:
        if (proper_prompt)
            canned_msg(MSG_OK);
        return;
    }

    if (proper_prompt)
    {
        mpr(item.name(DESC_INVENTORY).c_str(), MSGCH_EQUIPMENT);
        you.wield_change  = true;
    }

}

bool _get_spell_description(const spell_type spell, std::string &description,
                            const item_def* item = NULL)
{
    description.reserve(500);

    description  = spell_title( spell );
    description += "$$";
    const std::string long_descrip = getLongDescription(spell_title(spell));

    if (!long_descrip.empty())
        description += long_descrip;
    else
    {
        description += "This spell has no description. "
                       "Casting it may therefore be unwise. "
#ifdef DEBUG
                       "Instead, go fix it. ";
#else
                       "Please file a bug report.";
#endif
    }

    if (you_cannot_memorise(spell))
    {
        description += "$$";
        description += "You cannot memorise or cast this spell because you "
                       "are a ";
        description += lowercase_string(species_name(you.species, 0));
        description += ".";
    }
    else if (item && item->base_type == OBJ_BOOKS && in_inventory(*item))
    {
        description += "$$";
        description += "(M)emorise this spell.";
        return (true);
    }
#ifdef USE_TILE
    else
    {
        const std::string schools = spell_schools_string(spell);
        snprintf(info, INFO_SIZE,
                 "$Level: %d        School%s:  %s    (%s)",
                 spell_difficulty(spell),
                 schools.find("/") != std::string::npos ? "s" : "",
                 schools.c_str(),
                 failure_rate_to_string(spell_fail(spell)));
        description += info;

        description += "$$Power : ";
        description += spell_power_string(spell);
        description += "$Range : ";
        description += spell_range_string(spell);
        description += "$Hunger: ";
        description += spell_hunger_string(spell);
    }
#endif
    return (false);
}

void get_spell_desc(const spell_type spell, describe_info &inf)
{
    std::string desc;
    _get_spell_description(spell, desc);
    inf.body << desc;
}

//---------------------------------------------------------------
//
// describe_spell
//
// Describes (most) every spell in the game.
//
//---------------------------------------------------------------
void describe_spell(spell_type spelled, const item_def* item)
{
    std::string desc;
    bool can_mem = _get_spell_description(spelled, desc, item);
    print_description(desc);

    mouse_control mc(MOUSE_MODE_MORE);

    char ch;
    if ((ch = getch()) == 0)
        ch = getch();

    if (can_mem && toupper(ch) == 'M')
    {
        if (!learn_spell(spelled, item->sub_type, false) || !you.turn_is_over)
            more();
        redraw_screen();
    }
}

static std::string _describe_draconian_role(const monsters *mon)
{
    switch (mon->type)
    {
    case MONS_DRACONIAN_SHIFTER:
        return "It darts around disconcertingly without taking a step.";
    case MONS_DRACONIAN_SCORCHER:
        return "Its scales are sooty black from years of magical pyrotechnics.";
    case MONS_DRACONIAN_ZEALOT:
        return "In its gaze you see all the malefic power of its "
               "terrible god.";
    case MONS_DRACONIAN_ANNIHILATOR:
        return "Crackling balls of pure energy hum and spark up and down its "
               "scaled fists and arms.";
    case MONS_DRACONIAN_CALLER:
        return "It looks especially reptilian, and eager for company.";
    case MONS_DRACONIAN_MONK:
        return "It looks unnaturally strong and dangerous with its fists.";
    case MONS_DRACONIAN_KNIGHT:
        return "It wields a deadly weapon with menacing efficiency.";
    default:
        return ("");
    }
}

static std::string _describe_draconian_colour(int species)
{
    switch (species)
    {
    case MONS_BLACK_DRACONIAN:
        return "Sparks crackle and flare out of its mouth and nostrils.";
    case MONS_MOTTLED_DRACONIAN:
        return "Liquid flames drip from its mouth.";
    case MONS_YELLOW_DRACONIAN:
        return "Acid fumes swirl around it.";
    case MONS_GREEN_DRACONIAN:
        return "Venom steams and drips from its jaws.";
    case MONS_PURPLE_DRACONIAN:
        return "Its outline shimmers with wild energies.";
    case MONS_RED_DRACONIAN:
        return "Smoke pours from its nostrils.";
    case MONS_WHITE_DRACONIAN:
        return "Frost pours from its nostrils.";
    case MONS_PALE_DRACONIAN:
        return "It is cloaked in a pall of superheated steam.";
    }
    return ("");
}

static std::string _describe_draconian(const monsters *mon)
{
    std::string description;
    const int subsp = draco_subspecies( mon );

    if (subsp == MONS_DRACONIAN)
        description += "A ";
    else
        description += "A muscular ";

    switch (subsp)
    {
    case MONS_DRACONIAN:            description += "brown-";   break;
    case MONS_BLACK_DRACONIAN:      description += "black-";   break;
    case MONS_MOTTLED_DRACONIAN:    description += "mottled-"; break;
    case MONS_YELLOW_DRACONIAN:     description += "yellow-";  break;
    case MONS_GREEN_DRACONIAN:      description += "green-";   break;
    case MONS_PURPLE_DRACONIAN:     description += "purple-";  break;
    case MONS_RED_DRACONIAN:        description += "red-";     break;
    case MONS_WHITE_DRACONIAN:      description += "white-";   break;
    case MONS_PALE_DRACONIAN:       description += "pale-";    break;
    default:
        break;
    }

    description += "scaled humanoid with wings.";

    if (subsp != MONS_DRACONIAN)
    {
        const std::string drac_col = _describe_draconian_colour(subsp);
        if (!drac_col.empty())
            description += "  " + drac_col;
    }

    if (subsp != mon->type)
    {
        const std::string drac_role = _describe_draconian_role(mon);
        if (!drac_role.empty())
            description += "  " + drac_role;
    }

    return (description);
}

static const char* _get_resist_name(mon_resist_flags res_type)
{
    switch (res_type)
    {
    case MR_RES_ELEC:
        return "electricity";
    case MR_RES_POISON:
        return "poison";
    case MR_RES_FIRE:
        return "fire";
    case MR_RES_STEAM:
        return "steam";
    case MR_RES_COLD:
        return "cold";
    case MR_RES_ACID:
        return "acid";
    case MR_RES_ROTTING:
        return "rotting";
    default:
        return "buggy resistance";
    }
}

// Describe a monster's (intrinsic) resistances, speed and a few other
// attributes.
static std::string _monster_stat_description(const monsters& mon)
{
    std::ostringstream result;

    // Don't leak or duplicate resistance information for ghost demon
    // monsters, except for (very) ugly things.
    const mon_resist_def resist =
        (mons_is_ghost_demon(mon.type)
                && mon.type != MONS_UGLY_THING
                && mon.type != MONS_VERY_UGLY_THING)
            ? get_mons_class_resists(mon.type) : get_mons_resists(&mon);

    const mon_resist_flags resists[] = {
        MR_RES_ELEC,   MR_RES_POISON, MR_RES_FIRE,
        MR_RES_STEAM,  MR_RES_COLD,   MR_RES_ACID,
        MR_RES_ROTTING
    };

    std::vector<std::string> extreme_resists;
    std::vector<std::string> high_resists;
    std::vector<std::string> base_resists;
    std::vector<std::string> suscept;

    for (unsigned int i = 0; i < ARRAYSZ(resists); ++i)
    {
        int level = resist.get_resist_level(resists[i]);
        if (resists[i] == MR_RES_FIRE && resist.hellfire)
            level = 3;

        if (level != 0)
        {
            const char* attackname = _get_resist_name(resists[i]);
            level = std::max(level, -1);
            level = std::min(level,  3);
            switch (level)
            {
                case -1:
                    suscept.push_back(attackname);
                    break;
                case 1:
                    base_resists.push_back(attackname);
                    break;
                case 2:
                    high_resists.push_back(attackname);
                    break;
                case 3:
                    extreme_resists.push_back(attackname);
                    break;
            }
        }
    }

    std::vector<std::string> resist_descriptions;
    if (!extreme_resists.empty())
    {
        const std::string tmp = "extremely resistant to "
            + comma_separated_line(extreme_resists.begin(),
                                   extreme_resists.end());
        resist_descriptions.push_back(tmp);
    }
    if (!high_resists.empty())
    {
        const std::string tmp = "very resistant to "
            + comma_separated_line(high_resists.begin(), high_resists.end());
        resist_descriptions.push_back(tmp);
    }
    if (!base_resists.empty())
    {
        const std::string tmp = "resistant to "
            + comma_separated_line(base_resists.begin(), base_resists.end());
        resist_descriptions.push_back(tmp);
    }

    const char* pronoun = mons_pronoun(static_cast<monster_type>(mon.type),
                                       PRONOUN_CAP, true);

    if (!resist_descriptions.empty())
    {
        result << pronoun << " is "
               << comma_separated_line(resist_descriptions.begin(),
                                       resist_descriptions.end(),
                                       "; and ", "; ")
               << ".$";
    }

    // Is monster susceptible to anything? (On a new line.)
    if (!suscept.empty())
    {
        result << pronoun << " is susceptible to "
               << comma_separated_line(suscept.begin(), suscept.end())
               << ".$";
    }

    // Magic resistance at MAG_IMMUNE, but not for Rs, as there is then
    // too much information leak.
    if (mon.type != MONS_RAKSHASA && mon.type != MONS_MARA
        && mon.type != MONS_RAKSHASA_FAKE && mon.type != MONS_MARA_FAKE)
    {
        if (mons_immune_magic(&mon))
            result << pronoun << " is immune to magical enchantments.$";
        else // How resistant is it? Same scale as the player.
        {
            const int mr = mon.res_magic();
            if (mr >= 10)
            {
                result << pronoun << make_stringf(" is %s resistant to magic.$",
                                                  magic_res_adjective(mr).c_str());
            }
        }
    }

    if (mons_class_flag(mon.type, M_STATIONARY))
        result << pronoun << " cannot move.$";

    // These differ between ghost demon monsters, so would be spoily.
    if (!mons_is_ghost_demon(mon.type))
    {
        // Seeing/sensing invisible.
        if (mons_class_flag(mon.type, M_SEE_INVIS))
            result << pronoun << " can see invisible.$";
        else if (mons_class_flag(mon.type, M_SENSE_INVIS))
            result << pronoun << " can sense the presence of invisible creatures.$";

        // Unusual monster speed.
        const int speed = mons_base_speed(&mon);
        if (speed != 10 && speed != 0)
        {
            result << pronoun << " is ";
            if (speed < 7)
                result << "very slow";
            else if (speed < 10)
                result << "slow";
            else if (speed > 20)
                result << "extremely fast";
            else if (speed > 15)
                result << "very fast";
            else if (speed > 10)
                result << "fast";
            result << ".$";
        }
    }

    // Can the monster levitate/fly?
    // This doesn't give anything away since no (very) ugly things can
    // fly, all ghosts can fly, and for demons it's already mentioned in
    // their flavour description.
    const flight_type fly = mons_flies(&mon, false);

    if (fly != FL_NONE)
    {
        result << pronoun << " can "
               << (fly == FL_FLY ? "fly" : "levitate") << ".$";
    }

    // Unusual regeneration rates.
    if (!mons_can_regenerate(&mon))
        result << pronoun << " cannot regenerate.$";
    else if (monster_descriptor(mon.type, MDSC_REGENERATES))
        result << pronoun << " regenerates quickly.$";

    return (result.str());
}

// Fetches the monster's database description and reads it into inf.
void get_monster_db_desc(const monsters& mons, describe_info &inf,
                         bool force_seen)
{
    // For undetected mimics describe mimicked item instead.
    if (!force_seen && mons_is_unknown_mimic(&mons))
    {
        get_item_desc(get_mimic_item(&mons), inf);
        return;
    }

    if (inf.title.empty())
        inf.title = mons.full_name(DESC_CAP_A, true);

    std::string db_name = mons.base_name(DESC_DBNAME, force_seen);

    // This is somewhat hackish, but it's a good way of over-riding monsters'
    // descriptions in Lua vaults by using MonPropsMarker. This is also the
    // method used by set_feature_desc_long, etc. {due}
    if (mons.props.exists("description"))
        inf.body << mons.props["description"].get_string();
    // Don't get description for player ghosts.
    else if (mons.type != MONS_PLAYER_GHOST)
        inf.body << getLongDescription(db_name);

    // And quotes {due}
    if (mons.props.exists("quote"))
        inf.quote = mons.props["quote"].get_string();
    else
        inf.quote = getQuoteString(db_name);

    std::string symbol;
    symbol += get_monster_data(mons.type)->showchar;
    if (isupper(symbol[0]))
        symbol = "cap-" + symbol;

    std::string quote2;
    if (!mons_is_unique(mons.type))
    {
        std::string symbol_prefix = "__";
        symbol_prefix += symbol;
        symbol_prefix += "_prefix";
        inf.prefix = getLongDescription(symbol_prefix);
        quote2 = getQuoteString(symbol_prefix);
    }

    if (!inf.quote.empty() && !quote2.empty())
        inf.quote += "$";
    inf.quote += quote2;

    // Except for draconians and player ghosts, I have to admit I find the
    // following special descriptions rather pointless. I certainly can't
    // say I like them, though "It has come for your soul!" and
    // "It wants to drink your blood!" have something going for them. (jpeg)
    switch (mons.type)
    {
    case MONS_VAMPIRE:
    case MONS_VAMPIRE_KNIGHT:
    case MONS_VAMPIRE_MAGE:
        if (you.is_undead == US_ALIVE && !mons.wont_attack())
            inf.body << "$It wants to drink your blood!$";
        break;

    case MONS_REAPER:
        if (you.is_undead == US_ALIVE && !mons.wont_attack())
            inf.body <<  "$It has come for your soul!$";
        break;

    case MONS_DRACONIAN:
    case MONS_RED_DRACONIAN:
    case MONS_WHITE_DRACONIAN:
    case MONS_GREEN_DRACONIAN:
    case MONS_PALE_DRACONIAN:
    case MONS_MOTTLED_DRACONIAN:
    case MONS_BLACK_DRACONIAN:
    case MONS_YELLOW_DRACONIAN:
    case MONS_PURPLE_DRACONIAN:
    case MONS_DRACONIAN_SHIFTER:
    case MONS_DRACONIAN_SCORCHER:
    case MONS_DRACONIAN_ZEALOT:
    case MONS_DRACONIAN_ANNIHILATOR:
    case MONS_DRACONIAN_CALLER:
    case MONS_DRACONIAN_MONK:
    case MONS_DRACONIAN_KNIGHT:
    {
        inf.body << "$" << _describe_draconian( &mons );
        break;
    }

    case MONS_PLAYER_GHOST:
        if (mons.is_summoned())
            inf.body << "An illusion of " << get_ghost_description(mons) << ".$";
        else
            inf.body << "The apparition of " << get_ghost_description(mons) << ".$";
        break;

    case MONS_PANDEMONIUM_DEMON:
        inf.body << _describe_demon(mons) << "$";
        break;

    case MONS_PROGRAM_BUG:
        inf.body << "If this monster is a \"program bug\", then it's "
                "recommended that you save your game and reload.  Please report "
                "monsters who masquerade as program bugs or run around the "
                "dungeon without a proper description to the authorities.$";
        break;

    default:
        break;
    }

    if (!mons_is_unique(mons.type))
    {
        std::string symbol_suffix = "__";
        symbol_suffix += symbol;
        symbol_suffix += "_suffix";

        std::string suffix = getLongDescription(symbol_suffix);
                    suffix += getLongDescription(symbol_suffix + "_examine");

        if (!suffix.empty())
            inf.body << "$" << suffix;
    }

    // Get information on resistances, speed, etc.
    std::string result = _monster_stat_description(mons);
    if (!result.empty())
        inf.body << "$" << result;

    if (!mons_can_use_stairs(&mons))
    {
        inf.body << "$" << mons_pronoun(static_cast<monster_type>(mons.type),
                                    PRONOUN_CAP, true)
                 << " is incapable of using stairs.$";
    }

    if (mons.is_summoned() && (mons.type != MONS_RAKSHASA_FAKE
                               && mons.type != MONS_MARA_FAKE))
    {
        inf.body << "$" << "This monster has been summoned, and is thus only "
                       "temporary. Killing it yields no experience, nutrition "
                       "or items.$";
    }

    if (!inf.quote.empty())
        inf.quote += "$";

#if DEBUG_DIAGNOSTICS
    if (mons.can_use_spells())
    {
        const monster_spells &hspell_pass = mons.spells;
        bool found_spell = false;

        for (int i = 0; i < NUM_MONSTER_SPELL_SLOTS; ++i)
        {
            if (hspell_pass[i] != SPELL_NO_SPELL)
            {
                if (!found_spell)
                {
                    inf.body << "$$Monster Spells:$";
                    found_spell = true;
                }

                inf.body << "    " << i << ": "
                         << spell_title(hspell_pass[i])
                         << " (" << static_cast<int>(hspell_pass[i])
                         << ")$";
            }
        }
    }

    bool has_item = false;
    for (int i = 0; i < NUM_MONSTER_SLOTS; ++i)
    {
        if (mons.inv[i] != NON_ITEM)
        {
            if (!has_item)
            {
                inf.body << "$Monster Inventory:$";
                has_item = true;
            }
            inf.body << "    " << i << ") "
                     << mitm[mons.inv[i]].name(DESC_NOCAP_A, false, true);
        }
    }

    if (mons.props.exists("blame"))
    {
        inf.body << "$$Monster blame chain:$";

        const CrawlVector& blame = mons.props["blame"].get_vector();

        for (CrawlVector::const_iterator it = blame.begin();
             it != blame.end(); ++it)
        {
            inf.body << "    " << it->get_string() << "$";
        }
    }
#endif
}

void describe_monsters(const monsters& mons, bool force_seen)
{
    describe_info inf;
    get_monster_db_desc(mons, inf, force_seen);
    print_description(inf);

    mouse_control mc(MOUSE_MODE_MORE);

    // TODO enne - this should really move into get_monster_db_desc
    // and an additional tutorial string added to describe_info.
    if (Tutorial.tutorial_left)
        tutorial_describe_monster(&mons);

    if (getch() == 0)
        getch();
}

// Describes the current ghost's previous owner. The caller must
// prepend "The apparition of" or whatever and append any trailing
// punctuation that's wanted.
std::string get_ghost_description(const monsters &mons, bool concise)
{
    ASSERT(mons.ghost.get());
    std::ostringstream gstr;

    const ghost_demon &ghost = *(mons.ghost);

    const species_type gspecies = ghost.species;

    // We're fudging stats so that unarmed combat gets based off
    // of the ghost's species, not the player's stats... exact
    // stats aren't required anyways, all that matters is whether
    // dex >= str. -- bwr
    const int dex = 10;
    int str = 5;

    switch (gspecies)
    {
    case SP_MOUNTAIN_DWARF:
    case SP_DEEP_DWARF:
    case SP_TROLL:
    case SP_OGRE:
    case SP_MINOTAUR:
    case SP_HILL_ORC:
    case SP_CENTAUR:
    case SP_NAGA:
    case SP_MUMMY:
    case SP_GHOUL:
        str += 10;
        break;

    case SP_HUMAN:
    case SP_DEMIGOD:
    case SP_DEMONSPAWN:
        str += 5;
        break;

    default:
        break;
    }

    gstr << ghost.name << " the "
         << skill_title(ghost.best_skill,
                        (unsigned char)ghost.best_skill_level,
                        gspecies,
                        str, dex, ghost.religion)
         << ", a"
         << ((ghost.xl <  4) ? " weakling" :
             (ghost.xl <  7) ? "n average" :
             (ghost.xl < 11) ? "n experienced" :
             (ghost.xl < 16) ? " powerful" :
             (ghost.xl < 22) ? " mighty" :
             (ghost.xl < 26) ? " great" :
             (ghost.xl < 27) ? "n awesomely powerful"
                             : " legendary")
         << " ";

    if (concise)
    {
        gstr << get_species_abbrev(gspecies)
             << get_class_abbrev(ghost.job);
    }
    else
    {
        gstr << species_name(gspecies,
                             ghost.xl)
             << " "
             << get_class_name(ghost.job);
    }

    if (ghost.religion != GOD_NO_GOD)
    {
        gstr << " of "
             << god_name(ghost.religion);
    }

    return (gstr.str());
}

extern ability_type god_abilities[MAX_NUM_GODS][MAX_GOD_ABILITIES];

static bool _print_final_god_abil_desc(int god, const std::string &final_msg,
                                       const ability_type abil)
{
    // If no message then no power.
    if (final_msg.empty())
        return (false);

    std::ostringstream buf;
    buf << final_msg;
    const std::string cost = "(" + make_cost_description(abil) + ")";
    if (cost != "(None)")
    {
        const int spacesleft = 79 - buf.str().length();
        buf << std::setw(spacesleft) << cost;
    }
    cprintf("%s\n", buf.str().c_str());

    return (true);
}

static bool _print_god_abil_desc(int god, int numpower)
{
    const char* pmsg = god_gain_power_messages[god][numpower];

    // If no message then no power.
    if (!pmsg[0])
        return (false);

    std::string buf;
    if (isupper(pmsg[0]))
        buf = pmsg;             // Complete sentence given.
    else
    {
        buf = "You can ";
        buf += pmsg;
        buf += ".";
    }

    // This might be ABIL_NON_ABILITY for passive abilities.
    const ability_type abil = god_abilities[god][numpower];
    _print_final_god_abil_desc(god, buf, abil);

    return (true);
}

static std::string _describe_favour_generic(god_type which_god)
{
    const std::string godname = god_name(which_god);
    return (you.piety > 130) ? "A prized avatar of " + godname + ".":
           (you.piety > 100) ? "A shining star in the eyes of " + godname + "." :
           (you.piety >  70) ? "A rising star in the eyes of " + godname + "." :
           (you.piety >  40) ? godname + " is most pleased with you." :
           (you.piety >  20) ? godname + " has noted your presence." :
           (you.piety >   5) ? godname + " is noncommittal."
                             : "You are beneath notice.";
}

//---------------------------------------------------------------
//
// describe_god
//
// Describes the player's standing with his deity.
//
//---------------------------------------------------------------

std::string describe_favour(god_type which_god)
{
    if (player_under_penance())
    {
        const int penance = you.penance[which_god];
        return (penance >= 50) ? "Godly wrath is upon you!" :
               (penance >= 20) ? "You've transgressed heavily! Be penitent!" :
               (penance >= 5 ) ? "You are under penance."
                               : "You should show more discipline.";
    }

    return (which_god == GOD_XOM) ? describe_xom_favour(true)
                                  : _describe_favour_generic(which_god);
}

static std::string _religion_help(god_type god)
{
    std::string result = "";

    switch (god)
    {
    case GOD_ZIN:
        result += "You can pray at an altar to donate your money.";
        if (!player_under_penance() && you.piety > 160
            && !you.num_gifts[god])
        {
            if (!result.empty())
                result += " ";

            result += "You can have all your mutations cured.";
        }
        break;

    case GOD_SHINING_ONE:
    {
        result += "You can pray at an altar to sacrifice evil items.";
        int halo_size = you.halo_radius();
        if (halo_size > 0)
        {
            result += "You radiate a ";

            if (halo_size > 6)
                result += "large ";
            else if (halo_size > 3)
                result += "";
            else
                result += "small ";

            result += "righteous aura, and all beings within it are "
                      "easier to hit.";
        }
        if (!player_under_penance() && you.piety > 160
            && !you.num_gifts[god])
        {
            if (!result.empty())
                result += " ";

            result += "You can pray at an altar to have your weapon "
                      "blessed, especially a long blade or demon whip.";
        }
        break;
    }

    case GOD_LUGONU:
        if (!player_under_penance() && you.piety > 160
            && !you.num_gifts[god])
        {
            result += "You can pray at an altar to have your weapon "
                      "corrupted.";
        }
        break;

    case GOD_BEOGH:
        result += "You can pray to sacrifice all orcish remains on your "
                  "square. Inscribe orcish remains with !p, !* or =p to avoid "
                  "sacrificing them accidentally.";
        break;

    case GOD_NEMELEX_XOBEH:
        result += "You can pray to sacrifice all items on your square. "
                  "Inscribe items with !p, !* or =p to avoid sacrificing "
                  "them accidentally.";
        break;

    case GOD_VEHUMET:
        if (you.piety >= piety_breakpoint(1))
        {
            result += god_name(god) + " assists you in casting "
                      "Conjurations and Summonings.";
        }
        break;

    default:
        break;
    }

    if (god_likes_fresh_corpses(god))
    {
        if (!result.empty())
            result += " ";

        result += "You can pray to sacrifice all fresh corpses on your "
                  "square. Inscribe fresh corpses with !p, !* or =p to avoid "
                  "sacrificing them accidentally.";
    }

    return result;
}

// The various titles granted by the god of your choice.  Note that Xom
// doesn't use piety the same way as the other gods, so these are just
// placeholders.
const char *divine_title[NUM_GODS][8] =
{
    // No god.
    {"Buglet",             "Firebug",               "Bogeybug",                 "Bugger",
     "Bugbear",            "Bugged One",            "Giant Bug",                "Lord of the Bugs"},

    // Zin.
    {"Sinner",             "Anchorite",             "Apologist",                "Pious",
     "Devout",             "Orthodox",              "Immaculate",               "Bringer of Law"},

    // The Shining One.
    {"Sinner",             "Acolyte",               "Righteous",                "Unflinching",
     "Holy Warrior",       "Exorcist",              "Demon Slayer",             "Bringer of Light"},

    // Kikubaaqudgha -- scholarly death.
    {"Sinner",             "Purveyor of Pain",      "Death's Scholar",          "Merchant of Misery",
     "Death's Artisan",    "Dealer of Despair",     "Black Sun",                "Lord of Darkness"},

    // Yredelemnul -- zombie death.
    {"Sinner",             "Zealot",                "Exhumer",                  "Fey %s",
     "Soul Tainter",       "Sculptor of Flesh",     "Harbinger of Death",       "Grim Reaper"},

    // Xom.
    {"Toy",                "Toy",                   "Toy",                      "Toy",
     "Toy",                "Toy",                   "Toy",                      "Toy"},

    // Vehumet -- battle mage theme.
    {"Meek",               "Sorcerer's Apprentice", "Scholar of Destruction",   "Caster of Ruination",
     "Battle Magician",    "Warlock",               "Annihilator",              "Luminary of Lethal Lore"},

    // Okawaru -- battle theme.
    {"Coward",             "Struggler",             "Combatant",                "Warrior",
     "Knight",             "Warmonger",             "Commander",                "Victor of a Thousand Battles"},

    // Makhleb -- chaos theme.
    {"Orderly",            "Spawn of Chaos",        "Disciple of Annihilation", "Fanfare of Bloodshed",
     "Fiendish",           "Demolition %s",         "Pandemonic",               "Champion of Chaos"},

    // Sif Muna -- scholarly theme.
    {"Ignorant",           "Disciple",              "Student",                  "Adept",
     "Scribe",             "Scholar",               "Sage",                     "Genius of the Arcane"},

    // Trog -- anger theme.
    {"Faithless",          "Troglodyte",            "Angry Troglodyte",         "Frenzied",
     "%s of Prey",         "Rampant",               "Wild %s",                  "Bane of Scribes"},

    // Nemelex Xobeh -- alluding to Tarot and cards.
    {"Unlucky %s",         "Pannier",               "Jester",                   "Fortune-Teller",
     "Soothsayer",         "Magus",                 "Cardsharp",                "Hand of Fortune"},

    // Elyvilon.
    {"Sinner",             "Comforter",             "Caregiver",                "Practitioner",
     "Pacifier",           "Purifying %s",          "Faith Healer",             "Bringer of Life"},

    // Lugonu -- distortion theme.
    {"Faithless",          "Abyss-Baptised",        "Unweaver",                 "Distorting %s",
     "Agent of Entropy",   "Schismatic",            "Envoy of Void",            "Corrupter of Planes"},

    // Beogh -- messiah theme.
    {"Apostate",           "Messenger",             "Proselytiser",             "Priest",
     "Missionary",         "Evangelist",            "Apostle",                  "Messiah"},

    // Jiyva -- slime and jelly theme.
    {"Scum",               "Jelly",                 "Squelcher",                "Dissolver",
     "Putrid Slime",       "Consuming %s",          "Archjelly",                "Royal Jelly"},

    // Fedhas Madash -- nature theme.  Titles could use some work
    {"Walking Fertiliser", "Green %s",           "Inducer",                  "Photosynthesist",
     "Planter",            "Sporadic Warrior",   "Nimbus",                   "Force of Nature"},

    // Cheibriados -- slow theme
    {"Unwound %s",         "Timekeeper",            "Righteous Timekeeper",     "Chronographer",
     "Splendid Chronographer", "Chronicler",        "Eternal Chronicler",       "Ticktocktomancer"}
};

static int _piety_level()
{
    return ((you.piety >  160) ? 7 :
            (you.piety >= 120) ? 6 :
            (you.piety >= 100) ? 5 :
            (you.piety >=  75) ? 4 :
            (you.piety >=  50) ? 3 :
            (you.piety >=  30) ? 2 :
            (you.piety >    5) ? 1
                               : 0 );

}

std::string god_title(god_type which_god)
{
    std::string title;
    if (you.penance[which_god])
        title = divine_title[which_god][0];
    else
        title = divine_title[which_god][_piety_level()];

    title = replace_all(title, "%s",
                        species_name(you.species, 1, true, false));

    return (title);
}

static void _detailed_god_description(god_type which_god)
{
    clrscr();

    const int width = std::min(80, get_number_of_cols());

    std::string godname = god_name(which_god, true);
    int len = get_number_of_cols() - godname.length();
    textcolor(god_colour(which_god));
    cprintf("%s%s" EOL, std::string(len / 2, ' ').c_str(), godname.c_str());
    textcolor(LIGHTGREY);
    cprintf(EOL);

    std::string broken;
    if (which_god != GOD_NEMELEX_XOBEH)
    {
        broken = get_god_powers(which_god);
        if (!broken.empty())
        {
            linebreak_string2(broken, width);
            formatted_string::parse_block(broken, false).display();
            cprintf(EOL);
            cprintf(EOL);
        }
    }

    if (which_god != GOD_XOM)
    {
        broken = get_god_likes(which_god, true);
        linebreak_string2(broken, width);
        formatted_string::parse_block(broken, false).display();

        broken = get_god_dislikes(which_god, true);
        if (!broken.empty())
        {
            cprintf(EOL);
            cprintf(EOL);
            linebreak_string2(broken, width);
            formatted_string::parse_block(broken, false).display();
        }
        // Some special handling.
        broken = "";
        switch (which_god)
        {
        case GOD_TROG:
            broken = "Note that Trog does not demand training of the "
                     "Invocations skill. All abilities are purely based on "
                     "piety.";
            break;

        case GOD_ZIN:
            broken = "Zin will feed starving followers upon <w>p</w>rayer.";
            break;

        case GOD_ELYVILON:
            broken = "Using your healing abilities on monsters may pacify "
                     "hostile ones, turning them neutral. Pacification "
                     "works best on natural beasts, worse on humanoids of "
                     "your species, worse on other humanoids, and worst of "
                     "all on demons and undead. Whether it succeeds or not, "
                     "all costs are spent. If it does succeed, the monster "
                     "is healed and you gain half of its experience value "
                     "and possibly some piety. Otherwise, the monster is "
                     "unaffected and you gain nothing. Pacified monsters "
                     "try to leave the level.";
            break;

        case GOD_NEMELEX_XOBEH:
            if (which_god == you.religion)
            {
                broken = "The piety increase when sacrificing mostly depends "
                         "on the value of the item. To prevent items from "
                         "being accidentally sacrificed, you can "
                         "<w>i</w>nscribe them with <w>!p</w> (protects the "
                         "whole stack), with <w>=p</w> (protects only the "
                         "item), or with <w>!D</w> (causes item to be ignored "
                         "in sacrifices)."
                         EOL EOL
                         "Nemelex Xobeh gifts various types of decks of cards. "
                         "Each deck type comes in three power levels: plain, "
                         "ornate, legendary. The latter contain very powerful "
                         "card effects, potentially hazardous. High piety and "
                         "Evocations skill help here, as the power of Nemelex' "
                         "abilities is governed by Evocations instead of "
                         "Invocations. The type of the deck gifts strongly "
                         "depends on the dominating item class sacrificed:" EOL
                         "  decks of Escape      -- armour" EOL
                         "  decks of Destruction -- weapons and ammunition" EOL
                         "  decks of Dungeons    -- jewellery, books, "
                                                    "miscellaneous items" EOL
                         "  decks of Summoning   -- corpses, chunks, blood" EOL
                         "  decks of Wonders     -- consumables: food, potions, "
                                                    "scrolls, wands" EOL;
            }
        default:
            break;
        }

        if (!broken.empty())
        {
            cprintf(EOL);
            cprintf(EOL);
            linebreak_string2(broken, width);
            formatted_string::parse_block(broken, false).display();
        }
    }

    const int bottom_line = std::min(30, get_number_of_lines());

    cgotoxy(1, bottom_line);
    formatted_string::parse_string(
#ifndef USE_TILE
        "Press '<w>!</w>'"
#else
        "<w>Right-click</w>"
#endif
        " to toggle between the overview and the more detailed "
        "description.").display();

    mouse_control mc(MOUSE_MODE_MORE);

    const int keyin = getch();
    if (keyin == '!' || keyin == CK_MOUSE_CMD)
        describe_god(which_god, true);
}

void describe_god( god_type which_god, bool give_title )
{
    int colour;              // Colour used for some messages.

    clrscr();

    if (give_title)
    {
        textcolor( WHITE );
        cprintf( "                                  Religion" EOL );
        textcolor( LIGHTGREY );
    }

    if (which_god == GOD_NO_GOD) //mv: No god -> say it and go away.
    {
        cprintf( EOL "You are not religious." );
        get_ch();
        return;
    }

    colour = god_colour(which_god);

    // Print long god's name.
    textcolor(colour);
    cprintf( "%s", god_name(which_god, true).c_str());
    cprintf(EOL EOL);

    // Print god's description.
    textcolor(LIGHTGREY);

    std::string god_desc = getLongDescription(god_name(which_god));
    const int numcols = get_number_of_cols();
    cprintf("%s", get_linebreak_string(god_desc.c_str(), numcols).c_str());

    // Title only shown for our own god.
    if (you.religion == which_god)
    {
        // Print title based on piety.
        cprintf(EOL "Title - ");
        textcolor(colour);

        std::string title = god_title(which_god);
        cprintf("%s", title.c_str());
    }

    // mv: Now let's print favour as Brent suggested.
    // I know these messages aren't perfect so if you can think up
    // something better, do it.

    textcolor(LIGHTGREY);
    cprintf(EOL EOL "Favour - ");
    textcolor(colour);

    //mv: Player is praying at altar without appropriate religion.
    // It means player isn't checking his own religion and so we only
    // display favour and go out.
    if (you.religion != which_god)
    {
        textcolor(colour);
        int which_god_penance = you.penance[which_god];

        // Give more appropriate message for the good gods.
        if (which_god_penance > 0 && is_good_god(which_god))
        {
            if (is_good_god(you.religion))
                which_god_penance = 0;
            else if (!god_hates_your_god(which_god) && which_god_penance >= 5)
                which_god_penance = 2; // == "Come back to the one true church!"
        }

        cprintf( (which_god == GOD_NEMELEX_XOBEH
                     && which_god_penance > 0 && which_god_penance <= 100)
                                             ? "%s doesn't play fair with you." :
                 (which_god_penance >= 50)   ? "%s's wrath is upon you!" :
                 (which_god_penance >= 20)   ? "%s is annoyed with you." :
                 (which_god_penance >=  5)   ? "%s well remembers your sins." :
                 (which_god_penance >   0)   ? "%s is ready to forgive your sins." :
                 (you.worshipped[which_god]) ? "%s is ambivalent towards you."
                                             : "%s is neutral towards you.",
                 god_name(which_god).c_str() );
    }
    else
    {
        cprintf(describe_favour(which_god).c_str());

        //mv: The following code shows abilities given by your god (if any).

        textcolor(LIGHTGREY);
        cprintf(EOL EOL "Granted powers:                                                          (Cost)" EOL);
        textcolor(colour);

        // mv: Some gods can protect you from harm.
        // The god isn't really protecting the player - only sometimes saving
        // his life.
        bool have_any = false;

        if (harm_protection_type hpt =
                god_protects_from_harm(which_god, false))
        {
            have_any = true;

            int prayer_prot = 0;

            if (hpt == HPT_PRAYING || hpt == HPT_PRAYING_PLUS_ANYTIME
                || hpt == HPT_RELIABLE_PRAYING_PLUS_ANYTIME)
            {
                prayer_prot = 100 - 3000/you.piety;
            }

            int prot_chance = 10 + you.piety/10 + prayer_prot; // chance * 100

            const char *how = (prot_chance >= 85) ? "carefully" :
                              (prot_chance >= 55) ? "often" :
                              (prot_chance >= 25) ? "sometimes"
                                                  : "occasionally";
            const char *when =
                (hpt == HPT_PRAYING)              ? " during prayer" :
                (hpt == HPT_PRAYING_PLUS_ANYTIME) ? ", especially during prayer" :
                (hpt == HPT_RELIABLE_PRAYING_PLUS_ANYTIME)
                                                  ? ", and always does so during prayer"
                                                  : "";

            std::string buf = god_name(which_god);
            buf += " ";
            buf += how;
            buf += " watches over you";
            buf += when;
            buf += ".";

            _print_final_god_abil_desc(which_god, buf,
                (hpt == HPT_RELIABLE_PRAYING_PLUS_ANYTIME) ?
                    ABIL_HARM_PROTECTION_II : ABIL_HARM_PROTECTION);
        }

        if (which_god == GOD_ZIN)
        {
            if (zin_sustenance(false))
            {
                have_any = true;
                std::string buf = "Praying to ";
                buf += god_name(which_god);
                buf += " will provide sustenance if starving.";
                _print_final_god_abil_desc(which_god, buf,
                                           ABIL_ZIN_SUSTENANCE);
            }
            const char *how = (you.piety >= 150) ? "carefully" :
                              (you.piety >= 100) ? "often" :
                              (you.piety >=  50) ? "sometimes" :
                                                   "occasionally";

            cprintf("%s %s shields you from unclean and chaotic effects." EOL,
                    god_name(which_god).c_str(), how);
        }
        else if (which_god == GOD_SHINING_ONE)
        {
            have_any = true;
            const char *how = (you.piety >= 150) ? "carefully" :
                              (you.piety >= 100) ? "often" :
                              (you.piety >=  50) ? "sometimes" :
                                                   "occasionally";

            cprintf("%s %s shields you from negative energy." EOL,
                    god_name(which_god).c_str(), how);
        }
        else if (which_god == GOD_TROG)
        {
            have_any = true;
            std::string buf = "You can call upon ";
            buf += god_name(which_god);
            buf += " to burn spellbooks in your surroundings.";
            _print_final_god_abil_desc(which_god, buf,
                                       ABIL_TROG_BURN_SPELLBOOKS);
        }
        else if (which_god == GOD_ELYVILON)
        {
            have_any = true;
            std::string buf = "You can destroy weapons on the ground in ";
            buf += god_name(which_god);
            buf += "'s name.";
            _print_final_god_abil_desc(which_god, buf,
                                       ABIL_ELYVILON_DESTROY_WEAPONS);
        }
        else if (which_god == GOD_YREDELEMNUL)
        {
            if (yred_injury_mirror(false))
            {
                have_any = true;
                std::string buf = god_name(which_god);
                buf += " mirrors your injuries on your foes during prayer.";
                _print_final_god_abil_desc(which_god, buf,
                                           ABIL_YRED_INJURY_MIRROR);
            }
        }
        else if (which_god == GOD_JIYVA)
        {
            if (jiyva_grant_jelly(false))
            {
                have_any = true;
                std::string buf = "You can pray to create a jelly shield.";
                _print_final_god_abil_desc(which_god, buf,
                                           ABIL_JIYVA_JELLY_SHIELD);
            }
        }
        else if (which_god == GOD_FEDHAS)
        {
            have_any = true;

            std::string buf = "You can speed up decomposition.";
            _print_final_god_abil_desc(which_god, buf,
                                       ABIL_FEDHAS_FUNGAL_BLOOM);
            _print_final_god_abil_desc(which_god,
                                       "You can walk through plants.",
                                       ABIL_NON_ABILITY);
            _print_final_god_abil_desc(which_god,
                                       "You can fire through allied plants.",
                                       ABIL_NON_ABILITY);
        }

        // mv: No abilities (except divine protection) under penance
        if (!player_under_penance())
        {
            for (int i = 0; i < MAX_GOD_ABILITIES; ++i)
                if (you.piety >= piety_breakpoint(i)
                    && _print_god_abil_desc(which_god, i))
                {
                    have_any = true;
                }
        }
        if (!have_any)
            cprintf( "None." EOL );
    }

    int bottom_line = get_number_of_lines();
    if (bottom_line > 30)
        bottom_line = 30;

    // Only give this additional information for worshippers.
    if (which_god == you.religion)
    {
        std::string extra = get_linebreak_string(_religion_help(which_god),
                                                 numcols).c_str();
        cgotoxy(1, bottom_line - std::count(extra.begin(), extra.end(), '\n')-1,
                GOTO_CRT);
        textcolor(LIGHTGREY);
        cprintf( "%s", extra.c_str() );
    }

    cgotoxy(1, bottom_line);
    textcolor(LIGHTGREY);
    formatted_string::parse_string(
#ifndef USE_TILE
        "Press '<w>!</w>'"
#else
        "<w>Right-click</w>"
#endif
        " to toggle between the overview and the more detailed "
        "description.").display();

    mouse_control mc(MOUSE_MODE_MORE);
    const int keyin = getch();
    if (keyin == '!' || keyin == CK_MOUSE_CMD)
        _detailed_god_description(which_god);
}

std::string get_skill_description(int skill, bool need_title)
{
    std::string lookup = skill_name(skill);
    std::string result = "";

    if (need_title)
    {
        result = lookup;
        result += EOL EOL;
    }

    result += getLongDescription(lookup);

    switch (skill)
    {
    case SK_UNARMED_COMBAT:
    {
        // Give a detailed listing of what attacks the character may perform.
        std::vector<std::string> unarmed_attacks;

        if (you.attribute[ATTR_TRANSFORMATION] == TRAN_DRAGON
            || player_genus(GENPC_DRACONIAN)
            || you.species == SP_MERFOLK && you.swimming()
            || player_mutation_level( MUT_STINGER ))
        {
            // TSO worshippers will not use their venomous tails.
            if (you.religion != GOD_SHINING_ONE
                || !player_mutation_level(MUT_STINGER))
            {
                unarmed_attacks.push_back("slap with your tail");
            }
        }

        if (player_mutation_level(MUT_FANGS)
            || you.attribute[ATTR_TRANSFORMATION] == TRAN_DRAGON)
        {
            unarmed_attacks.push_back("bite with your sharp teeth");
        }
        else if (player_mutation_level(MUT_BEAK))
            unarmed_attacks.push_back("peck with your beak");

        if (player_mutation_level(MUT_HORNS))
            unarmed_attacks.push_back("headbutt with your horns");
        else if (you.species == SP_NAGA)
            unarmed_attacks.push_back("do a headbutt attack");

        if (player_mutation_level(MUT_HOOVES))
            unarmed_attacks.push_back("kick with your hooves");
        else if (player_mutation_level(MUT_TALONS))
            unarmed_attacks.push_back("claw with your talons");
        else if (you.species != SP_NAGA
                 && (you.species != SP_MERFOLK || !you.swimming()))
        {
            unarmed_attacks.push_back("deliver a kick");
        }

        if (!you.weapon())
            unarmed_attacks.push_back("throw a punch");
        else if (!you.shield())
            unarmed_attacks.push_back("punch with your free hand");

        if (!unarmed_attacks.empty())
        {
            std::string broken = "For example, you could ";
                        broken += comma_separated_line(unarmed_attacks.begin(),
                                                       unarmed_attacks.end(),
                                                       " or ", ", ");
                        broken += ".";
            linebreak_string2(broken, 72);

            result += EOL;
            result += broken;
        }
        break;
    }

    case SK_INVOCATIONS:
        if (you.species == SP_DEMIGOD)
        {
            result += EOL;
            result += "How on earth did you manage to pick this up?";
        }
        else if (you.religion == GOD_TROG)
        {
            result += EOL;
            result += "Note that Trog doesn't use Invocations, its being too "
                      "closely connected to magic.";
        }
        else if (you.religion == GOD_NEMELEX_XOBEH)
        {
            result += EOL;
            result += "Note that Nemelex uses Evocations rather than "
                      "Invocations.";
        }
        break;

    case SK_EVOCATIONS:
        if (you.religion == GOD_NEMELEX_XOBEH)
        {
            result += EOL;
            result += "This is the skill all of Nemelex' abilities rely on.";
        }
        break;

    case SK_SPELLCASTING:
        if (you.religion == GOD_TROG)
        {
            result += EOL;
            result += "Keep in mind, though, that Trog will greatly disapprove "
                      "of this.";
        }
        break;
    default:
        // No further information.
        break;
    }

    return result;
}

void describe_skill(int skill)
{
    std::ostringstream data;

    data << get_skill_description(skill, true);

    print_description(data.str());
    if (getch() == 0)
        getch();
}