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 | 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 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 | // explode.js — Port of explode.c
// Explosions, scattering objects, burning oil explosions.
import { game } from './gstate.js';
import { rn2, rnd, c_d } from './rng.js';
import { pline, You, Your, You_feel, You_hear, pline_The, impossible } from './pline.js';
import { Acid_resistance, Antimagic, Blind, Cold_resistance, Deaf, Disint_resistance, Fire_resistance, Hallucination, Invulnerable, Maybe_Half_Phys, Poison_resistance, Role_switch, Shock_resistance, Upolyd } from './macros.js';
import { levl, m_at, t_at } from './map_access.js';
import { bigmonst, digests, hides_under, is_demon, is_vampshifter, nonliving, resists_acid, resists_cold, resists_disint, resists_elec, resists_fire, resists_magm, resists_poison, sticks, completelyburns } from './mondata.js';
import { breaks } from './dothrow.js';
import { canspotmon, cmap_to_glyph, curs_on_u, delay_output, map_invisible, newsym, seemimic, setBotl, show_glyph, tmp_at, unmap_invisible } from './display.js';
import {
mons,
PM_CLERIC, PM_MONK, PM_WIZARD, PM_HEALER, PM_KNIGHT,
AD_PHYS, AD_MAGM, AD_FIRE, AD_COLD, AD_DISN, AD_ELEC,
AD_DRST, AD_ACID, AD_RBRE, AD_SPEL, AD_DREN, AD_ENCH,
AD_DRDX, AD_DRCO, AD_DISE, AD_PEST, AD_SPC2,
AT_BOOM,
} from './monsters.js';
import { A_STR, BURNING, BURNING_OIL, DIED, DISP_BEAM, DISP_CHANGE, DISP_END, EXPL_FIERY, EXPL_FROSTY, EXPL_MAGICAL, EXPL_NOXIOUS, IS_SINK, KILLED_BY, KILLED_BY_AN, LARGEST_INT, MAY_DESTROY, MAY_FRACTURE, MAY_HIT, MAY_HITMON, MAY_HITYOU, MON_EXPLODE, NO_KILLER_PREFIX, N_DIRS, PHYS_EXPL_TYPE, PLNMSG_CAUGHT_IN_EXPLOSION, PLNMSG_TOWER_OF_FLAME, SHOPBASE, STATUE_TRAP, STONE, TRAP_EXPLODE, VIS_EFFECTS, XKILL_GIVEMSG, XKILL_NOCONDUCT, XKILL_NOCORPSE, XKILL_NOMSG, ZAP_POS, engulfing_u, isok, u_at, xdir, ydir } from './const.js';
import { BOULDER, EGG, GLASS, GOLD_PIECE, POT_OIL, RAY, SCR_FIRE, SCROLL_CLASS, STATUE, WAN_DIGGING, WAN_MAGIC_MISSILE, WAN_SLEEP, WAND_CLASS } from './objects.js';
import {
S_expl_tl, S_expl_tc, S_expl_tr,
S_expl_ml, S_expl_mc, S_expl_mr,
S_expl_bl, S_expl_bc, S_expl_br,
S_ss1, S_ss2, S_ss3, S_ss4,
} from './symbols.js';
import { GLYPH_EXPLODE_OFF } from './glyph.js';
import { MAXEXPCHARS } from './const.js';
import { cansee } from './vision.js';
import { dist2, lowc, Mgender, s_suffix } from './hacklib.js';
import { rndmonnam } from './do_name.js';
import { pmname } from './do_name.js';
import { nomul } from './cmd.js';
import { stackobj } from './invent.js';
import { DEADMONSTER, Monnam, golemeffects, hideunder, maybe_unhide_at, mondead, setmangry, stop_occupation, uhim, uhis, wake_nearto } from './mon.js';
import { destroy_items, ignite_items, obj_extract_self, place_object, sobj_at, splitobj } from './mkobj.js';
import { addtobill, costly_spot, credit_report, in_rooms, pay_for_damage, shop_keeper } from './shk.js';
import { end_burn } from './light.js';
import { burn_away_slime, done, monkilled, next2u } from './hack.js';
import { break_statue, fracture_rock, resist } from './zap.js';
import { flooreffects } from './do.js';
import { Soundeffect } from './sounds.js';
import { deltrap, burnarmor } from './trap.js';
import { ohitmon, thitu } from './mthrowu.js';
import { xkilled } from './uhitm.js';
import { dmgval } from './weapon.js';
import { closed_door } from './monmove.js';
import { exercise } from './attrib.js';
import { rehumanize, ugolemeffects } from './polyself.js';
import { Tobjnam } from './objnam.js';
// ── Non-RNG stubs for functions not yet ported ──
// exercise imported from attrib.js
// uhim, uhis: imported from mon.js
// sticks imported from mondata.js
// bigmonst — imported from mondata.js
// is_demon imported // TODO: port from mondata.c
// is_vampshifter imported from mondata.js
// digests imported from mondata.js
// canspotmon imported from display.js
// tmp_at: imported from display.js
// C ref: display.h explosion_to_glyph(expltyp, sym) — encodes (type, pos)
// into the canonical EXPLODE glyph range. map_glyphinfo's EXPLODE branch
// decodes back to S_expl_* + explode_colors[type].
function explosion_to_glyph(expltype, sym) {
return ((sym - S_expl_tl) + (expltype * MAXEXPCHARS)) + GLYPH_EXPLODE_OFF;
}
// show_glyph: imported from display.js
// C ref: display.c shield_static[] — 4-frame sparkle animation (S_ss1..S_ss4).
const _SHIELD_STATIC_SYMS = [S_ss1, S_ss2, S_ss3, S_ss4];
function shield_static(k) { return _SHIELD_STATIC_SYMS[k] ?? S_ss1; }
const SHIELD_COUNT = 4; // from display.h
// cmap_to_glyph: imported from display.js
// NOTE: differs from canonical mondata.js — local always returns false; canonical checks dmgtype/artifacts/worn items
// resists_fire imported // TODO: port from mondata.c
// resists_cold imported // TODO: port from mondata.c
// resists_elec imported // TODO: port from mondata.c
// resists_poison imported // TODO: port from mondata.c
// resists_acid imported // TODO: port from mondata.c
// resists_disint imported // TODO: port from mondata.c
function zap_over_floor(_x, _y, _type, _shdmg, _skip, _wtyp) { /* TODO */ }
// destroy_items: imported from mkobj.js
// burnarmor imported from trap.js
// ignite_items: imported from mkobj.js
// resist imported from zap.js
// monkilled imported from hack.js
// burn_away_slime imported from hack.js
// Invulnerable: imported from macros.js
function monstseesu_ad(_adtyp) { /* TODO */ }
function monstunseesu_ad(_adtyp) { /* TODO */ }
// NOTE: differs from canonical polyself.js — local is no-op; canonical has full async polymorph reversion
// done imported from hack.js
// wake_nearto imported from mon.js
// Role_switch: imported from macros.js
// scatter stubs
// shop_keeper imported from shk.js
// in_rooms imported from shk.js
// costly_spot imported from shk.js
// splitobj imported from mkobj.js
// sobj_at imported from mkobj.js
// NOTE: differs from canonical monmove.js — local always returns false; canonical checks door type/mask
// closed_door imported from monmove.js
// ohitmon — imported from dothrow.js
// NOTE: differs from canonical mthrowu.js — local is sync returning false; canonical is async
// thitu imported from mthrowu.js
// dmgval imported from uhitm.js
// stop_occupation imported from mon.js
// flooreffects imported from do.js
// addtobill imported
// stackobj imported from invent.js
// hideunder: imported from mon.js
// hides_under imported from mondata.js
// maybe_unhide_at: imported from mon.js
// Note: Arrays are column first, while the screen is row first
const explosion_syms = [
[S_expl_tl, S_expl_ml, S_expl_bl],
[S_expl_tc, S_expl_mc, S_expl_bc],
[S_expl_tr, S_expl_mr, S_expl_br],
];
// enum explode_action
const EXPL_NONE = 0;
const EXPL_MON = 1;
const EXPL_HERO = 2;
const EXPL_SKIP = 4;
// C ref: explode.c explosionmask()
function explosionmask(m, adtyp, olet) {
let res = EXPL_NONE;
const isHero = (m === game.player);
if (isHero) {
switch (adtyp) {
case AD_PHYS:
break;
case AD_MAGM:
if (Antimagic()) res = EXPL_HERO;
break;
case AD_FIRE:
if (Fire_resistance()) res = EXPL_HERO;
break;
case AD_COLD:
if (Cold_resistance()) res = EXPL_HERO;
break;
case AD_DISN:
if ((olet === WAND_CLASS)
? (nonliving(m.data) || is_demon(m.data))
: Disint_resistance())
res = EXPL_HERO;
break;
case AD_ELEC:
if (Shock_resistance()) res = EXPL_HERO;
break;
case AD_DRST:
if (Poison_resistance()) res = EXPL_HERO;
break;
case AD_ACID:
if (Acid_resistance()) res = EXPL_HERO;
break;
default:
impossible(`explosion type ${adtyp}?`);
break;
}
} else {
switch (adtyp) {
case AD_PHYS:
break;
case AD_MAGM:
if (resists_magm(m)) res = EXPL_MON;
break;
case AD_FIRE:
if (resists_fire(m)) res = EXPL_MON;
break;
case AD_COLD:
if (resists_cold(m)) res = EXPL_MON;
break;
case AD_DISN:
if ((olet === WAND_CLASS)
? (nonliving(m.data) || is_demon(m.data) || is_vampshifter(m))
: !!resists_disint(m))
res = EXPL_MON;
break;
case AD_ELEC:
if (resists_elec(m)) res = EXPL_MON;
break;
case AD_DRST:
if (resists_poison(m)) res = EXPL_MON;
break;
case AD_ACID:
if (resists_acid(m)) res = EXPL_MON;
break;
default:
impossible(`explosion type ${adtyp}?`);
break;
}
}
return res;
}
// C ref: explode.c engulfer_explosion_msg()
async function engulfer_explosion_msg(adtyp, olet) {
let adj = null;
if (digests(game.u.ustuck?.data)) {
switch (adtyp) {
case AD_FIRE: adj = 'heartburn'; break;
case AD_COLD: adj = 'chilly'; break;
case AD_DISN:
adj = (olet === WAND_CLASS) ? 'irradiated by pure energy' : 'perforated';
break;
case AD_ELEC: adj = 'shocked'; break;
case AD_DRST: adj = 'poisoned'; break;
case AD_ACID: adj = 'an upset stomach'; break;
default: adj = 'fried'; break;
}
await pline(`${Monnam(game.u.ustuck)} gets ${adj}!`);
} else {
switch (adtyp) {
case AD_FIRE: adj = 'toasted'; break;
case AD_COLD: adj = 'chilly'; break;
case AD_DISN:
adj = (olet === WAND_CLASS) ? 'overwhelmed by pure energy' : 'perforated';
break;
case AD_ELEC: adj = 'shocked'; break;
case AD_DRST: adj = 'intoxicated'; break;
case AD_ACID: adj = 'burned'; break;
default: adj = 'fried'; break;
}
await pline(`${Monnam(game.u.ustuck)} gets slightly ${adj}!`);
}
}
// C ref: explode.c explode()
export async function explode(x, y, type, dam, olet, expltype) {
const u = game.u;
let i, j, k, damu = dam;
let starting = true;
let visible, any_shield;
let uhurt = 0; // 0=unhurt, 1=items damaged, 2=you and items damaged
let str = null;
let mtmp, mdef = null;
let adtyp;
const explmask = [[0,0,0],[0,0,0],[0,0,0]];
let xx, yy;
let shopdamage = false, generic = false,
do_hallu = false, inside_engulfer, grabbed, grabbing;
const grabxy = { x: 0, y: 0 };
let hallu_buf = '';
let killr_buf = '';
let exploding_wand_typ = 0;
const you_exploding = (olet === MON_EXPLODE && type >= 0);
let didmsg = false;
if (olet === WAND_CLASS) { // retributive strike
if (type < 0) {
type = -type;
exploding_wand_typ = type;
if (game.objects[type].oc_dir === RAY
&& type !== WAN_DIGGING && type !== WAN_SLEEP) {
type -= WAN_MAGIC_MISSILE;
if (type < 0 || type > 9) {
impossible(`explode: wand has bad zap type (${type}).`);
type = 0;
}
} else {
type = 0;
}
}
// C: Role_switch is a macro expanding to flags.initrole
switch (Role_switch()) {
case PM_CLERIC:
case PM_MONK:
case PM_WIZARD:
damu = Math.trunc(damu / 5);
break;
case PM_HEALER:
case PM_KNIGHT:
damu = Math.trunc(damu / 2);
break;
default:
break;
}
} else if (olet === BURNING_OIL) {
exploding_wand_typ = POT_OIL;
} else if (olet === SCROLL_CLASS) {
exploding_wand_typ = SCR_FIRE;
} else if (olet === TRAP_EXPLODE) {
type = 0;
}
if (expltype < 0) {
mdef = m_at(x, y);
expltype = -expltype;
}
inside_engulfer = (u.uswallow && type >= 0);
grabbed = false;
grabbing = false;
if (u.ustuck && !u.uswallow) {
if (Upolyd() && sticks(game.player.data))
grabbing = true;
else
grabbed = true;
grabxy.x = u.ustuck.mx;
grabxy.y = u.ustuck.my;
} else {
grabxy.x = 0;
grabxy.y = 0;
}
if (olet === MON_EXPLODE && !you_exploding) {
killr_buf = game.killer?.name || '';
str = killr_buf;
do_hallu = (Hallucination()
&& (str.includes("'s explosion")
|| str.includes("s' explosion")));
}
if (type === PHYS_EXPL_TYPE) {
adtyp = AD_PHYS;
} else {
let adstr = null;
switch (Math.abs(type) % 10) {
case 0:
adstr = 'magical blast';
adtyp = AD_MAGM;
break;
case 1:
adstr = (olet === BURNING_OIL) ? 'burning oil'
: (olet === SCROLL_CLASS) ? 'tower of flame' : 'fireball';
adtyp = AD_FIRE;
break;
case 2:
adstr = 'ball of cold';
adtyp = AD_COLD;
break;
case 4:
adstr = (olet === WAND_CLASS) ? 'death field' : 'disintegration field';
adtyp = AD_DISN;
break;
case 5:
adstr = 'ball of lightning';
adtyp = AD_ELEC;
break;
case 6:
adstr = 'poison gas cloud';
adtyp = AD_DRST;
break;
case 7:
adstr = 'splash of acid';
adtyp = AD_ACID;
break;
default:
impossible(`explosion base type ${type}?`);
return;
}
if (!str)
str = adstr;
}
any_shield = false;
visible = false;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
xx = x + i - 1;
yy = y + j - 1;
if (!isok(xx, yy)) {
explmask[i][j] = EXPL_SKIP;
continue;
}
explmask[i][j] = EXPL_NONE;
if (u_at(xx, yy)) {
explmask[i][j] = explosionmask(game.player, adtyp, olet);
}
mtmp = m_at(xx, yy);
if (!mtmp && u_at(xx, yy))
mtmp = u.usteed || null;
if (mtmp && DEADMONSTER(mtmp))
mtmp = null;
if (mtmp) {
explmask[i][j] |= explosionmask(mtmp, adtyp, olet);
}
if (mtmp && cansee(xx, yy) && !canspotmon(mtmp))
map_invisible(xx, yy);
else if (!mtmp)
unmap_invisible(xx, yy);
if (cansee(xx, yy))
visible = true;
if ((explmask[i][j] & (EXPL_MON | EXPL_HERO)) !== 0)
any_shield = true;
}
}
if (visible) {
// Start the explosion
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
if (explmask[i][j] === EXPL_SKIP)
continue;
xx = x + i - 1;
yy = y + j - 1;
await tmp_at(starting ? DISP_BEAM : DISP_CHANGE,
explosion_to_glyph(expltype, explosion_syms[i][j]));
await tmp_at(xx, yy);
starting = false;
}
}
await curs_on_u();
if (any_shield && game.flags?.sparkle !== false) {
for (k = 0; k < SHIELD_COUNT; k++) {
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
xx = x + i - 1;
yy = y + j - 1;
if ((explmask[i][j] & (EXPL_MON | EXPL_HERO)) !== 0)
show_glyph(xx, yy, cmap_to_glyph(shield_static(k)));
}
}
await curs_on_u();
await delay_output();
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
xx = x + i - 1;
yy = y + j - 1;
if ((explmask[i][j] & (EXPL_MON | EXPL_HERO)) !== 0)
show_glyph(xx, yy,
explosion_to_glyph(expltype, explosion_syms[i][j]));
}
}
} else {
await delay_output();
await delay_output();
}
await tmp_at(DISP_END, 0);
} else {
if (olet === MON_EXPLODE || olet === TRAP_EXPLODE) {
str = 'explosion';
generic = true;
}
if (!Deaf() && olet !== SCROLL_CLASS) {
Soundeffect('se_blast', 75);
await You_hear('a blast.');
didmsg = true;
}
}
if (!Deaf() && !didmsg)
await pline('Boom!');
// Apply effects to monsters and floor objects first
if (dam) {
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
let itemdmg = 0;
if (explmask[i][j] === EXPL_SKIP)
continue;
xx = x + i - 1;
yy = y + j - 1;
if (u_at(xx, yy)) {
uhurt = ((explmask[i][j] & EXPL_HERO) !== 0) ? 1 : 2;
if (!game.context?.mon_moving && you_exploding)
uhurt = 0;
} else if (inside_engulfer) {
continue;
}
if (!(u.uswallow && !game.context?.mon_moving))
await zap_over_floor(xx, yy, type, { shopdamage }, false, exploding_wand_typ);
mtmp = m_at(xx, yy);
if (!mtmp && u_at(xx, yy))
mtmp = u.usteed || null;
if (!mtmp)
continue;
if (do_hallu) {
let tryct = 0;
do {
hallu_buf = `${s_suffix(rndmonnam(null))} explosion`;
} while (hallu_buf[0] !== lowc(hallu_buf[0]) && ++tryct < 20);
str = hallu_buf;
}
if (engulfing_u(mtmp)) {
await engulfer_explosion_msg(adtyp, olet);
} else if (cansee(xx, yy)) {
if (mtmp.m_ap_type)
seemimic(mtmp);
await pline(`${Monnam(mtmp)} is caught in the ${str}!`);
}
itemdmg = await destroy_items(mtmp, adtyp, dam);
if (adtyp === AD_FIRE) {
await burnarmor(mtmp);
ignite_items(mtmp.minvent);
}
if ((explmask[i][j] & EXPL_MON) !== 0) {
await golemeffects(mtmp, adtyp, dam);
mtmp.mhp -= itemdmg;
} else {
let mdam = dam;
if (resist(mtmp, olet, 0, false)) {
if (cansee(xx, yy) || inside_engulfer)
await pline(`${Monnam(mtmp)} resists the ${str}!`);
mdam = Math.trunc((dam + 1) / 2);
}
if (grabbed && mtmp === u.ustuck && next2u(x, y))
mdam *= 2;
if (resists_cold(mtmp) && adtyp === AD_FIRE)
mdam *= 2;
else if (resists_fire(mtmp) && adtyp === AD_COLD)
mdam *= 2;
mtmp.mhp -= mdam + itemdmg;
}
if (DEADMONSTER(mtmp)) {
const xkflg = ((adtyp === AD_FIRE
&& completelyburns(mtmp.data))
? XKILL_NOCORPSE : 0);
if (!game.context?.mon_moving) {
await xkilled(mtmp, XKILL_GIVEMSG | xkflg);
} else if (mdef && mtmp === mdef) {
if (cansee(mtmp.mx, mtmp.my) || canspotmon(mtmp))
await pline(`${Monnam(mtmp)} is ${
xkflg ? 'burned completely'
: nonliving(mtmp.data) ? 'destroyed' : 'killed'
}!`);
await xkilled(mtmp, XKILL_NOMSG | XKILL_NOCONDUCT | xkflg);
} else {
if (xkflg)
adtyp = AD_RBRE;
await monkilled(mtmp, '', adtyp);
}
} else if (!game.context?.mon_moving) {
await setmangry(mtmp, true);
}
}
}
}
// Do your injury last
if (uhurt) {
if (game.flags?.verbose && (type < 0 || olet !== SCROLL_CLASS)) {
if (do_hallu) {
do {
hallu_buf = `${s_suffix(rndmonnam(null))} explosion`;
} while (hallu_buf[0] !== lowc(hallu_buf[0]));
str = hallu_buf;
}
await You(`are caught in the ${str}!`);
game.iflags = game.iflags || {};
game.iflags.last_msg = PLNMSG_CAUGHT_IN_EXPLOSION;
}
if (adtyp === AD_FIRE)
await burn_away_slime();
if (Invulnerable()) {
damu = 0;
await You('are unharmed!');
} else if (adtyp === AD_PHYS || adtyp === AD_ACID) {
damu = Maybe_Half_Phys(damu);
}
if (adtyp === AD_FIRE) {
await burnarmor(game.player);
ignite_items(game.invent);
}
await destroy_items(game.player, adtyp, dam);
await ugolemeffects(adtyp, damu);
if (uhurt === 2) {
if (grabbing && dist2(grabxy.x, grabxy.y, x, y) <= 2)
damu *= 2;
if (Upolyd())
u.mh -= damu;
else
u.uhp -= damu;
game.disp = game.disp || {};
setBotl('explode');
}
if (uhurt === 1)
monstseesu_ad(adtyp);
else
monstunseesu_ad(adtyp);
if (u.uhp <= 0 || (Upolyd() && u.mh <= 0)) {
if (Upolyd()) {
await rehumanize();
} else {
game.killer = game.killer || { name: '', format: 0 };
if (olet === MON_EXPLODE) {
if (generic) {
// explosion was unseen; str=="explosion",
// killer.name=="gas spore's explosion".
} else if (str !== game.killer.name && str !== hallu_buf) {
game.killer.name = str;
}
game.killer.format = KILLED_BY_AN;
} else if (olet === TRAP_EXPLODE) {
game.killer.format = NO_KILLER_PREFIX;
game.killer.name = `caught ${uhim()}self in a ${str}`;
} else if (type >= 0 && olet !== SCROLL_CLASS) {
game.killer.format = NO_KILLER_PREFIX;
game.killer.name = `caught ${uhim()}self in ${uhis()} own ${str}`;
} else {
game.killer.format = (str.toLowerCase() === 'tower of flame'
|| str.toLowerCase() === 'fireball')
? KILLED_BY_AN : KILLED_BY;
game.killer.name = str;
}
if ((game.iflags?.last_msg === PLNMSG_CAUGHT_IN_EXPLOSION)
|| (game.iflags?.last_msg === PLNMSG_TOWER_OF_FLAME))
await pline('It is fatal.');
else
await pline_The(`${str} is fatal.`);
await done((adtyp === AD_FIRE) ? BURNING : DIED);
}
}
exercise(A_STR, false);
}
if (shopdamage) {
await pay_for_damage(
(adtyp === AD_FIRE) ? 'burn away'
: (adtyp === AD_COLD) ? 'shatter'
: (adtyp === AD_DISN) ? 'disintegrate'
: 'destroy',
false);
}
// explosions are noisy
i = dam * dam;
if (i < 50) i = 50;
if (inside_engulfer)
i = Math.trunc((i + 3) / 4);
wake_nearto(x, y, i);
}
// C ref: explode.c scatter()
// returns number of scattered objects
export async function scatter(sx, sy, blastforce, scflags, obj) {
let otmp;
let tmp;
let farthest = 0;
let typ;
let qtmp;
let used_up;
const individual_object = obj ? true : false;
let shop_origin, lostgoods = false;
let mtmp, shkp = null;
let schain = null;
let stmp2 = null;
let total = 0;
if (individual_object && (obj.ox !== sx || obj.oy !== sy))
impossible(`scattered object <${obj.ox},${obj.oy}> not at scatter site <${sx},${sy}>`);
shkp = shop_keeper(in_rooms(sx, sy, SHOPBASE));
shop_origin = (shkp !== null && costly_spot(sx, sy));
if (shop_origin)
await credit_report(shkp, 0, true);
while ((otmp = (individual_object ? obj
: game.level?.objects?.[sx]?.[sy] || null)) !== null) {
if (otmp === game.u.uball || otmp === game.u.uchain) {
const waschain = (otmp === game.u.uchain);
Soundeffect('se_chain_shatters', 25);
await pline_The('chain shatters!');
// unpunish(); // TODO
if (waschain)
continue;
}
if (otmp.quan > 1) {
qtmp = otmp.quan - 1;
if (qtmp > LARGEST_INT)
qtmp = LARGEST_INT;
qtmp = rnd(qtmp);
otmp = splitobj(otmp, qtmp);
} else {
obj = null; // all used
}
obj_extract_self(otmp);
used_up = false;
// 9 in 10 chance of fracturing boulders or statues
if ((scflags & MAY_FRACTURE) !== 0
&& (otmp.otyp === BOULDER || otmp.otyp === STATUE)
&& rn2(10)) {
if (otmp.otyp === BOULDER) {
if (cansee(sx, sy)) {
await pline(`${Tobjnam(otmp, 'break')} apart.`);
} else {
Soundeffect('se_stone_breaking', 100);
await You_hear('stone breaking.');
}
fracture_rock(otmp);
place_object(otmp, sx, sy);
const bobj = sobj_at(BOULDER, sx, sy);
if (bobj) {
obj_extract_self(bobj);
place_object(bobj, sx, sy);
}
} else {
const trap = t_at(sx, sy);
if (trap && trap.ttyp === STATUE_TRAP)
deltrap(trap);
if (cansee(sx, sy)) {
await pline(`${Tobjnam(otmp, 'crumble')}.`);
} else {
Soundeffect('se_stone_crumbling', 100);
await You_hear('stone crumbling.');
}
break_statue(otmp);
place_object(otmp, sx, sy);
}
newsym(sx, sy);
used_up = true;
} else if ((scflags & MAY_DESTROY) !== 0
&& (!rn2(10) || (game.objects[otmp.otyp]?.oc_material === GLASS
|| otmp.otyp === EGG))) {
if (await breaks(otmp, sx, sy))
used_up = true;
}
if (!used_up) {
const stmp = {
next: null,
obj: otmp,
ox: sx,
oy: sy,
dx: 0,
dy: 0,
range: 0,
stopped: false,
};
tmp = rn2(N_DIRS);
stmp.dx = xdir[tmp];
stmp.dy = ydir[tmp];
tmp = blastforce - Math.trunc(otmp.owt / 40);
if (tmp < 1) tmp = 1;
stmp.range = rnd(tmp);
if (farthest < stmp.range)
farthest = stmp.range;
stmp.stopped = false;
if (!schain)
schain = stmp;
else
stmp2.next = stmp;
stmp2 = stmp;
}
}
while (farthest-- > 0) {
for (let stmp = schain; stmp; stmp = stmp.next) {
if ((stmp.range-- > 0) && (!stmp.stopped)) {
game.thrownobj = stmp.obj;
game.bhitpos = game.bhitpos || { x: 0, y: 0 };
game.bhitpos.x = stmp.ox + stmp.dx;
game.bhitpos.y = stmp.oy + stmp.dy;
if (isok(game.bhitpos.x, game.bhitpos.y))
typ = levl(game.bhitpos.x, game.bhitpos.y).typ;
else
typ = STONE;
if (!isok(game.bhitpos.x, game.bhitpos.y)) {
game.bhitpos.x -= stmp.dx;
game.bhitpos.y -= stmp.dy;
stmp.stopped = true;
} else if (!ZAP_POS(typ)
|| closed_door(game.bhitpos.x, game.bhitpos.y)) {
game.bhitpos.x -= stmp.dx;
game.bhitpos.y -= stmp.dy;
stmp.stopped = true;
} else if ((mtmp = m_at(game.bhitpos.x, game.bhitpos.y)) !== null) {
if (scflags & MAY_HITMON) {
stmp.range--;
if (await ohitmon(mtmp, stmp.obj, 1, false)) {
stmp.obj = null;
stmp.stopped = true;
}
}
} else if (u_at(game.bhitpos.x, game.bhitpos.y)) {
if (scflags & MAY_HITYOU) {
let hitvalu, hitu;
if (game.multi)
nomul(0);
hitvalu = 8 + stmp.obj.spe;
if (bigmonst(game.player.data))
hitvalu++;
hitu = await thitu(hitvalu, dmgval(stmp.obj, game.player),
{ obj: stmp.obj }, null);
if (!stmp.obj)
stmp.stopped = true;
if (hitu) {
stmp.range -= 3;
await stop_occupation();
}
}
} else {
if (scflags & VIS_EFFECTS) {
// visual effects (TODO)
}
}
stmp.ox = game.bhitpos.x;
stmp.oy = game.bhitpos.y;
if (IS_SINK(levl(stmp.ox, stmp.oy).typ))
stmp.stopped = true;
game.thrownobj = null;
}
}
}
for (let stmp = schain; stmp; stmp = stmp.next) {
let obj_left_shop = false;
const fx = stmp.ox;
const fy = stmp.oy;
if (stmp.obj) {
if (fx !== sx || fy !== sy) {
total += stmp.obj.quan;
obj_left_shop = (shop_origin && !costly_spot(fx, fy));
}
if (!await flooreffects(stmp.obj, fx, fy, 'land')) {
if (obj_left_shop
&& (u.urooms || '').includes(in_rooms(u.ux, u.uy, SHOPBASE))) {
if (stmp.obj.otyp === GOLD_PIECE) {
await addtobill(stmp.obj, false, false, true);
lostgoods = true;
}
}
place_object(stmp.obj, fx, fy);
stackobj(stmp.obj);
}
}
newsym(fx, fy);
}
newsym(sx, sy);
if (u_at(sx, sy) && u.uundetected && hides_under(game.player.data))
hideunder(game.player);
mtmp = m_at(sx, sy);
if (mtmp && mtmp.mtrapped)
mtmp.mtrapped = 0;
maybe_unhide_at(sx, sy);
if (lostgoods)
await credit_report(shkp, 1, false);
return total;
}
// C ref: explode.c splatter_burning_oil()
export async function splatter_burning_oil(x, y, diluted_oil) {
const dmg = c_d(diluted_oil ? 3 : 4, 4);
const ZT_SPELL_O_FIRE = 11;
await explode(x, y, ZT_SPELL_O_FIRE, dmg, BURNING_OIL, EXPL_FIERY);
}
// C ref: explode.c explode_oil()
export async function explode_oil(obj, x, y) {
const diluted_oil = obj.odiluted;
if (!obj.lamplit)
impossible('exploding unlit oil');
end_burn(obj, true);
obj.how_lost = 4; // LOST_EXPLODING
await splatter_burning_oil(x, y, diluted_oil);
}
// C ref: explode.c adtyp_to_expltype()
export function adtyp_to_expltype(adtyp) {
switch (adtyp) {
case AD_ELEC:
case AD_SPEL:
case AD_DREN:
case AD_ENCH:
return EXPL_MAGICAL;
case AD_FIRE:
return EXPL_FIERY;
case AD_COLD:
return EXPL_FROSTY;
case AD_DRST:
case AD_DRDX:
case AD_DRCO:
case AD_DISE:
case AD_PEST:
case AD_PHYS:
return EXPL_NOXIOUS;
default:
impossible(`adtyp_to_expltype: bad explosion type ${adtyp}`);
return EXPL_FIERY;
}
}
// C ref: explode.c mon_explodes()
export async function mon_explodes(mon, mattk) {
let dmg;
let type;
if (mattk.damn) {
dmg = c_d(mattk.damn, mattk.damd);
} else if (mattk.damd) {
dmg = c_d(mon.data.mlevel + 1, mattk.damd);
} else {
dmg = 0;
}
if (mattk.adtyp === AD_PHYS) {
type = PHYS_EXPL_TYPE;
} else if (mattk.adtyp >= AD_MAGM && mattk.adtyp <= AD_SPC2) {
type = -((mattk.adtyp - 1) + 20);
} else {
impossible(`unknown type for mon_explode ${mattk.adtyp}`);
return;
}
if (!DEADMONSTER(mon)) {
mondead(mon);
}
game.killer = game.killer || { name: '', format: 0 };
game.killer.name = `${s_suffix(pmname(mon.data, Mgender(mon)))} explosion`;
game.killer.format = KILLED_BY_AN;
await explode(mon.mx, mon.my, type, dmg, MON_EXPLODE,
adtyp_to_expltype(mattk.adtyp));
game.killer.name = '';
} |