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
|
/*
* File: misc.cc
* Summary: Misc functions.
* Written by: Linley Henzell
*/
#include "AppHdr.h"
#include "misc.h"
#include "notes.h"
#include <string.h>
#include <algorithm>
#if !defined(__IBMCPP__) && !defined(TARGET_COMPILER_VC)
#include <unistd.h>
#endif
#ifdef TARGET_COMPILER_MINGW
#include <io.h>
#endif
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include "externs.h"
#include "options.h"
#include "misc.h"
#include "abyss.h"
#include "areas.h"
#include "branch.h"
#include "chardump.h"
#include "clua.h"
#include "cloud.h"
#include "coord.h"
#include "coordit.h"
#include "database.h"
#include "delay.h"
#include "dgn-overview.h"
#include "dgn-shoals.h"
#include "directn.h"
#include "dgnevent.h"
#include "directn.h"
#include "env.h"
#include "fight.h"
#include "files.h"
#include "flood_find.h"
#include "fprop.h"
#include "food.h"
#include "ghost.h"
#include "godabil.h"
#include "hiscores.h"
#include "itemname.h"
#include "itemprop.h"
#include "items.h"
#include "item_use.h"
#include "lev-pand.h"
#include "libutil.h"
#include "macro.h"
#include "makeitem.h"
#include "mapmark.h"
#include "message.h"
#include "mon-place.h"
#include "mon-pathfind.h"
#include "mon-info.h"
#include "mon-iter.h"
#include "mon-util.h"
#include "mon-stuff.h"
#include "ouch.h"
#include "output.h"
#include "place.h"
#include "player.h"
#include "player-stats.h"
#include "random.h"
#include "religion.h"
#include "godconduct.h"
#include "shopping.h"
#include "skills.h"
#include "skills2.h"
#include "spells1.h"
#include "spells3.h"
#include "stash.h"
#include "state.h"
#include "stuff.h"
#include "tagstring.h"
#include "terrain.h"
#include "transform.h"
#include "traps.h"
#include "travel.h"
#include "hints.h"
#include "view.h"
#include "viewgeom.h"
#include "shout.h"
#include "viewchar.h"
#include "xom.h"
static void _create_monster_hide(const item_def corpse)
{
// kiku_receive_corpses() creates corpses that are easily scummed
// for hides. We prevent this by setting "DoNotDropHide" as an item
// property of corpses it creates.
if (corpse.props.exists("DoNotDropHide"))
return;
int mons_class = corpse.plus;
int o = get_item_slot();
if (o == NON_ITEM)
return;
item_def& item = mitm[o];
// These values are common to all: {dlb}
item.base_type = OBJ_ARMOUR;
item.quantity = 1;
item.plus = 0;
item.plus2 = 0;
item.special = 0;
item.flags = 0;
item.colour = mons_class_colour(mons_class);
// These values cannot be set by a reasonable formula: {dlb}
switch (mons_class)
{
case MONS_DRAGON: item.sub_type = ARM_DRAGON_HIDE; break;
case MONS_TROLL: item.sub_type = ARM_TROLL_HIDE; break;
case MONS_ICE_DRAGON: item.sub_type = ARM_ICE_DRAGON_HIDE; break;
case MONS_STEAM_DRAGON: item.sub_type = ARM_STEAM_DRAGON_HIDE; break;
case MONS_MOTTLED_DRAGON: item.sub_type = ARM_MOTTLED_DRAGON_HIDE; break;
case MONS_STORM_DRAGON: item.sub_type = ARM_STORM_DRAGON_HIDE; break;
case MONS_GOLDEN_DRAGON: item.sub_type = ARM_GOLD_DRAGON_HIDE; break;
case MONS_SWAMP_DRAGON: item.sub_type = ARM_SWAMP_DRAGON_HIDE; break;
case MONS_SHEEP:
case MONS_YAK:
default:
item.sub_type = ARM_ANIMAL_SKIN;
break;
}
monster_type montype = static_cast<monster_type>(corpse.orig_monnum - 1);
if (!invalid_monster_type(montype) && mons_is_unique(montype))
item.inscription = mons_type_name(montype, DESC_PLAIN);
move_item_to_grid(&o, you.pos());
}
int get_max_corpse_chunks(int mons_class)
{
return (mons_weight(mons_class) / 150);
}
void turn_corpse_into_skeleton(item_def &item)
{
ASSERT(item.base_type == OBJ_CORPSES && item.sub_type == CORPSE_BODY);
// Some monsters' corpses lack the structure to leave skeletons
// behind.
if (!mons_skeleton(item.plus))
return;
item.sub_type = CORPSE_SKELETON;
item.special = FRESHEST_CORPSE; // reset rotting counter
item.colour = LIGHTGREY;
}
void turn_corpse_into_chunks(item_def &item, bool bloodspatter,
bool make_hide)
{
ASSERT(item.base_type == OBJ_CORPSES && item.sub_type == CORPSE_BODY);
const monster_type montype = static_cast<monster_type>(item.plus);
const int max_chunks = get_max_corpse_chunks(item.plus);
// Only fresh corpses bleed enough to colour the ground.
if (bloodspatter && !food_is_rotten(item))
bleed_onto_floor(you.pos(), montype, max_chunks, true);
item.base_type = OBJ_FOOD;
item.sub_type = FOOD_CHUNK;
item.quantity = 1 + random2(max_chunks);
item.quantity = stepdown_value(item.quantity, 4, 4, 12, 12);
if (you.species != SP_VAMPIRE)
item.flags &= ~(ISFLAG_THROWN | ISFLAG_DROPPED);
// Happens after the corpse has been butchered.
if (make_hide && monster_descriptor(item.plus, MDSC_LEAVES_HIDE)
&& !one_chance_in(3))
{
_create_monster_hide(item);
}
}
void turn_corpse_into_skeleton_and_chunks(item_def &item)
{
item_def chunks = item;
if (mons_skeleton(item.plus))
turn_corpse_into_skeleton(item);
int o = get_item_slot();
if (o != NON_ITEM)
{
turn_corpse_into_chunks(chunks);
copy_item_to_grid(chunks, you.pos());
}
}
// Initialise blood potions with a vector of timers.
void init_stack_blood_potions(item_def &stack, int age)
{
ASSERT(is_blood_potion(stack));
CrawlHashTable &props = stack.props;
props.clear(); // sanity measure
props["timer"].new_vector(SV_INT, SFLAG_CONST_TYPE);
CrawlVector &timer = props["timer"].get_vector();
if (age == -1)
{
if (stack.sub_type == POT_BLOOD)
age = 2500;
else // coagulated blood
age = 500;
}
// For a newly created stack, all potions use the same timer.
const int max_age = you.num_turns + age;
#ifdef DEBUG_BLOOD_POTIONS
mprf(MSGCH_DIAGNOSTICS, "newly created stack will time out at turn %d",
max_age);
#endif
for (int i = 0; i < stack.quantity; i++)
timer.push_back(max_age);
stack.special = 0;
ASSERT(timer.size() == stack.quantity);
props.assert_validity();
}
// Sort a CrawlVector<int>, should probably be done properly with templates.
static void _int_sort(CrawlVector &vec)
{
std::vector<int> help;
while (!vec.empty())
{
help.push_back(vec[vec.size()-1].get_int());
vec.pop_back();
}
std::sort(help.begin(), help.end());
while (!help.empty())
{
vec.push_back(help[help.size()-1]);
help.pop_back();
}
}
static void _compare_blood_quantity(item_def &stack, int timer_size)
{
if (timer_size != stack.quantity)
{
mprf(MSGCH_WARN,
"ERROR: blood potion quantity (%d) doesn't match timer (%d)",
stack.quantity, timer_size);
// sanity measure
stack.quantity = timer_size;
}
}
void maybe_coagulate_blood_potions_floor(int obj)
{
item_def &blood = mitm[obj];
ASSERT(blood.defined());
ASSERT(is_blood_potion(blood));
CrawlHashTable &props = blood.props;
if (!props.exists("timer"))
init_stack_blood_potions(blood, blood.special);
ASSERT(props.exists("timer"));
CrawlVector &timer = props["timer"].get_vector();
ASSERT(!timer.empty());
_compare_blood_quantity(blood, timer.size());
// blood.sub_type could be POT_BLOOD or POT_BLOOD_COAGULATED
// -> need different handling
int rot_limit = you.num_turns;
int coag_limit = you.num_turns + 500; // check 500 turns later
// First count whether coagulating is even necessary.
int rot_count = 0;
int coag_count = 0;
std::vector<int> age_timer;
int current;
while (!timer.empty())
{
current = timer[timer.size()-1].get_int();
if (current > coag_limit
|| blood.sub_type == POT_BLOOD_COAGULATED && current > rot_limit)
{
// Still some time until rotting/coagulating.
break;
}
timer.pop_back();
if (current <= rot_limit)
rot_count++;
else if (blood.sub_type == POT_BLOOD && current <= coag_limit)
{
coag_count++;
age_timer.push_back(current);
}
}
if (!rot_count && !coag_count)
// Nothing to be done.
return;
#ifdef DEBUG_BLOOD_POTIONS
mprf(MSGCH_DIAGNOSTICS, "in maybe_coagulate_blood_potions_FLOOR "
"(turns: %d)", you.num_turns);
mprf(MSGCH_DIAGNOSTICS, "Something happened at pos (%d, %d)!",
blood.x, blood.y);
mprf(MSGCH_DIAGNOSTICS, "coagulated: %d, rotted: %d, total: %d",
coag_count, rot_count, blood.quantity);
more();
#endif
if (!coag_count) // Some potions rotted away.
{
dec_mitm_item_quantity(obj, rot_count);
// Timer is already up to date.
return;
}
// Coagulated blood cannot coagulate any further...
ASSERT(blood.sub_type == POT_BLOOD);
if (!blood.held_by_monster())
{
// Now that coagulating is necessary, check square for
// !coagulated blood.
ASSERT(blood.pos.x >= 0 && blood.pos.y >= 0);
for (stack_iterator si(blood.pos); si; ++si)
{
if (si->base_type == OBJ_POTIONS
&& si->sub_type == POT_BLOOD_COAGULATED)
{
// Merge with existing stack.
CrawlHashTable &props2 = si->props;
if (!props2.exists("timer"))
init_stack_blood_potions(*si, si->special);
ASSERT(props2.exists("timer"));
CrawlVector &timer2 = props2["timer"].get_vector();
ASSERT(timer2.size() == si->quantity);
// Update timer -> push(pop).
while (!age_timer.empty())
{
const int val = age_timer.back();
age_timer.pop_back();
timer2.push_back(val);
}
_int_sort(timer2);
inc_mitm_item_quantity(si.link(), coag_count);
ASSERT(timer2.size() == si->quantity);
dec_mitm_item_quantity(obj, rot_count + coag_count);
return;
}
}
}
// If we got here, nothing was found! (Or it's in a monster's
// inventory.)
// Entire stack is gone, rotted or coagulated.
// -> Change potions to coagulated type.
if (rot_count + coag_count == blood.quantity)
{
ASSERT(timer.empty());
// Update subtype.
blood.sub_type = POT_BLOOD_COAGULATED;
item_colour(blood);
// Re-fill vector.
int val;
while (!age_timer.empty())
{
val = age_timer[age_timer.size() - 1];
age_timer.pop_back();
timer.push_back(val);
}
dec_mitm_item_quantity(obj, rot_count);
_compare_blood_quantity(blood, timer.size());
return;
}
// Else, create a new stack of potions.
int o = get_item_slot(20);
if (o == NON_ITEM)
return;
item_def &item = mitm[o];
item.base_type = OBJ_POTIONS;
item.sub_type = POT_BLOOD_COAGULATED;
item.quantity = coag_count;
item.plus = 0;
item.plus2 = 0;
item.special = 0;
item.flags = 0;
item_colour(item);
CrawlHashTable &props_new = item.props;
props_new["timer"].new_vector(SV_INT, SFLAG_CONST_TYPE);
CrawlVector &timer_new = props_new["timer"].get_vector();
int val;
while (!age_timer.empty())
{
val = age_timer[age_timer.size() - 1];
age_timer.pop_back();
timer_new.push_back(val);
}
ASSERT(timer_new.size() == coag_count);
props_new.assert_validity();
if (blood.held_by_monster())
move_item_to_grid(&o, blood.holding_monster()->pos());
else
move_item_to_grid(&o, blood.pos);
dec_mitm_item_quantity(obj, rot_count + coag_count);
_compare_blood_quantity(blood, timer.size());
}
static std::string _get_desc_quantity(const int quant, const int total)
{
if (total == quant)
return "Your";
else if (quant == 1)
return "One of your";
else if (quant == 2)
return "Two of your";
else if (quant >= (total * 3) / 4)
return "Most of your";
else
return "Some of your";
}
// Prints messages for blood potions coagulating in inventory (coagulate = true)
// or whenever potions are cursed into potions of decay (coagulate = false).
static void _potion_stack_changed_message(item_def &potion, int num_changed,
std::string verb)
{
ASSERT(num_changed > 0);
verb = replace_all(verb, "%s", num_changed == 1 ? "s" : "");
mprf(MSGCH_ROTTEN_MEAT, "%s %s %s.",
_get_desc_quantity(num_changed, potion.quantity).c_str(),
potion.name(DESC_PLAIN, false).c_str(),
verb.c_str());
}
// Returns true if "equipment weighs less" message needed.
// Also handles coagulation messages.
bool maybe_coagulate_blood_potions_inv(item_def &blood)
{
ASSERT(blood.defined());
ASSERT(is_blood_potion(blood));
CrawlHashTable &props = blood.props;
if (!props.exists("timer"))
init_stack_blood_potions(blood, blood.special);
ASSERT(props.exists("timer"));
CrawlVector &timer = props["timer"].get_vector();
_compare_blood_quantity(blood, timer.size());
ASSERT(!timer.empty());
// blood.sub_type could be POT_BLOOD or POT_BLOOD_COAGULATED
// -> need different handling
int rot_limit = you.num_turns;
int coag_limit = you.num_turns + 500; // check 500 turns later
// First count whether coagulating is even necessary.
int rot_count = 0;
int coag_count = 0;
std::vector<int> age_timer;
int current;
const int size = timer.size();
for (int i = 0; i < size; i++)
{
current = timer[timer.size()-1].get_int();
if (current > coag_limit
|| blood.sub_type == POT_BLOOD_COAGULATED && current > rot_limit)
{
// Still some time until rotting/coagulating.
break;
}
timer.pop_back();
if (current <= rot_limit)
rot_count++;
else if (blood.sub_type == POT_BLOOD && current <= coag_limit)
{
coag_count++;
age_timer.push_back(current);
}
}
if (!rot_count && !coag_count)
return (false); // Nothing to be done.
#ifdef DEBUG_BLOOD_POTIONS
mprf(MSGCH_DIAGNOSTICS, "in maybe_coagulate_blood_potions_INV "
"(turns: %d)", you.num_turns);
mprf(MSGCH_DIAGNOSTICS, "coagulated: %d, rotted: %d, total: %d",
coag_count, rot_count, blood.quantity);
more();
#endif
// just in case
you.wield_change = true;
you.redraw_quiver = true;
const bool knew_coag = (get_ident_type(OBJ_POTIONS, POT_BLOOD_COAGULATED)
== ID_KNOWN_TYPE);
if (!coag_count) // Some potions rotted away, but none coagulated.
{
// Only coagulated blood can rot.
ASSERT(blood.sub_type == POT_BLOOD_COAGULATED);
_potion_stack_changed_message(blood, rot_count, "rot%s away");
blood.quantity -= rot_count;
if (!knew_coag)
{
set_ident_type( OBJ_POTIONS, POT_BLOOD_COAGULATED, ID_KNOWN_TYPE );
if (blood.quantity >= 1)
mpr(blood.name(DESC_INVENTORY).c_str());
}
if (blood.quantity < 1)
{
if (you.equip[EQ_WEAPON] == blood.link)
you.equip[EQ_WEAPON] = -1;
destroy_item(blood);
}
else
_compare_blood_quantity(blood, timer.size());
return (true);
}
// Coagulated blood cannot coagulate any further...
ASSERT(blood.sub_type == POT_BLOOD);
const bool knew_blood = get_ident_type(OBJ_POTIONS, POT_BLOOD)
== ID_KNOWN_TYPE;
_potion_stack_changed_message(blood, coag_count, "coagulate%s");
// Identify both blood and coagulated blood, if necessary.
if (!knew_blood)
set_ident_type( OBJ_POTIONS, POT_BLOOD, ID_KNOWN_TYPE );
if (!knew_coag)
set_ident_type( OBJ_POTIONS, POT_BLOOD_COAGULATED, ID_KNOWN_TYPE );
// Now that coagulating is necessary, check inventory for !coagulated blood.
for (int m = 0; m < ENDOFPACK; m++)
{
if (!you.inv[m].defined())
continue;
if (you.inv[m].base_type == OBJ_POTIONS
&& you.inv[m].sub_type == POT_BLOOD_COAGULATED)
{
CrawlHashTable &props2 = you.inv[m].props;
if (!props2.exists("timer"))
init_stack_blood_potions(you.inv[m], you.inv[m].special);
ASSERT(props2.exists("timer"));
CrawlVector &timer2 = props2["timer"].get_vector();
blood.quantity -= coag_count + rot_count;
if (blood.quantity < 1)
{
if (you.equip[EQ_WEAPON] == blood.link)
you.equip[EQ_WEAPON] = -1;
destroy_item(blood);
}
else
{
_compare_blood_quantity(blood, timer.size());
if (!knew_blood)
mpr(blood.name(DESC_INVENTORY).c_str());
}
// Update timer -> push(pop).
int val;
while (!age_timer.empty())
{
val = age_timer[age_timer.size() - 1];
age_timer.pop_back();
timer2.push_back(val);
}
you.inv[m].quantity += coag_count;
ASSERT(timer2.size() == you.inv[m].quantity);
if (!knew_coag)
mpr(you.inv[m].name(DESC_INVENTORY).c_str());
// re-sort timer
_int_sort(timer2);
return (rot_count > 0);
}
}
// If entire stack has coagulated, simply change subtype.
if (rot_count + coag_count == blood.quantity)
{
ASSERT(timer.empty());
// Update subtype.
blood.sub_type = POT_BLOOD_COAGULATED;
item_colour(blood);
// Re-fill vector.
int val;
while (!age_timer.empty())
{
val = age_timer[age_timer.size() - 1];
age_timer.pop_back();
timer.push_back(val);
}
blood.quantity -= rot_count;
// Stack still exists because of coag_count.
_compare_blood_quantity(blood, timer.size());
if (!knew_coag)
mpr(blood.name(DESC_INVENTORY).c_str());
return (rot_count > 0);
}
// Else, create new stack in inventory.
int freeslot = find_free_slot(blood);
if (freeslot >= 0 && freeslot < ENDOFPACK)
{
item_def &item = you.inv[freeslot];
item.clear();
item.link = freeslot;
item.slot = index_to_letter(item.link);
item.base_type = OBJ_POTIONS;
item.sub_type = POT_BLOOD_COAGULATED;
item.quantity = coag_count;
item.plus = 0;
item.plus2 = 0;
item.special = 0;
item.flags = (ISFLAG_KNOW_TYPE & ISFLAG_BEEN_IN_INV);
item.pos.set(-1, -1);
item_colour(item);
CrawlHashTable &props_new = item.props;
props_new["timer"].new_vector(SV_INT, SFLAG_CONST_TYPE);
CrawlVector &timer_new = props_new["timer"].get_vector();
int val;
while (!age_timer.empty())
{
val = age_timer[age_timer.size() - 1];
age_timer.pop_back();
timer_new.push_back(val);
}
ASSERT(timer_new.size() == coag_count);
props_new.assert_validity();
blood.quantity -= coag_count + rot_count;
_compare_blood_quantity(blood, timer.size());
if (!knew_blood)
mpr(blood.name(DESC_INVENTORY).c_str());
if (!knew_coag)
mpr(item.name(DESC_INVENTORY).c_str());
return (rot_count > 0);
}
// No space in inventory, check floor.
int o = igrd(you.pos());
while (o != NON_ITEM)
{
if (mitm[o].base_type == OBJ_POTIONS
&& mitm[o].sub_type == POT_BLOOD_COAGULATED)
{
// Merge with existing stack.
CrawlHashTable &props2 = mitm[o].props;
if (!props2.exists("timer"))
init_stack_blood_potions(mitm[o], mitm[o].special);
ASSERT(props2.exists("timer"));
CrawlVector &timer2 = props2["timer"].get_vector();
ASSERT(timer2.size() == mitm[o].quantity);
// Update timer -> push(pop).
int val;
while (!age_timer.empty())
{
val = age_timer[age_timer.size() - 1];
age_timer.pop_back();
timer2.push_back(val);
}
_int_sort(timer2);
inc_mitm_item_quantity(o, coag_count);
ASSERT(timer2.size() == mitm[o].quantity);
dec_inv_item_quantity(blood.link, rot_count + coag_count);
_compare_blood_quantity(blood, timer.size());
if (!knew_blood)
mpr(blood.name(DESC_INVENTORY).c_str());
return (true);
}
o = mitm[o].link;
}
// If we got here nothing was found!
// Create a new stack of potions.
o = get_item_slot();
if (o == NON_ITEM)
return (false);
// These values are common to all: {dlb}
mitm[o].base_type = OBJ_POTIONS;
mitm[o].sub_type = POT_BLOOD_COAGULATED;
mitm[o].quantity = coag_count;
mitm[o].plus = 0;
mitm[o].plus2 = 0;
mitm[o].special = 0;
mitm[o].flags = (ISFLAG_KNOW_TYPE & ISFLAG_BEEN_IN_INV);
item_colour(mitm[o]);
CrawlHashTable &props_new = mitm[o].props;
props_new["timer"].new_vector(SV_INT, SFLAG_CONST_TYPE);
CrawlVector &timer_new = props_new["timer"].get_vector();
int val;
while (!age_timer.empty())
{
val = age_timer[age_timer.size() - 1];
age_timer.pop_back();
timer_new.push_back(val);
}
ASSERT(timer_new.size() == coag_count);
props_new.assert_validity();
move_item_to_grid(&o, you.pos());
blood.quantity -= rot_count + coag_count;
if (blood.quantity < 1)
{
if (you.equip[EQ_WEAPON] == blood.link)
you.equip[EQ_WEAPON] = -1;
destroy_item(blood);
}
else
{
_compare_blood_quantity(blood, timer.size());
if (!knew_blood)
mpr(blood.name(DESC_INVENTORY).c_str());
}
return (true);
}
// Removes the oldest timer of a stack of blood potions.
// Mostly used for (q)uaff, (f)ire, and Evaporate.
int remove_oldest_blood_potion(item_def &stack)
{
ASSERT(stack.defined());
ASSERT(is_blood_potion(stack));
CrawlHashTable &props = stack.props;
if (!props.exists("timer"))
init_stack_blood_potions(stack, stack.special);
ASSERT(props.exists("timer"));
CrawlVector &timer = props["timer"].get_vector();
ASSERT(!timer.empty());
// Assuming already sorted, and first (oldest) potion valid.
const int val = timer[timer.size() - 1].get_int();
timer.pop_back();
// The quantity will be decreased elsewhere.
return (val);
}
// Used whenever copies of blood potions have to be cleaned up.
void remove_newest_blood_potion(item_def &stack, int quant)
{
ASSERT(stack.defined());
ASSERT(is_blood_potion(stack));
CrawlHashTable &props = stack.props;
if (!props.exists("timer"))
init_stack_blood_potions(stack, stack.special);
ASSERT(props.exists("timer"));
CrawlVector &timer = props["timer"].get_vector();
ASSERT(!timer.empty());
if (quant == -1)
quant = timer.size() - stack.quantity;
// Overwrite newest potions with oldest ones.
int repeats = stack.quantity;
if (repeats > quant)
repeats = quant;
for (int i = 0; i < repeats; i++)
{
timer[i] = timer[timer.size() - 1];
timer.pop_back();
}
// Now remove remaining oldest potions...
repeats = quant - repeats;
for (int i = 0; i < repeats; i++)
timer.pop_back();
// ... and re-sort.
_int_sort(timer);
}
void merge_blood_potion_stacks(item_def &source, item_def &dest, int quant)
{
if (!source.defined() || !dest.defined())
return;
ASSERT(quant > 0 && quant <= source.quantity);
ASSERT(is_blood_potion(source) && is_blood_potion(dest));
CrawlHashTable &props = source.props;
if (!props.exists("timer"))
init_stack_blood_potions(source, source.special);
ASSERT(props.exists("timer"));
CrawlVector &timer = props["timer"].get_vector();
ASSERT(!timer.empty());
CrawlHashTable &props2 = dest.props;
if (!props2.exists("timer"))
init_stack_blood_potions(dest, dest.special);
ASSERT(props2.exists("timer"));
CrawlVector &timer2 = props2["timer"].get_vector();
// Update timer -> push(pop).
for (int i = 0; i < quant; i++)
{
timer2.push_back(timer[timer.size() - 1].get_int());
timer.pop_back();
}
// Re-sort timer.
_int_sort(timer2);
}
bool check_blood_corpses_on_ground()
{
for (stack_iterator si(you.pos(), true); si; ++si)
{
if (si->base_type == OBJ_CORPSES && si->sub_type == CORPSE_BODY
&& !food_is_rotten(*si)
&& mons_has_blood(si->plus))
{
return (true);
}
}
return (false);
}
// Deliberately don't check for rottenness here, so this check
// can also be used to verify whether you *could* have bottled
// a now rotten corpse.
bool can_bottle_blood_from_corpse(int mons_class)
{
if (you.species != SP_VAMPIRE || you.experience_level < 6
|| !mons_has_blood(mons_class))
{
return (false);
}
int chunk_type = mons_corpse_effect(mons_class);
if (chunk_type == CE_CLEAN || chunk_type == CE_CONTAMINATED)
return (true);
return (false);
}
int num_blood_potions_from_corpse(int mons_class, int chunk_type)
{
if (chunk_type == -1)
chunk_type = mons_corpse_effect(mons_class);
// Max. amount is about one third of the max. amount for chunks.
const int max_chunks = get_max_corpse_chunks(mons_class);
// Max. amount is about one third of the max. amount for chunks.
int pot_quantity = max_chunks / 3;
pot_quantity = stepdown_value(pot_quantity, 2, 2, 6, 6);
// Halve number of potions obtained from contaminated chunk type corpses.
if (chunk_type == CE_CONTAMINATED)
pot_quantity /= 2;
if (pot_quantity < 1)
pot_quantity = 1;
return (pot_quantity);
}
// If autopickup is active, the potions are auto-picked up after creation.
void turn_corpse_into_blood_potions(item_def &item)
{
ASSERT(item.base_type == OBJ_CORPSES);
ASSERT(!food_is_rotten(item));
item_def corpse = item;
const int mons_class = corpse.plus;
ASSERT(can_bottle_blood_from_corpse(mons_class));
item.base_type = OBJ_POTIONS;
item.sub_type = POT_BLOOD;
item_colour(item);
item.flags &= ~(ISFLAG_THROWN | ISFLAG_DROPPED);
item.quantity = num_blood_potions_from_corpse(mons_class);
// Initialise timer depending on corpse age:
// almost rotting: age = 100 --> potion timer = 500 --> will coagulate soon
// freshly killed: age = 200 --> potion timer = 2500 --> fresh !blood
init_stack_blood_potions(item, (item.special - 100) * 20 + 500);
// Happens after the blood has been bottled.
if (monster_descriptor(mons_class, MDSC_LEAVES_HIDE) && !one_chance_in(3))
_create_monster_hide(corpse);
}
void turn_corpse_into_skeleton_and_blood_potions(item_def &item)
{
item_def blood_potions = item;
if (mons_skeleton(item.plus))
turn_corpse_into_skeleton(item);
int o = get_item_slot();
if (o != NON_ITEM)
{
turn_corpse_into_blood_potions(blood_potions);
copy_item_to_grid(blood_potions, you.pos());
}
}
// A variation of the mummy curse:
// Instead of trashing the entire stack, split the stack and only turn part
// of it into POT_DECAY.
void split_potions_into_decay( int obj, int amount, bool need_msg )
{
ASSERT(obj != -1);
item_def &potion = you.inv[obj];
ASSERT(potion.defined());
ASSERT(potion.base_type == OBJ_POTIONS);
ASSERT(amount > 0);
ASSERT(amount <= potion.quantity);
// Output decay message.
if (need_msg && get_ident_type(OBJ_POTIONS, POT_DECAY) == ID_KNOWN_TYPE)
_potion_stack_changed_message(potion, amount, "decay%s");
if (you.equip[EQ_WEAPON] == obj)
you.wield_change = true;
you.redraw_quiver = true;
if (is_blood_potion(potion))
{
// We're being nice here, and only decay the *oldest* potions.
for (int i = 0; i < amount; i++)
remove_oldest_blood_potion(potion);
}
// Try to merge into existing stacks of decayed potions.
for (int m = 0; m < ENDOFPACK; m++)
{
if (you.inv[m].base_type == OBJ_POTIONS
&& you.inv[m].sub_type == POT_DECAY)
{
if (potion.quantity == amount)
{
if (you.equip[EQ_WEAPON] == obj)
you.equip[EQ_WEAPON] = -1;
destroy_item(potion);
}
else
you.inv[obj].quantity -= amount;
you.inv[m].quantity += amount;
return;
}
}
// Else, if entire stack affected just change subtype.
if (amount == potion.quantity)
{
you.inv[obj].sub_type = POT_DECAY;
unset_ident_flags( you.inv[obj], ISFLAG_IDENT_MASK ); // all different
return;
}
// Else, create new stack in inventory.
int freeslot = find_free_slot(you.inv[obj]);
if (freeslot >= 0 && freeslot < ENDOFPACK
&& !you.inv[freeslot].defined())
{
item_def &item = you.inv[freeslot];
item.link = freeslot;
item.slot = index_to_letter(item.link);
item.base_type = OBJ_POTIONS;
item.sub_type = POT_DECAY;
item.quantity = amount;
// Keep description as it was.
item.plus = potion.plus;
item.plus2 = 0;
item.special = 0;
item.flags = 0;
item.colour = potion.colour;
item.inscription.clear();
item.pos.set(-1, -1);
you.inv[obj].quantity -= amount;
return;
}
// Okay, inventory is full.
// Check whether we can merge with an existing stack on the floor.
for (stack_iterator si(you.pos()); si; ++si)
{
if (si->base_type == OBJ_POTIONS && si->sub_type == POT_DECAY)
{
dec_inv_item_quantity(obj, amount);
inc_mitm_item_quantity(si->index(), amount);
return;
}
}
item_def potion2;
potion2.base_type = OBJ_POTIONS;
potion2.sub_type = POT_DECAY;
// Keep description as it was.
potion2.plus = potion.plus;
potion2.quantity = amount;
potion2.colour = potion.colour;
potion2.plus2 = 0;
potion2.flags = 0;
potion2.special = 0;
copy_item_to_grid(potion2, you.pos());
// Is decreased even if the decay stack goes splat.
dec_inv_item_quantity(obj, amount);
}
static bool allow_bleeding_on_square(const coord_def& where)
{
// No bleeding onto sanctuary ground, please.
// Also not necessary if already covered in blood.
if (is_bloodcovered(where) || is_sanctuary(where))
return (false);
// No spattering into lava or water.
if (grd(where) >= DNGN_LAVA && grd(where) < DNGN_FLOOR)
return (false);
// No spattering into fountains (other than blood).
if (grd(where) == DNGN_FOUNTAIN_BLUE
|| grd(where) == DNGN_FOUNTAIN_SPARKLING)
{
return (false);
}
// The good gods like to keep their altars pristine.
if (is_good_god(feat_altar_god(grd(where))))
return (false);
return (true);
}
bool maybe_bloodify_square(const coord_def& where)
{
if (!allow_bleeding_on_square(where))
return (false);
env.pgrid(where) |= FPROP_BLOODY;
return(true);
}
static void _maybe_bloodify_square(const coord_def& where, int amount,
bool spatter = false,
bool smell_alert = true)
{
if (amount < 1)
return;
bool may_bleed = allow_bleeding_on_square(where);
if (!spatter && !may_bleed)
return;
if (x_chance_in_y(amount, 20))
{
dprf("might bleed now; square: (%d, %d); amount = %d",
where.x, where.y, amount);
if (may_bleed)
{
env.pgrid(where) |= FPROP_BLOODY;
if (smell_alert && in_bounds(where))
blood_smell(12, where);
}
if (spatter)
{
// Smaller chance of spattering surrounding squares.
for (adjacent_iterator ai(where); ai; ++ai)
{
// Spattering onto walls etc. less likely.
if (grd(*ai) < DNGN_MINMOVE && !one_chance_in(3))
continue;
_maybe_bloodify_square(*ai, amount/15);
}
}
}
}
// Currently flavour only: colour ground (and possibly adjacent squares) red.
// "damage" depends on damage taken (or hitpoints, if damage higher),
// or, for sacrifices, on the number of chunks possible to get out of a corpse.
void bleed_onto_floor(const coord_def& where, monster_type montype,
int damage, bool spatter, bool smell_alert)
{
ASSERT(in_bounds(where));
if (montype == MONS_PLAYER && !you.can_bleed())
return;
if (montype != NUM_MONSTERS && montype != MONS_PLAYER)
{
monsters m;
m.type = montype;
if (!m.can_bleed())
return;
}
_maybe_bloodify_square(where, damage, spatter, smell_alert);
}
void blood_spray(const coord_def& origin, monster_type montype, int level)
{
los_def ld(origin, opc_solid);
ld.update();
int tries = 0;
for (int i = 0; i < level; ++i)
{
// Blood drops are small and light and suffer a lot of wind
// resistance.
int range = random2(8) + 1;
while (tries < 5000)
{
++tries;
coord_def bloody = origin;
bloody.x += random_range(-range, range);
bloody.y += random_range(-range, range);
if (in_bounds(bloody) && ld.see_cell(bloody))
{
if (feat_is_solid(grd(bloody)) && coinflip())
continue;
bleed_onto_floor(bloody, montype, 99);
break;
}
}
}
}
static void _spatter_neighbours(const coord_def& where, int chance)
{
for (adjacent_iterator ai(where, false); ai; ++ai)
{
if (!allow_bleeding_on_square(*ai))
continue;
if (grd(*ai) < DNGN_MINMOVE && !one_chance_in(3))
continue;
if (one_chance_in(chance))
{
env.pgrid(*ai) |= FPROP_BLOODY;
_spatter_neighbours(*ai, chance+1);
}
}
}
void generate_random_blood_spatter_on_level(const map_mask *susceptible_area)
{
const int max_cluster = 7 + random2(9);
// Lower chances for large bloodshed areas if we have many clusters,
// but increase chances if we have few.
// Chances for startprob are [1..3] for 7-9 clusters,
// ... [1..4] for 10-12 clusters, and
// ... [2..5] for 13-15 clusters.
int min_prob = 1;
int max_prob = 4;
if (max_cluster < 10)
max_prob--;
else if (max_cluster > 12)
min_prob++;
for (int i = 0; i < max_cluster; ++i)
{
const coord_def c = random_in_bounds();
if (susceptible_area && !(*susceptible_area)(c))
continue;
// startprob is used to initialise the chance for neighbours
// being spattered, which will be decreased by 1 per recursion
// round. We then use one_chance_in(chance) to determine
// whether to spatter a given grid or not. Thus, startprob = 1
// means that initially all surrounding grids will be
// spattered (3x3), and the _higher_ startprob the _lower_ the
// overall chance for spattering and the _smaller_ the
// bloodshed area.
const int startprob = min_prob + random2(max_prob);
maybe_bloodify_square(c);
_spatter_neighbours(c, startprob);
}
}
void search_around(bool only_adjacent)
{
ASSERT(!crawl_state.game_is_arena());
// Traps and doors stepdown skill:
// skill/(2x-1) for squares at distance x
int max_dist = (you.skills[SK_TRAPS_DOORS] + 1) / 2;
if (max_dist > 5)
max_dist = 5;
if (only_adjacent && max_dist > 1 || max_dist < 1)
max_dist = 1;
for (radius_iterator ri(you.pos(), max_dist); ri; ++ri )
{
// Must have LOS, with no translucent walls in the way.
if (you.see_cell_no_trans(*ri))
{
// Maybe we want distance() instead of feat_distance()?
int dist = grid_distance(*ri, you.pos());
// Don't exclude own square; may be levitating.
// XXX: Currently, levitating over a trap will always detect it.
if (dist == 0)
++dist;
// Making this harsher by removing the old +1...
int effective = you.skills[SK_TRAPS_DOORS] / (2*dist - 1);
if (grd(*ri) == DNGN_SECRET_DOOR && x_chance_in_y(effective+1, 17))
{
mpr("You found a secret door!");
reveal_secret_door(*ri);
exercise(SK_TRAPS_DOORS, (coinflip() ? 2 : 1));
}
else if (grd(*ri) == DNGN_UNDISCOVERED_TRAP
&& x_chance_in_y(effective + 1, 17))
{
trap_def* ptrap = find_trap(*ri);
if (ptrap)
{
ptrap->reveal();
mpr("You found a trap!");
learned_something_new(HINT_SEEN_TRAP, *ri);
exercise(SK_TRAPS_DOORS, (coinflip() ? 2 : 1));
}
else
{
// Maybe we shouldn't kill the trap for debugging
// purposes - oh well.
grd(*ri) = DNGN_FLOOR;
dprf("You found a buggy trap! It vanishes!");
}
}
}
}
}
void merfolk_start_swimming(bool stepped)
{
if (you.attribute[ATTR_TRANSFORMATION] != TRAN_NONE)
untransform(false, true); // We're already entering the water.
if (stepped)
mpr("Your legs become a tail as you enter the water.");
else
mpr("Your legs become a tail as you dive into the water.");
remove_one_equip(EQ_BOOTS);
you.redraw_evasion = true;
#ifdef USE_TILE
init_player_doll();
#endif
}
void merfolk_stop_swimming()
{
unmeld_one_equip(EQ_BOOTS);
you.redraw_evasion = true;
#ifdef USE_TILE
init_player_doll();
#endif
}
// Update the trackers after the player changed level.
void trackers_init_new_level(bool transit)
{
travel_init_new_level();
if (transit)
stash_init_new_level();
}
std::string weird_glowing_colour()
{
return getMiscString("glowing_colour_name");
}
std::string weird_writing()
{
return getMiscString("writing_name");
}
std::string weird_smell()
{
return getMiscString("smell_name");
}
std::string weird_sound()
{
return getMiscString("sound_name");
}
bool scramble(void)
{
ASSERT(!crawl_state.game_is_arena());
// Statues are too stiff and heavy to scramble out of the water.
if (you.attribute[ATTR_TRANSFORMATION] == TRAN_STATUE)
return (false);
int max_carry = carrying_capacity();
// When highly encumbered, scrambling out is hard to do.
if ((max_carry / 2) + random2(max_carry / 2) <= you.burden)
return (false);
else
return (true);
}
bool go_berserk(bool intentional, bool potion)
{
ASSERT(!crawl_state.game_is_arena());
if (!you.can_go_berserk(intentional, potion))
return (false);
if (stasis_blocks_effect(true,
true,
"%s thrums violently and saps your rage.",
3,
"%s vibrates violently and saps your rage."))
{
return (false);
}
if (Hints.hints_left)
Hints.hints_berserk_counter++;
// Che prevents hasting the player if the berserk was unintentional.
// Otherwise, the haste would be forgiven "just this once" every time.
const bool che_blocks_haste =
you.religion == GOD_CHEIBRIADOS && !intentional;
mpr("A red film seems to cover your vision as you go berserk!");
if (che_blocks_haste)
simple_god_message(" protects you from inadvertent hurry.");
else
mpr("You feel yourself moving faster!");
mpr("You feel mighty!");
// Cutting the duration in half since berserk causes haste and hasted
// actions have half the usual delay. This keeps player turns
// approximately consistent withe previous versions. -cao
int berserk_duration = (20 + random2avg(19,2)) / 2;
you.increase_duration(DUR_BERSERKER, berserk_duration);
calc_hp();
you.hp = you.hp * 3 / 2;
deflate_hp(you.hp_max, false);
if (!you.duration[DUR_MIGHT])
notify_stat_change(STAT_STR, 5, true, "going berserk");
you.increase_duration(DUR_MIGHT, berserk_duration);
if (!che_blocks_haste)
{
// doubling the duration here since haste_player already cuts input
// durations in half
haste_player(berserk_duration * 2);
did_god_conduct(DID_HASTY, 8, intentional);
}
if (you.berserk_penalty != NO_BERSERK_PENALTY)
you.berserk_penalty = 0;
return (true);
}
// Returns true if the monster has a path to the player, or it has to be
// assumed that this is the case.
static bool _mons_has_path_to_player(const monsters *mon, bool want_move = false)
{
// Don't consider sleeping monsters safe, in case the player would
// rather retreat and try another path for maximum stabbing chances.
// TODO: This doesn't cover monsters encaged in glass.
if (mon->asleep())
return (true);
if (mons_is_stationary(mon))
{
int dist = grid_distance(you.pos(), mon->pos());
if (want_move)
dist--;
if (dist >= 2)
return (false);
}
// If the monster is awake and knows a path towards the player
// (even though the player cannot know this) treat it as unsafe.
if (mon->travel_target == MTRAV_PLAYER)
return (true);
if (mon->travel_target == MTRAV_KNOWN_UNREACHABLE)
return (false);
// Try to find a path from monster to player, using the map as it's
// known to the player and assuming unknown terrain to be traversable.
monster_pathfind mp;
const int range = mons_tracking_range(mon);
if (range > 0)
mp.set_range(range);
if (mp.init_pathfind(mon, you.pos(), true, false, true))
return (true);
// Now we know the monster cannot possibly reach the player.
mon->travel_target = MTRAV_KNOWN_UNREACHABLE;
return (false);
}
bool mons_can_hurt_player(const monsters *mon, const bool want_move)
{
// FIXME: This takes into account whether the player knows the map!
// It also always returns true for sleeping monsters, but that's okay
// for its current purposes. (Travel interruptions and tension.)
if (_mons_has_path_to_player(mon, want_move))
return (true);
// The monster need only see you to hurt you.
if (mons_has_los_attack(mon))
return (true);
// Even if the monster can not actually reach the player it might
// still use some ranged form of attack.
if (you.see_cell_no_trans(mon->pos())
&& (mons_has_ranged_attack(mon)
|| mons_has_ranged_ability(mon)
|| mons_has_ranged_spell(mon)))
{
return (true);
}
return (false);
}
bool mons_is_safe(const monsters *mon, const bool want_move,
const bool consider_user_options)
{
if (mons_is_unknown_mimic(mon))
return (true);
int dist = grid_distance(you.pos(), mon->pos());
bool is_safe = (mon->wont_attack()
|| mons_class_flag(mon->type, M_NO_EXP_GAIN)
&& mon->type != MONS_KRAKEN_TENTACLE
|| mon->pacified() && dist > 1
|| mon->type == MONS_BALLISTOMYCETE && mon->number == 0
#ifdef WIZARD
// Wizmode skill setting enforces hiddenness.
|| you.skills[SK_STEALTH] > 27 && dist > 2
#endif
// Only seen through glass walls or within water?
// Assuming that there are no water-only/lava-only
// monsters capable of throwing or zapping wands.
|| ((!you.see_cell_no_trans(mon->pos())
|| mons_class_habitat(mon->type) == HT_WATER
|| mons_class_habitat(mon->type) == HT_LAVA
|| mons_is_stationary(mon))
&& !mons_can_hurt_player(mon, want_move)));
#ifdef CLUA_BINDINGS
if (consider_user_options)
{
bool moving = (!you.delay_queue.empty()
&& delay_is_run(you.delay_queue.front().type)
&& you.delay_queue.front().type != DELAY_REST
|| you.running < RMODE_NOT_RUNNING
|| want_move);
bool result = is_safe;
monster_info mi(mon, true);
if (clua.callfn("ch_mon_is_safe", "Ibbd>b",
&mi, is_safe, moving, dist,
&result))
{
is_safe = result;
}
}
#endif
return (is_safe);
}
// Return all nearby monsters in range (default: LOS) that the player
// is able to recognise as being monsters (i.e. no unknown mimics or
// submerged creatures.)
//
// want_move (??) Somehow affects what monsters are considered dangerous
// just_check Return zero or one monsters only
// dangerous_only Return only "dangerous" monsters
// require_visible Require that monsters be visible to the player
// range search radius (defaults: LOS)
//
std::vector<monsters*> get_nearby_monsters(bool want_move,
bool just_check,
bool dangerous_only,
bool consider_user_options,
bool require_visible,
int range)
{
ASSERT(!crawl_state.game_is_arena());
if (range == -1)
range = LOS_RADIUS;
std::vector<monsters*> mons;
// Sweep every visible square within range.
for (radius_iterator ri(you.pos(), range); ri; ++ri)
{
if (monsters* mon = monster_at(*ri))
{
if (mon->alive()
&& (!require_visible || mon->visible_to(&you))
&& !mon->submerged()
&& !mons_is_unknown_mimic(mon)
&& (!dangerous_only || !mons_is_safe(mon, want_move,
consider_user_options)))
{
mons.push_back(mon);
if (just_check) // stop once you find one
break;
}
}
}
return mons;
}
static bool _exposed_monsters_nearby(bool want_move)
{
const int radius = want_move ? 2 : 1;
for (radius_iterator ri(you.pos(), radius); ri; ++ri)
if (env.show(grid2show(*ri)).cls == SH_INVIS_EXPOSED)
return (true);
return (false);
}
bool i_feel_safe(bool announce, bool want_move, bool just_monsters, int range)
{
if (!just_monsters)
{
// check clouds
if (in_bounds(you.pos()) && env.cgrid(you.pos()) != EMPTY_CLOUD)
{
const int cloudidx = env.cgrid(you.pos());
const cloud_type type = env.cloud[cloudidx].type;
if (is_damaging_cloud(type, want_move))
{
if (announce)
{
mprf(MSGCH_WARN, "You're standing in a cloud of %s!",
cloud_name(cloudidx).c_str());
}
return (false);
}
}
// No monster will attack you inside a sanctuary,
// so presence of monsters won't matter -- until it starts shrinking...
if (is_sanctuary(you.pos()) && env.sanctuary_time >= 5)
return (true);
}
// Monster check.
std::vector<monsters*> visible =
get_nearby_monsters(want_move, !announce, true, true, true, range);
// Announce the presence of monsters (Eidolos).
std::string msg;
if (visible.size() == 1)
{
const monsters &m = *visible[0];
const std::string monname = mons_is_mimic(m.type)
? "A mimic"
: m.name(DESC_CAP_A);
msg = make_stringf("%s is nearby!", monname.c_str());
}
else if (visible.size() > 1)
msg = "There are monsters nearby!";
else if (_exposed_monsters_nearby(want_move))
msg = "There is a strange disturbance nearby!";
else
return (true);
if (announce)
mpr(msg, MSGCH_WARN);
return (false);
}
bool there_are_monsters_nearby(bool dangerous_only, bool require_visible,
bool consider_user_options)
{
return (!get_nearby_monsters(false, true, dangerous_only,
consider_user_options,
require_visible).empty());
}
static const char *shop_types[] = {
"weapon",
"armour",
"antique weapon",
"antique armour",
"antiques",
"jewellery",
"wand",
"book",
"food",
"distillery",
"scroll",
"general"
};
int str_to_shoptype(const std::string &s)
{
if (s == "random" || s == "any")
return (SHOP_RANDOM);
for (unsigned i = 0; i < sizeof(shop_types) / sizeof (*shop_types); ++i)
{
if (s == shop_types[i])
return (i);
}
return (-1);
}
// General threat = sum_of_logexpervalues_of_nearby_unfriendly_monsters.
// Highest threat = highest_logexpervalue_of_nearby_unfriendly_monsters.
static void monster_threat_values(double *general, double *highest,
bool *invis)
{
*invis = false;
double sum = 0;
int highest_xp = -1;
for (monster_iterator mi(you.get_los()); mi; ++mi)
{
if (!mi->friendly())
{
const int xp = exper_value(*mi);
const double log_xp = log((double)xp);
sum += log_xp;
if (xp > highest_xp)
{
highest_xp = xp;
*highest = log_xp;
}
if (!you.can_see(*mi))
*invis = true;
}
}
*general = sum;
}
bool player_in_a_dangerous_place(bool *invis)
{
bool junk;
if (invis == NULL)
invis = &junk;
const double logexp = log((double)you.experience);
double gen_threat = 0.0, hi_threat = 0.0;
monster_threat_values(&gen_threat, &hi_threat, invis);
return (gen_threat > logexp * 1.3 || hi_threat > logexp / 2);
}
static void _drop_tomb(const coord_def& pos, bool premature)
{
int count = 0;
monsters* mon = monster_at(pos);
// Don't wander on duty!
if (mon)
mon->behaviour = BEH_SEEK;
bool seen_change = false;
for (adjacent_iterator ai(pos); ai; ++ai)
{
if (grd(*ai) == DNGN_ROCK_WALL)
{
grd(*ai) = DNGN_FLOOR;
set_terrain_changed(*ai);
count++;
if (you.see_cell(*ai))
seen_change = true;
}
}
if (count)
{
if (seen_change)
mprf("The walls disappear%s!",
premature ? " prematurely" : "");
else
{
if (!silenced(you.pos()))
mpr("You hear a deep rumble.", MSGCH_SOUND);
else
mpr("You feel the ground shudder.");
}
}
}
void timeout_tombs(int duration)
{
if (!duration)
return;
std::vector<map_marker*> markers = env.markers.get_all(MAT_TOMB);
for (int i = 0, size = markers.size(); i < size; ++i)
{
map_marker *mark = markers[i];
if (mark->get_type() != MAT_TOMB)
continue;
map_tomb_marker *cmark = dynamic_cast<map_tomb_marker*>(mark);
cmark->duration -= duration;
// Tombs without monsters in them disappear early.
monsters *mon_entombed = monster_at(cmark->pos);
if (cmark->duration <= 0 || !mon_entombed)
{
_drop_tomb(cmark->pos, !mon_entombed);
monsters *mon_src =
!invalid_monster_index(cmark->source) ? &menv[cmark->source]
: NULL;
monsters *mon_targ =
!invalid_monster_index(cmark->target) ? &menv[cmark->target]
: NULL;
// Zin's Imprison ability.
if (cmark->source == -GOD_ZIN && mon_targ
&& mon_targ == mon_entombed)
{
zin_recite_to_single_monster(mon_targ->pos(), true);
}
// A monster's Tomb of Doroklohe spell.
else if (mon_src
&& mon_src == mon_entombed)
{
mon_src->lose_energy(EUT_SPELL);
}
env.markers.remove(cmark);
}
}
}
////////////////////////////////////////////////////////////////////////////
// Living breathing dungeon stuff.
//
static std::vector<coord_def> sfx_seeds;
void setup_environment_effects()
{
sfx_seeds.clear();
for (int x = X_BOUND_1; x <= X_BOUND_2; ++x)
{
for (int y = Y_BOUND_1; y <= Y_BOUND_2; ++y)
{
if (!in_bounds(x, y))
continue;
const int grid = grd[x][y];
if (grid == DNGN_LAVA
|| (grid == DNGN_SHALLOW_WATER
&& you.where_are_you == BRANCH_SWAMP))
{
const coord_def c(x, y);
sfx_seeds.push_back(c);
}
}
}
#ifdef DEBUG_DIAGNOSTICS
mprf(MSGCH_DIAGNOSTICS, "%u environment effect seeds", sfx_seeds.size());
#endif
}
static void apply_environment_effect(const coord_def &c)
{
const dungeon_feature_type grid = grd(c);
// Don't apply if if the feature doesn't want it.
if (testbits(env.pgrid(c), FPROP_NO_CLOUD_GEN))
return;
if (grid == DNGN_LAVA)
check_place_cloud(CLOUD_BLACK_SMOKE, c, random_range(4, 8), KC_OTHER);
else if (grid == DNGN_SHALLOW_WATER)
check_place_cloud(CLOUD_MIST, c, random_range(2, 5), KC_OTHER);
}
static const int Base_Sfx_Chance = 5;
void run_environment_effects()
{
if (!you.time_taken)
return;
dungeon_events.fire_event(DET_TURN_ELAPSED);
// Each square in sfx_seeds has this chance of doing something special
// per turn.
const int sfx_chance = Base_Sfx_Chance * you.time_taken / 10;
const int nseeds = sfx_seeds.size();
// If there are a large number of seeds, speed things up by fudging the
// numbers.
if (nseeds > 50)
{
int nsels = div_rand_round( sfx_seeds.size() * sfx_chance, 100 );
if (one_chance_in(5))
nsels += random2(nsels * 3);
for (int i = 0; i < nsels; ++i)
apply_environment_effect( sfx_seeds[ random2(nseeds) ] );
}
else
{
for (int i = 0; i < nseeds; ++i)
{
if (random2(100) >= sfx_chance)
continue;
apply_environment_effect( sfx_seeds[i] );
}
}
run_corruption_effects(you.time_taken);
shoals_apply_tides(div_rand_round(you.time_taken, 10));
timeout_tombs(you.time_taken);
}
coord_def pick_adjacent_free_square(const coord_def& p)
{
int num_ok = 0;
coord_def result(-1, -1);
for (adjacent_iterator ai(p); ai; ++ai)
if (grd(*ai) == DNGN_FLOOR && monster_at(*ai) == NULL)
if (one_chance_in(++num_ok))
result = *ai;
return result;
}
// Converts a movement speed to a duration. i.e., answers the
// question: if the monster is so fast, how much time has it spent in
// its last movement?
//
// If speed is 10 (normal), one movement is a duration of 10.
// If speed is 1 (very slow), each movement is a duration of 100.
// If speed is 15 (50% faster than normal), each movement is a duration of
// 6.6667.
int speed_to_duration(int speed)
{
if (speed < 1)
speed = 10;
else if (speed > 100)
speed = 100;
return div_rand_round(100, speed);
}
void reveal_secret_door(const coord_def& p)
{
ASSERT(grd(p) == DNGN_SECRET_DOOR);
dungeon_feature_type door = grid_secret_door_appearance(p);
// Former secret doors become known but are still hidden to monsters
// until opened.
grd(p) = feat_is_opaque(door) ? DNGN_DETECTED_SECRET_DOOR
: DNGN_OPEN_DOOR;
viewwindow();
learned_something_new(HINT_FOUND_SECRET_DOOR, p);
// If a transparent secret door was forced open to preserve LOS,
// check if it had an opening prompt.
if (grd(p) == DNGN_OPEN_DOOR)
{
std::string door_open_prompt =
env.markers.property_at(p, MAT_ANY, "door_open_prompt");
if (!door_open_prompt.empty())
{
mprf("That secret door had a prompt on it:", MSGCH_PROMPT);
mprf(MSGCH_PROMPT, "%s", door_open_prompt.c_str());
if (!is_exclude_root(p))
{
if (yesno("Put travel exclusion on door? (Y/n)", true, 'y'))
// Zero radius exclusion right on top of door.
set_exclude(p, 0);
}
}
}
}
// A feeble attempt at Nethack-like completeness for cute messages.
std::string your_hand(bool plural)
{
std::string result;
switch (you.attribute[ATTR_TRANSFORMATION])
{
default:
mpr("ERROR: unknown transformation in your_hand() (spells4.cc)",
MSGCH_ERROR);
case TRAN_NONE:
case TRAN_STATUE:
case TRAN_LICH:
result = (you.has_usable_claws()) ? "claw" : "hand";
break;
case TRAN_ICE_BEAST:
result = "hand";
break;
case TRAN_SPIDER:
case TRAN_PIG:
result = "front leg";
break;
case TRAN_DRAGON:
case TRAN_BAT:
result = "foreclaw";
break;
case TRAN_BLADE_HANDS:
result = "scythe-like blade";
break;
}
if (plural)
result += 's';
return result;
}
bool stop_attack_prompt(const monsters *mon, bool beam_attack,
coord_def beam_target)
{
ASSERT(!crawl_state.game_is_arena());
if (you.confused() || !you.can_see(mon))
return (false);
bool retval = false;
bool prompt = false;
const bool mon_target = (beam_target == mon->pos());
const bool inSanctuary = (is_sanctuary(you.pos())
|| is_sanctuary(mon->pos()));
const bool wontAttack = mon->wont_attack();
const bool isFriendly = mon->friendly();
const bool isNeutral = mon->neutral();
const bool isUnchivalric = is_unchivalric_attack(&you, mon);
const bool isHoly = mon->is_holy()
&& (mon->attitude != ATT_HOSTILE
|| testbits(mon->flags, MF_NO_REWARD)
|| testbits(mon->flags, MF_WAS_NEUTRAL));
if (isFriendly)
{
// Listed in the form: "your rat", "Blork the orc".
std::string verb = "";
bool need_mon_name = true;
if (beam_attack)
{
verb = "fire ";
if (mon_target)
verb += "at ";
else if (you.pos() < beam_target && beam_target < mon->pos()
|| you.pos() > beam_target && beam_target > mon->pos())
{
verb += "in " + mon->name(DESC_NOCAP_THE) + "'s direction";
need_mon_name = false;
}
else
verb += "through ";
}
else
verb = "attack ";
if (need_mon_name)
verb += mon->name(DESC_NOCAP_THE);
snprintf(info, INFO_SIZE, "Really %s%s?",
verb.c_str(),
(inSanctuary) ? ", despite your sanctuary" : "");
prompt = true;
}
else if (inSanctuary || wontAttack
|| (you.religion == GOD_JIYVA && mons_is_slime(mon)
&& !mon->is_shapeshifter())
|| (isNeutral || isHoly) && is_good_god(you.religion)
|| isUnchivalric
&& you.religion == GOD_SHINING_ONE
&& !tso_unchivalric_attack_safe_monster(mon))
{
snprintf(info, INFO_SIZE, "Really %s the %s%s%s%s%s?",
(beam_attack) ? (mon_target) ? "fire at"
: "fire through"
: "attack",
(isUnchivalric) ? "helpless "
: "",
(isFriendly) ? "friendly " :
(wontAttack) ? "non-hostile " :
(isNeutral) ? "neutral "
: "",
(isHoly) ? "holy "
: "",
mon->name(DESC_PLAIN).c_str(),
(inSanctuary) ? ", despite your sanctuary"
: "");
prompt = true;
}
if (prompt)
retval = !yesno(info, false, 'n');
return (retval);
}
bool is_orckind(const actor *act)
{
if (mons_genus(act->mons_species()) == MONS_ORC)
return (true);
if (act->atype() == ACT_MONSTER)
{
const monsters* mon = act->as_monster();
if (mons_is_zombified(mon)
&& mons_genus(mon->base_monster) == MONS_ORC)
{
return (true);
}
if (mons_is_ghost_demon(mon->type)
&& mon->ghost->species == SP_HILL_ORC)
{
return (true);
}
}
return (false);
}
bool is_dragonkind(const actor *act)
{
if (mons_genus(act->mons_species()) == MONS_DRAGON
|| mons_genus(act->mons_species()) == MONS_DRACONIAN)
{
return (true);
}
if (act->atype() == ACT_PLAYER)
return (you.attribute[ATTR_TRANSFORMATION] == TRAN_DRAGON);
// Else the actor is a monster.
const monsters* mon = act->as_monster();
if (mon->type == MONS_SERPENT_OF_HELL)
return (true);
if (mons_is_zombified(mon)
&& (mons_genus(mon->base_monster) == MONS_DRAGON
|| mons_genus(mon->base_monster) == MONS_DRACONIAN))
{
return (true);
}
if (mons_is_ghost_demon(mon->type)
&& species_genus(mon->ghost->species) == GENPC_DRACONIAN)
{
return (true);
}
return (false);
}
// Make the player swap positions with a given monster.
void swap_with_monster(monsters *mon_to_swap)
{
monsters& mon(*mon_to_swap);
ASSERT(mon.alive());
const coord_def newpos = mon.pos();
// Be nice: no swapping into uninhabitable environments.
if (!you.is_habitable(newpos) || !mon.is_habitable(you.pos()))
{
mpr("You spin around.");
return;
}
const bool mon_caught = mon.caught();
const bool you_caught = you.attribute[ATTR_HELD];
// If it was submerged, it surfaces first.
mon.del_ench(ENCH_SUBMERGED);
mprf("You swap places with %s.", mon.name(DESC_NOCAP_THE).c_str());
// Pick the monster up.
mgrd(newpos) = NON_MONSTER;
mon.moveto(you.pos());
// Plunk it down.
mgrd(mon.pos()) = mon_to_swap->mindex();
if (you_caught)
{
check_net_will_hold_monster(&mon);
if (!mon_caught)
you.attribute[ATTR_HELD] = 0;
}
// Move you to its previous location.
move_player_to_grid(newpos, false, true);
if (mon_caught)
{
if (you.body_size(PSIZE_BODY) >= SIZE_GIANT)
{
mpr("The net rips apart!");
you.attribute[ATTR_HELD] = 0;
int net = get_trapping_net(you.pos());
if (net != NON_ITEM)
destroy_item(net);
}
else
{
you.attribute[ATTR_HELD] = 10;
mpr("You become entangled in the net!");
// Xom thinks this is hilarious if you trap yourself this way.
if (you_caught)
xom_is_stimulated(16);
else
xom_is_stimulated(255);
}
if (!you_caught)
mon.del_ench(ENCH_HELD, true);
}
}
// AutoID an equipped ring of teleport.
// Code copied from fire/ice in spl-cast.cc
void maybe_id_ring_TC()
{
if (you.duration[DUR_CONTROL_TELEPORT]
|| player_mutation_level(MUT_TELEPORT_CONTROL))
{
return;
}
int num_unknown = 0;
for (int i = EQ_LEFT_RING; i <= EQ_RIGHT_RING; ++i)
{
if (player_wearing_slot(i)
&& !item_ident(you.inv[you.equip[i]], ISFLAG_KNOW_PROPERTIES))
{
++num_unknown;
}
}
if (num_unknown != 1)
return;
for (int i = EQ_LEFT_RING; i <= EQ_RIGHT_RING; ++i)
if (player_wearing_slot(i))
{
item_def& ring = you.inv[you.equip[i]];
if (!item_ident(ring, ISFLAG_KNOW_PROPERTIES)
&& ring.sub_type == RING_TELEPORT_CONTROL)
{
set_ident_type( ring.base_type, ring.sub_type, ID_KNOWN_TYPE );
set_ident_flags(ring, ISFLAG_KNOW_PROPERTIES);
mprf("You are wearing: %s",
ring.name(DESC_INVENTORY_EQUIP).c_str());
}
}
}
|