summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mutation.cc
blob: c1919d0750412d541511f7867061cfd2323bdf84 (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
/*
 *  File:       mutation.cc
 *  Summary:    Functions for handling player mutations.
 *  Written by: Linley Henzell
 */

#include "AppHdr.h"
#include "mutation.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sstream>

#if defined(UNIX) && !defined(USE_TILE)
#include "libunix.h"
#endif

#include "externs.h"

#include "abl-show.h"
#include "cio.h"
#include "delay.h"
#include "defines.h"
#include "effects.h"
#include "env.h"
#include "files.h"
#include "format.h"
#include "godabil.h"
#include "itemprop.h"
#include "macro.h"
#include "menu.h"
#include "notes.h"
#include "ouch.h"
#include "player.h"
#include "religion.h"
#include "random.h"
#include "skills2.h"
#include "transform.h"
#include "tutorial.h"
#include "view.h"
#include "xom.h"

static int _body_covered();

const char *troll_claw_descrip[4] = {
    "You have claws for hands.",
    "You have sharp claws for hands.",
    "You have very sharp claws for hands.",
    "You have claws sharper than steel for hands."
};

const char *troll_claw_gain[3] = {
    "Your claws sharpen.",
    "Your claws sharpen.",
    "Your claws steel!"
};

const char *troll_claw_lose[3] = {
    "Your claws look duller.",
    "Your claws look duller.",
    "Your claws feel softer."
};

const char *naga_speed_descrip[4] = {
    "You cover ground very slowly.",    // 10*14/10 = 14
    "You cover ground rather slowly.",  //  8*14/10 = 11
    "You cover ground rather quickly.", //  7*14/10 =  9
    "You cover ground quickly."         //  6*14/10 =  8
};

const char *centaur_deformed_descrip[3] = {
    "Armour fits poorly on your equine body.",
    "Armour fits poorly on your deformed equine body.",
    "Armour fits poorly on your badly deformed equine body."
};

const char *naga_deformed_descrip[3] = {
    "Armour fits poorly on your serpentine body.",
    "Armour fits poorly on your deformed serpentine body.",
    "Armour fits poorly on your badly deformed serpentine body."
};

// mutation definitions:
// first  number  = probability (0 means it doesn't appear naturally
//                  unless you have some level of it already)
// second number  = maximum levels
// first  boolean = is mutation mostly bad?
// second boolean = is mutation physical, i.e. external only?
// first  strings = what to show in 'A'
// second strings = message given when gaining the mutation
// third  strings = message given when losing the mutation
// fourth string  = wizard-mode name of mutation
mutation_def mutation_defs[] = {
    { MUT_TOUGH_SKIN,                10,  3, false,  true,
      {"You have tough skin (AC +1).",
       "You have very tough skin (AC +2).",
       "You have extremely tough skin (AC +3)."},

      {"Your skin toughens.",
       "Your skin toughens.",
       "Your skin toughens."},

      {"Your skin feels delicate.",
       "Your skin feels delicate.",
       "Your skin feels delicate."},

      "tough skin"
    },

    { MUT_STRONG,                     8, 14, false,  true,
      {"Your muscles are strong (Str +", "", ""},
      {"", "", ""},
      {"", "", ""},
      "strong"
    },
    { MUT_CLEVER,                     8, 14, false,  true,
      {"Your mind is acute (Int +", "", ""},
      {"", "", ""},
      {"", "", ""},
      "clever"
    },
    { MUT_AGILE,                      8, 14, false,  true,
      {"You are agile (Dex +", "", ""},
      {"", "", ""},
      {"", "", ""},
      "agile"
    },
    { MUT_GREEN_SCALES,               2,  3, false,  true,
      {"You are partially covered in green scales (AC +1).",
       "You are mostly covered in green scales (AC +3).",
       "You are covered in green scales (AC +5)."},

      {"Green scales grow over part of your body.",
       "Green scales spread over more of your body.",
       "Green scales cover you completely."},

      {"Your green scales disappear.",
       "Your green scales recede somewhat.",
       "Your green scales recede somewhat."},

      "green scales"
    },
    { MUT_BLACK_SCALES,               1,  3, false,  true,
      {"You are partially covered in thick black scales (AC +3, Dex -1).",
       "You are mostly covered in thick black scales (AC +6, Dex -2).",
       "You are completely covered in thick black scales (AC +9, Dex -3)."},

      {"Thick black scales grow over part of your body.",
       "Thick black scales spread over more of your body.",
       "Thick black scales cover you completely."},

      {"Your black scales disappear.",
       "Your black scales recede somewhat.",
       "Your black scales recede somewhat."},

      "black scales"
    },
    { MUT_GREY_SCALES,                2,  3, false,  true,
      {"You are partially covered in supple grey scales (AC +1).",
       "You are mostly covered in supple grey scales (AC +2).",
       "You are completely covered in supple grey scales (AC +3)."},

      {"Supple grey scales grow over part of your body.",
       "Supple grey scales spread over more of your body.",
       "Supple grey scales cover you completely."},

      {"Your grey scales disappear.",
       "Your grey scales recede somewhat.",
       "Your grey scales recede somewhat."},

      "grey scales"
    },
    { MUT_BONEY_PLATES,               1,  3, false,  true,
      {"You are protected by plates of bone (AC +2, Dex -1).",
       "You are protected by plates of bone (AC +3, Dex -2).",
       "You are protected by plates of bone (AC +4, Dex -3)."},

      {"You grow protective plates of bone.",
       "You grow more protective plates of bone.",
       "You grow more protective plates of bone."},

      {"Your bony plates shrink away.",
       "Your bony plates shrink.",
       "Your bony plates shrink."},

      "boney plates"
    },
    { MUT_REPULSION_FIELD,            1,  3, false, false,
      {"You are surrounded by a mild repulsion field (EV +1).",
       "You are surrounded by a moderate repulsion field (EV +3).",
       "You are surrounded by a strong repulsion field "
       "(EV +5; repel missiles)."},

      {"You begin to radiate repulsive energy.",
       "Your repulsive radiation grows stronger.",
       "Your repulsive radiation grows stronger."},

      {"You feel attractive.",
       "You feel attractive.",
       "You feel attractive."},

      "repulsion field"
    },

    { MUT_POISON_RESISTANCE,          4,  1, false, false,
      {"Your system is resistant to poisons.", "", ""},
      {"You feel healthy.", "",  ""},
      {"You feel a little less healthy.", "", ""},

      "poison resistance"
    },
    { MUT_CARNIVOROUS,                5,  3, false, false,
      {"Your digestive system is specialised to digest meat.",
       "Your digestive system is highly specialised to digest meat.",
       "You are carnivorous and can eat meat at any time."},

      {"You hunger for flesh.",
       "You hunger for flesh.",
       "You hunger for flesh."},

      {"You feel able to eat a more balanced diet.",
       "You feel able to eat a more balanced diet.",
       "You feel able to eat a more balanced diet."},

      "carnivorous"
    },
    { MUT_HERBIVOROUS,                5,  3,  true, false,
      {"You digest meat inefficiently.",
       "You digest meat very inefficiently.",
       "You are a herbivore."},

      {"You hunger for vegetation.",
       "You hunger for vegetation.",
       "You hunger for vegetation."},

      {"You feel able to eat a more balanced diet.",
       "You feel able to eat a more balanced diet.",
       "You feel able to eat a more balanced diet."},

      "herbivorous"
    },
    { MUT_HEAT_RESISTANCE,            4,  3, false, false,
      {"Your flesh is heat resistant.",
       "Your flesh is very heat resistant.",
       "Your flesh is almost immune to the effects of heat."},

      {"You feel a sudden chill.",
       "You feel a sudden chill.",
       "You feel a sudden chill."},

      {"You feel hot for a moment.",
       "You feel hot for a moment.",
       "You feel hot for a moment."},

      "heat resistance"
    },
    { MUT_COLD_RESISTANCE,            4,  3, false, false,
      {"Your flesh is cold resistant.",
       "Your flesh is very cold resistant.",
       "Your flesh is almost immune to the effects of cold."},

      {"You feel hot for a moment.",
       "You feel hot for a moment.",
       "You feel hot for a moment."},

      {"You feel a sudden chill.",
       "You feel a sudden chill.",
       "You feel a sudden chill."},

      "cold resistance"
    },
    { MUT_SHOCK_RESISTANCE,           2,  1, false, false,
      {"You are resistant to electric shocks.", "", ""},
      {"You feel insulated.", "", ""},
      {"You feel conductive.", "", ""},

      "shock resistance"
    },
    { MUT_REGENERATION,               3,  3, false, false,
      {"Your natural rate of healing is unusually fast.",
       "You heal very quickly.",
       "You regenerate."},

      {"You begin to heal more quickly.",
       "You begin to heal more quickly.",
       "You begin to regenerate."},

      {"Your rate of healing slows.",
       "Your rate of healing slows.",
       "Your rate of healing slows."},

      "regeneration"
    },
    // Deep Dwarf/Ghoul only
    { MUT_SLOW_HEALING,               0,  3,  true, false,
      {"You heal slowly.",
       "You heal very slowly.",
       "You do not heal naturally."},

      {"You begin to heal more slowly.",
       "You begin to heal more slowly.",
       "You stop healing."},

      {"Your rate of healing increases.",
       "Your rate of healing increases.",
       "Your rate of healing increases."},

      "slow healing"
    },
    { MUT_FAST_METABOLISM,           10,  3,  true, false,
      {"You have a fast metabolism.",
       "You have a very fast metabolism.",
       "Your metabolism is lightning-fast."},

      {"You feel a little hungry.",
       "You feel a little hungry.",
       "You feel a little hungry."},

      {"Your metabolism slows.",
       "Your metabolism slows.",
       "Your metabolism slows."},

      "fast metabolism"
    },
    { MUT_SLOW_METABOLISM,            7,  3, false, false,
      {"You have a slow metabolism.",
       "You have a slow metabolism.",
       "You need consume almost no food."},

      {"Your metabolism slows.",
       "Your metabolism slows.",
       "Your metabolism slows."},

      {"You feel a little hungry.",
       "You feel a little hungry.",
       "You feel a little hungry."},

      "slow metabolism"
    },

    { MUT_WEAK,                      10, 14,  true,  true,
      {"You are weak (Str -", "", ""},
      {"", "", ""},
      {"", "", ""},
      "weak"
    },
    { MUT_DOPEY,                     10, 14,  true,  true,
      {"You are dopey (Int -", "", ""},
      {"", "", ""},
      {"", "", ""},
      "dopey",
    },
    { MUT_CLUMSY,                    10, 14,  true,  true,
      {"You are clumsy (Dex -", "", ""},
      {"", "", ""},
      {"", "", ""},
      "clumsy"
    },
    { MUT_TELEPORT_CONTROL,           2,  1, false, false,
      {"You can control translocations.", "", ""},
      {"You feel controlled.", "", ""},
      {"You feel random.", "", ""},

      "teleport control"
    },

    { MUT_TELEPORT,                   3,  3,  true, false,
      {"Space occasionally distorts in your vicinity.",
       "Space sometimes distorts in your vicinity.",
       "Space frequently distorts in your vicinity."},

      {"You feel weirdly uncertain.",
       "You feel even more weirdly uncertain.",
       "You feel even more weirdly uncertain."},

      {"You feel stable.",
       "You feel stable.",
       "You feel stable."},

      "teleport"
    },
    { MUT_MAGIC_RESISTANCE,           5,  3, false, false,
      {"You are resistant to magic.",
       "You are highly resistant to magic.",
       "You are extremely resistant to the effects of magic."},

      {"You feel resistant to magic.",
       "You feel more resistant to magic.",
       "You feel almost impervious to the effects of magic."},

      {"You feel less resistant to magic.",
       "You feel less resistant to magic.",
       "You feel vulnerable to magic again."},

      "magic resistance"
    },

    { MUT_FAST,                       1,  3, false, false,
      {"You cover ground quickly.",
       "You cover ground very quickly.",
       "You cover ground extremely quickly."},

      {"You feel quick.",
       "You feel quick.",
       "You feel quick."},

      {"You feel sluggish.",
       "You feel sluggish.",
       "You feel sluggish."},

      "fast"
    },
    { MUT_ACUTE_VISION,               2,  1, false, false,
      {"You have supernaturally acute eyesight.", "", ""},

      {"Your vision sharpens.",
       "Your vision sharpens.",
       "Your vision sharpens."},

      {"Your vision seems duller.",
       "Your vision seems duller.",
       "Your vision seems duller."},

      "acute vision"
    },
    { MUT_DEFORMED,                   8,  3,  true,  true,
      {"Armour fits poorly on your deformed body.",
       "Armour fits poorly on your badly deformed body.",
       "Armour fits poorly on your hideously deformed body."},

      {"Your body twists and deforms.",
       "Your body twists and deforms.",
       "Your body twists and deforms."},

      {"Your body's shape seems more normal.",
       "Your body's shape seems slightly more normal.",
       "Your body's shape seems slightly more normal."},

      "deformed"
    },
    { MUT_TELEPORT_AT_WILL,           2,  3, false, false,
      {"You can teleport at will.",
       "You are good at teleporting at will.",
       "You can teleport instantly at will."},

      {"You feel jumpy.",
       "You feel more jumpy.",
       "You feel even more jumpy."},

      {"You feel static.",
       "You feel less jumpy.",
       "You feel less jumpy."},

      "teleport at will"
    },
    { MUT_SPIT_POISON,                8,  3, false, false,
      {"You can spit poison.",
       "You can spit moderately strong poison.",
       "You can spit strong poison."},

      {"There is a nasty taste in your mouth for a moment.",
       "There is a nasty taste in your mouth for a moment.",
       "There is a nasty taste in your mouth for a moment."},

      {"You feel an ache in your throat.",
       "You feel an ache in your throat.",
       "You feel an ache in your throat."},

      "spit poison"
    },
    { MUT_BREATHE_FLAMES,             4,  3, false, false,
      {"You can breathe flames.",
       "You can breathe fire.",
       "You can breathe blasts of fire."},

      {"Your throat feels hot.",
       "Your throat feels hot.",
       "Your throat feels hot."},

      {"A chill runs up and down your throat.",
       "A chill runs up and down your throat.",
       "A chill runs up and down your throat."},

      "breathe flames"
    },
    { MUT_BLINK,                      3,  3, false, false,
      {"You can translocate small distances instantaneously.",
       "You can translocate small distances instantaneously.",
       "You can translocate small distances instantaneously."},

      {"You feel a little jumpy.",
       "You feel more jumpy.",
       "You feel even more jumpy."},

      {"You feel a little less jumpy.",
       "You feel less jumpy.",
       "You feel less jumpy."},

      "blink"
    },
    { MUT_HORNS,                      7,  3, false,  true,
      {"You have a pair of small horns on your head.",
       "You have a pair of horns on your head.",
       "You have a pair of large horns on your head."},

      {"A pair of horns grows on your head!",
       "The horns on your head grow some more.",
       "The horns on your head grow some more."},

      {"The horns on your head shrink away.",
       "The horns on your head shrink a bit.",
       "The horns on your head shrink a bit."},

      "horns"
    },
    { MUT_BEAK,                       1,  1, false,  true,
      {"You have a beak for a mouth.", "", ""},
      {"Your mouth lengthens and hardens into a beak!", "", ""},
      {"Your beak shortens and softens into a mouth.", "", ""},

      "beak"
    },
    { MUT_STRONG_STIFF,              10,  3, false,  true,
      {"Your muscles are strong (Str +1), but stiff (Dex -1).",
       "Your muscles are very strong (Str +2), but stiff (Dex -2).",
       "Your muscles are extremely strong (Str +3), but stiff (Dex -3)."},

      {"Your muscles feel sore.",
       "Your muscles feel sore.",
       "Your muscles feel sore."},

      {"Your muscles feel loose.",
       "Your muscles feel loose.",
       "Your muscles feel loose."},

      "strong stiff"
    },
    { MUT_FLEXIBLE_WEAK,             10,  3, false,  true,
      {"Your muscles are flexible (Dex +1), but weak (Str -1).",
       "Your muscles are very flexible (Dex +2), but weak (Str -2).",
       "Your muscles are extremely flexible (Dex +3), but weak (Str -3)."},

      {"Your muscles feel loose.",
       "Your muscles feel loose.",
       "Your muscles feel loose."},

      {"Your muscles feel sore.",
       "Your muscles feel sore.",
       "Your muscles feel sore."},

      "flexible weak"
    },
    { MUT_SCREAM,                     6,  3,  true, false,
      {"You occasionally shout uncontrollably.",
       "You sometimes yell uncontrollably.",
       "You frequently scream uncontrollably."},

      {"You feel the urge to shout.",
       "You feel a strong urge to yell.",
       "You feel a strong urge to scream."},

      {"Your urge to shout disappears.",
       "Your urge to yell lessens.",
       "Your urge to scream lessens."},

      "scream"
    },
    { MUT_CLARITY,                    6,  1, false, false,
      {"You possess an exceptional clarity of mind.", "", ""},
      {"Your thoughts seem clearer.", "", ""},
      {"Your thinking seems confused.", "", ""},

      "clarity"
    },
    { MUT_BERSERK,                    7,  3,  true, false,
      {"You tend to lose your temper in combat.",
       "You often lose your temper in combat.",
       "You have an uncontrollable temper."},

      {"You feel a little pissed off.",
       "You feel angry.",
       "You feel extremely angry at everything!"},

      {"You feel a little more calm.",
       "You feel a little less angry.",
       "You feel a little less angry."},

      "berserk"
    },
    { MUT_DETERIORATION,             10,  3,  true, false,
      {"Your body is slowly deteriorating.",
       "Your body is deteriorating.",
       "Your body is rapidly deteriorating."},

      {"You feel yourself wasting away.",
       "You feel yourself wasting away.",
       "You feel your body start to fall apart."},

      {"You feel healthier.",
       "You feel a little healthier.",
       "You feel a little healthier."},

      "deterioration"
    },
    { MUT_BLURRY_VISION,             10,  3,  true, false,
      {"Your vision is a little blurry.",
       "Your vision is quite blurry.",
       "Your vision is extremely blurry."},

      {"Your vision blurs.",
       "Your vision blurs.",
       "Your vision blurs."},

      {"Your vision sharpens.",
       "Your vision sharpens a little.",
       "Your vision sharpens a little."},

      "blurry vision"
    },
    { MUT_MUTATION_RESISTANCE,        4,  3, false, false,
      {"You are somewhat resistant to further mutation.",
       "You are somewhat resistant to both further mutation "
       "and mutation removal.",
       "Your current mutations are irrevocably fixed, "
       "and you can mutate no more."},

      {"You feel genetically stable.",
       "You feel genetically stable.",
       "You feel genetically immutable."},

      {"You feel genetically unstable.",
       "You feel genetically unstable.",
       "You feel genetically unstable."},

      "mutation resistance"
    },
    { MUT_FRAIL,                     10,  3,  true,  true,
      {"You are frail (-10% HP).",
       "You are very frail (-20% HP).",
       "You are extremely frail (-30% HP)."},

      {"You feel frail.",
       "You feel frail.",
       "You feel frail."},

      {"You feel robust.",
       "You feel robust.",
       "You feel robust."},

      "frail"
    },
    { MUT_ROBUST,                     5,  3, false,  true,
      {"You are robust (+10% HP).",
       "You are very robust (+20% HP).",
       "You are extremely robust (+30% HP)."},

      {"You feel robust.",
       "You feel robust.",
       "You feel robust."},

      {"You feel frail.",
       "You feel frail.",
       "You feel frail."},

      "robust"
    },

// Some demonic powers start here:
    { MUT_TORMENT_RESISTANCE,         0,  1, false, false,
      {"You are immune to unholy pain and torment.", "", ""},
      {"You feel a strange anaesthesia.", "", ""},
      {"", "", ""},

      "torment resistance"
    },
    { MUT_NEGATIVE_ENERGY_RESISTANCE, 0,  3, false, false,
      {"You resist negative energy.",
       "You are quite resistant to negative energy.",
       "You are immune to negative energy."},

      {"You feel negative.",
       "You feel negative.",
       "You feel negative."},

      {"", "", ""},

      "negative energy resistance"
    },
    { MUT_SUMMON_MINOR_DEMONS,        0,  1, false, false,
      {"You can summon minor demons to your aid.", "", ""},
      {"A thousand chattering voices call out to you.", "", ""},
      {"", "", ""},

      "summon minor demons"
    },
    { MUT_SUMMON_DEMONS,              0,  1, false, false,
      {"You can summon demons to your aid.", "", ""},
      {"Help is not far away!", "", ""},
      {"", "", ""},

      "summon demons"
    },
    { MUT_HURL_HELLFIRE,              0,  1, false, false,
      {"You can hurl blasts of hellfire.", "", ""},
      {"You smell fire and brimstone.", "", ""},
      {"", "", ""},

      "hurl hellfire"
    },
    { MUT_CALL_TORMENT,               0,  1, false, false,
      {"You can call on the torments of Hell.", "", ""},
      {"You feel a terrifying power at your call.", "", ""},
      {"", "", ""},

      "call torment"
    },
    { MUT_RAISE_DEAD,                 0,  1, false, false,
      {"You can raise the dead to walk for you.", "", ""},
      {"You feel an affinity for the dead.", "", ""},
      {"", "", ""},

      "raise dead"
    },
    { MUT_CONTROL_DEMONS,             0,  1, false, false,
      {"You can control demons.", "", ""},
      {"You feel an affinity for all demonkind.", "", ""},
      {"", "", ""},

      "control demons"
    },
    { MUT_DEATH_STRENGTH,             0,  1, false, false,
      {"You can draw strength from death and destruction.", "", ""},
      {"You feel hungry for death.", "", ""},
      {"", "", ""},

      "death strength"
    },
    { MUT_CHANNEL_HELL,               0,  1, false, false,
      {"You can channel magical energy from Hell.", "", ""},
      {"You feel a flux of magical energy.", "", ""},
      {"", "", ""},

      "channel hell"
    },
    { MUT_DRAIN_LIFE,                 0,  1, false, false,
      {"You can drain life in unarmed combat.", "", ""},
      {"Your skin tingles in a strangely unpleasant way.", "", ""},
      {"", "", ""},

      "drain life"
    },
    { MUT_THROW_FLAMES,               0,  1, false, false,
      {"You can throw forth the flames of Gehenna.", "", ""},
      {"You smell the fires of Gehenna.", "", ""},
      {"", "", ""},

      "throw flames"
    },
    { MUT_THROW_FROST,                0,  1, false, false,
      {"You can throw forth the frost of Cocytus.", "", ""},
      {"You feel the icy cold of Cocytus chill your soul.", "", ""},
      {"", "", ""},

      "throw frost"
    },
    { MUT_SMITE,                      0,  1, false, false,
      {"You can invoke the powers of Tartarus to smite your living foes.",
       "", ""},
      {"A shadow passes over the world around you.", "", ""},
      {"", "", ""},

      "smite"
    },
// end of demonic powers

    { MUT_CLAWS,                      2,  3, false,  true,
      {"You have sharp fingernails.",
       "You have very sharp fingernails.",
       "You have claws for hands."},

      {"Your fingernails lengthen.",
       "Your fingernails sharpen.",
       "Your hands twist into claws."},

      {"Your fingernails shrink to normal size.",
       "Your fingernails look duller.",
       "Your hands feel fleshier."},

      "claws"
    },
    { MUT_FANGS,                      1,  3, false,  true,
      {"You have very sharp teeth.",
       "You have extremely sharp teeth.",
       "You have razor-sharp teeth."},

      {"Your teeth lengthen and sharpen.",
       "Your teeth lengthen and sharpen some more.",
       "Your teeth are very long and razor-sharp."},

      {"Your teeth shrink to normal size.",
       "Your teeth shrink and become duller.",
       "Your teeth shrink and become duller."},

      "fangs"
    },
    { MUT_HOOVES,                     1,  1, false,  true,
      {"You have hooves in place of feet.", "", ""},
      {"Your feet shrivel into cloven hooves.", "", ""},
      {"Your hooves expand and flesh out into feet!", "", ""},

      "hooves"
    },
    { MUT_TALONS,                     1,  1, false,  true,
      {"You have talons in place of feet.", "", ""},
      {"Your feet stretch and sharpen into talons.", "", ""},
      {"Your talons dull and shrink into feet!", "", ""},

      "talons"
    },

    // Naga only
    { MUT_BREATHE_POISON,             0,  1, false, false,
      {"You can exhale a cloud of poison.", "", ""},
      {"You taste something nasty.", "", ""},
      {"Your breath is less nasty.", "", ""},

      "breathe poison"
    },
    // Naga and Draconian only
    { MUT_STINGER,                    0,  3, false,  true,
      {"Your tail ends in a poisonous barb.",
       "Your tail ends in a sharp poisonous barb.",
       "Your tail ends in a wickedly sharp and poisonous barb."},

      {"A poisonous barb forms on the end of your tail.",
       "The barb on your tail looks sharper.",
       "The barb on your tail looks very sharp."},

      {"The barb on your tail disappears.",
       "The barb on your tail seems less sharp.",
       "The barb on your tail seems less sharp."},

      "stinger"
    },
    // Draconian only
    { MUT_BIG_WINGS,                  0,  1, false,  true,
      {"Your wings are large and strong.", "", ""},
      {"Your wings grow larger and stronger.", "", ""},
      {"Your wings shrivel and weaken.", "", ""},

      "big wings"
    },

    // species-dependent innate mutations
    { MUT_SAPROVOROUS,                0,  3, false, false,
      {"You can tolerate rotten meat.",
       "You can eat rotten meat.",
       "You thrive on rotten meat."},
      {"", "", ""},
      {"", "", ""},

      "saprovorous"
    },
    { MUT_GOURMAND,                   0,  1, false, false,
      {"You like to eat raw meat.", "", ""},
      {"", "", ""},
      {"", "", ""},

      "gourmand"
    },

    { MUT_SHAGGY_FUR,                 2,  3, false,  true,
      {"You are covered in fur (AC +1).",
       "You are covered in thick fur (AC +2).",
       "Your thick and shaggy fur keeps you warm (AC +3, cold resistant)."},

      {"Fur sprouts all over your body.",
       "Your fur grows into a thick mane.",
       "Your thick fur grows shaggy and warm."},

      {"You shed all your fur.",
       "Your thick fur recedes somewhat.",
       "Your shaggy fur recedes somewhat."},

      "shaggy fur"
    },
    { MUT_HIGH_MAGIC,                 1,  3, false, false,
      {"You have an increased reservoir of magic (+10% MP).",
       "You have a considerably increased reservoir of magic (+20% MP).",
       "You have an greatly increased reservoir of magic (+30% MP)."},

      {"You feel more energetic.",
       "You feel more energetic.",
       "You feel more energetic."},

      {"You feel less energetic.",
       "You feel less energetic.",
       "You feel less energetic."},

      "high mp"
    },
    { MUT_LOW_MAGIC,                  9,  3,  true, false,
      {"Your magical capacity is low (-10% MP).",
       "Your magical capacity is very low (-20% MP).",
       "Your magical capacity is extremely low (-30% MP)."},

      {"You feel less energetic.",
       "You feel less energetic.",
       "You feel less energetic."},

      {"You feel more energetic.",
       "You feel more energetic.",
       "You feel more energetic."},

      "low mp"
    },

    { RANDOM_MUTATION,                0,  3, false, false,
      {"", "", ""},
      {"", "", ""},
      {"", "", ""},

      ""
    },

// Scales of various colours and effects
    { MUT_RED_SCALES,                 2,  3, false,  true,
      {"You are partially covered in red scales (AC +1).",
       "You are mostly covered in red scales (AC +2).",
       "You are covered in red scales (AC +4)."},

      {"Red scales grow over part of your body.",
       "Red scales spread over more of your body.",
       "Red scales cover you completely."},

      {"Your red scales disappear.",
       "Your red scales recede somewhat.",
       "Your red scales recede somewhat."},

      "red scales"
    },
    { MUT_NACREOUS_SCALES,            1,  3, false,  true,
      {"You are partially covered in smooth nacreous scales (AC +1).",
       "You are mostly covered in smooth nacreous scales (AC +3).",
       "You are completely covered in smooth nacreous scales (AC +5)."},

      {"Smooth nacreous scales grow over part of your body.",
       "Smooth nacreous scales spread over more of your body.",
       "Smooth nacreous scales cover you completely."},

      {"Your smooth nacreous scales disappear.",
       "Your smooth nacreous scales recede somewhat.",
       "Your smooth nacreous scales recede somewhat."},

      "nacreous scales"
    },
    { MUT_GREY2_SCALES,               2,  3, false,  true,
      {"You are partially covered in ridged grey scales (AC +2, Dex -1).",
       "You are mostly covered in ridged grey scales (AC +4, Dex -1).",
       "You are completely covered in ridged grey scales (AC +6, Dex -2)."},

      {"Ridged grey scales grow over part of your body.",
       "Ridged grey scales spread over more of your body.",
       "Ridged grey scales cover you completely."},

      {"Your ridged grey scales disappear.",
       "Your ridged grey scales recede somewhat.",
       "Your ridged grey scales recede somewhat."},

      "grey2 scales"
    },
    { MUT_METALLIC_SCALES,            1,  3, false,  true,
      {"You are partially covered in metallic scales (AC +3, Dex -2).",
       "You are mostly covered in metallic scales (AC +7, Dex -3).",
       "You are completely covered in metallic scales (AC +10, Dex -4)."},

      {"Metallic scales grow over part of your body.",
       "Metallic scales spread over more of your body.",
       "Metallic scales cover you completely."},

      {"Your metallic scales disappear.",
       "Your metallic scales recede somewhat.",
       "Your metallic scales recede somewhat."},

      "metallic scales"
    },
    { MUT_BLACK2_SCALES,              2,  3, false,  true,
      {"You are partially covered in black scales (AC +1).",
       "You are mostly covered in black scales (AC +3).",
       "You are completely covered in black scales (AC +5)."},

      {"Black scales grow over part of your body.",
       "Black scales spread over more of your body.",
       "Black scales cover you completely."},

      {"Your black scales disappear.",
       "Your black scales recede somewhat.",
       "Your black scales recede somewhat."},

      "black2 scales"
    },
    { MUT_WHITE_SCALES,               2,  3, false,  true,
      {"You are partially covered in white scales (AC +1).",
       "You are mostly covered in white scales (AC +3).",
       "You are completely covered in white scales (AC +5)."},

      {"White scales grow over part of your body.",
       "White scales spread over more of your body.",
       "White scales cover you completely."},

      {"Your white scales disappear.",
       "Your white scales recede somewhat.",
       "Your white scales recede somewhat."},

      "white scales"
    },
    { MUT_YELLOW_SCALES,              2,  3, false,  true,
      {"You are partially covered in yellow scales (AC +2).",
       "You are mostly covered in yellow scales (AC +4, Dex -1).",
       "You are completely covered in yellow scales (AC +6, Dex -2)."},

      {"Yellow scales grow over part of your body.",
       "Yellow scales spread over more of your body.",
       "Yellow scales cover you completely."},

      {"Your yellow scales disappear.",
       "Your yellow scales recede somewhat.",
       "Your yellow scales recede somewhat."},

      "yellow scales"
    },
    { MUT_BROWN_SCALES,               2,  3, false,  true,
      {"You are partially covered in brown scales (AC +2).",
       "You are mostly covered in brown scales (AC +4).",
       "You are completely covered in brown scales (AC +5)."},

      {"Brown scales grow over part of your body.",
       "Brown scales spread over more of your body.",
       "Brown scales cover you completely."},

      {"Your brown scales disappear.",
       "Your brown scales recede somewhat.",
       "Your brown scales recede somewhat."},

      "brown scales"
    },
    { MUT_BLUE_SCALES,                2,  3, false,  true,
      {"You are partially covered in blue scales (AC +1).",
       "You are mostly covered in blue scales (AC +2).",
       "You are completely covered in blue scales (AC +3)."},

      {"Blue scales grow over part of your body.",
       "Blue scales spread over more of your body.",
       "Blue scales cover you completely."},

      {"Your blue scales disappear.",
       "Your blue scales recede somewhat.",
       "Your blue scales recede somewhat."},

      "blue scales"
    },
    { MUT_PURPLE_SCALES,              2,  3, false,  true,
      {"You are partially covered in purple scales (AC +2).",
       "You are mostly covered in purple scales (AC +4).",
       "You are completely covered in purple scales (AC +6)."},

      {"Purple scales grow over part of your body.",
       "Purple scales spread over more of your body.",
       "Purple scales cover you completely."},

      {"Your purple scales disappear.",
       "Your purple scales recede somewhat.",
       "Your purple scales recede somewhat."},

      "purple scales"
    },
    { MUT_SPECKLED_SCALES,            2,  3, false,  true,
      {"You are partially covered in speckled scales (AC +1).",
       "You are mostly covered in speckled scales (AC +2).",
       "You are covered in speckled scales (AC +3)."},

      {"Speckled scales grow over part of your body.",
       "Speckled scales spread over more of your body.",
       "Speckled scales cover you completely."},

      {"Your speckled scales disappear.",
       "Your speckled scales recede somewhat.",
       "Your speckled scales recede somewhat."},

      "speckled scales"
    },
    { MUT_ORANGE_SCALES,              2,  3, false,  true,
      {"You are partially covered in orange scales (AC +1).",
       "You are mostly covered in orange scales (AC +3).",
       "You are completely covered in orange scales (AC +4)."},

      {"Orange scales grow over part of your body.",
       "Orange scales spread over more of your body.",
       "Orange scales cover you completely."},

      {"Your orange scales disappear.",
       "Your orange scales recede somewhat.",
       "Your orange scales recede somewhat."},

      "orange scales"
    },
    { MUT_INDIGO_SCALES,              2,  3, false,  true,
      {"You are partially covered in indigo scales (AC +2).",
       "You are mostly covered in indigo scales (AC +3).",
       "You are completely covered in indigo scales (AC +5)."},

      {"Indigo scales grow over part of your body.",
       "Indigo scales spread over more of your body.",
       "Indigo scales cover you completely."},

      {"Your indigo scales disappear.",
       "Your indigo scales recede somewhat.",
       "Your indigo scales recede somewhat."},

      "indigo scales"
    },
    { MUT_RED2_SCALES,                1,  3, false,  true,
      {"You are partially covered in knobbly red scales (AC +2).",
       "You are mostly covered in knobbly red scales (AC +5, Dex -1).",
       "You are completely covered in knobbly red scales (AC +7, Dex -2)."},

      {"Knobbly red scales grow over part of your body.",
       "Knobbly red scales spread over more of your body.",
       "Knobbly red scales cover you completely."},

      {"Your knobbly red scales disappear.",
       "Your knobbly red scales recede somewhat.",
       "Your knobbly red scales recede somewhat."},

      "red2 scales"
    },
    { MUT_IRIDESCENT_SCALES,          1,  3, false,  true,
      {"You are partially covered in iridescent scales (AC +1).",
       "You are mostly covered in iridescent scales (AC +2).",
       "You are completely covered in iridescent scales (AC +3)."},

      {"Iridescent scales grow over part of your body.",
       "Iridescent scales spread over more of your body.",
       "Iridescent scales cover you completely."},

      {"Your iridescent scales disappear.",
       "Your iridescent scales recede somewhat.",
       "Your iridescent scales recede somewhat."},

      "iridescent scales"
    },
    { MUT_STOCHASTIC_TORMENT_RESISTANCE, 0, 3, false, false,
      {"You are somewhat able to resist unholy torments (1 in 5 success).",
       "You are decently able to resist unholy torments (2 in 5 success).",
       "You are rather able to resist unholy torments (3 in 5 success)."},

      {"You feel a slight anaesthesia.",
       "You feel a slight anaesthesia.",
       "You feel a strange anaesthesia."},

      {"","",""},

      "stochastic torment resistance"},
    { MUT_PASSIVE_MAPPING,            3,  3, false, false,
      {"You passively map a small area around you.",
       "You passively map the area around you.",
       "You passively map a large area around you."},

      {"You feel a strange attunement to the structure of the dungeons.",
       "Your attunement to dungeon structure grows.",
       "Your attunement to dungeon structure grows further."},

      {"You feel slightly disoriented.",
       "You feel slightly disoriented.",
       "You feel slightly disoriented."},

      "passive mapping"
    },

    { MUT_ICEMAIL,                    0,  1, false, false,
      {"A meltable icy envelope protects you from harm (AC+", "", ""},
      {"An icy envelope takes form around you.", "", ""},
      {"", "", ""},
      "icemail"
    },

    { MUT_CONSERVE_SCROLLS,           0,  1, false, false,
      {"You are very good at protecting items from fire.", "", ""},
      {"You feel less concerned about heat.", "", ""},
      {"", "", ""},
      "conserve scrolls",
    },

    { MUT_CONSERVE_POTIONS,           0,  1, false, false,
      {"You are very good at protecting items from cold.", "", ""},
      {"You feel less concerned about cold.", "", ""},
      {"", "", ""},
      "conserve potions",
    },

    { MUT_PASSIVE_FREEZE,             0,  1, false, false,
      {"A frigid envelope surrounds you and freezes all who hurt you.", "", ""},
      {"Your skin feels very cold...", "", ""},
      {"", "", ""},
      "passive freeze",
    },
    // Anything after PATTERNED SCALES will be ignored by the debug code
    { MUT_PATTERNED_SCALES,           1,  3, false,  true,
      {"You are partially covered in patterned scales (AC +1).",
       "You are mostly covered in patterned scales (AC +2).",
       "You are completely covered in patterned scales (AC +3)."},

      {"Patterned scales grow over part of your body.",
       "Patterned scales spread over more of your body.",
       "Patterned scales cover you completely."},

      {"Your patterned scales disappear.",
       "Your patterned scales recede somewhat.",
       "Your patterned scales recede somewhat."},

      "patterned scales"
    },
};

const mutation_def& get_mutation_def(mutation_type mut)
{
    for (unsigned i = 0; i < ARRAYSZ(mutation_defs); ++i)
        if (mut == mutation_defs[i].mutation)
            return mutation_defs[i];

    ASSERT(0);
    return mutation_defs[0];
}

void fixup_mutations()
{
    if (player_genus(GENPC_DRACONIAN))
    {
        for (unsigned i = 0; i < ARRAYSZ(mutation_defs); ++i)
        {
            if (mutation_defs[i].mutation == MUT_STINGER
                || mutation_defs[i].mutation == MUT_BIG_WINGS)
            {
                mutation_defs[i].rarity = 1;
            }
        }
    }

    if (you.species == SP_TROLL)
    {
        for (unsigned i = 0; i < ARRAYSZ(mutation_defs); ++i)
        {
            if (mutation_defs[i].mutation == MUT_CLAWS)
            {
                for (int j = 0; j < 3; ++j)
                {
                    mutation_defs[i].gain[j] = troll_claw_gain[j];
                    mutation_defs[i].lose[j] = troll_claw_lose[j];
                }
            }
        }
    }

    if (you.species == SP_NAGA)
    {
        for (unsigned i = 0; i < ARRAYSZ(mutation_defs); ++i)
        {
            if (mutation_defs[i].mutation == MUT_DEFORMED)
            {
                for (int j = 0; j < 3; ++j)
                    mutation_defs[i].have[j] = naga_deformed_descrip[j];
            }
            else if (mutation_defs[i].mutation == MUT_STINGER)
                mutation_defs[i].rarity = 1;
        }
    }

    if (you.species == SP_CENTAUR)
        for (unsigned i = 0; i < ARRAYSZ(mutation_defs); ++i)
            if (mutation_defs[i].mutation == MUT_DEFORMED)
                for (int j = 0; j < 3; ++j)
                    mutation_defs[i].have[j] = centaur_deformed_descrip[j];
}

bool mutation_is_fully_active(mutation_type mut)
{
    // For all except the semi-undead, mutations always apply.
    if (you.is_undead != US_SEMI_UNDEAD)
        return (true);

    // Innate mutations are always active
    if (you.demon_pow[mut])
        return (true);

    // ... as are all mutations for semi-undead who are fully alive
    if (you.hunger_state == HS_ENGORGED)
        return (true);

    // ... as are physical mutations.
    if (get_mutation_def(mut).physical)
        return (true);

    return (false);
}

static bool _mutation_is_fully_inactive(mutation_type mut)
{
    const mutation_def& mdef = get_mutation_def(mut);
    return (you.is_undead == US_SEMI_UNDEAD && you.hunger_state < HS_SATIATED
            && !you.demon_pow[mut] && !mdef.physical);
}

formatted_string describe_mutations()
{
    std::string result;
    bool have_any = false;
    const char *mut_title = "Innate Abilities, Weirdness & Mutations";

    // center title
    int offset = 39 - strlen(mut_title) / 2;
    if ( offset < 0 ) offset = 0;

    result += std::string(offset, ' ');

    result += "<white>";
    result += mut_title;
    result += "</white>" EOL EOL;

    // Innate abilities which don't fit as mutations.
    result += "<lightblue>";
    switch (you.species)
    {
    case SP_MERFOLK:
        result += "You revert to your normal form in water." EOL;
        have_any = true;
        break;

    case SP_NAGA:
        result += "You cannot wear boots." EOL;
        if (!you.mutation[MUT_FAST])
        {
            result += mutation_name(MUT_FAST, -1, true);
            result += EOL;
        }
        // Breathe poison replaces spit poison.
        if (!you.mutation[MUT_BREATHE_POISON])
            result += "You can spit poison." EOL;
        if (you.experience_level > 2)
        {
            std::ostringstream num;
            num << you.experience_level/3;
            result += "Your serpentine skin is tough (AC +" + num.str() + ")." EOL;
        }
        have_any = true;
        break;

    case SP_GHOUL:
        result += "Your body is rotting away." EOL;
        result += "You have sharp claws for hands." EOL;
        have_any = true;
        break;

    case SP_TROLL:
        if (!you.mutation[MUT_CLAWS])
        {
            result += mutation_name(MUT_CLAWS, -1, true);
            result += EOL;
        }
        have_any = true;
        break;

    case SP_KENKU:
        if (you.experience_level > 4)
        {
            result += "You can fly";
            if (you.experience_level > 14)
                result += " continuously";
            result += "." EOL;
            have_any = true;
        }
        break;

    case SP_MUMMY:
        result += "Your flesh is vulnerable to fire." EOL;
        if (you.experience_level > 12)
        {
            result += "You are";
            if (you.experience_level > 25)
                result += " strongly";

            result += " in touch with the powers of death." EOL;
            result +=
                "You can restore your body by infusing magical energy." EOL;
        }
        have_any = true;
        break;

    case SP_GREY_DRACONIAN:
        if (you.experience_level > 6)
        {
            result += "Your tail is studded with spikes." EOL;
            have_any = true;
        }
        break;

    case SP_GREEN_DRACONIAN:
        if (you.experience_level > 6)
        {
            result += "You can breathe poison." EOL;
            have_any = true;
        }
        break;

    case SP_RED_DRACONIAN:
        if (you.experience_level > 6)
        {
            result += "You can breathe fire." EOL;
            have_any = true;
        }
        break;

    case SP_WHITE_DRACONIAN:
        if (you.experience_level > 6)
        {
            result += "You can breathe cold." EOL;
            have_any = true;
        }
        break;

    case SP_BLACK_DRACONIAN:
        if (you.experience_level > 6)
        {
            result += "You can breathe lightning." EOL;
            have_any = true;
        }
        break;

    case SP_YELLOW_DRACONIAN:
        if (you.experience_level > 6)
        {
            result += "You can spit acid." EOL;
            result += "You are resistant to acid." EOL;
            have_any = true;
        }
        break;

    case SP_PURPLE_DRACONIAN:
        if (you.experience_level > 6)
        {
            result += "You can breathe power." EOL;
            have_any = true;
        }
        break;

    case SP_MOTTLED_DRACONIAN:
        if (you.experience_level > 6)
        {
            result += "You can breathe sticky flames." EOL;
            have_any = true;
        }
        break;

    case SP_PALE_DRACONIAN:
        if (you.experience_level > 6)
        {
            result += "You can breathe steam." EOL;
            have_any = true;
        }
        break;

    case SP_KOBOLD:
        result += "You recuperate from illness quickly." EOL;
        have_any = true;
        break;

    case SP_VAMPIRE:
        have_any = true;
        if (you.hunger_state == HS_STARVING)
            result += "<green>You do not heal naturally.</green>" EOL;
        else if (you.hunger_state == HS_ENGORGED)
            result += "<green>Your natural rate of healing is extremely fast.</green>" EOL;
        else if (you.hunger_state < HS_SATIATED)
            result += "<green>You heal slowly.</green>" EOL;
        else if (you.hunger_state >= HS_FULL)
            result += "<green>Your natural rate of healing is unusually fast.</green>" EOL;
        else
            have_any = false;

        if (you.experience_level >= 6)
        {
            result += "You can bottle blood from corpses with 'c'." EOL;
            have_any = true;
        }
        break;

    case SP_DEEP_DWARF:
        result += "You are resistant to damage." EOL;
        result += "You can recharge devices by infusing magical energy." EOL;
        have_any = true;
        break;

    default:
        break;
    }

    // a bit more stuff
    if (player_genus(GENPC_OGRE) || you.species == SP_TROLL
        || player_genus(GENPC_DRACONIAN) || you.species == SP_SPRIGGAN)
    {
        result += "Your body does not fit into most forms of armour." EOL;
        have_any = true;
    }

    if (player_genus(GENPC_DRACONIAN))
    {
        int ac = (you.experience_level < 8) ? 2 :
                 (you.species == SP_GREY_DRACONIAN)
                     ? (you.experience_level - 4) / 2 + 1 :
                       you.experience_level / 4 + 1;
        std::ostringstream num;
        num << ac;
        result += "Your scales are hard (AC +" + num.str() + ")." EOL;
    }

    result += "</lightblue>";

    if (beogh_water_walk())
    {
        result += "<green>You can walk on water.</green>" EOL;
        have_any = true;
    }

    if (you.duration[DUR_FIRE_SHIELD])
    {
        result += "<green>You are immune to clouds of flame.</green>" EOL;
        have_any = true;
    }

    textcolor(LIGHTGREY);

    // First add (non-removable) inborn abilities and demon powers.
    for (int i = 0; i < NUM_MUTATIONS; i++)
    {
        if (you.mutation[i] != 0 && you.demon_pow[i])
        {
            mutation_type mut_type = static_cast<mutation_type>(i);
            result += mutation_name(mut_type, -1, true);
            result += EOL;
            have_any = true;
        }
    }

    // Now add removable mutations.
    for (int i = 0; i < NUM_MUTATIONS; i++)
    {
        if (you.mutation[i] != 0 && !you.demon_pow[i])
        {
            mutation_type mut_type = static_cast<mutation_type>(i);
            result += mutation_name(mut_type, -1, true);
            result += EOL;
            have_any = true;
        }
    }

    if (!have_any)
        result +=  "You are rather mundane." EOL;

    if (you.species == SP_VAMPIRE)
    {
        result += EOL EOL;
        result += EOL EOL;
        result +=
#ifndef USE_TILE
            "Press '<w>!</w>'"
#else
            "<w>Right-click</w>"
#endif
            " to toggle between mutations and properties depending on your" EOL
            "hunger status." EOL;
    }

    return formatted_string::parse_string(result);
}

static void _display_vampire_attributes()
{
    ASSERT(you.species == SP_VAMPIRE);

    clrscr();
    cgotoxy(1,1);

    std::string result;

    const int lines = 15;
    std::string column[lines][7] =
    {
       {"                     ", "<lightgreen>Alive</lightgreen>      ", "<green>Full</green>    ",
        "Satiated  ", "<yellow>Thirsty</yellow>  ", "<yellow>Near...</yellow>  ",
        "<lightred>Bloodless</lightred>"},
                                //Alive          Full       Satiated      Thirsty   Near...      Bloodless
       {"Metabolism           ", "very fast  ", "fast    ", "fast      ", "normal   ", "slow     ", "none  "},

       {"Regeneration         ", "very fast  ", "fast    ", "normal    ", "slow     ", "slow     ", "none  "},

       {"Stealth boost        ", "none       ", "none    ", "none      ", "minor    ", "major    ", "large "},

       {"Spell hunger         ", "full       ", "full    ", "full      ", "halved   ", "none     ", "none  "},

       {EOL "<w>Resistances</w>" EOL
        "Poison resistance    ", "           ", "        ", "          ", " +       ", " +       ", " +    "},

       {"Cold resistance      ", "           ", "        ", "          ", " +       ", " +       ", " ++   "},

       {"Negative resistance  ", "           ", "        ", " +        ", " ++      ", " +++     ", " +++  "},

       {"Rotting resistance   ", "           ", "        ", "          ", " +       ", " +       ", " +    "},

       {"Torment resistance   ", "           ", "        ", "          ", "         ", "         ", " +    "},

       {EOL "<w>Other effects</w>" EOL
        "Mutation chance      ", "always     ", "often   ", "sometimes ", "never    ", "never    ", "never "},

       {"Non-physical " EOL
        "mutation effects     ", "full       ", "capped  ", "capped    ", "none     ", "none     ", "none  "},

       {"Potion effects       ", "full       ", "full    ", "full      ", "halved   ", "halved   ", "halved"},

       {"Bat Form             ", "no         ", "no      ", "yes       ", "yes      ", "yes      ", "yes   "},

       {"Other transformation " EOL
        "or going berserk     ", "yes        ", "yes     ", "no        ", "no       ", "no       ", "no    "}
    };

    int current = 0;
    switch (you.hunger_state)
    {
    case HS_ENGORGED:
        current = 1;
        break;
    case HS_VERY_FULL:
    case HS_FULL:
        current = 2;
        break;
    case HS_SATIATED:
        current = 3;
        break;
    case HS_HUNGRY:
    case HS_VERY_HUNGRY:
        current = 4;
        break;
    case HS_NEAR_STARVING:
        current = 5;
        break;
    case HS_STARVING:
        current = 6;
    }

    for (int y = 0; y < lines; y++)  // lines   (properties)
    {
        for (int x = 0; x < 7; x++)  // columns (hunger states)
        {
             if (y > 0 && x == current)
                 result += "<w>";
             result += column[y][x];
             if (y > 0 && x == current)
                 result += "</w>";
        }
        result += EOL;
    }

    result += EOL;
    result +=
#ifndef USE_TILE
        "Press '<w>!</w>'"
#else
        "<w>Right-click</w>"
#endif
        " to toggle between mutations and properties depending on your" EOL
        "hunger status." EOL;

    const formatted_string vp_props = formatted_string::parse_string(result);
    vp_props.display();

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

void display_mutations()
{
    clrscr();
    cgotoxy(1,1);

    const formatted_string mutation_fs = describe_mutations();

    if (you.species == SP_VAMPIRE)
    {
        mutation_fs.display();
        mouse_control mc(MOUSE_MODE_MORE);
        const int keyin = getch();
        if (keyin == '!' || keyin == CK_MOUSE_CMD)
            _display_vampire_attributes();
    }
    else
    {
        Menu mutation_menu(mutation_fs);
        mutation_menu.show();
    }
}

static int _calc_mutation_amusement_value(mutation_type which_mutation)
{
    int amusement = 16 * (11 - get_mutation_def(which_mutation).rarity);

    switch (which_mutation)
    {
    case MUT_STRONG:
    case MUT_CLEVER:
    case MUT_AGILE:
    case MUT_POISON_RESISTANCE:
    case MUT_SHOCK_RESISTANCE:
    case MUT_REGENERATION:
    case MUT_SLOW_METABOLISM:
    case MUT_TELEPORT_CONTROL:
    case MUT_MAGIC_RESISTANCE:
    case MUT_TELEPORT_AT_WILL:
    case MUT_CLARITY:
    case MUT_MUTATION_RESISTANCE:
    case MUT_ROBUST:
    case MUT_HIGH_MAGIC:
        amusement /= 2;  // not funny
        break;

    case MUT_CARNIVOROUS:
    case MUT_HERBIVOROUS:
    case MUT_SLOW_HEALING:
    case MUT_FAST_METABOLISM:
    case MUT_WEAK:
    case MUT_DOPEY:
    case MUT_CLUMSY:
    case MUT_TELEPORT:
    case MUT_FAST:
    case MUT_DEFORMED:
    case MUT_SPIT_POISON:
    case MUT_BREATHE_FLAMES:
    case MUT_BLINK:
    case MUT_HORNS:
    case MUT_BEAK:
    case MUT_SCREAM:
    case MUT_BERSERK:
    case MUT_DETERIORATION:
    case MUT_BLURRY_VISION:
    case MUT_FRAIL:
    case MUT_CLAWS:
    case MUT_FANGS:
    case MUT_HOOVES:
    case MUT_TALONS:
    case MUT_BREATHE_POISON:
    case MUT_STINGER:
    case MUT_BIG_WINGS:
    case MUT_LOW_MAGIC:
        amusement *= 2; // funny!
        break;

    default:
        break;
    }

    return (amusement);
}

static bool _is_deadly(mutation_type mutat, bool delete_mut)
{
    if (delete_mut)
    {
        // First handle non-stat related problems.
        if ( mutat == MUT_HEAT_RESISTANCE && grd(you.pos()) == DNGN_LAVA
             && player_res_fire() == 1 && !you.airborne() )
        {
            // Don't let player instantly fry to a crisp in lava.
            return (true);
        }

        // Swap things around to the same effect, but as if we were
        // gaining a mutation, or return early if deleting the mutation
        // is never a problem.
        switch (mutat)
        {
        case MUT_GREY2_SCALES:
        case MUT_METALLIC_SCALES:
        case MUT_YELLOW_SCALES:
        case MUT_RED2_SCALES:
        case MUT_WEAK:
        case MUT_DOPEY:
        case MUT_CLUMSY:
            return (false);

        case MUT_STRONG_STIFF:
            mutat = MUT_FLEXIBLE_WEAK;
            break;

        case MUT_FLEXIBLE_WEAK:
            mutat = MUT_STRONG_STIFF;
            break;

        case MUT_STRONG:
            mutat = MUT_WEAK;
            break;

        case MUT_CLEVER:
            mutat = MUT_DOPEY;
            break;

        case MUT_AGILE:
            mutat = MUT_CLUMSY;
            break;

        default:
            break;
        }
    }

    unsigned char cur_level = you.mutation[mutat];

    char *stat_ptr = &you.dex; // Default for the scales.
    char  amnt     = 1;
    char  mod      = 0;

    switch (mutat)
    {
    case MUT_GREY2_SCALES:
        if (cur_level == 0 || cur_level == 2)
            amnt = 1;
        else
            amnt = 0;
        break;

    case MUT_METALLIC_SCALES:
        if (cur_level == 0)
            amnt = 2;
        else
            amnt = 1;
        break;

    case MUT_YELLOW_SCALES:
    case MUT_RED2_SCALES:
        if (cur_level == 0)
            amnt = 0;
        else
            amnt = 1;
        break;

    case MUT_FLEXIBLE_WEAK:
    case MUT_WEAK:
        stat_ptr = &you.strength;
        // Take might into account so we don't lower base strength below
        // one.
        if (you.duration[DUR_MIGHT])
            mod = -5;
        break;

    case MUT_DOPEY:
        stat_ptr = &you.intel;
        if (you.duration[DUR_BRILLIANCE])
            mod = -5;
        break;

    case MUT_STRONG_STIFF:
    case MUT_CLUMSY:
        stat_ptr = &you.dex;
        if (you.duration[DUR_AGILITY])
            mod = -5;
        break;

    default:
        return (false);
    }

    return (amnt >= (*stat_ptr + mod));
}

static bool _accept_mutation(mutation_type mutat, bool ignore_rarity = false,
                             bool non_fatal = false, bool delete_mut = false)
{
    if (mutat == RANDOM_MUTATION)
        return (false);

    const mutation_def& mdef = get_mutation_def(mutat);

    if (delete_mut)
        return (!non_fatal || !_is_deadly(mutat, delete_mut));

    if (you.mutation[mutat] >= mdef.levels)
        return (false);

    if (non_fatal && _is_deadly(mutat, delete_mut))
        return (false);

    if (ignore_rarity)
        return (true);

    const int rarity = mdef.rarity + you.demon_pow[mutat];

    // Low rarity means unlikely to choose it.
    return (x_chance_in_y(rarity, 10));
}

static mutation_type _get_random_xom_mutation(bool non_fatal = false)
{
    const mutation_type bad_muts[] = {
        MUT_WEAK,          MUT_DOPEY,
        MUT_CLUMSY,        MUT_DEFORMED,      MUT_SCREAM,
        MUT_DETERIORATION, MUT_BLURRY_VISION, MUT_FRAIL
    };

    mutation_type mutat = NUM_MUTATIONS;

    do
    {
        mutat = static_cast<mutation_type>(random2(NUM_MUTATIONS));

        if (one_chance_in(1000))
            return (NUM_MUTATIONS);
        else if (one_chance_in(5))
            mutat = RANDOM_ELEMENT(bad_muts);
    }
    while (!_accept_mutation(mutat, false, non_fatal));

    return (mutat);
}

static mutation_type _get_random_mutation(bool prefer_good,
                                          int preferred_multiplier,
                                          bool non_fatal = false)
{
    int cweight = 0;
    mutation_type chosen = NUM_MUTATIONS;
    for (unsigned i = 0; i < ARRAYSZ(mutation_defs); ++i)
    {
        if (!mutation_defs[i].rarity)
            continue;

        const mutation_type curr = mutation_defs[i].mutation;
        if (!_accept_mutation(curr, true, non_fatal))
            continue;

        const bool weighted = mutation_defs[i].bad != prefer_good;
        int weight = mutation_defs[i].rarity;
        if (weighted)
            weight = weight * preferred_multiplier / 100;

        cweight += weight;

        if (x_chance_in_y(weight, cweight))
            chosen = curr;
    }

    return (chosen);
}

#ifdef DEBUG
static bool _is_random(mutation_type which_mutation)
{
    return (which_mutation == RANDOM_MUTATION
            || which_mutation == RANDOM_XOM_MUTATION
            || which_mutation == RANDOM_GOOD_MUTATION
            || which_mutation == RANDOM_BAD_MUTATION);
}
#endif

// Tries to give you the mutation by deleting a conflicting
// one, or clears out conflicting mutations if we should give
// you the mutation anyway.
// Return:
//  1 if we should stop processing (success);
//  0 if we should continue processing;
// -1 if we should stop processing (failure).
static int _handle_conflicting_mutations(mutation_type mutation,
                                         bool override)
{
    if (override)
    {
        // These are mutations which should be cleared away if forced.
        const mutation_type override_conflict[][2] = {
            { MUT_REGENERATION, MUT_SLOW_METABOLISM },
            { MUT_REGENERATION, MUT_SLOW_HEALING    },
            { MUT_ACUTE_VISION, MUT_BLURRY_VISION   }
        };

        // If we have one of the pair, delete all levels of the other,
        // and continue processing.
        for (unsigned i = 0; i < ARRAYSZ(override_conflict); ++i)
        {
            for (int j = 0; j < 2; ++j)
            {
                const mutation_type a = override_conflict[i][j];
                const mutation_type b = override_conflict[i][1-j];

                if (mutation == a)
                    while (delete_mutation(b, true, true))
                        ;
            }
        }
    }

    // These are mutations which can't be traded off against each other,
    // so we just fail.
    const mutation_type fail_conflict[][2] = {
        { MUT_REGENERATION, MUT_SLOW_METABOLISM },
        { MUT_FANGS,        MUT_BEAK            },
        { MUT_HOOVES,       MUT_TALONS          }
    };

    for (unsigned i = 0; i < ARRAYSZ(fail_conflict); ++i)
    {
        for (int j = 0; j < 2; ++j)
        {
            const mutation_type a = fail_conflict[i][j];
            const mutation_type b = fail_conflict[i][1-j];
            if (mutation == a && you.mutation[b] > 0)
                return (-1);    // Fail.
        }
    }

    // These are mutations which trade off against each other.
    const mutation_type simple_conflict[][2] = {
        { MUT_STRONG,          MUT_WEAK            },
        { MUT_CLEVER,          MUT_DOPEY           },
        { MUT_AGILE,           MUT_CLUMSY          },
        { MUT_STRONG_STIFF,    MUT_FLEXIBLE_WEAK   },
        { MUT_ROBUST,          MUT_FRAIL           },
        { MUT_HIGH_MAGIC,      MUT_LOW_MAGIC       },
        { MUT_CARNIVOROUS,     MUT_HERBIVOROUS     },
        { MUT_SLOW_METABOLISM, MUT_FAST_METABOLISM },
        { MUT_REGENERATION,    MUT_SLOW_HEALING    },
        { MUT_ACUTE_VISION,    MUT_BLURRY_VISION   }
    };

    for (unsigned i = 0; i < ARRAYSZ(simple_conflict); ++i)
        for (int j = 0; j < 2; ++j)
        {
            // If we have one of the pair, delete a level of the other,
            // and that's it.
            const mutation_type a = simple_conflict[i][j];
            const mutation_type b = simple_conflict[i][1-j];
            if (mutation == a && you.mutation[b] > 0)
            {
                delete_mutation(b);
                return (1);     // Nothing more to do.
            }
        }

    return (0);
}

static bool _physiology_mutation_conflict(mutation_type mutat)
{
    // Only Nagas and Draconians can get this one.
    if (mutat == MUT_STINGER
        && you.species != SP_NAGA && !player_genus(GENPC_DRACONIAN))
    {
        return (true);
    }

    if ((mutat == MUT_HOOVES || mutat == MUT_TALONS) && !player_has_feet())
        return (true);

    // Already innate.
    if (mutat == MUT_BREATHE_POISON && you.species != SP_NAGA)
        return (true);

    // Red Draconians can already breathe flames.
    if (mutat == MUT_BREATHE_FLAMES && you.species == SP_RED_DRACONIAN)
        return (true);

    // Green Draconians can already breathe poison, so they don't need
    // to spit it.
    if (mutat == MUT_SPIT_POISON && you.species == SP_GREEN_DRACONIAN)
        return (true);

    // Only Draconians can get wings.
    if (mutat == MUT_BIG_WINGS && !player_genus(GENPC_DRACONIAN))
        return (true);

    // Vampires' healing and thirst rates depend on their blood level.
    if (you.species == SP_VAMPIRE
        && (mutat == MUT_CARNIVOROUS || mutat == MUT_HERBIVOROUS
            || mutat == MUT_REGENERATION || mutat == MUT_SLOW_HEALING
            || mutat == MUT_FAST_METABOLISM || mutat == MUT_SLOW_METABOLISM))
    {
        return (true);
    }

    return (false);
}

static bool _reautomap_callback()
{
    reautomap_level();
    return true;
}

bool mutate(mutation_type which_mutation, bool failMsg,
            bool force_mutation, bool god_gift, bool stat_gain_potion,
            bool demonspawn, bool non_fatal)
{
    ASSERT(!non_fatal || _is_random(which_mutation));

    if (!god_gift)
    {
        const god_type god =
            (crawl_state.is_god_acting()) ? crawl_state.which_god_acting()
                                          : GOD_NO_GOD;

        if (god != GOD_NO_GOD)
            god_gift = true;
    }

    if (demonspawn)
        force_mutation = true;

    mutation_type mutat = which_mutation;

    if (!force_mutation)
    {
        // God gifts override all sources of mutation resistance other
        // than divine protection, and stat gain potions override all
        // sources of mutation resistance other than the mutation
        // resistance mutation.
        if (!god_gift)
        {
            if (wearing_amulet(AMU_RESIST_MUTATION)
                    && !one_chance_in(10) && !stat_gain_potion
                || player_mutation_level(MUT_MUTATION_RESISTANCE) == 3
                || player_mutation_level(MUT_MUTATION_RESISTANCE)
                    && !one_chance_in(3))
            {
                if (failMsg)
                    mpr("You feel odd for a moment.", MSGCH_MUTATION);
                return (false);
            }
        }

        // Zin's protection.
        if (you.religion == GOD_ZIN && x_chance_in_y(you.piety, MAX_PIETY)
            && !stat_gain_potion)
        {
            simple_god_message(" protects your body from mutation!");
            return (false);
        }
    }

    bool rotting = you.is_undead;

    if (you.is_undead == US_SEMI_UNDEAD)
    {
        // The stat gain mutations always come through at Satiated or
        // higher (mostly for convenience), and, for consistency, also
        // their negative counterparts.
        if (which_mutation == MUT_STRONG || which_mutation == MUT_CLEVER
            || which_mutation == MUT_AGILE || which_mutation == MUT_WEAK
            || which_mutation == MUT_DOPEY || which_mutation == MUT_CLUMSY)
        {
            if (you.hunger_state > HS_SATIATED)
                rotting = false;
        }
        else
        {
            // Else, chances depend on hunger state.
            switch (you.hunger_state)
            {
            case HS_SATIATED:  rotting = !one_chance_in(3); break;
            case HS_FULL:      rotting = coinflip();        break;
            case HS_VERY_FULL: rotting = one_chance_in(3);  break;
            case HS_ENGORGED:  rotting = false;             break;
            }
        }
    }

    // Undead bodies don't mutate, they fall apart. -- bwr
    // except for demonspawn (or other permamutations) in lichform -- haranp
    if (rotting && !demonspawn)
    {
        mpr("Your body decomposes!", MSGCH_MUTATION);

        if (coinflip())
            lose_stat(STAT_RANDOM, 1, false, "mutating");
        else
        {
            ouch(3, NON_MONSTER, KILLED_BY_ROTTING);
            rot_hp(roll_dice(1, 3));
        }

        xom_is_stimulated(64);
        return (true);
    }

    if (which_mutation == RANDOM_MUTATION
        || which_mutation == RANDOM_XOM_MUTATION)
    {
        // If already heavily mutated, remove a mutation instead.
        if (x_chance_in_y(how_mutated(false, true), 15))
        {
            // God gifts override mutation loss due to being heavily
            // mutated.
            if (!one_chance_in(3) && !god_gift && !force_mutation)
                return (false);
            else
                return (delete_mutation(RANDOM_MUTATION, failMsg,
                                        force_mutation, false, non_fatal));
        }
    }

    if (which_mutation == RANDOM_MUTATION)
    {
        do
        {
            mutat = static_cast<mutation_type>(random2(NUM_MUTATIONS));
            if (one_chance_in(1000))
                return (false);
        }
        while (!_accept_mutation(mutat, false, non_fatal));
    }
    else if (which_mutation == RANDOM_XOM_MUTATION)
    {
        if ((mutat = _get_random_xom_mutation(non_fatal)) == NUM_MUTATIONS)
            return (false);
    }
    else if (which_mutation == RANDOM_GOOD_MUTATION)
    {
        mutat = _get_random_mutation(true, 500, non_fatal);
        if (mutat == NUM_MUTATIONS)
            return (false);
    }
    else if (which_mutation == RANDOM_BAD_MUTATION)
    {
        mutat = _get_random_mutation(false, 500, non_fatal);
        if (mutat == NUM_MUTATIONS)
            return (false);
    }

    // Saprovorous/gourmand can't be randomly acquired.
    if ((mutat == MUT_SAPROVOROUS || mutat == MUT_GOURMAND) && !force_mutation)
        return (false);

    // These can be forced by demonspawn or god gifts.
    if ((mutat == MUT_SHAGGY_FUR
            || mutat >= MUT_GREEN_SCALES && mutat <= MUT_BONEY_PLATES
            || mutat >= MUT_RED_SCALES && mutat <= MUT_PATTERNED_SCALES)
        && _body_covered() >= 3 && !god_gift && !force_mutation)
    {
        return (false);
    }

    if (you.species == SP_NAGA)
    {
        // gdl: Spit poison 'upgrades' to breathe poison.  Why not...
        if (mutat == MUT_SPIT_POISON)
        {
            if (coinflip())
                return (false);

            mutat = MUT_BREATHE_POISON;

            // Breathe poison replaces spit poison (so it takes the slot).
            for (int i = 0; i < 52; ++i)
                if (you.ability_letter_table[i] == ABIL_SPIT_POISON)
                    you.ability_letter_table[i] = ABIL_BREATHE_POISON;
        }
    }

    if (_physiology_mutation_conflict(mutat))
        return (false);

    const mutation_def& mdef = get_mutation_def(mutat);

    if (you.mutation[mutat] >= mdef.levels)
        return (false);

    // God gifts and forced mutations clear away conflicting mutations.
    int rc =_handle_conflicting_mutations(mutat, god_gift || force_mutation);
    if (rc == 1)
        return (true);
    if (rc == -1)
        return (false);

    ASSERT(rc == 0);

    const unsigned int old_talents = your_talents(false).size();

    bool gain_msg = true;
    bool stat_msg = false;

    // Save original stats.
    const stat_type stats[] = {STAT_STRENGTH, STAT_DEXTERITY,
                               STAT_INTELLIGENCE};
    int modifiers[3];

    for (int i = 0; i < 3; ++i)
        modifiers[i] = stat_modifier(stats[i]);

    bool modified_eq = false;

    switch (mutat)
    {
    case MUT_STRONG: case MUT_AGILE:  case MUT_CLEVER:
    case MUT_WEAK:   case MUT_CLUMSY: case MUT_DOPEY:
        stat_msg = true;
        gain_msg = false;
        break;

        // FIXME: these cases should be handled better.
    case MUT_HOOVES:
    case MUT_TALONS:
        mpr(mdef.gain[you.mutation[mutat]], MSGCH_MUTATION);
        gain_msg = false;

        // Hooves and talons force boots off.
        if (you_tran_can_wear(EQ_BOOTS))
        {
            remove_one_equip(EQ_BOOTS, false, true);
            modified_eq = true;
        }
        break;

    case MUT_CLAWS:
        mpr(mdef.gain[you.mutation[mutat]], MSGCH_MUTATION);
        gain_msg = false;

        // Gloves aren't prevented until level 3.  We don't have the
        // mutation yet, so we have to check for level 2 or higher claws
        // here.
        if (you.mutation[mutat] >= 2 && you_tran_can_wear(EQ_GLOVES))
        {
            remove_one_equip(EQ_GLOVES, false, true);
            modified_eq = true;
        }
        break;

    case MUT_HORNS:
    case MUT_BEAK:
        mpr(mdef.gain[you.mutation[mutat]], MSGCH_MUTATION);
        gain_msg = false;

        // Horns and beaks force hard helmets off.
        if (you.equip[EQ_HELMET] != -1
            && is_hard_helmet(you.inv[you.equip[EQ_HELMET]])
            && you_tran_can_wear(EQ_HELMET))
        {
            remove_one_equip(EQ_HELMET, false, true);
            modified_eq = true;
        }
        break;

    case MUT_ACUTE_VISION:
        // We might have to turn autopickup back on again.
        mpr(mdef.gain[you.mutation[mutat]], MSGCH_MUTATION);
        gain_msg = false;
        autotoggle_autopickup(false);
        break;

    default:
        break;
    }

    // For all those scale mutations.
    you.redraw_armour_class = true;

    you.mutation[mutat]++;

    // Don't run this loop if we lost some equipment slots, since
    // removing armour with stat modifiers makes the value of
    // new_modifier below different from the previously recorded value,
    // and the remove_one_equip() call chain already does stat change
    // from removing items correctly. -cao
    if (!modified_eq)
    {
        for (int i = 0; i < 3; ++i)
        {
            const int new_modifier = stat_modifier(stats[i]);
            if (new_modifier != modifiers[i])
            {
                modify_stat(stats[i], new_modifier - modifiers[i],
                            !stat_msg, "losing a mutation");
            }
        }
    }

    if (gain_msg)
        mpr(mdef.gain[you.mutation[mutat]-1], MSGCH_MUTATION);

    // Do post-mutation effects.
    if (mutat == MUT_FRAIL || mutat == MUT_ROBUST)
        calc_hp();
    if (mutat == MUT_LOW_MAGIC || mutat == MUT_HIGH_MAGIC)
        calc_mp();
    if (mutat == MUT_PASSIVE_MAPPING)
        apply_to_all_dungeons(_reautomap_callback);

    // Amusement value will be 16 * (11-rarity) * Xom's-sense-of-humor.
    xom_is_stimulated(_calc_mutation_amusement_value(mutat));

    take_note(Note(NOTE_GET_MUTATION, mutat, you.mutation[mutat]));

    if (Tutorial.tutorial_left && your_talents(false).size() > old_talents)
        learned_something_new(TUT_NEW_ABILITY_MUT);

    return (true);
}

static bool _delete_single_mutation_level(mutation_type mutat)
{
    if (you.mutation[mutat] == 0)
        return (false);

    if (you.demon_pow[mutat] >= you.mutation[mutat])
        return (false);

    const mutation_def& mdef = get_mutation_def(mutat);

    bool lose_msg = true;
    bool stat_msg = false;

    // Save original stats.
    const stat_type stats[] = {STAT_STRENGTH, STAT_DEXTERITY,
                               STAT_INTELLIGENCE};
    int modifiers[3];

    for (int i = 0; i < 3; ++i)
        modifiers[i] = stat_modifier(stats[i]);

    switch (mutat)
    {
    case MUT_STRONG: case MUT_AGILE:  case MUT_CLEVER:
    case MUT_WEAK:   case MUT_CLUMSY: case MUT_DOPEY:
        stat_msg = true;
        lose_msg = false;
        break;

    case MUT_BREATHE_POISON:
        // can't be removed yet, but still covered:
        if (you.species == SP_NAGA)
        {
            // natural ability to spit poison retakes the slot
            for (int i = 0; i < 52; ++i)
            {
                if (you.ability_letter_table[i] == ABIL_BREATHE_POISON)
                    you.ability_letter_table[i] = ABIL_SPIT_POISON;
            }
        }
        break;

    default:
        break;
    }

    // For all those scale mutations.
    you.redraw_armour_class = true;

    you.mutation[mutat]--;

    for (int i = 0; i < 3; ++i)
    {
        const int new_modifier = stat_modifier(stats[i]);
        if (new_modifier != modifiers[i])
        {
            modify_stat(stats[i], new_modifier - modifiers[i],
                        !stat_msg, "losing a mutation");
        }
    }

    if (lose_msg)
        mpr(mdef.lose[you.mutation[mutat]], MSGCH_MUTATION);

    // Do post-mutation effects.
    if (mutat == MUT_FRAIL || mutat == MUT_ROBUST)
        calc_hp();
    if (mutat == MUT_LOW_MAGIC || mutat == MUT_HIGH_MAGIC)
        calc_mp();

    take_note(Note(NOTE_LOSE_MUTATION, mutat, you.mutation[mutat]));

    return (true);
}

bool delete_mutation(mutation_type which_mutation, bool failMsg,
                     bool force_mutation, bool god_gift,
                     bool disallow_mismatch, bool non_fatal)
{
    ASSERT(!non_fatal || _is_random(which_mutation));

    if (!god_gift)
    {
        const god_type god =
            (crawl_state.is_god_acting()) ? crawl_state.which_god_acting()
                                          : GOD_NO_GOD;

        if (god != GOD_NO_GOD)
            god_gift = true;
    }

    mutation_type mutat = which_mutation;

    if (!force_mutation)
    {
        if (!god_gift)
        {
            if (player_mutation_level(MUT_MUTATION_RESISTANCE) > 1
                && (player_mutation_level(MUT_MUTATION_RESISTANCE) == 3
                    || coinflip()))
            {
                if (failMsg)
                    mpr("You feel rather odd for a moment.", MSGCH_MUTATION);
                return (false);
            }
        }
    }

    if (which_mutation == RANDOM_MUTATION
        || which_mutation == RANDOM_XOM_MUTATION
        || which_mutation == RANDOM_GOOD_MUTATION
        || which_mutation == RANDOM_BAD_MUTATION)
    {
        while (true)
        {
            if (one_chance_in(1000))
                return (false);

            mutat = static_cast<mutation_type>(random2(NUM_MUTATIONS));

            if (you.mutation[mutat] == 0
                && mutat != MUT_STRONG
                && mutat != MUT_CLEVER
                && mutat != MUT_AGILE
                && mutat != MUT_WEAK
                && mutat != MUT_DOPEY
                && mutat != MUT_CLUMSY)
            {
                continue;
            }

            if (!_accept_mutation(mutat, true, non_fatal, true))
                continue;

            if (you.demon_pow[mutat] >= you.mutation[mutat])
                continue;

            const mutation_def& mdef = get_mutation_def(mutat);

            if (random2(10) >= mdef.rarity)
                continue;

            const bool mismatch =
                (which_mutation == RANDOM_GOOD_MUTATION && mdef.bad)
                    || (which_mutation == RANDOM_BAD_MUTATION && !mdef.bad);

            if (mismatch && (disallow_mismatch || !one_chance_in(10)))
                continue;

            break;
        }
    }

    return (_delete_single_mutation_level(mutat));
}

bool delete_all_mutations()
{
    for (int i = 0; i < NUM_MUTATIONS; ++i)
    {
        while (_delete_single_mutation_level(static_cast<mutation_type>(i)))
            ;
    }

    return (!how_mutated());
}

static const mutation_type _all_scales[] = {
    MUT_SHAGGY_FUR,

    MUT_BONEY_PLATES,      MUT_GREEN_SCALES,    MUT_BLACK_SCALES,
    MUT_GREY_SCALES,       MUT_RED_SCALES,      MUT_NACREOUS_SCALES,
    MUT_GREY2_SCALES,      MUT_METALLIC_SCALES, MUT_BLACK2_SCALES,
    MUT_WHITE_SCALES,      MUT_YELLOW_SCALES,   MUT_BROWN_SCALES,
    MUT_BLUE_SCALES,       MUT_PURPLE_SCALES,   MUT_SPECKLED_SCALES,
    MUT_ORANGE_SCALES,     MUT_INDIGO_SCALES,   MUT_RED2_SCALES,
    MUT_IRIDESCENT_SCALES, MUT_PATTERNED_SCALES
};

static int _is_covering(mutation_type mut)
{
    for (unsigned i = 0; i < ARRAYSZ(_all_scales); ++i)
        if (_all_scales[i] == mut)
            return 1;

    return 0;
}

static int _body_covered()
{
    // Check how much of your body is covered by scales, etc.
    int covered = 0;

    if (you.species == SP_NAGA)
        covered++;

    if (player_genus(GENPC_DRACONIAN))
        covered += 3;


    for (unsigned i = 0; i < ARRAYSZ(_all_scales); ++i)
        covered += you.mutation[_all_scales[i]];

    return (covered);
}

// Return a string describing the mutation.
// If colour is true, also add the colour annotation.
std::string mutation_name(mutation_type mut, int level, bool colour)
{
    const bool fully_active = mutation_is_fully_active(mut);
    const bool fully_inactive =
        (!fully_active && _mutation_is_fully_inactive(mut));

    // level == -1 means default action of current level
    if (level == -1)
    {
        if (!fully_inactive)
            level = player_mutation_level(mut);
        else // give description of fully active mutation
            level = you.mutation[mut];
    }

    std::string result;
    bool innate = false;

    if (mut == MUT_CLAWS
        && (you.species == SP_TROLL || you.species == SP_GHOUL))
    {
        innate = true;
        if (you.species == SP_TROLL)
            result = troll_claw_descrip[level];
    }

    if ((mut == MUT_FAST || mut == MUT_BREATHE_POISON)
        && you.species == SP_NAGA)
    {
        innate = true;
        if (mut == MUT_FAST)
            result = naga_speed_descrip[level];
    }

    const mutation_def& mdef = get_mutation_def(mut);

    if (mut == MUT_STRONG || mut == MUT_CLEVER
        || mut == MUT_AGILE || mut == MUT_WEAK
        || mut == MUT_DOPEY || mut == MUT_CLUMSY)
    {
        std::ostringstream ostr;
        ostr << mdef.have[0] << level << ").";
        result = ostr.str();
    }
    else if (mut == MUT_ICEMAIL)
    {
        std::ostringstream ostr;

        int amt = ICEMAIL_MAX;
        amt -= you.duration[DUR_ICEMAIL_DEPLETED] * ICEMAIL_MAX / ICEMAIL_TIME;

        ostr << mdef.have[0] << amt << ").";
        result = ostr.str();
    }
    else if (result.empty() && level > 0)
        result = mdef.have[level - 1];

    if (fully_inactive || player_mutation_level(mut) < you.mutation[mut])
    {
        result = "(" + result;
        result += ")";
    }

    if (colour)
    {
        const char* colourname = "lightgrey"; // the default
        const bool permanent   = (you.demon_pow[mut] > 0);
        if (innate)
            colourname = (level > 0 ? "cyan" : "lightblue");
        else if (permanent)
        {
            const bool demonspawn = (you.species == SP_DEMONSPAWN);
            const bool extra = (you.mutation[mut] > you.demon_pow[mut]);

            if (fully_inactive)
                colourname = "darkgrey";
            else if (!fully_active)
                colourname = demonspawn ? "yellow"   : "blue";
            else if (extra)
                colourname = demonspawn ? "lightred" : "cyan";
            else
                colourname = demonspawn ? "red"      : "lightblue";
        }
        else if (fully_inactive)
            colourname = "darkgrey";

        // Build the result
        std::ostringstream ostr;
        ostr << '<' << colourname << '>' << result
             << "</" << colourname << ">";
        result = ostr.str();
    }

    return (result);
}

struct facet_def
{
    mutation_type muts[3];
    int tiers[3];
};

struct demon_mutation_info
{
    mutation_type mut;
    int tier;
    int facet;

    demon_mutation_info(mutation_type m, int t, int f)
        : mut(m), tier(t), facet(f) { }
};

static int ct_of_tier[] = { 0, 2, 3, 1 };

static const facet_def _demon_facets[] =
{
    { { MUT_CLAWS, MUT_CLAWS, MUT_CLAWS },
      { 2, 2, 2 } },
    { { MUT_HORNS, MUT_HORNS, MUT_HORNS },
      { 2, 2, 2 } },
    { { MUT_THROW_FLAMES, MUT_HEAT_RESISTANCE, MUT_HURL_HELLFIRE },
      { 3, 3, 3 } },
    { { MUT_THROW_FLAMES, MUT_HEAT_RESISTANCE, MUT_CONSERVE_SCROLLS },
      { 3, 3, 3 } },
    { { MUT_FAST, MUT_FAST, MUT_FAST },
      { 3, 3, 3 } },
    { { MUT_TELEPORT_AT_WILL, MUT_TELEPORT_AT_WILL, MUT_TELEPORT_AT_WILL },
      { 3, 3, 3 } },
    { { MUT_ROBUST, MUT_ROBUST, MUT_ROBUST },
      { 3, 3, 3 } },
    { { MUT_NEGATIVE_ENERGY_RESISTANCE, MUT_NEGATIVE_ENERGY_RESISTANCE,
          MUT_NEGATIVE_ENERGY_RESISTANCE },
      { 3, 3, 3 } },
    { { MUT_BLACK_SCALES, MUT_BLACK_SCALES, MUT_BLACK_SCALES },
      { 3, 3, 3 } },
    { { MUT_METALLIC_SCALES, MUT_METALLIC_SCALES, MUT_METALLIC_SCALES },
      { 3, 3, 3 } },
    { { MUT_RED2_SCALES, MUT_RED2_SCALES, MUT_RED2_SCALES },
      { 3, 3, 3 } },
    { { MUT_STOCHASTIC_TORMENT_RESISTANCE, MUT_STOCHASTIC_TORMENT_RESISTANCE,
          MUT_STOCHASTIC_TORMENT_RESISTANCE },
      { 3, 3, 3 } },
    { { MUT_REGENERATION, MUT_REGENERATION, MUT_REGENERATION },
      { 2, 2, 2 } },
    { { MUT_GREEN_SCALES, MUT_GREEN_SCALES, MUT_GREEN_SCALES },
      { 2, 2, 2 } },
    { { MUT_BLACK_SCALES, MUT_BLACK_SCALES, MUT_BLACK_SCALES },
      { 2, 2, 2 } },
    { { MUT_REPULSION_FIELD, MUT_REPULSION_FIELD, MUT_REPULSION_FIELD },
      { 2, 2, 2 } },
    { { MUT_MAGIC_RESISTANCE, MUT_MAGIC_RESISTANCE, MUT_MAGIC_RESISTANCE },
      { 2, 2, 2 } },
    { { MUT_BREATHE_FLAMES, MUT_BREATHE_FLAMES, MUT_BREATHE_FLAMES },
      { 2, 2, 2 } },
    { { MUT_NACREOUS_SCALES, MUT_NACREOUS_SCALES, MUT_NACREOUS_SCALES },
      { 2, 2, 2 } },
    { { MUT_GREY2_SCALES, MUT_GREY2_SCALES, MUT_GREY2_SCALES },
      { 2, 2, 2 } },
    { { MUT_BLACK2_SCALES, MUT_BLACK2_SCALES, MUT_BLACK2_SCALES },
      { 2, 2, 2 } },
    { { MUT_WHITE_SCALES, MUT_WHITE_SCALES, MUT_WHITE_SCALES },
      { 2, 2, 2 } },
    { { MUT_YELLOW_SCALES, MUT_YELLOW_SCALES, MUT_YELLOW_SCALES },
      { 2, 2, 2 } },
    { { MUT_BROWN_SCALES, MUT_BROWN_SCALES, MUT_BROWN_SCALES },
      { 2, 2, 2 } },
    { { MUT_PURPLE_SCALES, MUT_PURPLE_SCALES, MUT_PURPLE_SCALES },
      { 2, 2, 2 } },
    { { MUT_INDIGO_SCALES, MUT_INDIGO_SCALES, MUT_INDIGO_SCALES },
      { 2, 2, 2 } },
    { { MUT_PASSIVE_MAPPING, MUT_PASSIVE_MAPPING, MUT_PASSIVE_MAPPING },
      { 2, 2, 2 } },
    { { MUT_COLD_RESISTANCE, MUT_CONSERVE_POTIONS, MUT_ICEMAIL },
      { 2, 2, 2 } },
    { { MUT_COLD_RESISTANCE, MUT_CONSERVE_POTIONS, MUT_PASSIVE_FREEZE },
      { 2, 2, 2 } },
    { { MUT_TOUGH_SKIN, MUT_TOUGH_SKIN, MUT_TOUGH_SKIN },
      { 1, 1, 1 } },
    { { MUT_GREY_SCALES, MUT_GREY_SCALES, MUT_GREY_SCALES },
      { 1, 1, 1 } },
    { { MUT_BONEY_PLATES, MUT_BONEY_PLATES, MUT_BONEY_PLATES },
      { 1, 1, 1 } },
    { { MUT_SLOW_METABOLISM, MUT_SLOW_METABOLISM, MUT_SLOW_METABOLISM },
      { 1, 1, 1 } },
    { { MUT_SPIT_POISON, MUT_SPIT_POISON, MUT_SPIT_POISON },
      { 1, 1, 1 } },
    { { MUT_BLINK, MUT_BLINK, MUT_BLINK },
      { 1, 1, 1 } },
    { { MUT_SHAGGY_FUR, MUT_SHAGGY_FUR, MUT_SHAGGY_FUR },
      { 1, 1, 1 } },
    { { MUT_HIGH_MAGIC, MUT_HIGH_MAGIC, MUT_HIGH_MAGIC },
      { 1, 1, 1 } },
    { { MUT_RED_SCALES, MUT_RED_SCALES, MUT_RED_SCALES },
      { 1, 1, 1 } },
    { { MUT_BLUE_SCALES, MUT_BLUE_SCALES, MUT_BLUE_SCALES },
      { 1, 1, 1 } },
    { { MUT_SPECKLED_SCALES, MUT_SPECKLED_SCALES, MUT_SPECKLED_SCALES },
      { 1, 1, 1 } },
    { { MUT_ORANGE_SCALES, MUT_ORANGE_SCALES, MUT_ORANGE_SCALES },
      { 1, 1, 1 } },
    { { MUT_IRIDESCENT_SCALES, MUT_IRIDESCENT_SCALES, MUT_IRIDESCENT_SCALES },
      { 1, 1, 1 } },
    { { MUT_PATTERNED_SCALES, MUT_PATTERNED_SCALES, MUT_PATTERNED_SCALES },
      { 1, 1, 1 } },
};

static bool _works_at_tier(const facet_def& facet, int tier)
{
    return facet.tiers[0] == tier
        || facet.tiers[1] == tier
        || facet.tiers[2] == tier;
}

static int _rank_for_tier(const facet_def& facet, int tier)
{
    int k;

    for (k = 0; k < 3 && facet.tiers[k] <= tier; ++k);

    return (k);
}

static std::vector<demon_mutation_info> _select_ds_mutations()
{
try_again:
    std::vector<demon_mutation_info> ret;

    ret.clear();
    int absfacet = 0;
    int scales = 0;
    int slow_dig = 0;
    int regen = 0;
    int slots_lost = 0;
    int breath_weapons = 0;

    std::set<const facet_def *> facets_used;

    for (int tier = ARRAYSZ(ct_of_tier) - 1; tier >= 0; --tier)
    {
        for (int nfacet = 0; nfacet < ct_of_tier[tier]; ++nfacet)
        {
            const facet_def* next_facet;

            do
            {
                next_facet = &RANDOM_ELEMENT(_demon_facets);
            }
            while (!_works_at_tier(*next_facet, tier)
                   || facets_used.find(next_facet) != facets_used.end());

            facets_used.insert(next_facet);

            for (int i = 0; i < _rank_for_tier(*next_facet, tier); ++i)
            {
                mutation_type m = next_facet->muts[i];

                ret.push_back(demon_mutation_info(m, next_facet->tiers[i],
                                                  absfacet));

                if (_is_covering(m))
                    ++scales;

                if (m == MUT_SLOW_METABOLISM)
                    slow_dig = 1;

                if (m == MUT_REGENERATION)
                    regen = 1;

                if (m == MUT_SPIT_POISON || m == MUT_BREATHE_POISON
                        || m == MUT_BREATHE_FLAMES)
                    breath_weapons++;

                if (m == MUT_CLAWS && i == 2 || m == MUT_HORNS && i == 0)
                    ++slots_lost;
            }

            ++absfacet;
        }
    }

    if (scales > 3)
        goto try_again;

    if (slots_lost != 1)
        goto try_again;

    if (slow_dig && regen)
        goto try_again;

    if (breath_weapons > 1)
        goto try_again;

    return ret;
}

static std::vector<mutation_type>
_order_ds_mutations(std::vector<demon_mutation_info> muts)
{
    std::vector<mutation_type> out;

    while (! muts.empty())
    {
        int first_tier = 99;

        for (unsigned i = 0; i < muts.size(); ++i)
        {
            first_tier = std::min(first_tier, muts[i].tier);
        }

        int ix;

        do
        {
            ix = random2(muts.size());
        }
        // Don't consider mutations from more than two tiers at a time
        while (muts[ix].tier >= first_tier + 2);

        // Don't reorder mutations within a facet
        for (int j = 0; j < ix; ++j)
        {
            if (muts[j].facet == muts[ix].facet)
            {
                ix = j;
                break;
            }
        }

        out.push_back(muts[ix].mut);
        muts.erase(muts.begin() + ix);
    }

    return out;
}

static std::vector<player::demon_trait>
_schedule_ds_mutations(std::vector<mutation_type> muts)
{
    std::list<mutation_type> muts_left(muts.begin(), muts.end());

    std::list<int> slots_left;

    std::vector<player::demon_trait> out;

    for (int level = 2; level <= 27; ++level)
    {
        int ct = coinflip() ? 2 : 1;

        for (int i = 0; i < ct; ++i)
            slots_left.push_back(level);
    }

    while (!muts_left.empty())
    {
        if (x_chance_in_y(muts_left.size(), slots_left.size()))
        {
            player::demon_trait dt;

            dt.level_gained = slots_left.front();
            dt.mutation     = muts_left.front();

#ifdef DEBUG_DIAGNOSTICS
            mprf(MSGCH_DIAGNOSTICS, "Demonspawn will gain %s at level %d",
                    get_mutation_def(dt.mutation).wizname, dt.level_gained);
#endif

            out.push_back(dt);

            muts_left.pop_front();
        }
        slots_left.pop_front();
    }

    return out;
}

void roll_demonspawn_mutations()
{
    you.demonic_traits = _schedule_ds_mutations(
                         _order_ds_mutations(
                         _select_ds_mutations()));
}

bool perma_mutate(mutation_type which_mut, int how_much)
{
    int levels = 0;

    how_much = std::min(static_cast<short>(how_much),
                        mutation_defs[which_mut].levels);

    if (mutate(which_mut, false, true, false, false, true))
        levels++;

    if (how_much >= 2 && mutate(which_mut, false, true, false, false, true))
        levels++;

    if (how_much >= 3 && mutate(which_mut, false, true, false, false, true))
        levels++;

    you.demon_pow[which_mut] += levels;

    return (levels > 0);
}

int how_mutated(bool all, bool levels)
{
    int j = 0;

    for (int i = 0; i < NUM_MUTATIONS; ++i)
    {
        if (you.mutation[i])
        {
            if (!all && you.demon_pow[i] >= you.mutation[i])
                continue;

            if (levels)
            {
                // These allow for 14 levels.
                if (i == MUT_STRONG || i == MUT_CLEVER || i == MUT_AGILE
                    || i == MUT_WEAK || i == MUT_DOPEY || i == MUT_CLUMSY)
                {
                    j += (you.mutation[i] / 5 + 1);
                }
                else
                    j += you.mutation[i];
            }
            else
                j++;
        }
    }

    dprf("how_mutated(): all = %u, levels = %u, j = %d", all, levels, j);

    return (j);
}

bool give_bad_mutation(bool failMsg, bool force_mutation, bool non_fatal)
{
    const mutation_type bad_muts[] = {
        MUT_CARNIVOROUS,   MUT_HERBIVOROUS,   MUT_FAST_METABOLISM,
        MUT_WEAK,          MUT_DOPEY,
        MUT_CLUMSY,        MUT_TELEPORT,      MUT_DEFORMED,
        MUT_SCREAM,        MUT_DETERIORATION, MUT_BLURRY_VISION,
        MUT_FRAIL,         MUT_LOW_MAGIC
    };

    mutation_type mutat;

    do
        mutat = RANDOM_ELEMENT(bad_muts);
    while (non_fatal && !_accept_mutation(mutat, true, true));

    const bool result = mutate(mutat, failMsg, force_mutation);
    if (result)
        learned_something_new(TUT_YOU_MUTATED);

    return (result);
}