Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 4x 9x 73x 73x 73x 73x 73x 111x 111x 111x 111x 111x 111x 111x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 2x 2x 2x 73x 73x 73x 73x 73x 73x 73x 73x 63451x 63451x 192330x 192330x 192330x 192330x 192330x 243x 178022x 243x 243x 63208x 63451x 73x 1592x 1592x 1592x 1592x 1592x 1592x 1592x 1592x 1592x 1592x 1592x 1592x 65x 65x 845x 845x 845x 845x 845x 629x 629x 629x 845x 65x 1592x 1592x 1592x 1592x 1592x 1592x 70x 70x 70x 70x 70x 70x 70x 70x 1592x 1592x 1592x 37366x 37366x 37366x 37366x 37366x 37366x 37366x 18612x 18612x 7929x 7929x 7929x 7929x 7929x 18612x 6024x 6024x 18612x 1561x 1561x 18612x 18612x 18612x 18612x 18612x 37366x 21983x 21983x 21983x 21983x 21983x 21983x 37366x 1480x 1592x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 11x 11x 11x 73x 73x 73x 73x 290x 290x 3x 5x 5x 5x 287x 290x 73x 73x 10x 10x 10x 10x 10x 10x 6x 6x 6x 6x 6x 6x 10x 4x 4x 4x 4x 4x 4x 10x 10x 10x 10x 10x 10x 5x 5x 1x 5x 2x 2x 2x 2x 2x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 10x 73x 10x 10x 10x 10x 1x 10x 9x 9x 10x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 10x 10x 10x 73x 9x 9x 9x 9x 6x 6x 9x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 9x 9x 9x 9x 9x 9x 73x 9x 9x 9x 9x 9x 9x 9x 9x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 9x 4x 4x 4x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 73x 73x 6x 6x 6x 6x 6x 6x 6x 6x 6x 73x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 28x 73x 73x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 3x 3x 3x 3x 3x 3x 3x 4x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 73x 73x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 4x 4x 4x 4x 4x 10x 6x 6x 6x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 28x 28x 28x 28x 28x 28x 28x 4x 4x 28x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 6x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 6x 6x 6x 4x 6x 6x 6x 6x 4x 4x 4x 4x 4x 6x 20x 20x 26x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 18x 18x 18x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 73x 73x 73x 73x 73x 23x 23x 23x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 5x 5x 5x 6x 22x 23x 73x 73x 1x 1x 1x 1x 73x 1x 1x 1x 73x 73x 73x 6x 6x 6x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 5x 6x 73x 73x 5x 5x 5x 73x 73x 5x 5x 5x 5x 5x 73x 73x 801x 801x 801x 801x 801x 801x 801x 801x 791x 801x 801x 584x 51x 51x 51x 51x 51x 51x 582x 11x 801x 801x 9x 9x 9x 801x 73x 73x 23x 23x 73x 73x 6x 6x 73x 73x 831x 831x 831x 831x 831x 831x 831x 375x 831x 73x 73x 73x 73x 9196x 9196x 9196x 9196x 9196x 9196x 9196x 715x 715x 460x 715x 460x 460x 460x 616x 831x 831x 831x 831x 375x 831x 715x 715x 715x 715x 8482x 9196x 73x 9208x 9208x 9208x 9208x 9208x 9208x 9208x 9208x 9208x 9208x 9196x 9208x 9208x 73x 73x 9179x 9179x 73x 73x 22667x 22667x 39593x 39593x 21867x 22667x 73x 73x 73x 73x 73x | // mthrowu.js — Monster throwing/spitting/breathing (port of mthrowu.c)
// Handles monster ranged attacks at the player and other monsters.
//
// Ported functions:
// m_has_launcher_and_ammo(mtmp) — check if mon has ammo+launcher (mthrowu.c:58)
// thitu(tlev, dam, objp, name) — thrown object hits hero (mthrowu.c:76)
// drop_throw(obj, ohit, x, y) — handle thrown obj landing (mthrowu.c:162)
// monmulti(mtmp, otmp, mwep) — multishot count (mthrowu.c:201)
// monshoot(mtmp, otmp, mwep) — shoot/throw execution (mthrowu.c:262)
// ohitmon(mtmp, otmp, range, verbose) — thrown obj hits monster (mthrowu.c:321)
// ucatchgem(gem, mon) — hero catches gem (mthrowu.c:506)
// u_catch_thrown_obj(otmp) — hero catches thrown obj (mthrowu.c:533)
// m_throw(mon, x, y, dx, dy, range, obj) — main throw routine (mthrowu.c:572)
// return_from_mtoss(magr, otmp, tethered) — returning weapon (mthrowu.c:848)
// thrwmm(mtmp, mdef) — monster throws at monster (mthrowu.c:967)
// spitmm(mtmp, mattk, mtarg) — monster spits at monster (mthrowu.c:1014)
// breathwep_name(typ) — breath weapon name (mthrowu.c:1081)
// breamm(mtmp, mattk, mtarg) — monster breathes at monster (mthrowu.c:1091)
// m_useupall(mon, obj) — remove all of obj (mthrowu.c:1152)
// m_useup(mon, obj) — use up one of obj (mthrowu.c:1160)
// thrwmu(mtmp) — monster throws at hero (mthrowu.c:1172)
// spitmu(mtmp, mattk) — monster spits at hero (mthrowu.c:1266)
// breamu(mtmp, mattk) — monster breathes at hero (mthrowu.c:1273)
// blocking_terrain(x, y) — check blocking terrain (mthrowu.c:1280)
// linedup_callback(ax, ay, bx, by, fnc) — line check with callback (mthrowu.c:1293)
// linedup(ax, ay, bx, by, bhandling) — line-of-fire check (mthrowu.c:1328)
// m_lined_up(mtarg, mtmp) — monster lined up check (mthrowu.c:1374)
// lined_up(mtmp) — cached line check vs hero (mthrowu.c:1396)
// m_carrying(mtmp, type) — check monster inventory (mthrowu.c:1402)
// hit_bars(objp, objx, objy, barsx, barsy, breakflags) — hit iron bars (mthrowu.c:1415)
// hits_bars(obj_p, x, y, barsx, barsy, always_hit, whodidit) — check bar hit (mthrowu.c:1497)
import { game } from './gstate.js';
import { closed_door } from './monmove.js';
import { rn2, rnd, pushRngLogEntry } from './rng.js';
import { impossible, pline, pline_The, set_msg_xy, You, You_hear, Your } from './pline.js';
import { cansee, clear_path, couldsee } from './vision.js';
import { DEADMONSTER, Monnam, is_mplayer, mhim, mon_nam, mon_wield_item, mondied, setmangry, some_mon_nam, stop_occupation, wake_nearto, wakeup } from './mon.js';
import { ACID_VENOM, AKLYS, ARMOR_CLASS, ARROW, BALL_CLASS, BARDICHE, BEC_DE_CORBIN, BILL_GUISARME, BLINDING_VENOM, BOOMERANG, BOULDER, BOW, CHAIN_CLASS, COIN_CLASS, CORPSE, CREAM_PIE, CREDIT_CARD, CROSSBOW, CROSSBOW_BOLT, DAGGER, DART, DWARVISH_SPEAR, EGG, ELVEN_ARROW, ELVEN_BOW, ELVEN_DAGGER, ELVEN_SPEAR, ENORMOUS_MEATBALL, FAUCHARD, FIRST_GLASS_GEM, FLINT, FOOD_CLASS, GEM_CLASS, GLAIVE, GOLD, GUISARME, HALBERD, HEAVY_IRON_BALL, is_ammo, is_flimsy, is_poisonable, JAVELIN, KNIFE, LANCE, LENSES, LOADSTONE, LOCK_PICK, LUCERN_HAMMER, LUCKSTONE, MAGIC_WHISTLE, MEAT_STICK, ORCISH_ARROW, ORCISH_BOW, ORCISH_DAGGER, ORCISH_SPEAR, PARTISAN, POT_ACID, POTION_CLASS, RANSEUR, ROCK, ROCK_CLASS, SHURIKEN, SILVER, SILVER_ARROW, SILVER_DAGGER, SILVER_SPEAR, SKELETON_KEY, SLING, SPBOOK_CLASS, SPEAR, SPETUM, STATUE, stone_missile, STRANGE_OBJECT, TALLOW_CANDLE, TIN_WHISTLE, TOOL_CLASS, VENOM_CLASS, VOULGE, WAN_STRIKING, WAND_CLASS, WAR_HAMMER, WAX_CANDLE, WEAPON_CLASS, YA, YUMI } from './objects.js';
import { A_STR, A_CON, A_DEX, W_WEP, BACKTRACK, BOLT_LIM, MON_POLE_DIST, PET_MISSILE_RANGE2, DISP_FLASH, DISP_END, DISP_TETHER, M_ATTK_MISS, M_ATTK_HIT, M_SEEN_ACID, M_SEEN_REFL, NEED_WEAPON, NEED_RANGED_WEAPON, NO_WEAPON_WANTED, M_AP_NOTHING, M_AP_MONSTER, P_BOW, P_CROSSBOW, P_DART, P_KNIFE, P_SHURIKEN, P_SPEAR, PRONOUN_HALLU, WT_IRON_BALL_INCR, XKILL_NOMSG, KILLED_BY, KILLED_BY_AN, POTHIT_OTHER_THROW, POTHIT_MONST_THROW, isok, u_at, M_AP_TYPE, BRK_BY_HERO, BRK_MELEE, SLT_ENCUMBER, EYE, FACE, HAND, FOOT, ARM, BZ_OFS_AD, AKLYS_LIM } from './const.js';
import { dist2, distmin, is_art, MON_WEP, nh_delay_output, s_suffix, sgn, upstart } from './hacklib.js';
import { monkilled, rounddiv } from './hack.js';
import { m_at } from './map_access.js';
import { nomul } from './cmd.js';
import { splitobj, obfree, mksobj, place_object, add_to_minv } from './mkobj.js';
import { obj_extract_self, sobj_at } from './mkobj.js';
import { stackobj, delobj, makeknown, observe_object } from './invent.js';
import { The, Tobjnam, an, distant_name, doname, killer_xname, makeplural, obj_is_pname, otense, simpleonames, singular, the, vtense, xname } from './objnam.js';
import { ACURR, ACURRSTR, exercise, poisoned } from './attrib.js';
import { canseemon, canspotmon, delay_output, newsym, seemimic, tmp_at, tmp_obj_glyph } from './display.js';
import { buzz, hit, miss, exclam } from './zap.js';
import { find_mac } from './worn.js';
import { extract_from_minvent } from './worn.js';
import { make_blinded, make_stoned, potionhit } from './potion.js';
import { losehp } from './hack.js';
import { multishot_class_bonus, should_mulch_missile, harmless_missile, mhurtle, omon_adj } from './dothrow.js';
import { hero_breaks, breaks } from './dothrow.js';
import { ship_object, down_gate } from './dokick.js';
import { flooreffects, dropy } from './do.js';
import { hold_another_object } from './invent.js';
import { passive_obj, shade_miss, xkilled } from './uhitm.js';
import { dmgval } from './weapon.js';
import { amorphous, bigmonst, can_blnd, cvt_adtyp_to_mseenres, get_atkdam_type, hates_silver, is_animal, is_elf, is_gnome, is_launcher, is_lord, is_mindless, is_orc, is_pole, is_prince, is_unicorn, is_vampshifter, likes_gems, m_seenres, mdistu, mon_hates_silver, monsndx, monstseesu, monstunseesu, nohands, noncorporeal, nonliving, passes_rocks, poly_when_stoned, resists_acid, resists_poison, resists_ston, strongmonst, throws_rocks, touch_petrifies } from './mondata.js';
import {
Acid_resistance,
Blind,
Confusion,
Deaf,
Fumbling,
Hallucination,
Role_if,
Sleep_resistance,
Stone_resistance,
Stunned,
U_AP_TYPE,
Upolyd
} from './macros.js';
import { body_part, mbodypart, polymon } from './polyself.js';
import { munstone } from './muse.js';
// TODO: port from mhitm.c
import { snuff_candle } from './apply.js';
import { calc_capacity } from './pickup.js';
import { hliquid } from './do_name.js';
import { EDOG, IS_OBSTRUCTED, IS_SINK, P_SLING, W_ARMS } from './const.js';
import { BlindedTimeout, Stoned } from './macros.js';
import {
mons, AD_PHYS, AD_MAGM, AD_FIRE, AD_COLD, AD_SLEE, AD_BLND, AD_DRST, AD_ACID,
AT_SPIT, AT_WEAP, MZ_TINY, PM_STONE_GOLEM, PM_MONK, PM_ROGUE,
S_KOP,
} from './monsters.js';
import { Soundeffect } from './sounds.js';
import { is_waterwall } from './dbridge.js';
import { freehand } from './engrave.js';
import { obj_sheds_light } from './light.js';
import { mswings_verb } from './mhitu.js';
import { mwelded, setmnotwielded } from './wield.js';
import { artifact_hit } from './artifact.js';
import { ART_SNICKERSNEE } from './artifacts.js';
import { ammo_and_launcher, matching_launcher } from './weapon.js';
import { can_touch_safely } from './monmove.js';
// ── Local stubs for unported/unavailable functions ──
// setmnotwielded imported from wield.js
function clear_dknown(obj) { if (obj) obj.dknown = 0; }
function mshot_xname(obj) { return xname(obj); }
// is_launcher: imported from mondata.js
// ammo_and_launcher: imported from weapon.js
// matching_launcher: imported from weapon.js
// is_mplayer: imported from mon.js
export function autoreturn_weapon(obj) {
// C: checks if weapon is aklys/boomerang/mjollnir
if (!obj) return null;
if (obj.otyp === AKLYS) return { tethered: 1, range: 8 };
if (obj.otyp === BOOMERANG) return { tethered: 0, range: 50 };
// TODO: Mjollnir
return null;
}
// TODO: port
// stone_missile imported from objects.js
// TODO: port
// C: Hate_silver = (u.ulycn >= LOW_PM || hates_silver(youmonst.data))
function Hate_silver() {
return (game.u?.ulycn >= 0) || hates_silver(game.youmonst?.data);
}
// tmp_at: imported from display.js
// obj_to_glyph: imported from display.js
// set_msg_xy: imported from pline.js
// some_mon_nam: imported from mon.js
// C ref: weapon.c:533 select_rwep
// Ranged weapon arrays matching C's rwep[], pwep[], arwep[]
const rwep = [
DWARVISH_SPEAR, SILVER_SPEAR, ELVEN_SPEAR, SPEAR, ORCISH_SPEAR, JAVELIN,
SHURIKEN, YA, SILVER_ARROW, ELVEN_ARROW, ARROW, ORCISH_ARROW,
CROSSBOW_BOLT, SILVER_DAGGER, ELVEN_DAGGER, DAGGER, ORCISH_DAGGER, KNIFE,
FLINT, ROCK, LOADSTONE, LUCKSTONE, DART, CREAM_PIE,
];
// C ref: weapon.c:680 monmightthrowwep
export function monmightthrowwep(obj) {
if (!obj) return false;
return rwep.includes(obj.otyp);
}
const pwep = [
HALBERD, BARDICHE, SPETUM, BILL_GUISARME, VOULGE, RANSEUR,
GUISARME, GLAIVE, LUCERN_HAMMER, BEC_DE_CORBIN, FAUCHARD, PARTISAN, LANCE,
];
const hands_obj = { _sentinel: 'hands' }; // C: &hands_obj — sentinel for "thrown by hand"
const arwep = [
{ otyp: AKLYS, range: AKLYS_LIM * AKLYS_LIM, tethered: 1 },
];
async function oselect(mtmp, type) {
for (let otmp = mtmp.minvent; otmp; otmp = otmp.nobj) {
if (otmp.otyp !== type) continue;
if ((type === CORPSE || type === EGG)
&& (otmp.corpsenm === undefined || otmp.corpsenm === -1
|| !touch_petrifies(mons[otmp.corpsenm])))
continue;
if (!(await can_touch_safely(mtmp, otmp)))
continue;
return otmp;
}
return null;
}
export async function select_rwep(mtmp) {
let otmp, mwep, mweponly;
const mlet = mtmp.data?.mlet;
game.propellor = hands_obj;
// Oselect macro: check for specific items first
if ((otmp = await oselect(mtmp, EGG)) != null) return otmp;
if (mlet === 37 /* S_KOP */) { if ((otmp = await oselect(mtmp, CREAM_PIE)) != null) return otmp; }
if (throws_rocks(mtmp.data)) { if ((otmp = await oselect(mtmp, BOULDER)) != null) return otmp; }
// Polearm selection
mwep = MON_WEP(mtmp);
mweponly = (mwelded(mwep) && mtmp.weapon_check === NO_WEAPON_WANTED);
if (dist2(mtmp.mx, mtmp.my, mtmp.mux, mtmp.muy) <= 13
&& couldsee(mtmp.mx, mtmp.my)) {
if (is_art(mwep, ART_SNICKERSNEE)) {
game.propellor = mwep;
return mwep;
}
for (let i = 0; i < pwep.length; i++) {
if (((strongmonst(mtmp.data)
&& (mtmp.misc_worn_check & W_ARMS) === 0)
|| !game.objects[pwep[i]]?.oc_bimanual)
&& ((game.objects[pwep[i]]?.oc_material ?? 0) !== SILVER
|| !mon_hates_silver(mtmp))) {
if ((otmp = await oselect(mtmp, pwep[i])) != null
&& (otmp === mwep || !mweponly)) {
game.propellor = otmp;
return otmp;
}
}
}
}
// Throw-and-return weapons
for (let i = 0; i < arwep.length; i++) {
const arw = arwep[i];
if (!is_mindless(mtmp.data) && !is_animal(mtmp.data) && !mweponly
&& dist2(mtmp.mx, mtmp.my, mtmp.mux, mtmp.muy) <= arw.range
&& couldsee(mtmp.mx, mtmp.my)) {
if (((mtmp.misc_worn_check & W_ARMS) === 0
|| !game.objects[arw.otyp]?.oc_bimanual)
&& ((game.objects[arw.otyp]?.oc_material ?? 0) !== SILVER
|| !mon_hates_silver(mtmp))) {
if ((otmp = await oselect(mtmp, arw.otyp)) != null
&& (otmp === mwep || !mweponly)) {
game.propellor = otmp;
return otmp;
}
}
}
}
// General ranged weapons (most potent first)
for (let i = 0; i < rwep.length; i++) {
let prop;
// Shooting gems from slings before darts
if (rwep[i] === DART && !likes_gems(mtmp.data)
&& m_carrying(mtmp, SLING)) {
for (otmp = mtmp.minvent; otmp; otmp = otmp.nobj)
if (otmp.oclass === GEM_CLASS
&& (otmp.otyp !== LOADSTONE || !otmp.cursed)) {
game.propellor = m_carrying(mtmp, SLING);
return otmp;
}
}
game.propellor = hands_obj;
prop = game.objects[rwep[i]]?.oc_skill ?? 0;
if (prop < 0) {
switch (-prop) {
case P_BOW:
game.propellor = await oselect(mtmp, YUMI);
if (!game.propellor) game.propellor = await oselect(mtmp, ELVEN_BOW);
if (!game.propellor) game.propellor = await oselect(mtmp, BOW);
if (!game.propellor) game.propellor = await oselect(mtmp, ORCISH_BOW);
break;
case P_SLING:
game.propellor = await oselect(mtmp, SLING);
break;
case P_CROSSBOW:
game.propellor = await oselect(mtmp, CROSSBOW);
break;
}
if ((otmp = MON_WEP(mtmp)) && mwelded(otmp) && otmp !== game.propellor
&& mtmp.weapon_check === NO_WEAPON_WANTED)
game.propellor = null; // 0 in C: needed launcher but welded weapon prevents
}
if (game.propellor != null) {
if (rwep[i] !== LOADSTONE) {
if ((otmp = await oselect(mtmp, rwep[i])) && !otmp.oartifact
&& !(otmp === MON_WEP(mtmp) && mwelded(otmp)))
return otmp;
} else {
for (otmp = mtmp.minvent; otmp; otmp = otmp.nobj) {
if (otmp.otyp === LOADSTONE && !otmp.cursed)
return otmp;
}
}
}
}
return null;
}
// mon_wield_item: imported from mon.js
function vision_clears() { return 'vision clears'; }
// is_flimsy: imported from objects.js
function dissolve_bars(x, y) { /* TODO */ }
// add_to_minv: imported from mkobj.js
// dobuzz: C's dobuzz wraps buzz() with extra args (sayhit/saymiss/forcemiss).
// JS buzz() already handles the core logic. Use buzz() directly at call sites.
// TODO
// Use ACURRSTR from attrib.js (condensed 3-25 range, not raw encoded)
// closed_door: imported from monmove.js
// TODO
// TODO
// C macros
const ARM_GLOVES = 3; // from objects.js — was wrong (5=ARM_CLOAK)
// Breath weapon names (C: breathwep[])
const breathwep = [
'fragments', 'fire', 'frost', 'sleep gas', 'a disintegration blast',
'lightning', 'poison gas', 'acid', 'strange breath #8',
'strange breath #9',
];
// Hallucinatory blast names
const hallublasts = [
'asteroids', 'beads', 'bubbles', 'butterflies', 'champagne', 'chaos',
'coins', 'cotton candy', 'crumbs', 'dark matter', 'darkness', 'data',
'dust specks', 'emoticons', 'emotions', 'entropy', 'flowers', 'foam',
'fog', 'gamma rays', 'gelatin', 'gemstones', 'ghosts', 'glass shards',
'glitter', 'good vibes', 'gravel', 'gravity', 'gravy', 'grawlixes',
'holy light', 'hornets', 'hot air', 'hyphens', 'hypnosis', 'infrared',
'insects', 'jargon', 'laser beams', 'leaves', 'lightening', 'logic gates',
'magma', 'marbles', 'mathematics', 'megabytes', 'metal shavings',
'metapatterns', 'meteors', 'mist', 'mud', 'music', 'nanites', 'needles',
'noise', 'nostalgia', 'oil', 'paint', 'photons', 'pixels', 'plasma',
'polarity', 'powder', 'powerups', 'prismatic light', 'pure logic',
'purple', 'radio waves', 'rainbows', 'rock music', 'rocket fuel', 'rope',
'sadness', 'salt', 'sand', 'scrolls', 'sludge', 'smileys', 'snowflakes',
'sparkles', 'specularity', 'spores', 'stars', 'steam', 'tetrahedrons',
'text', 'the past', 'tornadoes', 'toxic waste', 'ultraviolet light',
'viruses', 'water', 'waveforms', 'wind', 'X-rays', 'zorkmids',
];
// C macro: URETREATING(x, y)
function URETREATING(x, y) {
return distmin(game.u.ux, game.u.uy, x, y) > distmin(game.u.ux0, game.u.uy0, x, y);
}
// C: rnd_hallublast()
export function rnd_hallublast() {
return hallublasts[rn2(hallublasts.length)];
}
// C ref: mthrowu.c:58 m_has_launcher_and_ammo
export function m_has_launcher_and_ammo(mtmp) {
const mwep = MON_WEP(mtmp);
if (mwep && is_launcher(mwep)) {
for (let otmp = mtmp.minvent; otmp; otmp = otmp.nobj) {
if (ammo_and_launcher(otmp, mwep))
return true;
}
}
return false;
}
// C ref: mthrowu.c:76 thitu — hero is hit by something
export async function thitu(tlev, dam, objp_ref, name) {
const obj = objp_ref ? objp_ref[0] : null;
let onm, knm;
const named = (name !== null && name !== undefined);
let kprefix = KILLED_BY_AN;
let onmbuf, knmbuf;
if (!name) {
if (!obj) {
impossible('thitu: name & obj both null?');
return 0;
}
onmbuf = (obj.quan > 1) ? doname(obj) : mshot_xname(obj);
name = onmbuf;
knmbuf = killer_xname(obj);
knm = knmbuf;
kprefix = KILLED_BY;
} else {
knm = name;
if (name.toLowerCase().startsWith('the ') ||
name.toLowerCase().startsWith('an ') ||
name.toLowerCase().startsWith('a '))
kprefix = KILLED_BY;
}
onm = (obj && obj_is_pname(obj)) ? the(name)
: (obj && obj.quan > 1) ? name
: an(name);
const is_acid = (obj && obj.otyp === ACID_VENOM);
const dieroll = rnd(20);
if (game.u.uac + tlev <= dieroll) {
game.mesg_given = (game.mesg_given || 0) + 1;
if (Blind() || !game.flags.verbose) {
await pline('It misses.');
} else if (game.u.uac + tlev <= dieroll - 2) {
onmbuf = onm;
await pline('%s %s you.', upstart(onmbuf), vtense(onmbuf, 'miss'));
} else {
await You('are almost hit by %s.', onm);
}
return 0;
} else {
if (Blind() || !game.flags.verbose)
await You('are hit%s', exclam(dam));
else
await You('are hit by %s%s', onm, exclam(dam));
if (is_acid && Acid_resistance()) {
await pline("It doesn't seem to hurt you.");
monstseesu(M_SEEN_ACID);
} else if (obj && stone_missile(obj) && passes_rocks(game.youmonst?.data)) {
await pline('It %s you.',
named ? 'passes harmlessly through' : "doesn't harm");
} else if (obj && obj.oclass === POTION_CLASS) {
await potionhit(game.youmonst, obj, POTHIT_OTHER_THROW);
if (objp_ref) objp_ref[0] = null;
} else {
if (obj && game.objects[obj.otyp]?.oc_material === SILVER && Hate_silver()) {
await pline_The('silver sears your flesh!');
exercise(A_CON, false);
}
if (is_acid) {
await pline('It burns!');
monstunseesu(M_SEEN_ACID);
}
await losehp(dam, knm, kprefix);
exercise(A_STR, false);
}
return 1;
}
}
// C ref: mthrowu.c:162 drop_throw
async function drop_throw(obj, ohit, x, y) {
let broken;
if (obj.otyp === CREAM_PIE || obj.oclass === VENOM_CLASS
|| (ohit && obj.otyp === EGG)) {
broken = true;
} else {
broken = (ohit && should_mulch_missile(obj));
}
if (broken) {
delobj(obj);
} else {
if (down_gate(x, y) !== -1)
broken = await ship_object(obj, x, y, false);
if (!broken) {
const mtmp = m_at(x, y);
if (!(broken = await flooreffects(obj, x, y, 'fall'))) {
place_object(obj, x, y);
let mon = mtmp;
if (!mon && u_at(x, y))
mon = game.youmonst;
if (mon && ohit)
await passive_obj(mon, obj, null);
stackobj(obj);
}
}
}
game.thrownobj = null;
return broken;
}
// C ref: mthrowu.c:201 monmulti
function monmulti(mtmp, otmp, mwep) {
let multishot = 1;
if (otmp.quan > 1
&& (is_ammo(otmp)
? matching_launcher(otmp, mwep)
: otmp.oclass === WEAPON_CLASS)
&& !mtmp.mconf) {
if (is_prince(mtmp.data))
multishot += 2;
else if (is_lord(mtmp.data))
multishot++;
else if (is_mplayer(mtmp.data))
multishot++;
if (otmp.otyp === ELVEN_ARROW && !otmp.cursed)
multishot++;
if (mwep && mwep.otyp === ELVEN_BOW && ammo_and_launcher(otmp, mwep)
&& !mwep.cursed)
multishot++;
if (ammo_and_launcher(otmp, mwep) && mwep.spe > 1)
multishot += rounddiv(mwep.spe, 3);
// RNG: rnd(multishot)
multishot = rnd(Math.trunc(multishot));
// class bonus
multishot += multishot_class_bonus(monsndx(mtmp.data), otmp, mwep);
// racial bonus
if ((is_elf(mtmp.data) && otmp.otyp === ELVEN_ARROW
&& mwep && mwep.otyp === ELVEN_BOW)
|| (is_orc(mtmp.data) && otmp.otyp === ORCISH_ARROW
&& mwep && mwep.otyp === ORCISH_BOW)
|| (is_gnome(mtmp.data) && otmp.otyp === CROSSBOW_BOLT
&& mwep && mwep.otyp === CROSSBOW))
multishot++;
}
if (otmp.quan < multishot)
multishot = Math.trunc(otmp.quan);
if (multishot < 1)
multishot = 1;
return multishot;
}
// C ref: mthrowu.c:262 monshoot
async function monshoot(mtmp, otmp, mwep) {
const g = game;
const mtarg = g.mtarget;
const dm = distmin(mtmp.mx, mtmp.my,
mtarg ? mtarg.mx : mtmp.mux,
mtarg ? mtarg.my : mtmp.muy);
const multishot = monmulti(mtmp, otmp, mwep);
if (canseemon(mtmp)) {
let onm;
if (multishot > 1) {
onm = multishot + ' ' + xname(otmp);
} else {
onm = singular(otmp, xname);
onm = obj_is_pname(otmp) ? the(onm) : an(onm);
}
g.m_shot = g.m_shot || {};
g.m_shot.s = ammo_and_launcher(otmp, mwep) ? true : false;
const trgbuf = mtarg ? some_mon_nam(mtarg) : '';
set_msg_xy(mtmp.mx, mtmp.my);
await pline('%s %s %s%s%s!', Monnam(mtmp),
g.m_shot.s ? 'shoots' : 'throws', onm,
mtarg ? ' at ' : '', trgbuf);
g.m_shot.o = otmp.otyp;
} else {
g.m_shot = g.m_shot || {};
g.m_shot.o = STRANGE_OBJECT;
}
g.m_shot.n = multishot;
for (g.m_shot.i = 1; g.m_shot.i <= g.m_shot.n; g.m_shot.i++) {
await m_throw(mtmp, mtmp.mx, mtmp.my, sgn(game.tbx), sgn(game.tby), dm, otmp);
if (DEADMONSTER(mtmp) && g.m_shot.i < g.m_shot.n)
break;
}
g.m_shot.n = g.m_shot.i = 0;
g.m_shot.o = STRANGE_OBJECT;
g.m_shot.s = false;
}
// C ref: mthrowu.c:506 ucatchgem
async function ucatchgem(gem, mon) {
// LAST_GLASS_GEM and FIRST_GLASS_GEM checks simplified
if (gem.oclass === GEM_CLASS && is_unicorn(game.youmonst?.data)) {
const gem_xname_str = xname(gem);
const mon_s_name = s_suffix(mon_nam(mon));
// glass gem check simplified
if (gem.otyp >= FIRST_GLASS_GEM) {
await You('catch the %s.', gem_xname_str);
await You('are not interested in %s junk.', mon_s_name);
makeknown(gem.otyp);
await dropy(gem);
} else {
await You("accept %s gift in the spirit in which it was intended.",
mon_s_name);
await hold_another_object(gem, 'You catch, but drop, %s.',
gem_xname_str, 'You catch:');
}
return true;
}
return false;
}
// C ref: mthrowu.c:533 u_catch_thrown_obj
async function u_catch_thrown_obj(otmp) {
const catch_chance = 100 - ACURR(A_DEX)
- ((Role_if(PM_MONK) || Role_if(PM_ROGUE)) ? 20 : 0);
if (!Blind() && !Confusion() && !Stunned() && !Fumbling()
&& otmp.oclass !== VENOM_CLASS
&& !nohands(game.youmonst?.data) && freehand()
&& calc_capacity(otmp.owt || 0) <= SLT_ENCUMBER && !rn2(catch_chance)) {
const buf = 'You catch the ' + simpleonames(otmp) + '!';
await hold_another_object(otmp, 'You catch, but drop, the %s.',
simpleonames(otmp), buf);
return true;
}
return false;
}
// C macro: MT_FLIGHTCHECK
async function MT_FLIGHTCHECK(pre, forcehit, singleobj_ref, dx, dy) {
const g = game;
const bx = g.bhitpos.x;
const by = g.bhitpos.y;
const lev = g.level;
const nx = bx + dx;
const ny = by + dy;
if (!isok(nx, ny)) return true;
const cell = lev?.locations?.[nx]?.[ny];
const typ = cell?.typ ?? 0;
if (IS_OBSTRUCTED(typ)) return true;
if (closed_door(nx, ny)) return true;
if (typ === 19 /* IRONBARS */ &&
await hits_bars(singleobj_ref, bx, by, nx, ny, pre ? 0 : forcehit, 0))
return true;
if (!pre && IS_SINK(lev?.locations?.[bx]?.[by]?.typ ?? 0))
return true;
return false;
}
// C ref: mthrowu.c:321 ohitmon
export async function ohitmon(mtmp, otmp, range, verbose) {
const g = game;
let damage, tmp;
const mon_launcher = g.marcher ? MON_WEP(g.marcher) : null;
g.notonhead = (g.bhitpos.x !== mtmp.mx || g.bhitpos.y !== mtmp.my);
const ismimic = M_AP_TYPE(mtmp) && M_AP_TYPE(mtmp) !== M_AP_MONSTER;
const vis = cansee(g.bhitpos.x, g.bhitpos.y);
if (vis)
observe_object(otmp);
tmp = 5 + find_mac(mtmp) + omon_adj(mtmp, otmp, false);
if (g.marcher && g.mtarget === mtmp) {
if (g.marcher.m_lev > 5)
tmp += g.marcher.m_lev - 5;
if (mon_launcher && mon_launcher.oartifact)
tmp += 0; // spec_abon stub
}
if (tmp < rnd(20)) {
if (!ismimic) {
if (vis)
await miss(distant_name(otmp, mshot_xname), mtmp);
else if (verbose && !g.mtarget)
await pline('It is missed.');
}
if (!range) {
await drop_throw(otmp, 0, mtmp.mx, mtmp.my);
return 1;
}
} else if (otmp.oclass === POTION_CLASS) {
if (ismimic) seemimic(mtmp);
mtmp.msleeping = 0;
await potionhit(mtmp, otmp, POTHIT_OTHER_THROW);
return 1;
} else {
const material = game.objects[otmp.otyp]?.oc_material ?? 0;
const harmless = (stone_missile(otmp) && passes_rocks(mtmp.data));
damage = dmgval(otmp, mtmp);
if (otmp.otyp === ACID_VENOM && resists_acid(mtmp))
damage = 0;
if (ismimic) seemimic(mtmp);
mtmp.msleeping = 0;
Soundeffect('se_splat_egg', 35);
if (vis) {
if (otmp.otyp === EGG) {
await pline('Splat! %s is hit with %s egg!', Monnam(mtmp),
otmp.known ? an(mons[otmp.corpsenm]?.mname || 'unknown') : 'an');
} else {
let how;
if (!harmless)
how = exclam(damage);
else
how = ' but passes harmlessly through ' + mhim(mtmp) + '.';
await hit(distant_name(otmp, mshot_xname), mtmp, how);
}
} else if (verbose && !g.mtarget) {
await pline('%s%s is hit%s', (otmp.otyp === EGG) ? 'Splat! ' : '',
Monnam(mtmp), exclam(damage));
}
if (otmp.opoisoned && is_poisonable(otmp)) {
if (resists_poison(mtmp)) {
if (vis)
await pline_The("poison doesn't seem to affect %s.", mon_nam(mtmp));
} else {
if (rn2(30)) {
damage += rnd(6);
} else {
if (vis)
await pline_The('poison was deadly...');
damage = mtmp.mhp;
}
}
}
if (material === SILVER && mon_hates_silver(mtmp)) {
const flesh = (!noncorporeal(mtmp.data) && !amorphous(mtmp.data));
if (vis) {
let m_name = mon_nam(mtmp);
if (flesh)
m_name = s_suffix(m_name) + ' flesh';
await pline_The('silver sears %s!', m_name);
} else if (verbose && !g.mtarget) {
await pline('%s is seared!', flesh ? 'Its flesh' : 'It');
}
}
if (otmp.otyp === ACID_VENOM && cansee(mtmp.mx, mtmp.my)) {
if (resists_acid(mtmp)) {
if (vis || (verbose && !g.mtarget))
await pline('%s is unaffected.', Monnam(mtmp));
} else {
if (vis)
await pline_The('%s burns %s!', hliquid('acid'), mon_nam(mtmp));
else if (verbose && !g.mtarget)
await pline('It is burned!');
}
}
if (otmp.otyp === EGG && otmp.corpsenm !== undefined
&& mons[otmp.corpsenm] && false /* touch_petrifies stub */) {
// petrification path - stub
}
if (!harmless && !DEADMONSTER(mtmp)) {
mtmp.mhp -= damage;
if (DEADMONSTER(mtmp)) {
if (vis || (verbose && !g.mtarget))
await pline('%s is %s!', Monnam(mtmp),
(nonliving(mtmp.data) || is_vampshifter(mtmp)
|| !canspotmon(mtmp)) ? 'destroyed' : 'killed');
if (!game.context?.mon_moving
&& (otmp.otyp !== BOULDER || range >= 0 || otmp.otrapped))
await xkilled(mtmp, XKILL_NOMSG);
else
await mondied(mtmp);
}
}
if (!DEADMONSTER(mtmp)
&& can_blnd(null, mtmp,
(otmp.otyp === BLINDING_VENOM) ? AT_SPIT : AT_WEAP, otmp)) {
if (vis && mtmp.mcansee)
await pline('%s is blinded by %s.', Monnam(mtmp),
the((otmp.oclass === VENOM_CLASS) ? 'venom'
: (otmp.otyp === CREAM_PIE) ? 'pie'
: xname(otmp)));
mtmp.mcansee = 0;
let blnd = (mtmp.mblinded || 0) + rnd(25) + 20;
if (blnd > 127) blnd = 127;
mtmp.mblinded = blnd;
}
if (!DEADMONSTER(mtmp) && !game.context?.mon_moving)
await setmangry(mtmp, true);
const objgone = await drop_throw(otmp, 1, g.bhitpos.x, g.bhitpos.y);
if (!objgone && range === -1) {
obj_extract_self(otmp);
return false;
}
return true;
}
return false;
}
// C ref: mthrowu.c:572 m_throw
export async function m_throw(mon, x, y, dx, dy, range, obj) {
const g = game;
let mtmp;
let singleobj;
let forcehit;
const sym = obj.oclass;
let hitu = 0, blindinc = 0;
const arw = autoreturn_weapon(obj);
const tethered_weapon = (obj === MON_WEP(mon) && arw && arw.tethered !== 0);
let return_flightpath = false;
g.bhitpos = g.bhitpos || {};
g.bhitpos.x = x;
g.bhitpos.y = y;
g.notonhead = false;
if (obj.quan === 1 || obj.quan === 1n) {
if (MON_WEP(mon) === obj)
setmnotwielded(mon, obj);
obj_extract_self(obj);
singleobj = obj;
obj = null;
} else {
singleobj = splitobj(obj, 1);
obj_extract_self(singleobj);
}
g.thrownobj = singleobj;
singleobj.owornmask = 0;
if (!canseemon(mon))
clear_dknown(singleobj);
// RNG: rn2(7) for cursed/greased misfire
if ((singleobj.cursed || singleobj.greased) && (dx || dy) && !rn2(7)) {
if (canseemon(mon) && game.flags.verbose) {
if (is_ammo(singleobj))
await pline('%s misfires!', Monnam(mon));
else
await pline('%s as %s throws it!', Tobjnam(singleobj, 'slip'),
mon_nam(mon));
}
dx = rn2(3) - 1;
dy = rn2(3) - 1;
if (!dx && !dy) {
await drop_throw(singleobj, 0, g.bhitpos.x, g.bhitpos.y);
return;
}
}
// singleobj_ref for MT_FLIGHTCHECK (pass-by-reference for hits_bars)
const singleobj_ref = [singleobj];
if (await MT_FLIGHTCHECK(true, 0, singleobj_ref, dx, dy)) {
await drop_throw(singleobj, 0, g.bhitpos.x, g.bhitpos.y);
return;
}
g.mesg_given = 0;
if (sym) {
if (!tethered_weapon) {
await tmp_at(DISP_FLASH, tmp_obj_glyph(singleobj));
} else {
await tmp_at(DISP_TETHER, tmp_obj_glyph(singleobj));
}
}
while (range-- > 0) {
singleobj.ox = g.bhitpos.x += dx;
singleobj.oy = g.bhitpos.y += dy;
if (cansee(g.bhitpos.x, g.bhitpos.y))
observe_object(singleobj);
mtmp = m_at(g.bhitpos.x, g.bhitpos.y);
if (mtmp && await shade_miss(mon, mtmp, singleobj, true, true)) {
mtmp = null;
} else if (mtmp) {
if (await ohitmon(mtmp, singleobj, range, true))
break;
} else if (u_at(g.bhitpos.x, g.bhitpos.y)) {
if (game.multi)
nomul(0);
if (singleobj.oclass === GEM_CLASS && await ucatchgem(singleobj, mon))
break;
if (!tethered_weapon && await u_catch_thrown_obj(singleobj))
break;
if (singleobj.oclass === POTION_CLASS) {
await potionhit(game.youmonst, singleobj, POTHIT_MONST_THROW);
break;
}
const oldumort = game.u.umortality || 0;
switch (singleobj.otyp) {
case EGG:
if (singleobj.corpsenm === undefined || !mons[singleobj.corpsenm]
/* touch_petrifies check stub */) {
impossible('monster throwing egg type %d', singleobj.corpsenm);
hitu = 0;
break;
}
// FALLTHROUGH
case CREAM_PIE:
case BLINDING_VENOM:
hitu = await thitu(8, 0, [singleobj], null);
break;
default: {
let dam = dmgval(singleobj, game.youmonst);
let hitv = 3 - distmin(game.u.ux, game.u.uy, mon.mx, mon.my);
if (hitv < -4) hitv = -4;
if (is_elf(mon.data)
&& (game.objects[singleobj.otyp]?.oc_skill || 0) === -P_BOW) {
hitv++;
if (MON_WEP(mon) && MON_WEP(mon).otyp === ELVEN_BOW)
hitv++;
if (singleobj.otyp === ELVEN_ARROW)
dam++;
}
if (bigmonst(game.youmonst?.data))
hitv++;
hitv += 8 + (singleobj.spe || 0);
if (dam < 1) dam = 1;
hitu = await thitu(hitv, dam, [singleobj], null);
}
}
if (hitu && singleobj.opoisoned && is_poisonable(singleobj)) {
const onm_p = xname(singleobj);
const knm_p = killer_xname(singleobj);
await poisoned(onm_p, A_STR, knm_p,
((game.u.umortality || 0) > oldumort) ? 0 : 10, true);
}
if (hitu && can_blnd(null, game.youmonst,
(singleobj.otyp === BLINDING_VENOM) ? AT_SPIT : AT_WEAP,
singleobj)) {
blindinc = rnd(25);
if (singleobj.otyp === CREAM_PIE) {
if (!Blind())
await pline("Yecch! You've been creamed.");
else
await pline("There's %s sticky all over your %s.",
'something', body_part(FACE));
} else if (singleobj.otyp === BLINDING_VENOM) {
const eyes = body_part(EYE);
if (!Blind())
await pline_The('venom blinds you.');
else
await Your('%s %s.', eyes, vtense(eyes, 'sting'));
}
}
if (hitu && singleobj.otyp === EGG) {
if (!Stoned() && !Stone_resistance()
&& !(poly_when_stoned(game.youmonst?.data)
&& await polymon(PM_STONE_GOLEM))) {
await make_stoned(5, null, KILLED_BY, '');
}
}
await stop_occupation();
if (hitu) {
if (!tethered_weapon) {
await drop_throw(singleobj, hitu, game.u.ux, game.u.uy);
} else {
return_flightpath = true;
}
break;
}
}
forcehit = !rn2(5);
singleobj_ref[0] = singleobj;
if (!range || await MT_FLIGHTCHECK(false, forcehit, singleobj_ref, dx, dy)) {
if (singleobj) {
const lev = g.level;
const btyp = lev?.locations?.[g.bhitpos.x]?.[g.bhitpos.y]?.typ ?? 0;
if (range && cansee(g.bhitpos.x, g.bhitpos.y) && IS_SINK(btyp))
await pline('%s %s onto the sink.', The(mshot_xname(singleobj)),
otense(singleobj, Hallucination() ? 'plop' : 'drop'));
else if ((g.m_shot?.n || 0) > 1
&& (!g.mesg_given
|| g.bhitpos.x !== game.u.ux || g.bhitpos.y !== game.u.uy)
&& (cansee(g.bhitpos.x, g.bhitpos.y)
|| (g.marcher && canseemon(g.marcher))))
await pline('%s misses.', The(mshot_xname(singleobj)));
if (!tethered_weapon) {
await drop_throw(singleobj, 0, g.bhitpos.x, g.bhitpos.y);
} else {
return_flightpath = true;
}
}
break;
}
await tmp_at(g.bhitpos.x, g.bhitpos.y);
await delay_output();
}
await tmp_at(g.bhitpos.x, g.bhitpos.y);
nh_delay_output();
if (arw && return_flightpath)
await return_from_mtoss(mon, singleobj, tethered_weapon);
else
await tmp_at(DISP_END, 0);
g.mesg_given = 0;
if (blindinc) {
game.u.ucreamed = (game.u.ucreamed || 0) + blindinc;
await make_blinded(BlindedTimeout() + blindinc, false);
if (!Blind())
await Your(vision_clears());
}
g.thrownobj = null;
}
// C ref: mthrowu.c:848 return_from_mtoss
async function return_from_mtoss(magr, otmp, tethered_weapon) {
const impaired = (magr.mconf || magr.mstun || magr.mblinded);
let notcaught = false, hits_thrower = false;
let x = game.bhitpos.x, y = game.bhitpos.y;
const made_it_back = rn2(100);
let dmg = 0;
if (otmp && made_it_back) {
if (tethered_weapon) {
await tmp_at(DISP_END, BACKTRACK);
} else {
let dx_r = sgn(x - magr.mx);
let dy_r = sgn(y - magr.my);
if (x !== magr.mx || y !== magr.my) {
await tmp_at(DISP_FLASH, tmp_obj_glyph(otmp));
while (isok(x, y) && (x !== magr.mx || y !== magr.my)) {
await tmp_at(x, y);
await delay_output();
x -= dx_r;
y -= dy_r;
}
await tmp_at(DISP_END, 0);
}
}
x = magr.mx;
y = magr.my;
if (!impaired && rn2(100)) {
// weapon returns to thrower's hand
if (otmp) {
await add_to_minv(magr, otmp);
if (tethered_weapon) {
magr.mw = otmp;
otmp.owornmask |= W_WEP;
}
}
if (cansee(x, y))
newsym(x, y);
} else {
dmg = rn2(2);
if (!dmg) {
// lands at feet
} else {
dmg += rnd(3);
hits_thrower = true;
}
notcaught = true;
}
} else {
if (tethered_weapon)
await tmp_at(DISP_END, 0);
// "You hear a loud snap!"
notcaught = true;
}
if (otmp) {
if (hits_thrower) {
if (otmp.oartifact)
artifact_hit(null, magr, otmp, { val: dmg }, 0);
magr.mhp -= dmg;
if (DEADMONSTER(magr))
await monkilled(magr, canspotmon(magr) ? '' : null, AD_PHYS);
}
if (notcaught) {
snuff_candle(otmp);
if (!await ship_object(otmp, x, y, false)) {
if (await flooreffects(otmp, x, y, 'drop')) {
if (cansee(x, y))
newsym(x, y);
return;
}
place_object(otmp, x, y);
stackobj(otmp);
}
if (obj_sheds_light(otmp))
game.vision_full_recalc = 1;
}
}
if (cansee(x, y))
newsym(x, y);
}
// C ref: mthrowu.c:967 thrwmm — monster throws at monster
export async function thrwmm(mtmp, mdef) {
let otmp, mwep;
if (mtmp.weapon_check === NEED_WEAPON || !MON_WEP(mtmp)) {
mtmp.weapon_check = NEED_RANGED_WEAPON;
if ((await mon_wield_item(mtmp)) !== 0)
return M_ATTK_MISS;
}
otmp = await select_rwep(mtmp);
if (!otmp)
return M_ATTK_MISS;
const ispole = is_pole(otmp);
const x = mtmp.mx;
const y = mtmp.my;
mwep = MON_WEP(mtmp);
if (!ispole && m_lined_up(mdef, mtmp)) {
const chance = Math.max(BOLT_LIM - distmin(x, y, mdef.mx, mdef.my), 1);
if (!mdef.mflee || !rn2(chance)) {
if (ammo_and_launcher(otmp, mwep)
&& dist2(mtmp.mx, mtmp.my, mdef.mx, mdef.my) > PET_MISSILE_RANGE2)
return M_ATTK_MISS;
game.mtarget = mdef;
game.marcher = mtmp;
await monshoot(mtmp, otmp, mwep);
game.marcher = game.mtarget = null;
nomul(0);
return M_ATTK_HIT;
}
}
return M_ATTK_MISS;
}
// C ref: mthrowu.c:1014 spitmm
export async function spitmm(mtmp, mattk, mtarg) {
let otmp;
if (mtmp.mcan) {
if (!Deaf() && mdistu(mtmp) < BOLT_LIM * BOLT_LIM) {
if (canspotmon(mtmp)) {
await pline('A dry rattle comes from %s throat.',
s_suffix(mon_nam(mtmp)));
} else {
Soundeffect('se_dry_throat_rattle', 50);
await You_hear('a dry rattle nearby.');
}
}
return M_ATTK_MISS;
}
if (m_lined_up(mtarg, mtmp)) {
const utarg = (mtarg === game.youmonst);
const tx = utarg ? mtmp.mux : mtarg.mx;
const ty = utarg ? mtmp.muy : mtarg.my;
switch (mattk.adtyp) {
case AD_BLND:
case AD_DRST:
otmp = mksobj(BLINDING_VENOM, true, false);
break;
default:
impossible('bad attack type in spitmm');
// FALLTHROUGH
case AD_ACID:
otmp = mksobj(ACID_VENOM, true, false);
break;
}
if (!rn2(BOLT_LIM - distmin(mtmp.mx, mtmp.my, tx, ty))) {
if (canseemon(mtmp))
await pline('%s spits venom!', Monnam(mtmp));
if (!utarg)
game.mtarget = mtarg;
await m_throw(mtmp, mtmp.mx, mtmp.my, sgn(game.tbx), sgn(game.tby),
distmin(mtmp.mx, mtmp.my, tx, ty), otmp);
game.mtarget = null;
nomul(0);
if (mtmp.mtame && !mtmp.isminion) {
const dog = EDOG(mtmp);
if (dog && dog.hungrytime > 1)
dog.hungrytime -= 5;
}
return M_ATTK_HIT;
} else {
obj_extract_self(otmp);
obfree(otmp, null);
}
}
return M_ATTK_MISS;
}
// C ref: mthrowu.c:1081 breathwep_name
export function breathwep_name(typ) {
if (Hallucination())
return rnd_hallublast();
return breathwep[BZ_OFS_AD(typ)] || 'magical';
}
// BZ_OFS_AD: imported from const.js
function BZ_VALID_ADTYP(typ) {
return (BZ_OFS_AD(typ) >= 0 && BZ_OFS_AD(typ) < breathwep.length);
}
function BZ_M_BREATH(bztyp) { return 20 + bztyp; } // C: (20 + (x))
// C ref: mthrowu.c:1091 breamm
export async function breamm(mtmp, mattk, mtarg) {
const typ = get_atkdam_type(mattk.adtyp);
const utarget = (mtarg === game.youmonst);
if (m_lined_up(mtarg, mtmp)) {
if (mtmp.mcan) {
if (!Deaf()) {
if (canseemon(mtmp)) {
await pline('%s coughs.', Monnam(mtmp));
} else {
Soundeffect('se_cough', 100);
await You_hear('a cough.');
}
}
return M_ATTK_MISS;
}
if (utarget && (m_seenres(mtmp, cvt_adtyp_to_mseenres(typ))
|| m_seenres(mtmp, M_SEEN_REFL)))
return M_ATTK_HIT;
if (!mtmp.mspec_used && rn2(3)) {
if (BZ_VALID_ADTYP(typ)) {
if (canseemon(mtmp))
await pline('%s breathes %s!', Monnam(mtmp), breathwep_name(typ));
game.buzzer = mtmp;
await buzz(BZ_M_BREATH(BZ_OFS_AD(typ)), mattk.damn || 0,
mtmp.mx, mtmp.my, sgn(game.tbx), sgn(game.tby));
game.buzzer = null;
nomul(0);
if (!utarget || !rn2(3))
mtmp.mspec_used = 8 + rn2(18);
if (utarget && typ === AD_SLEE && !Sleep_resistance())
mtmp.mspec_used += rnd(20);
if (mtmp.mtame && !mtmp.isminion) {
const dog = EDOG(mtmp);
if (dog && dog.hungrytime >= 10)
dog.hungrytime -= 10;
}
} else {
impossible('Breath weapon %d used', typ - 1);
}
} else {
return M_ATTK_MISS;
}
}
return M_ATTK_HIT;
}
// C ref: mthrowu.c:1152 m_useupall
export async function m_useupall(mon, obj) {
await extract_from_minvent(mon, obj, true, false);
obfree(obj, null);
}
// C ref: mthrowu.c:1160 m_useup
export async function m_useup(mon, obj) {
if (obj.quan > 1) {
obj.quan--;
obj.owt = (game.objects[obj.otyp]?.oc_weight || 0) * obj.quan; // simplified weight
} else {
await m_useupall(mon, obj);
}
}
// C ref: mthrowu.c:1172 thrwmu — monster throws at hero
export async function thrwmu(mtmp) {
let otmp, mwep;
let rang;
let always_toss = false;
if (mtmp.weapon_check === NEED_WEAPON || !MON_WEP(mtmp)) {
mtmp.weapon_check = NEED_RANGED_WEAPON;
if ((await mon_wield_item(mtmp)) !== 0)
return;
}
otmp = await select_rwep(mtmp);
if (!otmp) return;
if (is_pole(otmp)) {
let dam, hitv;
if (otmp !== MON_WEP(mtmp))
return; // polearm must be wielded
rang = dist2(mtmp.mx, mtmp.my, mtmp.mux, mtmp.muy);
if (rang > MON_POLE_DIST || !couldsee(mtmp.mx, mtmp.my))
return;
if (canseemon(mtmp)) {
const onm = xname(otmp);
await pline('%s %s %s.', Monnam(mtmp),
mswings_verb(otmp, rang <= 2),
obj_is_pname(otmp) ? the(onm) : an(onm));
}
dam = dmgval(otmp, game.youmonst);
hitv = 3 - distmin(game.u.ux, game.u.uy, mtmp.mx, mtmp.my);
if (hitv < -4) hitv = -4;
if (bigmonst(game.youmonst?.data))
hitv++;
hitv += 8 + (otmp.spe || 0);
if (dam < 1) dam = 1;
await thitu(hitv, dam, [otmp], null);
await stop_occupation();
return;
} else {
const arw = autoreturn_weapon(otmp);
if (arw && !mwelded(otmp)) {
rang = dist2(mtmp.mx, mtmp.my, mtmp.mux, mtmp.muy);
if (rang > arw.range || !couldsee(mtmp.mx, mtmp.my))
return;
always_toss = true;
}
}
const x = mtmp.mx;
const y = mtmp.my;
if (!lined_up(mtmp)
|| (URETREATING(x, y)
&& (!always_toss
&& rn2(BOLT_LIM - distmin(x, y, mtmp.mux, mtmp.muy)))))
return;
mwep = MON_WEP(mtmp);
await monshoot(mtmp, otmp, mwep);
nomul(0);
}
// C ref: mthrowu.c:1266 spitmu
export async function spitmu(mtmp, mattk) {
return await spitmm(mtmp, mattk, game.youmonst);
}
// C ref: mthrowu.c:1273 breamu
export async function breamu(mtmp, mattk) {
return await breamm(mtmp, mattk, game.youmonst);
}
// C ref: mthrowu.c:1280 blocking_terrain
export function blocking_terrain(x, y) {
if (!isok(x, y)) return true;
const lev = game.level;
const cell = lev?.locations?.[x]?.[y];
const typ = cell?.typ ?? 0;
if (IS_OBSTRUCTED(typ) || closed_door(x, y)
|| is_waterwall(x, y) || typ === 21 /* LAVAWALL */)
return true;
return false;
}
// C ref: mthrowu.c:1293 linedup_callback
export function linedup_callback(ax, ay, bx, by, fnc) {
const g = game;
g.tbx = ax - bx;
g.tby = ay - by;
if (!g.tbx && !g.tby)
return false;
if ((!g.tbx || !g.tby || Math.abs(g.tbx) === Math.abs(g.tby))
&& distmin(g.tbx, g.tby, 0, 0) < BOLT_LIM) {
const dx = sgn(ax - bx), dy = sgn(ay - by);
do {
bx += dx;
by += dy;
if (blocking_terrain(bx, by))
return false;
if (fnc(bx, by))
return true;
} while (bx !== ax || by !== ay);
}
return false;
}
// C ref: mthrowu.c:1328 linedup
export function linedup(ax, ay, bx, by, boulderhandling) {
const g = game;
g.tbx = ax - bx;
g.tby = ay - by;
if (!g.tbx && !g.tby)
return false;
if ((!g.tbx || !g.tby || Math.abs(g.tbx) === Math.abs(g.tby))
&& distmin(g.tbx, g.tby, 0, 0) < BOLT_LIM) {
if (u_at(ax, ay) ? couldsee(bx, by) : clear_path(ax, ay, bx, by))
return true;
if (boulderhandling === 0)
return false;
let dx = sgn(ax - bx), dy = sgn(ay - by);
let boulderspots = 0;
let cx = bx, cy = by;
do {
cx += dx;
cy += dy;
if (blocking_terrain(cx, cy))
return false;
if (sobj_at(BOULDER, cx, cy))
++boulderspots;
} while (cx !== ax || cy !== ay);
if (boulderhandling === 1 || rn2(2 + boulderspots) < 2)
return true;
}
return false;
}
// C ref: mthrowu.c:1374 m_lined_up
function m_lined_up(mtarg, mtmp) {
const utarget = (mtarg === game.youmonst);
const tx = utarget ? mtmp.mux : mtarg.mx;
const ty = utarget ? mtmp.muy : mtarg.my;
const ignore_boulders = utarget && (throws_rocks(mtmp.data)
|| m_carrying(mtmp, WAN_STRIKING));
if (utarget && Upolyd() && rn2(25)
&& (game.u.uundetected || (U_AP_TYPE() !== M_AP_NOTHING
&& U_AP_TYPE() !== M_AP_MONSTER)))
return false;
return linedup(tx, ty, mtmp.mx, mtmp.my,
utarget ? (ignore_boulders ? 1 : 2) : 0);
}
// C ref: mthrowu.c:1396 lined_up
export function lined_up(mtmp) {
return m_lined_up(game.youmonst, mtmp) ? true : false;
}
// C ref: mthrowu.c:1402 m_carrying
export function m_carrying(mtmp, type) {
for (let otmp = (mtmp === game.youmonst) ? game.invent : mtmp.minvent;
otmp; otmp = otmp.nobj) {
if (otmp.otyp === type) return otmp;
}
return null;
}
// C ref: mthrowu.c:1415 hit_bars
export async function hit_bars(objp, objx, objy, barsx, barsy, breakflags) {
const otmp = objp[0];
if (!otmp) return;
const obj_type = otmp.otyp;
const lev = game.level;
const nodissolve = !!((lev?.locations?.[barsx]?.[barsy]?.wall_info ?? 0) & 8); // W_NONDIGGABLE
const your_fault = !!(breakflags & BRK_BY_HERO);
const melee_attk = !!(breakflags & BRK_MELEE);
let noise = 0;
if (your_fault
? await hero_breaks(otmp, objx, objy, breakflags)
: await breaks(otmp, objx, objy)) {
objp[0] = null;
if (obj_type === POT_ACID) {
if (cansee(barsx, barsy) && !nodissolve) {
await pline_The('iron bars are dissolved!');
} else {
Soundeffect('se_angry_snakes', 100);
await You_hear(Hallucination() ? 'angry snakes!' : 'a hissing noise.');
}
if (!nodissolve)
dissolve_bars(barsx, barsy);
}
} else {
if (!Deaf()) {
const barsounds = ['', 'Whang', 'Whap', 'Flapp', 'Clink', 'Clonk'];
const bsindx = (obj_type === BOULDER || obj_type === HEAVY_IRON_BALL)
? 1
: harmless_missile(otmp) ? 2
: is_flimsy(otmp) ? 3
: (otmp.oclass === COIN_CLASS
|| (game.objects[obj_type]?.oc_material ?? 0) === GOLD
|| (game.objects[obj_type]?.oc_material ?? 0) === SILVER)
? 4
: barsounds.length - 1;
await pline('%s!', barsounds[bsindx]);
}
if (!(harmless_missile(otmp) || is_flimsy(otmp)))
noise = 4 * 4;
if (your_fault && (otmp.otyp === WAR_HAMMER || otmp.otyp === HEAVY_IRON_BALL)) {
const spe = (otmp.otyp === HEAVY_IRON_BALL)
? Math.trunc((otmp.owt || 0) / WT_IRON_BALL_INCR)
: (otmp.spe || 0);
const chance = (melee_attk ? 40 : 60) - ACURRSTR() - spe;
if (!rn2(Math.max(2, chance))) {
await You('break the bars apart!');
dissolve_bars(barsx, barsy);
noise = noise * 2;
}
}
if (noise)
wake_nearto(barsx, barsy, noise);
}
}
// C ref: mthrowu.c:1497 hits_bars
export async function hits_bars(obj_p, x, y, barsx, barsy, always_hit, whodidit) {
const otmp = obj_p[0] || (Array.isArray(obj_p) ? obj_p[0] : obj_p);
if (!otmp) return false;
const obj_type = otmp.otyp;
let hits = !!always_hit;
if (!hits) {
switch (otmp.oclass) {
case WEAPON_CLASS: {
const oskill = game.objects[obj_type]?.oc_skill || 0;
hits = (oskill !== -P_BOW && oskill !== -P_CROSSBOW
&& oskill !== -P_DART && oskill !== -P_SHURIKEN
&& oskill !== P_SPEAR
&& oskill !== P_KNIFE);
break;
}
case ARMOR_CLASS:
hits = ((game.objects[obj_type]?.oc_armcat ?? 0) !== ARM_GLOVES);
break;
case TOOL_CLASS:
hits = (obj_type !== SKELETON_KEY && obj_type !== LOCK_PICK
&& obj_type !== CREDIT_CARD && obj_type !== TALLOW_CANDLE
&& obj_type !== WAX_CANDLE && obj_type !== LENSES
&& obj_type !== TIN_WHISTLE && obj_type !== MAGIC_WHISTLE);
break;
case ROCK_CLASS:
if (obj_type !== STATUE || (mons[otmp.corpsenm]?.msize ?? 0) > MZ_TINY)
hits = true;
break;
case FOOD_CLASS:
if (obj_type === CORPSE && (mons[otmp.corpsenm]?.msize ?? 0) > MZ_TINY)
hits = true;
else
hits = (obj_type === MEAT_STICK || obj_type === ENORMOUS_MEATBALL);
break;
case SPBOOK_CLASS:
case WAND_CLASS:
case BALL_CLASS:
case CHAIN_CLASS:
hits = true;
break;
default:
break;
}
}
if (hits && whodidit !== -1) {
await hit_bars(obj_p, x, y, barsx, barsy,
(whodidit === 1) ? BRK_BY_HERO : 0);
}
return hits;
}
/*mthrowu.js*/
|