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 | 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 1x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 1x 73x 73x 43x 43x 43x 43x 43x 42x 42x 1x 1x 43x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 43x 1x 1x 43x 43x 1x 1x 43x 73x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 6x 6x 3x 3x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 6x 73x 73x 73x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 2x 2x 2x 2x 2x 1x 1x 2x 2x 2x 4x 5x 73x 73x 73x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 2x 2x 2x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 3x 2x 2x 3x 73x 73x 73x 73x 73x 73x 73x 73x 73x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 2x 2x 73x 73x 73x 73x 73x 73x 73x 73x | // fountain.js — Port of fountain.c
// Code for drinking from fountains, dipping, sinks.
import { game } from './gstate.js';
import { rn2, rnd, rn1 } from './rng.js';
import { pline, You, Your, You_feel, You_see, You_hear, pline_The, verbalize } from './pline.js';
import {
Blind,
Deaf,
Fire_resistance,
Glib,
Hallucination,
Invis,
Invisible,
Levitation,
Poison_resistance,
Role_if
} from './macros.js';
import { levl, m_at, t_at } from './map_access.js';
import { ABASE, AMAX, ACURR, adjattrib, exercise } from './attrib.js';
import { livelog_printf, losehp, money_cnt } from './hack.js';
import { canspotmon, glyph_at, newsym, setBotl, tty_display_nhwindow } from './display.js';
import { level_difficulty, makemon } from './makemon.js';
import { mons, PM_WATER_MOCCASIN, PM_WATER_DEMON, PM_WATER_NYMPH, PM_KNIGHT, PM_SEWER_RAT, PM_WATER_ELEMENTAL } from './monsters.js';
import { A_CHA, A_CON, A_DEX, A_INT, A_MAX, A_STR, A_WIS, ENL_GAMEINPROGRESS, ER_DESTROYED, ER_GREASED, ER_NOTHING, FOUNTAIN, FROMOUTSIDE, GLIB, G_GONE, IS_FOUNTAIN, KILLED_BY, KILLED_BY_AN, MAGICENLIGHTENMENT, MM_NOMSG, NO_TRAP_FLAGS, POOL, ROOM, SEE_INVIS, S_LRING, TT_INFLOOR, TT_LAVA, nothing_seems_to_happen, u_at, ARM, HAND, HEAD, FACE,
} from './const.js';
import { LONG_SWORD, COIN_CLASS, DILITHIUM_CRYSTAL, LUCKSTONE, BOULDER, POTION_CLASS, RING_CLASS, POT_WATER, OBJ_DESCR } from './objects.js';
import { ART_EXCALIBUR } from './artifacts.js';
import { bless, curse, mkgold, mkobj, mkobj_at, mksobj_at, rnd_class, sobj_at, uncurse } from './mkobj.js';
import { do_clear_area, cansee, couldsee } from './vision.js';
import { enlightenment } from './insight.js';
import { distmin, get_iter_mons, set_levltyp, surface } from './hacklib.js';
import { makeplural, the, xname } from './objnam.js';
import { hcolor, hliquid, oname, oname_deferred_untwoweapon, rndmonnam } from './do_name.js';
import { S_cloud } from './symbols.js';
import { ynFunction } from './input.js';
import { delfloortrap, mintrap, water_damage, water_damage_chain } from './trap.js';
import { del_engr_at } from './engrave.js';
import { breathless, haseyes, is_watch, nolimbs } from './mondata.js';
import { delobj, useup } from './invent.js';
import { Amonnam, DEADMONSTER, a_monnam, mhe, mhis, minliquid, monflee, uhim, update_inventory } from './mon.js';
import { monster_detect } from './detect.js';
import { observe_object } from './invent.js';
import { make_glib } from './mhitu.js';
import { create_gas_cloud } from './region.js';
import { Soundeffect } from './sounds.js';
import { fingers_or_gloves } from './do_wear.js';
import { polymorph_sink, trycall } from './do.js';
import { morehungry, newuhs, vomit } from './eat.js';
import { more_experienced, newexplevel } from './exper.js';
import { nexttodoor } from './mkroom.js';
import { body_part, mbodypart } from './polyself.js';
import { dopotion, mongrantswish, potionbreathe } from './potion.js';
import { obfree } from './shk.js';
import { somegold } from './steal.js';
import { artiname, exist_artifact } from './artifact.js';
import { angry_guards, in_town } from './mklev.js';
import { dunlev, dunlevs_in_dungeon } from './dungeon.js';
// ── Non-RNG stubs for functions not yet ported ──
// uhim: imported from mon.js
// NOTE: differs from canonical mondata.js — always returns false; canonical checks M1_NOLIMBS flag
// NOTE: differs from canonical polyself.js — ignores monster type; canonical has full type-specific tables
// NOTE: differs from canonical polyself.js — simplified lookup table; canonical calls mbodypart(game.player, part)
// NOTE: differs from canonical do_wear.js — simplified; canonical checks uarmg and uses gloves_simple_name
// is_watch: imported from mondata.js
// mintrap imported from trap.js
// NOTE: differs from canonical potion.js — empty stub; canonical calls mongone+makewish
// delfloortrap imported from trap.js
// NOTE: differs from canonical mkroom.js — always returns false; canonical checks 3x3 area for doors
// sobj_at imported from mkobj.js
// del_engr_at imported from engrave.js below
// set_levltyp imported from hacklib.js
// update_inventory imported from mon.js
// newuhs + vomit imported from eat.js
function poison_strdmg(bonusdmg, strdmg, reason, how) { /* TODO */ }
// monster_detect imported from detect.js
// monflee imported from mon.js
// enlightenment: imported from insight.js
// in_town: imported from mklev.js
// angry_guards: imported from mklev.js
// NOTE: differs from canonical steal.js — simplified money/2; canonical uses rn1-based tier system
// NOTE: differs from canonical hack.js — uses quan||0; canonical uses quan||1
// delobj imported from invent.js
function discover_artifact(artid) { /* TODO */ }
// NOTE: differs from canonical mkobj.js — missing COIN_CLASS guard, uses 1/0 not true/false
// NOTE: differs from canonical mkobj.js — missing COIN_CLASS guard, uses 1/0 not true/false
// make_glib imported from mhitu.js
// NOTE: differs from canonical macros.js — checks intrinsic+extrinsic; canonical only checks H(GLIB)
// exercise imported from attrib.js (was local reimplementation)
// losehp imported from hack.js
// get_iter_mons: imported from hacklib.js
function glyph_is_cmap(glyph) { return false; } // TODO
function glyph_to_cmap(glyph) { return 0; } // TODO
// dunlev, dunlevs_in_dungeon: imported from dungeon.js
// livelog_printf imported from hack.js
// NOTE: differs from canonical exper.js — empty stub; canonical has full XP tracking
// NOTE: differs from canonical exper.js — empty stub; canonical calls pluslvl if enough XP
// NOTE: differs from canonical polyself.js — empty stub; canonical has full polymorph logic
// create_gas_cloud imported from region.js
// NOTE: differs from canonical potion.js — returns 0; canonical has full potion effects
// obfree imported from mkobj.js
// NOTE: differs from canonical detect.js — empty stub; canonical sets obj.dknown=true
// NOTE: differs from canonical do.js — empty stub; canonical calls docall(obj)
// useup imported from invent.js
// NOTE: differs from canonical potion.js — empty stub; canonical has full vapor effects
// breathless imported from mondata.js
// NOTE: differs from canonical mondata.js — always returns true; canonical checks M1_NOEYES flag
// NOTE: differs from canonical do.js — empty stub; canonical has full sink polymorph logic
function sink_backs_up_fn(x, y) { /* TODO - forward decl */ }
// NOTE: differs from canonical mkobj.js — returns null; canonical has full object creation
// canspotmon imported from display.js
// NOTE: differs from canonical objnam.js — returns 'object'; canonical has full name formatting
const something = 'something';
const ONAME_VIA_DIP = 0x01;
const ONAME_KNOW_ARTI = 0x02;
const LL_ARTIFACT = 0x0008;
const A_LAWFUL = 1;
const POLY_NOFLAGS = 0;
// POT_WATER, POTION_CLASS, RING_CLASS imported from objects.js
const hands_obj = { otyp: -1 }; // sentinel
// ── Fountain flag macros ──
// C ref: rm.h — looted field bit flags for fountains
function FOUNTAIN_IS_LOOTED(x, y) {
const loc = levl(x, y);
return loc ? !!(loc.looted & 0x01) : false; // F_LOOTED = 1
}
function FOUNTAIN_IS_WARNED(x, y) {
const loc = levl(x, y);
return loc ? !!(loc.looted & 0x02) : false; // F_WARNED = 2
}
function SET_FOUNTAIN_LOOTED(x, y) {
const loc = levl(x, y);
if (loc) loc.looted = (loc.looted || 0) | 0x01;
}
function SET_FOUNTAIN_WARNED(x, y) {
const loc = levl(x, y);
if (loc) loc.looted = (loc.looted || 0) | 0x02;
}
function CLEAR_FOUNTAIN_LOOTED(x, y) {
const loc = levl(x, y);
if (loc) loc.looted = (loc.looted || 0) & ~0x01;
}
// ── Helper: u_at ──
// ────────────────────────────────────────────────────────
// Ported functions from fountain.c
// ────────────────────────────────────────────────────────
// C ref: fountain.c:20 floating_above()
export async function floating_above(what) {
let umsg = 'are floating high above the %s.';
const u = game.u;
if (u.utrap && (u.utraptype === TT_INFLOOR || u.utraptype === TT_LAVA)) {
umsg = 'are trapped in the %s.';
what = surface(u.ux, u.uy);
}
await You(umsg.replace('%s', what));
}
// C ref: fountain.c:37 dowatersnakes()
async function dowatersnakes() {
const u = game.u;
const num_val = rn1(5, 2);
let num = num_val;
if (!(game.mvitals?.[PM_WATER_MOCCASIN]?.mvflags & G_GONE)) {
if (!Blind()) {
const monname = Hallucination() ? makeplural(rndmonnam(null)) : 'snakes';
await pline(`An endless stream of ${monname} pours forth!`);
} else {
Soundeffect('se_snakes_hissing', 75);
await You_hear(`${something} hissing!`);
}
while (num-- > 0) {
const mtmp = await makemon(mons[PM_WATER_MOCCASIN], u.ux, u.uy, MM_NOMSG);
if (mtmp !== null && t_at(mtmp.mx, mtmp.my)) {
await mintrap(mtmp, NO_TRAP_FLAGS);
}
}
} else {
Soundeffect('se_furious_bubbling', 20);
await pline_The('fountain bubbles furiously for a moment, then calms.');
}
}
// C ref: fountain.c:63 dowaterdemon()
async function dowaterdemon() {
const u = game.u;
if (!(game.mvitals?.[PM_WATER_DEMON]?.mvflags & G_GONE)) {
const mtmp = await makemon(mons[PM_WATER_DEMON], u.ux, u.uy, MM_NOMSG);
if (mtmp !== null) {
if (!Blind()) {
await You(`unleash ${a_monnam(mtmp)}!`);
} else {
await You_feel('the presence of evil.');
}
// Give those on low levels a (slightly) better chance of survival
if (rnd(100) > (80 + level_difficulty())) {
await pline(`Grateful for ${mhis(mtmp)} release, ${mhe(mtmp)} grants you a wish!`);
// give a wish and discard the monster (mtmp set to null)
await mongrantswish({ mtmp });
} else if (t_at(mtmp.mx, mtmp.my)) {
await mintrap(mtmp, NO_TRAP_FLAGS);
}
}
} else {
Soundeffect('se_furious_bubbling', 20);
await pline_The('fountain bubbles furiously for a moment, then calms.');
}
}
// C ref: fountain.c:93 dowaternymph()
async function dowaternymph() {
const u = game.u;
let mtmp = null;
if (!(game.mvitals?.[PM_WATER_NYMPH]?.mvflags & G_GONE)
&& (mtmp = await makemon(mons[PM_WATER_NYMPH], u.ux, u.uy, MM_NOMSG)) !== null) {
if (!Blind()) {
await You(`attract ${a_monnam(mtmp)}!`);
} else {
await You_hear('a seductive voice.');
}
mtmp.msleeping = 0;
if (t_at(mtmp.mx, mtmp.my)) {
await mintrap(mtmp, NO_TRAP_FLAGS);
}
} else if (!Blind()) {
Soundeffect('se_bubble_rising', 50);
Soundeffect('se_loud_pop', 50);
await pline('A large bubble rises to the surface and pops.');
} else {
Soundeffect('se_loud_pop', 50);
await You_hear('a loud pop.');
}
}
// C ref: fountain.c:119 dogushforth()
export async function dogushforth(drinking) {
const u = game.u;
let madepool = { value: 0 };
await do_clear_area(u.ux, u.uy, 7, gush, madepool);
if (!madepool.value) {
if (drinking) {
await Your('thirst is quenched.');
} else {
await pline('Water sprays all over you.');
}
}
}
// C ref: fountain.c:133 gush()
async function gush(x, y, poolcnt) {
if (((x + y) % 2) || u_at(x, y)
|| (rn2(1 + distmin(game.u.ux, game.u.uy, x, y)))
|| (levl(x, y)?.typ !== ROOM)
|| (sobj_at(BOULDER, x, y)) || nexttodoor(x, y)) {
return;
}
const ttmp = t_at(x, y);
if (ttmp !== null && !delfloortrap(ttmp)) {
return;
}
if (!(poolcnt.value++)) {
// Note: pline is async but gush is sync callback from do_clear_area.
// C calls pline synchronously here. We match C's structure.
// In practice this message is queued.
await pline('Water gushes forth from the overflowing fountain!');
}
// Put a pool at x, y
set_levltyp(x, y, POOL);
const loc = levl(x, y);
if (loc) loc.flags = 0;
// No kelp!
del_engr_at(x, y);
await water_damage_chain(game.level?.objects?.[x]?.[y], true);
const mtmp = m_at(x, y);
if (mtmp !== null) {
await minliquid(mtmp);
} else {
newsym(x, y);
}
}
// C ref: fountain.c:163 dofindgem()
async function dofindgem() {
const u = game.u;
if (!Blind()) {
await You('spot a gem in the sparkling waters!');
} else {
await You_feel('a gem here!');
}
// C ref: fountain.c:dofindgem -> mksobj_at(rnd_class(DILITHIUM_CRYSTAL, LUCKSTONE-1), ...)
mksobj_at(rnd_class(DILITHIUM_CRYSTAL, LUCKSTONE - 1), u.ux, u.uy, false, false);
SET_FOUNTAIN_LOOTED(u.ux, u.uy);
newsym(u.ux, u.uy);
exercise(A_WIS, true); // a discovery!
}
// C ref: fountain.c:178 watchman_warn_fountain()
async function watchman_warn_fountain(mtmp) {
if (is_watch(mtmp.data) && couldsee(mtmp.mx, mtmp.my)
&& mtmp.mpeaceful) {
if (!Deaf()) {
await pline(`${Amonnam(mtmp)} yells:`);
await verbalize('Hey, stop using that fountain!');
} else {
const limbs = nolimbs(mtmp.data);
const gesture = limbs ? 'shakes' : 'waves';
const bodyp = limbs ? mbodypart(mtmp, HEAD) : makeplural(mbodypart(mtmp, ARM));
await pline(`${Amonnam(mtmp)} earnestly ${gesture} ${mhis(mtmp)} ${bodyp}!`);
}
return true;
}
return false;
}
// C ref: fountain.c:200 dryup()
export async function dryup(x, y, isyou) {
if (IS_FOUNTAIN(levl(x, y)?.typ)
&& (!rn2(3) || FOUNTAIN_IS_WARNED(x, y))) {
if (isyou && in_town(x, y) && !FOUNTAIN_IS_WARNED(x, y)) {
SET_FOUNTAIN_WARNED(x, y);
// Warn about future fountain use.
const mtmp = await get_iter_mons(watchman_warn_fountain);
// You can see or hear this effect
if (!mtmp) {
await pline_The('flow reduces to a trickle.');
}
return;
}
if (isyou && game.flags.debug) {
if ((await ynFunction('Dry up fountain?', 'yn', 'n')) === 'n') {
return;
}
}
// FIXME: sight-blocking clouds should use block_point/unblock_point
if (cansee(x, y)) {
const glyph = glyph_at(x, y);
if (!glyph_is_cmap(glyph) || glyph_to_cmap(glyph) !== S_cloud) {
await pline_The('fountain dries up!');
}
}
// replace the fountain with ordinary floor
set_levltyp(x, y, ROOM); // updates level.flags.nfountains
const loc = levl(x, y);
if (loc) {
loc.flags = 0;
loc.blessedftn = 0;
}
newsym(x, y);
if (isyou && in_town(x, y)) {
angry_guards(false);
}
}
}
// C ref: fountain.c:242 drinkfountain()
export async function drinkfountain() {
const u = game.u;
// What happens when you drink from a fountain?
const mgkftn = (levl(u.ux, u.uy)?.blessedftn === 1);
const fate = rnd(30);
if (Levitation()) {
await floating_above('fountain');
return;
}
if (mgkftn && u.uluck >= 0 && fate >= 10) {
let i, ii;
const littleluck = (u.uluck < 4);
await pline('Wow! This makes you feel great!');
// blessed restore ability
for (ii = 0; ii < A_MAX; ii++) {
if (ABASE(ii) < AMAX(ii)) {
// C: ABASE(ii) = AMAX(ii)
u.acurr.a[ii] = u.amax.a[ii];
setBotl('drinkfountain');
}
}
// gain ability, blessed if "natural" luck is high
i = rn2(A_MAX); // start at a random attribute
for (ii = 0; ii < A_MAX; ii++) {
if (await adjattrib(i, 1, littleluck ? -1 : 0) && littleluck) {
break;
}
if (++i >= A_MAX) i = 0;
}
await tty_display_nhwindow('message', false);
await pline('A wisp of vapor escapes the fountain...');
exercise(A_WIS, true);
const loc = levl(u.ux, u.uy);
if (loc) loc.blessedftn = 0;
return;
}
if (fate < 10) {
await pline_The('cool draught refreshes you.');
u.uhunger += rnd(10); // don't choke on water
await newuhs(false);
if (mgkftn) return;
} else {
switch (fate) {
case 19: // Self-knowledge
await You_feel('self-knowledgeable...');
await tty_display_nhwindow('message', false);
await enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS);
exercise(A_WIS, true);
await pline_The('feeling subsides.');
break;
case 20: // Foul water
await pline_The('water is foul! You gag and vomit.');
await morehungry(rn1(20, 11));
vomit();
break;
case 21: // Poisonous
await pline_The('water is contaminated!');
if (Poison_resistance()) {
await pline(`Perhaps it is runoff from the nearby ${fruitname(false)} farm.`);
await losehp(rnd(4), 'unrefrigerated sip of juice', KILLED_BY_AN);
break;
}
poison_strdmg(rn1(4, 3), rnd(10), 'contaminated water', KILLED_BY);
exercise(A_CON, false);
break;
case 22: // Fountain of snakes!
await dowatersnakes();
break;
case 23: // Water demon
await dowaterdemon();
break;
case 24: { // Maybe curse some items
let buc_changed = 0;
await pline("This water's no good!");
await morehungry(rn1(20, 11));
exercise(A_CON, false);
// this is more severe than rndcurse()
for (let obj = game.invent; obj; obj = obj.nobj) {
if (obj.oclass !== COIN_CLASS && !obj.cursed && !rn2(5)) {
curse(obj);
++buc_changed;
}
}
if (buc_changed) update_inventory();
break;
}
case 25: // See invisible
if (Blind()) {
if (Invis()) {
await You_feel('transparent.');
} else {
await You_feel('very self-conscious.');
await pline('Then it passes.');
}
} else {
await You_see('an image of someone stalking you.');
await pline('But it disappears.');
}
// HSee_invisible |= FROMOUTSIDE
if (game.u.uprops?.[SEE_INVIS]) {
game.u.uprops[SEE_INVIS].intrinsic = (game.u.uprops[SEE_INVIS].intrinsic || 0) | FROMOUTSIDE;
}
newsym(u.ux, u.uy);
exercise(A_WIS, true);
break;
case 26: // See Monsters
if (await monster_detect(null, 0)) {
await pline_The(`${hliquid('water')} tastes like nothing.`);
}
exercise(A_WIS, true);
break;
case 27: // Find a gem in the sparkling waters.
if (!FOUNTAIN_IS_LOOTED(u.ux, u.uy)) {
await dofindgem();
break;
}
// FALLTHROUGH
/*falls through*/
case 28: // Water Nymph
await dowaternymph();
break;
case 29: { // Scare
await pline(`This ${hliquid('water')} gives you bad breath!`);
for (let mtmp = game.fmon; mtmp; mtmp = mtmp.nmon) {
if (DEADMONSTER(mtmp)) continue;
await monflee(mtmp, 0, false, false);
}
break;
}
case 30: // Gushing forth in this room
await dogushforth(true);
break;
default:
await pline(`This tepid ${hliquid('water')} is tasteless.`);
break;
}
}
await dryup(u.ux, u.uy, true);
}
// C ref: fountain.c:392 dipfountain()
export async function dipfountain(obj) {
const u = game.u;
let er = ER_NOTHING;
const is_hands = (obj === hands_obj);
if (Levitation()) {
await floating_above('fountain');
return;
}
if (obj.otyp === LONG_SWORD && u.ulevel >= 5
&& !rn2(Role_if(PM_KNIGHT) ? 6 : 30)
// once upon a time it was possible to poly N daggers into N swords
&& obj.quan === 1 && !obj.oartifact
&& !exist_artifact(LONG_SWORD, artiname(ART_EXCALIBUR))) {
const lady = 'Lady of the Lake';
if (u.ualign?.type !== A_LAWFUL) {
// Ha! Trying to cheat her.
await pline(`A freezing mist rises from the ${hliquid('water')} and envelopes the sword.`);
await pline_The('fountain disappears!');
curse(obj);
if (obj.spe > -6 && !rn2(3)) obj.spe--;
obj.oerodeproof = false;
exercise(A_WIS, false);
livelog_printf(LL_ARTIFACT,
`was denied ${artiname(ART_EXCALIBUR)}! The ${lady} has deemed ${uhim()} unworthy`);
} else {
// The lady of the lake acts! - Eric Backus
// Be *REAL* nice
await pline('From the murky depths, a hand reaches up to bless the sword.');
await pline('As the hand retreats, the fountain disappears!');
obj = oname(obj, artiname(ART_EXCALIBUR), ONAME_VIA_DIP | ONAME_KNOW_ARTI);
await oname_deferred_untwoweapon(obj);
discover_artifact(ART_EXCALIBUR);
bless(obj);
obj.oeroded = 0;
obj.oeroded2 = 0;
obj.oerodeproof = true;
exercise(A_WIS, true);
livelog_printf(LL_ARTIFACT,
`was given ${artiname(ART_EXCALIBUR)} by the ${lady}`);
}
update_inventory();
set_levltyp(u.ux, u.uy, ROOM);
const loc = levl(u.ux, u.uy);
if (loc) loc.flags = 0;
newsym(u.ux, u.uy);
if (in_town(u.ux, u.uy)) {
angry_guards(false);
}
return;
} else if (is_hands || obj === game.u?.uarmg) {
er = await wash_hands();
} else {
er = await water_damage(obj, null, true);
}
if (er === ER_DESTROYED || (er !== ER_NOTHING && !rn2(2))) {
return; // no further effect
}
switch (rnd(30)) {
case 16: // Curse the item
if (!is_hands && obj.oclass !== COIN_CLASS && !obj.cursed) {
curse(obj);
}
break;
case 17:
case 18:
case 19:
case 20: // Uncurse the item
if (!is_hands && obj.cursed) {
if (!Blind()) {
await pline_The(`${hliquid('water')} glows for a moment.`);
}
uncurse(obj);
} else {
await pline('A feeling of loss comes over you.');
}
break;
case 21: // Water Demon
await dowaterdemon();
break;
case 22: // Water Nymph
await dowaternymph();
break;
case 23: // an Endless Stream of Snakes
await dowatersnakes();
break;
case 24: // Find a gem
if (!FOUNTAIN_IS_LOOTED(u.ux, u.uy)) {
await dofindgem();
break;
}
// FALLTHROUGH
/*falls through*/
case 25: // Water gushes forth
await dogushforth(false);
break;
case 26: // Strange feeling
await pline(`A strange tingling runs up your ${body_part(ARM)}.`);
break;
case 27: // Strange feeling
await You_feel('a sudden chill.');
break;
case 28: { // Strange feeling
await pline('An urge to take a bath overwhelms you.');
let money = money_cnt(game.invent);
if (money > 10) {
// Amount to lose
money = Math.trunc(somegold(money) / 10);
for (let otmp = game.invent; otmp && money > 0; otmp = otmp.nobj) {
if (otmp.oclass === COIN_CLASS) {
const denomination = 1; // TODO: objects[otmp.otyp].oc_cost
let coin_loss = Math.trunc((money + denomination - 1) / denomination);
coin_loss = Math.min(coin_loss, otmp.quan || 0);
otmp.quan = (otmp.quan || 0) - coin_loss;
money -= coin_loss * denomination;
if (!otmp.quan) delobj(otmp);
}
}
await You('lost some of your gold in the fountain!');
CLEAR_FOUNTAIN_LOOTED(u.ux, u.uy);
exercise(A_WIS, false);
}
break;
}
case 29: { // You see coins
if (FOUNTAIN_IS_LOOTED(u.ux, u.uy)) break;
SET_FOUNTAIN_LOOTED(u.ux, u.uy);
const coinAmt = rnd((dunlevs_in_dungeon(u.uz) - dunlev(u.uz) + 1) * 2) + 5;
mkgold(coinAmt, u.ux, u.uy);
if (!Blind()) {
await pline(`Far below you, you see coins glistening in the ${hliquid('water')}.`);
}
exercise(A_WIS, true);
newsym(u.ux, u.uy);
break;
}
default:
if (er === ER_NOTHING) {
await pline(nothing_seems_to_happen);
}
break;
}
update_inventory();
await dryup(u.ux, u.uy, true);
}
// C ref: fountain.c:557 wash_hands()
export async function wash_hands() {
const u = game.u;
const hands = makeplural(body_part(HAND));
let res = ER_NOTHING;
const was_glib = !!Glib();
await You(`wash your ${u.uarmg ? 'gloved ' : ''}${hands} in the ${hliquid('water')}.`);
if (Glib()) {
make_glib(0);
await Your(`${fingers_or_gloves(true)} are no longer slippery.`);
}
if (u.uarmg) {
res = await water_damage(u.uarmg, null, true);
}
// not what ER_GREASED is for, but the checks in dipfountain just
// compare the result to ER_DESTROYED and ER_NOTHING, so it works
if (was_glib && res === ER_NOTHING) {
res = ER_GREASED;
}
return res;
}
// C ref: fountain.c:579 breaksink()
export async function breaksink(x, y) {
if (cansee(x, y) || u_at(x, y)) {
await pline_The('pipes break! Water spurts out!');
}
// updates level.flags.nsinks and level.flags.nfountains
set_levltyp(x, y, FOUNTAIN);
const loc = levl(x, y);
if (loc) {
loc.looted = 0;
loc.blessedftn = 0;
}
SET_FOUNTAIN_LOOTED(x, y);
newsym(x, y);
}
// C ref: fountain.c:593 drinksink()
export async function drinksink() {
const u = game.u;
if (Levitation()) {
await floating_above('sink');
return;
}
switch (rn2(20)) {
case 0:
await You(`take a sip of very cold ${hliquid('water')}.`);
break;
case 1:
await You(`take a sip of very warm ${hliquid('water')}.`);
break;
case 2:
await You(`take a sip of scalding hot ${hliquid('water')}.`);
if (Fire_resistance()) {
await pline('It seems quite tasty.');
// monstseesu(M_SEEN_FIRE); // TODO
} else {
await losehp(rnd(6), 'sipping boiling water', KILLED_BY);
// monstunseesu(M_SEEN_FIRE); // TODO
}
break;
case 3: {
// PM_SEWER_RAT imported from monsters.js
if (game.mvitals?.[PM_SEWER_RAT]?.mvflags & G_GONE) {
await pline_The('sink seems quite dirty.');
} else {
const mtmp = await makemon(mons[PM_SEWER_RAT], u.ux, u.uy, MM_NOMSG);
if (mtmp) {
const desc = (Blind() || !canspotmon(mtmp))
? 'something squirmy'
: a_monnam(mtmp);
await pline(`Eek! There's ${desc} in the sink!`);
}
}
break;
}
case 4: {
let otmp;
for (;;) {
otmp = mkobj(POTION_CLASS, false);
if (!otmp || otmp.otyp !== POT_WATER) break;
obfree(otmp, null);
}
if (otmp) {
otmp.cursed = 0;
otmp.blessed = 0;
const desc = Blind() ? 'odd' : hcolor(OBJ_DESCR(null));
await pline(`Some ${desc} liquid flows from the faucet.`);
if (!(Blind() || Hallucination())) observe_object(otmp);
otmp.quan = (otmp.quan || 1) + 1; // Avoid panic upon useup()
otmp.fromsink = 1; // kludge for docall()
await dopotion(otmp);
obfree(otmp, null);
}
break;
}
case 5: {
const loc = levl(u.ux, u.uy);
if (loc && !(loc.looted & S_LRING)) {
await You('find a ring in the sink!');
mkobj_at(RING_CLASS, u.ux, u.uy, true);
loc.looted |= S_LRING;
exercise(A_WIS, true);
newsym(u.ux, u.uy);
} else {
await pline(`Some dirty ${hliquid('water')} backs up in the drain.`);
}
break;
}
case 6:
await breaksink(u.ux, u.uy);
break;
case 7: {
await pline_The(`${hliquid('water')} moves as though of its own will!`);
// PM_WATER_ELEMENTAL imported from monsters.js
if ((game.mvitals?.[PM_WATER_ELEMENTAL]?.mvflags & G_GONE)
|| !await makemon(mons[PM_WATER_ELEMENTAL], u.ux, u.uy, MM_NOMSG)) {
await pline('But it quiets down.');
}
break;
}
case 8:
await pline(`Yuk, this ${hliquid('water')} tastes awful.`);
more_experienced(1, 0);
await newexplevel();
break;
case 9:
await pline('Gaggg... this tastes like sewage! You vomit.');
await morehungry(rn1(30 - ACURR(A_CON), 11));
vomit();
break;
case 10:
await pline(`This ${hliquid('water')} contains toxic wastes!`);
// if (!Unchanging) { // TODO
// await You('undergo a freakish metamorphosis!');
// polyself(POLY_NOFLAGS);
// }
break;
case 11:
Soundeffect('se_clanking_pipe', 50);
await You_hear('clanking from the pipes...');
break;
case 12:
Soundeffect('se_sewer_song', 100);
await You_hear('snatches of song from among the sewers...');
break;
case 13:
await pline('Ew, what a stench!');
await create_gas_cloud(u.ux, u.uy, 1, 4);
break;
case 19:
if (Hallucination()) {
await pline('From the murky drain, a hand reaches up... --oops--');
break;
}
// FALLTHROUGH
/*falls through*/
default: {
const temp = rn2(3) ? (rn2(2) ? 'cold' : 'warm') : 'hot';
await You(`take a sip of ${temp} ${hliquid('water')}.`);
break;
}
}
}
// C ref: fountain.c:714 dipsink()
export async function dipsink(obj) {
const u = game.u;
let try_call = false;
const loc = levl(u.ux, u.uy);
const not_looted_yet = loc ? (loc.looted & S_LRING) === 0 : false;
const is_hands = (obj === hands_obj || (u.uarmg && obj === u.uarmg));
if (!rn2(not_looted_yet ? 25 : 15)) {
// can't rely on using sink for unlimited scroll blanking
await breaksink(u.ux, u.uy);
if (Glib() && is_hands) {
await Your(`${fingers_or_gloves(true)} are still slippery.`);
}
return;
} else if (is_hands) {
await wash_hands();
return;
} else if (obj.oclass !== POTION_CLASS) {
await You(`hold ${the(xname(obj))} under the tap.`);
if (await water_damage(obj, null, true) === ER_NOTHING) {
await pline(nothing_seems_to_happen);
}
return;
}
// at this point the object must be a potion
const qtyPrefix = (obj.quan || 1) > 1 ? 'one of ' : '';
await You(`pour ${qtyPrefix}${the(xname(obj))} down the drain.`);
switch (obj.otyp) {
case 245: /* POT_POLYMORPH — TODO: import constant */
await polymorph_sink();
try_call = true;
break;
case 247: /* POT_OIL */
if (!Blind()) {
await pline('It leaves an oily film on the basin.');
try_call = true;
} else {
await pline(nothing_seems_to_happen);
}
break;
case 250: /* POT_ACID */
try_call = true;
if (!Blind()) {
await pline_The('drain seems less clogged.');
} else if (!Deaf()) {
await You_hear('a sucking sound.');
} else {
await pline(nothing_seems_to_happen);
try_call = false;
}
break;
case 236: /* POT_LEVITATION */
await sink_backs_up_export(u.ux, u.uy);
try_call = true;
break;
case 248: /* POT_OBJECT_DETECTION */
if (loc && !(loc.looted & S_LRING)) {
await You('sense a ring lost down the drain.');
try_call = true;
break;
}
// FALLTHROUGH
/*falls through*/
case 232: /* POT_GAIN_LEVEL */
case 233: /* POT_GAIN_ENERGY */
case 249: /* POT_MONSTER_DETECTION */
case 246: /* POT_FRUIT_JUICE */
case 251: /* POT_WATER */
await pline(nothing_seems_to_happen);
break;
default:
await pline('A wisp of vapor rises up...');
if (!breathless(game.player?.data) || haseyes(game.player?.data)) {
await potionbreathe(obj);
}
break;
}
if (try_call && obj.dknown) await trycall(obj);
useup(obj);
}
// C ref: fountain.c:803 sink_backs_up()
export async function sink_backs_up_export(x, y) {
const loc = levl(x, y);
let buf;
if (!Blind()) {
buf = 'Muddy waste pops up from the drain';
} else if (!Deaf()) {
buf = 'You hear a sloshing sound';
} else {
buf = `Something splashes you in the ${body_part(FACE)}`;
}
await pline(`${!Deaf() ? 'Flupp! ' : ''}${buf}.`);
if (loc && !(loc.looted & S_LRING)) { // once per sink
if (!Blind()) {
await You_see('a ring shining in its midst.');
}
mkobj_at(RING_CLASS, x, y, true);
newsym(x, y);
exercise(A_DEX, true);
exercise(A_WIS, true); // a discovery!
loc.looted |= S_LRING;
}
}
/*fountain.js*/
|