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
|
/*
* File: mutation.cc
* Summary: Functions for handling player mutations.
* Written by: Linley Henzell
*/
#include "AppHdr.h"
#include "mutation.h"
#include <math.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 "coordit.h"
#include "delay.h"
#include "defines.h"
#include "dgn-actions.h"
#include "effects.h"
#include "env.h"
#include "format.h"
#include "godabil.h"
#include "itemprop.h"
#include "macro.h"
#include "menu.h"
#include "mgen_data.h"
#include "mon-place.h"
#include "mon-iter.h"
#include "mon-stuff.h"
#include "mon-util.h"
#include "notes.h"
#include "ouch.h"
#include "player.h"
#include "player-stats.h"
#include "religion.h"
#include "random.h"
#include "skills2.h"
#include "stuff.h"
#include "transform.h"
#include "hints.h"
#include "view.h"
#include "xom.h"
static int _body_covered();
mutation_def mut_data[] = {
#include "mutation-data.h"
};
#define MUTDATASIZE (sizeof(mut_data)/sizeof(mutation_def))
static const body_facet_def _body_facets[] =
{
//{ EQ_NONE, MUT_FANGS, 1 },
{ EQ_HELMET, MUT_HORNS, 1 },
{ EQ_HELMET, MUT_ANTENNAE, 1 },
//{ EQ_HELMET, MUT_BEAK, 1 },
{ EQ_GLOVES, MUT_CLAWS, 3 },
{ EQ_BOOTS, MUT_HOOVES, 3 },
{ EQ_BOOTS, MUT_TALONS, 3 }
};
static int mut_index[NUM_MUTATIONS];
void init_mut_index()
{
for (int i = 0; i < NUM_MUTATIONS; ++i)
mut_index[i] = -1;
for (unsigned int i = 0; i < MUTDATASIZE; ++i)
{
const mutation_type mut = mut_data[i].mutation;
ASSERT(mut >= 0 && mut < NUM_MUTATIONS);
ASSERT(mut_index[mut] == -1);
mut_index[mut] = i;
}
}
static mutation_def* _seek_mutation(mutation_type mut)
{
ASSERT(mut >= 0 && mut < NUM_MUTATIONS);
if (mut_index[mut] == -1)
return (NULL);
else
return (&mut_data[mut_index[mut]]);
}
bool is_valid_mutation(mutation_type mut)
{
return (mut >= 0 && mut < NUM_MUTATIONS
&& _seek_mutation(mut));
}
bool is_body_facet(mutation_type mut)
{
for (unsigned i = 0; i < ARRAYSZ(_body_facets); i++)
{
if (_body_facets[i].mut == mut)
return (true);
}
return (false);
}
const mutation_def& get_mutation_def(mutation_type mut)
{
ASSERT(is_valid_mutation(mut));
return (*_seek_mutation(mut));
}
void fixup_mutations()
{
if (player_genus(GENPC_DRACONIAN))
{
ASSERT(is_valid_mutation(MUT_STINGER));
_seek_mutation(MUT_STINGER)->rarity = 8;
ASSERT(is_valid_mutation(MUT_BIG_WINGS));
_seek_mutation(MUT_BIG_WINGS)->rarity = 4;
}
if (you.species == SP_NAGA)
{
ASSERT(is_valid_mutation(MUT_STINGER));
_seek_mutation(MUT_STINGER)->rarity = 8;
}
}
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.innate_mutations[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.innate_mutations[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>\n\n";
// 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.\n";
have_any = true;
break;
case SP_NAGA:
result += "You cannot wear boots.\n";
// Breathe poison replaces spit poison.
if (!you.mutation[MUT_BREATHE_POISON])
result += "You can spit poison.\n";
if (you.experience_level > 2)
{
std::ostringstream num;
num << you.experience_level/3;
result += "Your serpentine skin is tough (AC +" + num.str() + ").\n";
}
have_any = true;
break;
case SP_GHOUL:
result += "Your body is rotting away.\n";
have_any = true;
break;
case SP_KENKU:
if (you.experience_level > 4)
{
result += "You can fly";
if (you.experience_level > 14)
result += " continuously";
result += ".\n";
have_any = true;
}
break;
case SP_MUMMY:
result += "Your flesh is vulnerable to fire.\n";
if (you.experience_level > 12)
{
result += "You are";
if (you.experience_level > 25)
result += " strongly";
result += " in touch with the powers of death.\n";
result +=
"You can restore your body by infusing magical energy.\n";
}
have_any = true;
break;
case SP_GREY_DRACONIAN:
result += "Your tail is studded with spikes.\n";
have_any = true;
break;
case SP_GREEN_DRACONIAN:
result += "You can breathe poison.\n";
have_any = true;
break;
case SP_RED_DRACONIAN:
result += "You can breathe fire.\n";
have_any = true;
break;
case SP_WHITE_DRACONIAN:
result += "You can breathe cold.\n";
have_any = true;
break;
case SP_BLACK_DRACONIAN:
result += "You can breathe lightning.\n";
have_any = true;
break;
case SP_YELLOW_DRACONIAN:
result += "You can spit acid.\n";
result += "You are resistant to acid.\n";
have_any = true;
break;
case SP_PURPLE_DRACONIAN:
result += "You can breathe power.\n";
have_any = true;
break;
case SP_MOTTLED_DRACONIAN:
result += "You can breathe sticky flames.\n";
have_any = true;
break;
case SP_PALE_DRACONIAN:
result += "You can breathe steam.\n";
have_any = true;
break;
case SP_KOBOLD:
result += "You recuperate from illness quickly.\n";
have_any = true;
break;
case SP_VAMPIRE:
have_any = true;
if (you.hunger_state == HS_STARVING)
result += "<green>You do not heal naturally.</green>\n";
else if (you.hunger_state == HS_ENGORGED)
result += "<green>Your natural rate of healing is extremely fast.</green>\n";
else if (you.hunger_state < HS_SATIATED)
result += "<green>You heal slowly.</green>\n";
else if (you.hunger_state >= HS_FULL)
result += "<green>Your natural rate of healing is unusually fast.</green>\n";
else
have_any = false;
if (you.experience_level >= 6)
{
result += "You can bottle blood from corpses.\n";
have_any = true;
}
break;
case SP_DEEP_DWARF:
result += "You are resistant to damage.\n";
result += "You can recharge devices by infusing magical energy.\n";
have_any = true;
break;
default:
break;
}
switch(you.body_size(PSIZE_TORSO, true))
{
case SIZE_LITTLE:
result += "You are tiny and cannot use many weapons and most armour.\n";
have_any = true;
break;
case SIZE_SMALL:
result += "You are small and have problems with some larger weapons.\n";
have_any = true;
break;
case SIZE_LARGE:
result += "You are too large for most types of armour.\n";
have_any = true;
break;
default:
;
}
if (player_genus(GENPC_DRACONIAN))
{
// Draconians are large for the purposes of armour, but only medium for
// weapons and carrying capacity.
result += "Your body does not fit into most forms of armour.\n";
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() + ").\n";
}
result += "</lightblue>";
if (beogh_water_walk())
{
result += "<green>You can walk on water.</green>\n";
have_any = true;
}
if (you.duration[DUR_FIRE_SHIELD])
{
result += "<green>You are immune to clouds of flame.</green>\n";
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.innate_mutations[i])
{
mutation_type mut_type = static_cast<mutation_type>(i);
result += mutation_name(mut_type, -1, true);
result += "\n";
have_any = true;
}
}
// Now add removable mutations.
for (int i = 0; i < NUM_MUTATIONS; i++)
{
if (you.mutation[i] != 0 && !you.innate_mutations[i])
{
mutation_type mut_type = static_cast<mutation_type>(i);
result += mutation_name(mut_type, -1, true);
result += "\n";
have_any = true;
}
}
if (!have_any)
result += "You are rather mundane.\n";
if (you.species == SP_VAMPIRE)
{
result += "\n\n";
result += "\n\n";
result +=
#ifndef USE_TILE
"Press '<w>!</w>'"
#else
"<w>Right-click</w>"
#endif
" to toggle between mutations and properties depending on your\n"
"hunger status.\n";
}
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 "},
{"\n<w>Resistances</w>\n"
"Poison resistance ", " ", " ", " ", " + ", " + ", " + "},
{"Cold resistance ", " ", " ", " ", " + ", " ++ ", " ++ "},
{"Negative resistance ", " ", " ", " + ", " ++ ", " +++ ", " +++ "},
{"Rotting resistance ", " ", " ", " ", " + ", " + ", " + "},
{"Torment resistance ", " ", " ", " ", " ", " ", " + "},
{"\n<w>Other effects</w>\n"
"Mutation chance ", "always ", "often ", "sometimes ", "never ", "never ", "never "},
{"Non-physical \n"
"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 \n"
"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 += "\n";
}
result += "\n";
result +=
#ifndef USE_TILE
"Press '<w>!</w>'"
#else
"<w>Right-click</w>"
#endif
" to toggle between mutations and properties depending on your\n"
"hunger status.\n";
const formatted_string vp_props = formatted_string::parse_string(result);
vp_props.display();
mouse_control mc(MOUSE_MODE_MORE);
const int keyin = getchm();
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 = getchm();
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:
case MUT_SLOW:
amusement *= 2; // funny!
break;
default:
break;
}
return (amusement);
}
static bool _accept_mutation(mutation_type mutat, bool ignore_rarity = false)
{
if (!is_valid_mutation(mutat))
return (false);
const mutation_def& mdef = get_mutation_def(mutat);
if (you.mutation[mutat] >= mdef.levels)
return (false);
if (ignore_rarity)
return (true);
const int rarity = mdef.rarity + you.innate_mutations[mutat];
// Low rarity means unlikely to choose it.
return (x_chance_in_y(rarity, 10));
}
static mutation_type _get_random_slime_mutation()
{
const mutation_type slime_muts[] = {
MUT_GELATINOUS_BODY, MUT_EYEBALLS, MUT_TRANSLUCENT_SKIN,
MUT_PSEUDOPODS, MUT_FOOD_JELLY, MUT_ACIDIC_BITE
};
return RANDOM_ELEMENT(slime_muts);
}
static mutation_type _delete_random_slime_mutation()
{
mutation_type mutat;
while (true)
{
mutat = _get_random_slime_mutation();
if (you.mutation[mutat] > 0)
break;
if (one_chance_in(500))
{
mutat = NUM_MUTATIONS;
break;
}
}
return mutat;
}
static bool _is_slime_mutation(mutation_type m)
{
return (m == MUT_GELATINOUS_BODY || m == MUT_EYEBALLS
|| m == MUT_TRANSLUCENT_SKIN || m == MUT_PSEUDOPODS
|| m == MUT_FOOD_JELLY || m == MUT_ACIDIC_BITE);
}
static mutation_type _get_random_xom_mutation()
{
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));
return (mutat);
}
static mutation_type _get_random_mutation(int preferred_multiplier = 100,
bool prefer_good = true)
{
int cweight = 0;
mutation_type chosen = NUM_MUTATIONS;
for (unsigned i = 0; i < NUM_MUTATIONS; ++i)
{
const mutation_type curr = static_cast<mutation_type>(i);
if (!is_valid_mutation(curr))
continue;
const mutation_def& mdef = get_mutation_def(curr);
if (!mdef.rarity)
continue;
if (!_accept_mutation(curr, true))
continue;
const bool weighted = mdef.bad != prefer_good;
int weight = mdef.rarity;
if (weighted)
weight = weight * preferred_multiplier / 100;
cweight += weight;
if (x_chance_in_y(weight, cweight))
chosen = curr;
}
return (chosen);
}
// 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 },
{ MUT_FAST, MUT_SLOW }
};
// 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_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 },
{ MUT_FAST, MUT_SLOW }
};
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 const mutation_type _all_scales[] = {
MUT_DISTORTION_FIELD, MUT_ICY_BLUE_SCALES,
MUT_IRIDESCENT_SCALES, MUT_LARGE_BONE_PLATES,
MUT_MOLTEN_SCALES, MUT_ROUGH_BLACK_SCALES,
MUT_RUGGED_BROWN_SCALES, MUT_SLIMY_GREEN_SCALES,
MUT_THIN_METALLIC_SCALES, MUT_THIN_SKELETAL_STRUCTURE,
MUT_YELLOW_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);
}
static bool _physiology_mutation_conflict(mutation_type mutat)
{
// If demonspawn, and mutat is a scale, see if they were going
// to get it sometime in the future anyway; otherwise, conflict.
if (you.species == SP_DEMONSPAWN && _is_covering(mutat) &&
std::find(_all_scales, _all_scales+ARRAYSZ(_all_scales), mutat) !=
_all_scales+ARRAYSZ(_all_scales))
{
bool found = false;
for (unsigned j = 0; j < you.demonic_traits.size(); ++j)
{
if (you.demonic_traits[j].mutation == mutat)
found = true;
}
return (!found);
}
// Strict 3-scale limit.
if (_is_covering(mutat) && _body_covered() >= 3)
return (true);
// 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);
}
equipment_type eq_type = EQ_NONE;
// Mutations of the same slot conflict
if (is_body_facet(mutat))
{
// Find equipment slot of attempted mutation
for (unsigned i = 0; i < ARRAYSZ(_body_facets); i++)
if (mutat == _body_facets[i].mut)
eq_type = _body_facets[i].eq;
if (eq_type != EQ_NONE)
{
for (unsigned i = 0; i < ARRAYSZ(_body_facets); i++)
{
if (eq_type == _body_facets[i].eq
&& mutat != _body_facets[i].mut
&& player_mutation_level(_body_facets[i].mut))
{
return (true);
}
}
}
}
return (false);
}
static const char* _stat_mut_desc(mutation_type mut, bool gain)
{
stat_type stat = STAT_STR;
bool positive = gain;
switch (mut)
{
case MUT_WEAK:
positive = !positive;
case MUT_STRONG:
stat = STAT_STR;
break;
case MUT_DOPEY:
positive = !positive;
case MUT_CLEVER:
stat = STAT_INT;
break;
case MUT_CLUMSY:
positive = !positive;
case MUT_AGILE:
stat = STAT_DEX;
break;
default:
ASSERT(false);
break;
}
return (stat_desc(stat, positive ? SD_INCREASE : SD_DECREASE));
}
bool mutate(mutation_type which_mutation, bool failMsg,
bool force_mutation, bool god_gift, bool stat_gain_potion,
bool demonspawn)
{
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));
}
}
switch (which_mutation)
{
case RANDOM_MUTATION:
mutat = _get_random_mutation();
break;
case RANDOM_XOM_MUTATION:
mutat = _get_random_xom_mutation();
break;
case RANDOM_GOOD_MUTATION:
mutat = _get_random_mutation(500, true);
break;
case RANDOM_BAD_MUTATION:
mutat = _get_random_mutation(500, false);
break;
case RANDOM_SLIME_MUTATION:
mutat = _get_random_slime_mutation();
break;
default:
break;
}
if (!is_valid_mutation(mutat))
return (false);
// [Cha] don't allow teleportation or teleport at will mutations in sprint
if ((mutat == MUT_TELEPORT || mutat == MUT_TELEPORT_AT_WILL)
&& crawl_state.game_is_sprint())
{
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)
{
bool found = false;
if (you.species == SP_DEMONSPAWN)
for (unsigned i = 0; i < you.demonic_traits.size(); ++i)
if (you.demonic_traits[i].mutation == mutat)
{
// This mutation is about to be re-gained, so there is
// no need to redraw any stats or print any messages.
found = true;
you.mutation[mutat]--;
break;
}
if (!found)
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;
switch (mutat)
{
case MUT_STRONG: case MUT_AGILE: case MUT_CLEVER:
case MUT_WEAK: case MUT_CLUMSY: case MUT_DOPEY:
mprf(MSGCH_MUTATION, "You feel %s.", _stat_mut_desc(mutat, 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 at 3. Check for level 2 or
// higher here.
if (you.mutation[mutat] >= 2 && !you.melded[EQ_BOOTS])
remove_one_equip(EQ_BOOTS, false, 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.melded[EQ_GLOVES])
remove_one_equip(EQ_GLOVES, false, true);
break;
case MUT_HORNS:
case MUT_BEAK:
case MUT_ANTENNAE:
mpr(mdef.gain[you.mutation[mutat]], MSGCH_MUTATION);
gain_msg = false;
// Horns, beaks, and antennae force hard helmets off.
if (you.equip[EQ_HELMET] != -1
&& is_hard_helmet(you.inv[you.equip[EQ_HELMET]])
&& !you.melded[EQ_HELMET])
{
remove_one_equip(EQ_HELMET, false, 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;
case MUT_NIGHTSTALKER:
// If we already have at least one level of the mutation, we're
// about to go to either level 2 or 3, so we need an LOS
// reduction.
if (player_mutation_level(mutat))
{
you.current_vision -= 2;
set_los_radius(you.current_vision);
}
break;
default:
break;
}
// For all those scale mutations.
you.redraw_armour_class = true;
you.mutation[mutat]++;
notify_stat_change("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
|| mutat == MUT_RUGGED_BROWN_SCALES)
{
calc_hp();
}
if (mutat == MUT_LOW_MAGIC || mutat == MUT_HIGH_MAGIC)
calc_mp();
if (mutat == MUT_PASSIVE_MAPPING)
add_daction(DACT_REAUTOMAP);
// 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 (Hints.hints_left && your_talents(false).size() > old_talents)
learned_something_new(HINT_NEW_ABILITY_MUT);
return (true);
}
static bool _delete_single_mutation_level(mutation_type mutat)
{
if (you.mutation[mutat] == 0)
return (false);
if (you.innate_mutations[mutat] >= you.mutation[mutat])
return (false);
const mutation_def& mdef = get_mutation_def(mutat);
bool lose_msg = true;
switch (mutat)
{
case MUT_STRONG: case MUT_AGILE: case MUT_CLEVER:
case MUT_WEAK: case MUT_CLUMSY: case MUT_DOPEY:
mprf(MSGCH_MUTATION, "You feel %s.", _stat_mut_desc(mutat, false));
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;
case MUT_NIGHTSTALKER:
// If we already have more than one level of the mutation, we're
// about to go to either level 2 or 1, so we need an LOS
// increase.
if (player_mutation_level(mutat) > 1)
{
you.current_vision += 2;
set_los_radius(you.current_vision);
}
break;
default:
break;
}
// For all those scale mutations.
you.redraw_armour_class = true;
you.mutation[mutat]--;
notify_stat_change("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
|| mutat == MUT_RUGGED_BROWN_SCALES)
{
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)
{
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
|| which_mutation == RANDOM_NON_SLIME_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 (which_mutation == RANDOM_NON_SLIME_MUTATION
&& _is_slime_mutation(mutat))
{
continue;
}
if (you.innate_mutations[mutat] >= you.mutation[mutat])
continue;
const mutation_def& mdef = get_mutation_def(mutat);
if (random2(10) >= mdef.rarity && !_is_slime_mutation(mutat))
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;
}
}
else if (which_mutation == RANDOM_SLIME_MUTATION)
{
mutat = _delete_random_slime_mutation();
if (mutat == NUM_MUTATIONS)
return false;
}
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());
}
// 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_BREATHE_POISON && you.species == SP_NAGA)
innate = true;
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;
ostr << mdef.have[0] << player_icemail_armour_class() << ").";
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 = (mdef.bad ? "red" : "lightgrey");
const bool permanent = (you.innate_mutations[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.innate_mutations[mut]);
if (fully_inactive)
colourname = "darkgrey";
else if (!fully_active)
colourname = demonspawn ? "yellow" : "blue";
else if (extra)
colourname = demonspawn ? "lightmagenta" : "cyan";
else
colourname = demonspawn ? "magenta" : "lightblue";
}
else if (fully_inactive)
colourname = "darkgrey";
else if (_is_slime_mutation(mut))
colourname = "green";
// Build the result
std::ostringstream ostr;
ostr << '<' << colourname << '>' << result
<< "</" << colourname << '>';
result = ostr.str();
}
return (result);
}
static const facet_def _demon_facets[] =
{
// Body Slot facets
{ { MUT_CLAWS, MUT_CLAWS, MUT_CLAWS },
{ 2, 2, 2 } },
{ { MUT_HORNS, MUT_HORNS, MUT_HORNS },
{ 2, 2, 2 } },
{ { MUT_ANTENNAE, MUT_ANTENNAE, MUT_ANTENNAE },
{ 2, 2, 2 } },
{ { MUT_HOOVES, MUT_HOOVES, MUT_HOOVES },
{ 2, 2, 2 } },
{ { MUT_TALONS, MUT_TALONS, MUT_TALONS },
{ 2, 2, 2 } },
// Regular facets
{ { 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_ROBUST, MUT_ROBUST, MUT_ROBUST },
{ 3, 3, 3 } },
{ { MUT_NEGATIVE_ENERGY_RESISTANCE, MUT_NEGATIVE_ENERGY_RESISTANCE,
MUT_NEGATIVE_ENERGY_RESISTANCE },
{ 3, 3, 3 } },
{ { MUT_STOCHASTIC_TORMENT_RESISTANCE, MUT_STOCHASTIC_TORMENT_RESISTANCE,
MUT_STOCHASTIC_TORMENT_RESISTANCE },
{ 3, 3, 3 } },
{ { MUT_POWERED_BY_DEATH, MUT_POWERED_BY_DEATH, MUT_POWERED_BY_DEATH },
{ 2, 2, 2 } },
{ { MUT_MAGIC_RESISTANCE, MUT_MAGIC_RESISTANCE, MUT_MAGIC_RESISTANCE },
{ 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_DEMONIC_GUARDIAN, MUT_DEMONIC_GUARDIAN, MUT_DEMONIC_GUARDIAN },
{ 2, 2, 2 } },
{ { MUT_NIGHTSTALKER, MUT_NIGHTSTALKER, MUT_NIGHTSTALKER },
{ 2, 2, 2 } },
{ { MUT_SPINY, MUT_SPINY, MUT_SPINY },
{ 2, 2, 2 } },
{ { MUT_SPIT_POISON, MUT_SPIT_POISON, MUT_SPIT_POISON },
{ 1, 1, 1 } },
{ { MUT_BREATHE_FLAMES, MUT_BREATHE_FLAMES, MUT_BREATHE_FLAMES },
{ 1, 1, 1 } },
// Scale mutations
{ { MUT_DISTORTION_FIELD, MUT_DISTORTION_FIELD, MUT_DISTORTION_FIELD },
{ 1, 1, 1 } },
{ { MUT_ICY_BLUE_SCALES, MUT_ICY_BLUE_SCALES, MUT_ICY_BLUE_SCALES },
{ 1, 1, 1 } },
{ { MUT_IRIDESCENT_SCALES, MUT_IRIDESCENT_SCALES, MUT_IRIDESCENT_SCALES },
{ 1, 1, 1 } },
{ { MUT_LARGE_BONE_PLATES, MUT_LARGE_BONE_PLATES, MUT_LARGE_BONE_PLATES },
{ 1, 1, 1 } },
{ { MUT_MOLTEN_SCALES, MUT_MOLTEN_SCALES, MUT_MOLTEN_SCALES },
{ 1, 1, 1 } },
{ { MUT_ROUGH_BLACK_SCALES, MUT_ROUGH_BLACK_SCALES, MUT_ROUGH_BLACK_SCALES },
{ 1, 1, 1 } },
{ { MUT_RUGGED_BROWN_SCALES, MUT_RUGGED_BROWN_SCALES,
MUT_RUGGED_BROWN_SCALES },
{ 1, 1, 1 } },
{ { MUT_SLIMY_GREEN_SCALES, MUT_SLIMY_GREEN_SCALES, MUT_SLIMY_GREEN_SCALES },
{ 1, 1, 1 } },
{ { MUT_THIN_METALLIC_SCALES, MUT_THIN_METALLIC_SCALES,
MUT_THIN_METALLIC_SCALES },
{ 1, 1, 1 } },
{ { MUT_THIN_SKELETAL_STRUCTURE, MUT_THIN_SKELETAL_STRUCTURE,
MUT_THIN_SKELETAL_STRUCTURE },
{ 1, 1, 1 } },
{ { MUT_YELLOW_SCALES, MUT_YELLOW_SCALES, MUT_YELLOW_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 bool _slot_is_unique(const mutation_type mut[],
std::set<const facet_def *> facets_used)
{
std::set<const facet_def *>::const_iterator iter;
equipment_type eq[ARRAYSZ(mut)];
int k = 0;
// find the equipment slot(s) used by mut
for (unsigned i = 0; i < ARRAYSZ(_body_facets); i++)
{
for (unsigned j = 0; j < ARRAYSZ(mut); j++)
{
if (_body_facets[i].mut == mut[j])
eq[k++] = _body_facets[i].eq;
}
}
if (k == 0)
return true;
for (iter = facets_used.begin() ; iter != facets_used.end() ; iter++)
{
for (unsigned i = 0; i < ARRAYSZ(_body_facets); i++)
{
if (_body_facets[i].mut == (*iter)->muts[0])
{
for (unsigned j = 0; j < ARRAYSZ(eq); j++)
{
if (_body_facets[i].eq == eq[j])
return false;
}
}
}
}
return true;
}
static std::vector<demon_mutation_info> _select_ds_mutations()
{
int NUM_BODY_SLOTS = 1;
int ct_of_tier[] = { 0, 2, 3, 1 };
// 1 in 10 chance to create a monstrous set
if (one_chance_in(10))
{
NUM_BODY_SLOTS = 3;
ct_of_tier[1] = 1;
ct_of_tier[2] = 5;
}
try_again:
std::vector<demon_mutation_info> ret;
ret.clear();
int absfacet = 0;
int scales = 0;
int slots_lost = 0;
int breath_weapons = 0;
int elemental = 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()
|| !_slot_is_unique(next_facet->muts, facets_used));
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 (i == 0 && (m == MUT_SPIT_POISON || m == MUT_BREATHE_FLAMES))
breath_weapons++;
if (m == MUT_COLD_RESISTANCE || m == MUT_THROW_FLAMES)
elemental++;
if (m == MUT_CLAWS && i == 2
|| m == MUT_HORNS && i == 0
|| m == MUT_BEAK && i == 0
|| m == MUT_ANTENNAE && i == 0
|| m == MUT_TALONS && i == 2
|| m == MUT_HOOVES && i == 2)
{
++slots_lost;
}
}
++absfacet;
}
}
if (scales > 3)
goto try_again;
if (slots_lost != NUM_BODY_SLOTS)
goto try_again;
if (breath_weapons > 1)
goto try_again;
if (elemental > 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)
{
ASSERT(is_valid_mutation(which_mut));
int levels = 0;
how_much = std::min(static_cast<short>(how_much),
get_mutation_def(which_mut).levels);
int rc = 1;
// clear out conflicting mutations
while (rc == 1)
rc = _handle_conflicting_mutations(which_mut, true);
while (how_much-- > 0)
if (mutate(which_mut, false, true, false, false, true))
levels++;
you.innate_mutations[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.innate_mutations[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 balance_demonic_guardian()
{
const int mutlevel = player_mutation_level(MUT_DEMONIC_GUARDIAN);
int tension = get_tension(GOD_NO_GOD), mons_val = 0, total = 0;
monster_iterator mons;
if (tension*3/4 > mutlevel*6 + random2(mutlevel*mutlevel*2))
return (true);
for (int i = 0; mons && i <= 20/mutlevel; mons++)
{
mons_val = get_monster_tension(*mons, GOD_NO_GOD);
const mon_attitude_type att = mons_attitude(*mons);
if (testbits(mons->flags, MF_DEMONIC_GUARDIAN)
&& total < random2(mutlevel * 5)
&& att == ATT_FRIENDLY && !one_chance_in(3))
{
mpr(mons->name(DESC_CAP_THE) + " "
+ summoned_poof_msg(*mons) + "!", MSGCH_PLAIN);
monster_die(*mons, KILL_NONE, NON_MONSTER);
}
else
total += mons_val;
}
return (false);
}
void check_demonic_guardian()
{
const int mutlevel = player_mutation_level(MUT_DEMONIC_GUARDIAN);
if (you.duration[DUR_DEMONIC_GUARDIAN] == 0
&& balance_demonic_guardian())
{
const monster_type disallowed[] = { MONS_NEQOXEC, MONS_YNOXINUL, MONS_HELLWING,
MONS_BLUE_DEATH, MONS_GREEN_DEATH,
MONS_CACODEMON };
monster_type mt;
do
{
mt = static_cast<monster_type>(MONS_WHITE_IMP +
(mutlevel-1)*5 + random2(5));
}
while (std::find(disallowed, disallowed + ARRAYSZ(disallowed), mt)
!= disallowed + ARRAYSZ(disallowed));
const int guardian = create_monster(mgen_data(mt, BEH_FRIENDLY, &you,
2, 0, you.pos(),
MHITYOU, MG_FORCE_BEH));
if (guardian == -1)
return;
menv[guardian].flags |= MF_NO_REWARD;
menv[guardian].flags |= MF_DEMONIC_GUARDIAN;
you.duration[DUR_DEMONIC_GUARDIAN] = (mutlevel+1)*3*10;
}
}
void check_antennae_detect()
{
// we're already here, so the player has at least 1 level of Antennae
const int radius = player_mutation_level(MUT_ANTENNAE) == 1 ? 3 : 5;
for (radius_iterator ri(you.pos(), radius, C_SQUARE); ri; ++ri)
{
const monsters* mon = monster_at(*ri);
if (!mon)
map_knowledge_forget_mons(*ri);
else if (!mons_is_firewood(mon))
{
show_type old_obj = get_map_knowledge_obj(*ri);
show_type obj = show_type();
obj.cls = SH_MONSTER;
obj.feat = old_obj.feat;
obj.item = old_obj.item;
obj.mons = MONS_SENSED;
obj.colour = 0;
set_map_knowledge_obj(*ri, obj);
set_map_knowledge_detected_mons(*ri);
}
}
}
int handle_pbd_corpses(bool do_rot)
{
int corpse_count = 0;
for (radius_iterator ri(you.pos(),
player_mutation_level(MUT_POWERED_BY_DEATH) * 3); ri; ++ri)
{
for (stack_iterator j(*ri); j; ++j)
{
if (j->base_type == OBJ_CORPSES && j->sub_type == CORPSE_BODY
&& j->special > 50)
{
++corpse_count;
int chance = player_mutation_level(MUT_POWERED_BY_DEATH)*16;
if (do_rot && x_chance_in_y(you.duration[DUR_POWERED_BY_DEATH],
chance))
{
j->special -= random2(3);
}
if (corpse_count == 7)
break;
}
}
}
return (corpse_count);
}
|