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 | 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 3x 3x 3x 3x 6x 73x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 49x 49x 17x 49x 49x 49x 49x 73x 73x 73x 17x 1x 1x 1x 17x 73x 73x 73x 27x 27x 27x 27x 27x 73x 73x 73x 7x 7x 7x 7x 73x 73x 73x 1x 1x 1x 73x 73x 73x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 1x 1x 1x 8x 8x 8x 7x 7x 8x 7x 8x 73x 73x 73x 73x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 27x 27x 27x 27x 73x 73x 73x 1x 1x 73x 73x 73x 73x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 14x 14x 10x 18x 4x 18x 14x 18x 73x 73x 73x 73x 14x 14x 14x 14x 13x 14x 73x 73x 20x 20x 4x 4x 20x 20x 20x 73x 73x 73x 7x 7x 7x 7x 7x 7x 7x 7x 7x 4x 4x 4x 4x 4x 7x 7x 73x 73x 73x 73x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 6x 6x 6x 7x 6x 6x 6x 6x 6x 6x 6x 7x 7x 7x 73x 73x 73x 73x 73x 73x 73x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 4x 7x 3x 3x 7x 7x 7x 7x 7x 7x 3x 7x 7x 1x 1x 1x 1x 7x 2x 2x 2x 2x 7x 7x 7x 1x 1x 7x 7x 7x 73x 73x 73x 73x 204x 171x 171x 204x 204x 73x 73x 73x 73x 1061x 1061x 73x 73x 73x 73x 1286x 1286x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 3x 3x 3x 3x 73x 73x 73x 73x 73x 73x 73x 73x 14x 14x 14x 14x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 27x 27x 27x 27x 27x 27x 27x 98x 98x 98x 98x 98x 27x 27x 73x 73x 73x 73x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 73x 73x 73x 73x 3x 3x 3x 3x 3x 3x 3x 3x 3x 73x 73x 73x 73x | // do_name.js — Naming functions (port of do_name.c)
import { game } from './gstate.js';
import { LOW_PM, MD_PAD_BOGONS, CLR_MAX, PL_PSIZ, BUFSZ, ECMD_OK,
CMDQ_KEY, CQ_CANNED, GETOBJ_PROMPT, GETOBJ_NOFLAGS,
GETOBJ_EXCLUDE, GETOBJ_DOWNPLAY, GETOBJ_SUGGEST,
ONAME_VIA_NAMING, ONAME_KNOW_ARTI, ONAME_SKIP_INVUPD,
M_AP_FURNITURE, M_AP_OBJECT, isok, u_at, TOPLINE_NON_EMPTY,
ONAME, has_oname, MGIVENNAME, has_mgivenname, M_AP_TYPE,
MENU_BEHAVE_STANDARD, MENU_ITEMFLAGS_NONE,
ARTICLE_NONE, ARTICLE_THE, HAND, W_WEP } from './const.js';
import { rn2, rn2_on_display_rng, rnd_on_display_rng } from './rng.js';
import { Hallucination, See_invisible, Deaf } from './macros.js';
import { Mgender } from './hacklib.js';
import { mons, SPECIAL_PM, G_NOGEN, G_UNIQ, M2_PNAME,
PM_GHOST, PM_JUIBLEX, PM_SHOPKEEPER,
PM_HIGH_CLERIC } from './monsters.js';
import { NO_COLOR, ATR_NONE } from './terminal.js';
import { PICK_ONE } from './const.js';
import { cansee } from './vision.js';
import { Monnam, mon_nam, x_monnam, a_monnam } from './mon.js';
import { canspotmon, display_nhwindow, flush_screen, glyph_at, see_with_infrared, sensemon, tty_destroy_nhwindow } from './display.js';
import { upstart, mungspaces, strstri, fuzzymatch } from './hacklib.js';
import { The, Ysimple_name2, an, ansimpleoname, is_plural, safe_qbuf, simpleonames, xname } from './objnam.js';
import { getlin } from './input.js';
import { cmdq_pop, cmdq_clear } from './input.js';
import { m_at } from './map_access.js';
import { shkname } from './shk.js';
import { alter_cost } from './shk.js';
import { is_rider } from './mondata.js';
import { discover_object } from './u_init.js';
import { update_inventory } from './mon.js';
import { getobj } from './invent.js';
import { carried } from './invent.js';
import { getpos } from './getpos.js';
import { create_nhwindow_menu, start_menu, add_menu, end_menu,
select_menu } from './menu.js';
import { helpless, livelog_printf } from './hack.js';
import { SetVoice } from './sounds.js';
import { mhe, mhis } from './mon.js';
import { body_part } from './polyself.js';
import { wipeout_text } from './engrave.js';
import { rn1, rnd } from './rng.js';
import { SPE_NOVEL, STRANGE_OBJECT, WEAPON_CLASS, POTION_CLASS,
AMULET_CLASS, SCROLL_CLASS, WAND_CLASS, RING_CLASS,
GEM_CLASS, SPBOOK_CLASS, ARMOR_CLASS, TOOL_CLASS, VENOM_CLASS,
COIN_CLASS, FOOD_CLASS, HEAVY_IRON_BALL, TIN, TOWEL, STATUE,
FIGURINE, AMULET_OF_YENDOR, FAKE_AMULET_OF_YENDOR,
OBJ_DESCR } from './objects.js';
import { NON_PM } from './const.js';
import { untwoweapon } from './wield.js';
import { You, pline, verbalize } from './pline.js';
import { beautiful } from './apply.js';
import { dealloc_obj, vobj_at } from './mkobj.js';
import { artifact_exists, artifact_name, exist_artifact, restrict_name } from './artifact.js';
// ── Local stubs for functions not yet ported elsewhere ──
// apply.js has canonical version
function distant_monnam(mon, article, outbuf) {
// simplified version — full port belongs in mon.js
return x_monnam(mon, article, null, 0, true);
}
// Ysimple_name2: imported from objnam.js
// artifact_exists: imported from artifact.js
function set_artifact_intrinsic(_obj, _on, _which) {}
function bare_artifactname(_obj) { return ONAME(_obj) || 'artifact'; }
// discover_object: imported from u_init.js
function undiscover_object(_otyp) {}
function rename_disco() {}
function object_from_map(_glyph, _x, _y, _objref) { return false; }
// vobj_at: imported from mkobj.js
function glyph_is_swallow(_g) { return false; }
function glyph_is_object(_g) { return false; }
function roguename() {
return rn2(3) ? (rn2(2) ? 'Michael Toy' : 'Kenneth Arnold')
: 'Glenn Wichman';
}
function dupstr(s) { return s; }
// C ref: dungeon.c:2528 query_annotation() + 2565 donamelevel()
async function donamelevel() {
const key = `${game.u?.uz?.dnum ?? 0}:${game.u?.uz?.dlevel ?? 0}`;
if (!game.level_annotations) game.level_annotations = {};
const cur = game.level_annotations[key] || '';
const prompt = "What do you want to call this dungeon level?";
const nbuf = await getlin(prompt, null, { logHookedLifecycle: true });
if (!nbuf || nbuf === '\x1b') return ECMD_OK;
const munged = mungspaces(nbuf);
if (munged && munged !== ' ') {
game.level_annotations[key] = munged;
} else {
delete game.level_annotations[key];
}
return ECMD_OK;
}
// ── Constants ──
const BOGON_CODES = "-_+|=";
const BOGUSMONSIZE = 100;
const BOGUSMONS = ["jumbo shrimp","giant pigmy","gnu","killer penguin","giant cockroach","giant slug","maggot","pterodactyl","tyrannosaurus rex","basilisk","beholder","nightmare","efreeti","marid","rot grub","bookworm","master lichen","shadow","hologram","jester","attorney","sleazoid","killer tomato","amazon","robot","battlemech","rhinovirus","harpy","lion-dog","rat-ant","Y2K bug","angry mariachi","arch-pedant","bluebird of happiness","cardboard golem","duct tape golem","diagonally moving grid bug","evil overlord","newsgroup troll","ninja pirate zombie robot","octarine dragon","plaid unicorn","gonzo journalist","lag monster","loan shark","possessed waffle iron","poultrygeist","stuffed raccoon puppet","viking","wee green blobbie","wereplatypus","hag of bolding","blancmange","raging nerd","spelling bee","land octopus","frog prince","pigasus","_Semigorgon","conventioneer","large microbat","small megabat","uberhulk","tofurkey","+Dudley","shrinking violet","shallow one","spherical cow","electric giraffe","steam dragon","omnibus","slinky","maxotaur","millitaur","octahedron","dungeon core","quale","holloway","chiasmus","giant tetrapod","voussoir","barking spider","frog cloud","toothsayer","grue","Christmas-tree monster","luck sucker","paskald","brogmoid","dornbeast","Ancient Multi-Hued Dragon","+Evil Iggy","rattlesnake","ice monster","phantom","quagga","aquator","griffin","emu","kestrel","xeroc","venus flytrap","creeping coins","hydra","siren","killer bunny","rodent of unusual size","were-rabbit","+Smokey Bear","Luggage","vampiric watermelon","Ent","tangle tree","nickelpede","wiggle","white rabbit","snark","pushmi-pullyu","smurf","tribble","Klingon","Borg","Ewok","Totoro","ohmu","youma","nyaasu","-Godzilla","+King Kong","earthquake beast","Invid","Terminator","boomer","Dalek","microscopic space fleet","Ravenous Bugblatter Beast of Traal","leathery-winged avian","teenage mutant ninja turtle","samurai rabbit","aardvark","=Audrey II","witch doctor","one-eyed one-horned flying purple people eater","+Barney the dinosaur","+Morgoth","Vorlon","questing beast","Predator","dementor","mother-in-law","praying mantis","beluga whale","chicken","coelacanth","star-nosed mole","lungfish","slow loris","sea cucumber","tapeworm","liger","velociraptor","corpulent porpoise","quokka","potoo","lemming","dhole","wolpertinger","elwedritsche","skvader","+Nessie","tatzelwurm","dahu","dropbear","wild haggis","jackalope","flying monkey","flying pig","hippocampus","hippogriff","kelpie","catoblepas","phoenix","amphisbaena","bouncing eye","floating nose","wandering eye","buffer overflow","dangling pointer","walking disk drive","floating point","regex engine","netsplit","wiki","peer","COBOL","wire shark","bohrbug","mandelbug","schroedinbug","heisenbug","cacodemon","scrag","+Crow T. Robot","chess pawn","chocolate pudding","ooblecks","terracotta warrior","hearse","roomba","miniature blimp","dust speck","gazebo","gray goo","magnetic monopole","first category perpetual motion device","big dumb object","+Lord British","particle man","kitten prospecting robot","guillemet","solidus","obelus","dingbat","bold face","boustrophedon","ligature","rebus","dinkus","apostrophe golem","voluptuous ampersand","+Bob the angry flower","+Strong Bad","+Magical Trevor","smakken","mimmoth","one-winged dewinged stab-bat","Invisible Pink Unicorn","Flying Spaghetti Monster","three-headed monkey","+El Pollo Diablo","little green man","weighted Companion Cube","/b/tard","manbearpig","bonsai-kitten","tie-thulu","+Domo-kun","looooooooooooong cat","nyan cat","ceiling cat","basement cat","monorail cat","tridude","orcus cosmicus","yeek","quylthulg","Greater Hell Beast","+Vendor of Yizard","+Sigmund","lernaean hydra","-Ijyb","=Gloorx Vloq","+Blork the orc","unicorn pegasus kitten","enderman","wight supremacist","zergling","existential angst","figment of your imagination","flash of insight","ghoti","vermicious knid","meeple","womble","fraggle","stainless steel rat","antagonistic undecagonstring","mock role","clown","mime","peddler","haggler","gloating eye","flush golem","martyr orc","mortar orc","acid blog","acute blob","aria elemental","aliasing priest","aligned parasite","aligned parquet","aligned proctor","baby balky dragon","baby blues dragon","baby caricature","baby crochet","baby grainy dragon","baby bong worm","baby long word","baby parable worm","barfed devil","beer wight","boor wight","brawny mold","rave spider","clue golem","bust vortex","errata elemental","elastic eel","electrocardiogram eel","fir elemental","tire elemental","flamingo sphere","fallacy golem","frizzed centaur","forest centerfold","fierceness sphere","frosted giant","geriatric snake","gnat ant","giant bath","grant beetle","greater snake","grind bug","giant mango","glossy golem","gnome laureate","gnome dummy","gooier ooze","green slide","guardian nacho","hell hound pun","high purist","hairnet devil","ice trowel","killer beet","feather golem","lounge worm","mountain lymph","pager golem","pie fiend","prophylactic worm","sock mole","rogue piercer","seesawing sphere","simile mimic","moldier ant","stain vortex","scone giant","umbrella hulk","vampire mace","verbal jabberwock","water lemon","water melon","winged grizzly","yellow wight"];
const BOGUSMON_LINE_BYTES = BOGUSMONS.map((name) => Math.max(name.length, MD_PAD_BOGONS));
const BOGUSMON_RANGE = BOGUSMON_LINE_BYTES.reduce((sum, len) => sum + len, 0);
const HCOLORS = [
"ultraviolet", "infrared", "bluish-orange", "reddish-green", "dark white",
"light black", "sky blue-pink", "pinkish-cyan", "indigo-chartreuse",
"salty", "sweet", "sour", "bitter", "umami", "striped", "spiral",
"swirly", "plaid", "checkered", "argyle", "paisley", "blotchy",
"guernsey-spotted", "polka-dotted", "square", "round", "triangular",
"cabernet", "sangria", "fuchsia", "wisteria", "lemon-lime",
"strawberry-banana", "peppermint", "romantic", "incandescent",
"octarine", "excitingly dull", "mauve", "electric", "neon",
"fluorescent", "phosphorescent", "translucent", "opaque",
"psychedelic", "iridescent", "rainbow-colored", "polychromatic",
"colorless", "colorless green", "dancing", "singing", "loving", "loudy",
"noisy", "clattery", "silent", "apocyan", "infra-pink", "opalescent",
"violant", "tuneless", "viridian", "aureolin", "cinnabar", "purpurin",
"gamboge", "madder", "bistre", "ecru", "fulvous", "tekhelet",
"selective yellow",
];
const HLIQUIDS = [
"yoghurt", "oobleck", "clotted blood", "diluted water", "purified water",
"instant coffee", "tea", "herbal infusion", "liquid rainbow",
"creamy foam", "mulled wine", "bouillon", "nectar", "grog", "flubber",
"ketchup", "slow light", "oil", "vinaigrette", "liquid crystal", "honey",
"caramel sauce", "ink", "aqueous humour", "milk substitute",
"fruit juice", "glowing lava", "gastric acid", "mineral water",
"cough syrup", "quicksilver", "sweet vitriol", "grey goo", "pink slime",
"cosmic latte",
];
const C_OBJ_COLORS = [
"black", "red", "green", "brown", "blue", "magenta", "cyan", "gray",
"transparent", "orange", "bright green", "yellow", "bright blue",
"bright magenta", "bright cyan", "white",
];
const ghostnames = [
"Adri", "Andries", "Andreas", "Bert", "David", "Dirk",
"Emile", "Frans", "Fred", "Greg", "Hether", "Jay",
"John", "Jon", "Karnov", "Kay", "Kenny", "Kevin",
"Maud", "Michiel", "Mike", "Peter", "Robert", "Ron",
"Tom", "Wilmar", "Nick Danger", "Phoenix", "Jiro", "Mizue",
"Stephan", "Lance Braccus", "Shadowhawk", "Murphy"
];
const coynames = [
"Carnivorous Vulgaris", "Road-Runnerus Digestus", "Eatibus Anythingus",
"Famishus-Famishus", "Eatibus Almost Anythingus", "Eatius Birdius",
"Famishius Fantasticus", "Eternalii Famishiis", "Famishus Vulgarus",
"Famishius Vulgaris Ingeniusi", "Eatius-Slobbius", "Hardheadipus Oedipus",
"Carnivorous Slobbius", "Hard-Headipus Ravenus", "Evereadii Eatibus",
"Apetitius Giganticus", "Hungrii Flea-Bagius", "Overconfidentii Vulgaris",
"Caninus Nervous Rex", "Grotesques Appetitus", "Nemesis Ridiculii",
"Canis latrans"
];
const sir_Terry_novels = [
"The Colour of Magic", "The Light Fantastic", "Equal Rites", "Mort",
"Sourcery", "Wyrd Sisters", "Pyramids", "Guards! Guards!", "Eric",
"Moving Pictures", "Reaper Man", "Witches Abroad", "Small Gods",
"Lords and Ladies", "Men at Arms", "Soul Music", "Interesting Times",
"Maskerade", "Feet of Clay", "Hogfather", "Jingo", "The Last Continent",
"Carpe Jugulum", "The Fifth Elephant", "The Truth", "Thief of Time",
"The Last Hero", "The Amazing Maurice and His Educated Rodents",
"Night Watch", "The Wee Free Men", "Monstrous Regiment",
"A Hat Full of Sky", "Going Postal", "Thud!", "Wintersmith",
"Making Money", "Unseen Academicals", "I Shall Wear Midnight", "Snuff",
"Raising Steam", "The Shepherd's Crown"
];
const NVL_COLOUR_OF_MAGIC = 0;
const NVL_SOURCERY = 4;
const NVL_MASKERADE = 17;
const NVL_AMAZING_MAURICE = 27;
const NVL_THUD = 33;
// ── Utility ──
function offsetToPaddedLine(lineBytes, off) {
let pos = 0;
for (let i = 0; i < lineBytes.length; i++) {
if (off < pos + lineBytes[i]) {
return { line: i, remaining: lineBytes[i] - (off - pos) };
}
pos += lineBytes[i];
}
return { line: lineBytes.length - 1, remaining: 1 };
}
// ── Name allocation (C: new_mgivenname, free_mgivenname, etc.) ──
// C: new_mgivenname(mon, lth) — allocate space for monster name
export function new_mgivenname(mon, lth) {
if (lth) {
if (!mon.mextra) mon.mextra = {};
else free_mgivenname(mon);
// JS: just prepare the slot; actual string set by caller
mon.mextra.mgivenname = '';
} else {
if (has_mgivenname(mon))
free_mgivenname(mon);
}
}
// C: free_mgivenname(mon)
export function free_mgivenname(mon) {
if (has_mgivenname(mon)) {
if (mon.mextra) mon.mextra.mgivenname = '';
if (mon.mgivenname) mon.mgivenname = '';
}
}
// C: new_oname(obj, lth) — allocate space for object name
export function new_oname(obj, lth) {
if (lth) {
if (!obj.oextra) obj.oextra = {};
else free_oname(obj);
obj.oextra.oname = '';
} else {
if (has_oname(obj))
free_oname(obj);
}
}
// C: free_oname(obj)
export function free_oname(obj) {
if (has_oname(obj)) {
if (obj.oextra) obj.oextra.oname = '';
}
}
// C: safe_oname(obj)
export function safe_oname(obj) {
if (has_oname(obj)) return ONAME(obj);
return '';
}
// ── Name from player (C: name_from_player) ──
async function name_from_player(prompt, defres) {
let outbuf = '';
const stampedScrollCallPrompt = prompt.startsWith('Call a stamped scroll:');
// C seam: "Call a stamped scroll:" in seed0209 does not emit the
// hooked_tty_getlin lifecycle events that other naming prompts do.
const useHookedLifecycle = !stampedScrollCallPrompt;
const result = useHookedLifecycle
? await getlin(prompt, null, { logHookedLifecycle: true })
: await getlin(prompt);
if (stampedScrollCallPrompt) {
const disp = game?.nhDisplay || null;
if (disp) disp.toplin = TOPLINE_NON_EMPTY;
}
outbuf = result || '';
if (!outbuf || outbuf === '\x1b')
return null;
outbuf = mungspaces(outbuf);
if (outbuf.length >= PL_PSIZ)
outbuf = outbuf.slice(0, PL_PSIZ - 1);
return outbuf;
}
// ── christen_monst (C: christen_monst) ──
export function christen_monst(mtmp, name) {
let lth = (name && name.length) ? name.length + 1 : 0;
if (lth > PL_PSIZ) {
lth = PL_PSIZ;
name = name.slice(0, PL_PSIZ - 1);
}
new_mgivenname(mtmp, lth);
if (lth) {
if (!mtmp.mextra) mtmp.mextra = {};
mtmp.mextra.mgivenname = name;
}
if (mtmp.mleashed)
update_inventory();
return mtmp;
}
// ── alreadynamed (C: alreadynamed) ──
async function alreadynamed(mtmp, monnambuf, usrbuf) {
if (!usrbuf) {
const name_not_title = (has_mgivenname(mtmp)
|| type_is_pname(mtmp.data)
|| mtmp.isshk);
await pline(`${upstart(monnambuf)} would rather keep ${is_rider(mtmp.data) ? "its" : mhis(mtmp)} existing ${name_not_title ? "name" : "title"}.`);
return true;
} else if (fuzzymatch(usrbuf, monnambuf, " -_", true)
|| (monnambuf.toLowerCase().startsWith("the ")
&& fuzzymatch(usrbuf, monnambuf.slice(4), " -_", true))
|| (strstri(monnambuf, "invisible ") !== null
&& fuzzymatch(usrbuf, monnambuf.slice(monnambuf.toLowerCase().indexOf("invisible ") + 10), " -_", true))
|| (strstri(monnambuf, " of ") !== null
&& fuzzymatch(usrbuf, monnambuf.slice(monnambuf.toLowerCase().indexOf(" of ") + 4), " -_", true))) {
if (is_rider(mtmp.data)) {
await pline(`${upstart(monnambuf)} is already called that.`);
} else {
await pline(`${upstart(mhe(mtmp))} is already called ${monnambuf}.`);
}
return true;
} else if (mtmp.data === mons[PM_JUIBLEX]
&& strstri(monnambuf, "Juiblex") !== null
&& usrbuf.toLowerCase() === "jubilex") {
await pline(`${upstart(monnambuf)} doesn't like being called ${usrbuf}.`);
return true;
}
return false;
}
// ── do_mgivenname / do_mname (C: do_mgivenname) ──
async function do_mgivenname() {
const u = game.u;
if (Hallucination()) {
await You("would never recognize it anyway.");
return;
}
const cc = { x: u.ux, y: u.uy };
const posResult = await getpos(cc, false, "the monster you want to name");
if (posResult < 0 || !isok(cc.x, cc.y))
return;
const cx = cc.x, cy = cc.y;
let mtmp = null;
if (u_at(cx, cy)) {
if (u.usteed && canspotmon(u.usteed)) {
mtmp = u.usteed;
} else {
await pline(`This ${beautiful()} creature is called ${game.svp?.plname || 'you'} and cannot be renamed.`);
return;
}
} else {
mtmp = m_at(cx, cy);
}
let do_swallow = false;
if (!mtmp && u.uswallow) {
const glyph = glyph_at(cx, cy);
if (glyph_is_swallow(glyph)) {
mtmp = u.ustuck;
do_swallow = true;
}
}
if (!do_swallow && (!mtmp
|| (!sensemon(mtmp)
&& (!(cansee(cx, cy) || see_with_infrared(mtmp))
|| mtmp.mundetected || M_AP_TYPE(mtmp) === M_AP_FURNITURE
|| M_AP_TYPE(mtmp) === M_AP_OBJECT
|| (mtmp.minvis && !See_invisible()))))) {
await pline("I see no monster there.");
return;
}
const monnambuf = distant_monnam(mtmp, ARTICLE_THE, '');
const qbuf = `What do you want to call ${monnambuf}?`;
const buf = await name_from_player(qbuf,
has_mgivenname(mtmp) ? MGIVENNAME(mtmp) : null);
if (!buf) return;
if ((mtmp.data?.geno & G_UNIQ) && !mtmp.ispriest) {
if (!(await alreadynamed(mtmp, monnambuf, buf)))
await pline(`${upstart(monnambuf)} doesn't like being called names!`);
} else if (mtmp.isshk
&& !(Deaf() || helpless(mtmp)
|| (mtmp.data?.msound ?? 0) <= 0 /* MS_ANIMAL */)) {
if (!(await alreadynamed(mtmp, monnambuf, buf))) {
SetVoice(mtmp, 0, 80, 0);
await verbalize(`I'm ${shkname(mtmp)}, not ${buf}.`);
}
} else if (mtmp.ispriest || mtmp.isminion || mtmp.isshk
|| mtmp.data === mons[PM_GHOST] || mtmp.has_ebones) {
if (!(await alreadynamed(mtmp, monnambuf, buf)))
await pline(`${upstart(monnambuf)} will not accept the name ${buf}.`);
} else {
christen_monst(mtmp, buf);
}
}
// ── do_oname (C: do_oname) ──
async function do_oname(obj) {
if (obj.otyp === SPE_NOVEL) {
await pline(`${Ysimple_name2(obj)} already has a published name.`);
return;
}
const prefix = `What do you want to name ${is_plural(obj) ? "these" : "this"} `;
const qbuf = await safe_qbuf('', prefix, "?", obj, xname, simpleonames, "item");
const buf = await name_from_player(qbuf, safe_oname(obj));
if (!buf) return;
if (obj.oartifact) {
await pline(`${has_oname(obj) ? ONAME(obj) : "The artifact"} resists the attempt.`);
return;
}
// artifact name check (simplified — full artifact system not yet ported)
const aname = artifact_name(buf, {}, true);
if (aname && (restrict_name(obj, aname) || exist_artifact(obj.otyp, aname))) {
// hand slip — scuff the text
let bufCopy = buf;
let bufp = buf.toLowerCase().startsWith("the ") ? buf.slice(4) : buf;
let scuffed = bufp;
do {
scuffed = wipeout_text(bufp, rnd_on_display_rng(2), 0);
} while (scuffed === bufCopy);
await pline(`While engraving, your ${body_part(HAND)} slips.`);
await display_nhwindow(null, false);
await You(`engrave: "${scuffed}".`);
game.u.uconduct = game.u.uconduct || {};
game.u.uconduct.literate = (game.u.uconduct.literate || 0) + 1;
return;
}
obj = oname(obj, buf, ONAME_VIA_NAMING | ONAME_KNOW_ARTI);
await oname_deferred_untwoweapon(obj);
}
// ── oname (C: oname) ──
// C ref: do_name.c oname() — assign a name to an object.
// Synchronous core: all state mutation is immediate. The only async
// operation (untwoweapon) is deferred — callers that pass a wielded
// artifact during gameplay must await oname_untwoweapon_deferred()
// afterward if oname returns a deferred flag.
export function oname(obj, name, oflgs) {
const via_naming = !!(oflgs & ONAME_VIA_NAMING);
const skip_inv_update = !!(oflgs & ONAME_SKIP_INVUPD);
let lth = name.length ? name.length + 1 : 0;
if (lth > PL_PSIZ) {
lth = PL_PSIZ;
name = name.slice(0, PL_PSIZ - 1);
}
if (obj.oartifact || (lth && exist_artifact(obj.otyp, name)))
return obj;
new_oname(obj, lth);
if (lth) {
if (!obj.oextra) obj.oextra = {};
obj.oextra.oname = name;
}
if (lth)
artifact_exists(obj, name, true, oflgs);
if (obj.oartifact) {
// C calls untwoweapon() here synchronously (C is single-threaded).
// JS's untwoweapon() is async (calls pline). During level gen or
// object creation, the object is never the hero's swap weapon, so
// this is unreachable. For gameplay naming, callers that are already
// async (docall, do_oname) handle this via the deferred flag.
if (obj === game.u?.uswapwep)
obj._oname_needs_untwoweapon = true;
if (obj === game.u?.uwep)
set_artifact_intrinsic(obj, true, W_WEP);
if (obj.unpaid)
alter_cost(obj, 0);
if (via_naming) {
game.u.uconduct = game.u.uconduct || {};
game.u.uconduct.literate = (game.u.uconduct.literate || 0) + 1;
livelog_printf(0, `named ${bare_artifactname(obj)}`);
}
}
if (carried(obj) && !skip_inv_update)
update_inventory();
return obj;
}
// Call after oname() in async contexts to handle deferred untwoweapon.
export async function oname_deferred_untwoweapon(obj) {
if (obj?._oname_needs_untwoweapon) {
delete obj._oname_needs_untwoweapon;
await untwoweapon();
}
}
// ── objtyp_is_callable (C: objtyp_is_callable) ──
export function objtyp_is_callable(i) {
const objects = game.objects;
if (!objects || !objects[i]) return false;
if (objects[i].oc_uname) return true;
switch (objects[i].oc_class) {
case AMULET_CLASS:
if (i === AMULET_OF_YENDOR || i === FAKE_AMULET_OF_YENDOR)
break;
// fall through
case SCROLL_CLASS:
case POTION_CLASS:
case WAND_CLASS:
case RING_CLASS:
case GEM_CLASS:
case SPBOOK_CLASS:
case ARMOR_CLASS:
case TOOL_CLASS:
case VENOM_CLASS:
if (OBJ_DESCR(objects[i]))
return true;
break;
default:
break;
}
return false;
}
// ── name_ok / call_ok (C: name_ok, call_ok) ──
export function name_ok(obj) {
if (!obj || obj.oclass === COIN_CLASS)
return GETOBJ_EXCLUDE;
if (!obj.dknown || obj.oartifact || obj.otyp === SPE_NOVEL)
return GETOBJ_DOWNPLAY;
return GETOBJ_SUGGEST;
}
export function call_ok(obj) {
if (!obj || !objtyp_is_callable(obj.otyp))
return GETOBJ_EXCLUDE;
const objects = game.objects;
if (!obj.dknown || (objects && objects[obj.otyp]?.oc_name_known
&& !(objects[obj.otyp]?.oc_uname)))
return GETOBJ_DOWNPLAY;
return GETOBJ_SUGGEST;
}
// ── docall_xname (C: docall_xname) ──
function docall_xname(obj) {
// simplified copy of the object for naming
const otemp = Object.assign({}, obj);
otemp.oextra = null;
otemp.quan = 1;
otemp.blessed = 0;
otemp.cursed = 0;
if (otemp.oclass === WEAPON_CLASS) otemp.opoisoned = 0;
else if (otemp.oclass === POTION_CLASS) otemp.odiluted = 0;
else if (otemp.otyp === TOWEL || otemp.otyp === STATUE) otemp.spe = 0;
else if (otemp.otyp === TIN) otemp.known = 0;
else if (otemp.otyp === FIGURINE) otemp.corpsenm = NON_PM;
else if (otemp.otyp === HEAVY_IRON_BALL) {
const objects = game.objects;
otemp.owt = objects?.[HEAVY_IRON_BALL]?.oc_weight ?? 480;
} else if (otemp.oclass === FOOD_CLASS && otemp.globby) {
otemp.owt = 120;
}
return an(xname(otemp));
}
// ── docall (C: docall) ──
export async function docall(obj) {
const objects = game.objects;
if (!obj.dknown) return;
await flush_screen(1);
let qbuf;
if (obj.oclass === POTION_CLASS && obj.fromsink) {
qbuf = `Call a stream of ${OBJ_DESCR(objects?.[obj.otyp])} fluid:`;
} else {
qbuf = await safe_qbuf('', "Call ", ":", obj, docall_xname, simpleonames, "thing");
}
const uname_p = objects?.[obj.otyp];
const buf = await name_from_player(qbuf, uname_p?.oc_uname || null);
if (!buf) return;
let had_name = false;
if (uname_p?.oc_uname) {
had_name = true;
uname_p.oc_uname = null;
}
const cleaned = mungspaces(buf);
if (!cleaned) {
if (had_name) undiscover_object(obj.otyp);
} else {
if (uname_p) uname_p.oc_uname = dupstr(cleaned);
discover_object(obj.otyp, false, true, true);
}
if (obj.where === 2 /* OBJ_INVENT */ || carried(obj))
update_inventory();
}
// ── namefloorobj (C: namefloorobj) ──
async function namefloorobj() {
const u = game.u;
const cc = { x: u.ux, y: u.uy };
const buf_desc = `object on map (or '.' for one under you)`;
if (await getpos(cc, false, buf_desc) < 0 || cc.x <= 0)
return;
let obj = null;
let fakeobj = false;
if (u_at(cc.x, cc.y)) {
obj = vobj_at(u.ux, u.uy);
} else {
const glyph = glyph_at(cc.x, cc.y);
if (glyph_is_object(glyph)) {
const ref = {};
fakeobj = object_from_map(glyph, cc.x, cc.y, ref);
obj = ref.obj || null;
}
}
if (!obj) {
await pline(u_at(cc.x, cc.y)
? "There doesn't seem to be any object under you."
: "There doesn't seem to be any object there.");
return;
}
const buf = (obj.otyp !== STRANGE_OBJECT)
? simpleonames(obj)
: 'strange object';
const use_plural = (obj.quan || 1) > 1;
if (Hallucination()) {
// simplified hallucination naming
const unames = ['adventurer', 'explorer', bogusmon(), bogusmon(),
roguename(), 'Wibbly Wobbly'];
await pline(`${The(buf)} ${use_plural ? "decide" : "decides"} to call you "${unames[rn2_on_display_rng(unames.length)]}".`);
} else if (call_ok(obj) === GETOBJ_EXCLUDE) {
await pline(`${use_plural ? "Those" : "That"} ${buf} can't be assigned a type name.`);
} else if (!obj.dknown) {
await You(`don't know ${use_plural ? "those" : "that"} ${buf} well enough to name ${use_plural ? "them" : "it"}.`);
} else {
await docall(obj);
}
if (fakeobj) {
obj.where = 0; // OBJ_FREE
dealloc_obj(obj);
}
}
// ── docallcmd (C: docallcmd) — the #call / #name command ──
export async function docallcmd() {
let ch = '\0';
const abc = game.flags?.lootabc || false;
const clr = NO_COLOR;
const cmdq = cmdq_pop();
if (cmdq) {
if (cmdq.typ === CMDQ_KEY)
ch = (typeof cmdq.key === 'number')
? String.fromCharCode(cmdq.key)
: cmdq.key;
else
cmdq_clear(CQ_CANNED);
// goto docallcmd label
}
if (ch === '\0') {
const win = create_nhwindow_menu();
start_menu(win);
// C: any.a_char = 'm' with group accel 'C'
add_menu(win, 'm', abc ? 0 : 'm', 'C',
ATR_NONE, clr, "a monster", MENU_ITEMFLAGS_NONE);
if (game.invent) {
add_menu(win, 'i', abc ? 0 : 'i', 'y',
ATR_NONE, clr, "a particular object in inventory",
MENU_ITEMFLAGS_NONE);
add_menu(win, 'o', abc ? 0 : 'o', 'n',
ATR_NONE, clr, "the type of an object in inventory",
MENU_ITEMFLAGS_NONE);
}
add_menu(win, 'f', abc ? 0 : 'f', ',',
ATR_NONE, clr, "the type of an object upon the floor",
MENU_ITEMFLAGS_NONE);
add_menu(win, 'd', abc ? 0 : 'd', '\\',
ATR_NONE, clr, "the type of an object on discoveries list",
MENU_ITEMFLAGS_NONE);
add_menu(win, 'a', abc ? 0 : 'a', 'l',
ATR_NONE, clr, "record an annotation for the current level",
MENU_ITEMFLAGS_NONE);
end_menu(win, "What do you want to name?");
const picked = await select_menu(win, PICK_ONE);
if (picked && picked.count > 0 && picked.items?.length > 0) {
ch = picked.items[0]?.identifier || 'q';
} else {
ch = 'q';
}
tty_destroy_nhwindow(win.winId);
}
// docallcmd label
switch (ch) {
default:
case 'q':
break;
case 'm':
await do_mgivenname();
break;
case 'i': {
const obj = await getobj("name", name_ok, GETOBJ_PROMPT);
if (obj) await do_oname(obj);
break;
}
case 'o': {
const obj = await getobj("call", call_ok, GETOBJ_NOFLAGS);
if (obj) {
xname(obj);
if (!obj.dknown) {
await You("would never recognize another one.");
} else {
await docall(obj);
}
}
break;
}
case 'f':
await namefloorobj();
break;
case 'd':
rename_disco();
break;
case 'a':
await donamelevel();
break;
}
return ECMD_OK;
}
// ── rndghostname (C: rndghostname) ──
export function rndghostname() {
if (rn2(7)) {
return ghostnames[rn2(ghostnames.length)];
}
return game.svp?.plname || 'Adventurer';
}
// ── type_is_pname ──
export function type_is_pname(pm) {
return !!(pm?.mflags2 & M2_PNAME);
}
// ── pmname ──
export function pmname(pm, mgender) {
return pm?.mname ?? "creature";
}
// C ref: do_name.c:1313 — mon_pmname: pmname for a specific monster
export function mon_pmname(mon) {
return pmname(mon?.data, Mgender(mon));
}
// ── bogusmon ──
export function bogusmon(codeRef = null) {
if (codeRef) codeRef.value = '\0';
if (!BOGUSMONS.length || BOGUSMON_RANGE < 1) return "bogon";
let info = null;
for (let trylimit = 10; trylimit > 0; --trylimit) {
info = offsetToPaddedLine(BOGUSMON_LINE_BYTES, rn2_on_display_rng(BOGUSMON_RANGE));
if (info.remaining <= MD_PAD_BOGONS + 1) break;
}
const nextLine = info ? ((info.line + 1) % BOGUSMONS.length) : 0;
let mnam = BOGUSMONS[nextLine] || "bogon";
if (BOGON_CODES.includes(mnam[0])) {
if (codeRef) codeRef.value = mnam[0];
mnam = mnam.slice(1);
}
return mnam;
}
// ── rndmonnam ──
export function rndmonnam(codeRef = null) {
if (codeRef) codeRef.value = '\0';
let name;
do {
name = rn2_on_display_rng(SPECIAL_PM + BOGUSMONSIZE - LOW_PM) + LOW_PM;
} while (name < SPECIAL_PM
&& (type_is_pname(mons[name]) || (mons[name]?.geno & G_NOGEN)));
if (name >= SPECIAL_PM) return bogusmon(codeRef);
return pmname(mons[name], rn2_on_display_rng(2));
}
// ── bogon_is_pname ──
export function bogon_is_pname(code) {
return !!code && "-+=".includes(code);
}
// ── hcolor ──
export function hcolor(colorpref) {
return (Hallucination() || !colorpref)
? HCOLORS[rn2_on_display_rng(HCOLORS.length)]
: colorpref;
}
// ── rndcolor ──
export function rndcolor() {
const k = rn2(CLR_MAX);
return Hallucination()
? hcolor(null)
: (k === NO_COLOR ? "colorless" : C_OBJ_COLORS[k]);
}
// ── hliquid ──
export function hliquid(liquidpref) {
const hallucinate = Hallucination() && !game.program_state?.gameover;
if (hallucinate || !liquidpref || !liquidpref.length) {
let count = HLIQUIDS.length;
if (liquidpref && liquidpref.length) count++;
const idx = rn2_on_display_rng(count);
if (idx >= 0 && idx < HLIQUIDS.length) return HLIQUIDS[idx];
}
return liquidpref;
}
// ── roguename (C: roguename) ──
export { roguename, BOGUSMONS, BOGON_CODES };
// ── coyotename (C: coyotename) ──
export function coyotename(mtmp) {
if (!mtmp) return '';
const name = x_monnam(mtmp, ARTICLE_NONE, null, 0, true);
const alias = mtmp.mcan
? coynames[coynames.length - 1]
: coynames[mtmp.m_id % (coynames.length - 1)];
return `${name} - ${alias}`;
}
// ── rndorcname (C: rndorcname) ──
export function rndorcname() {
const v = ["a", "ai", "og", "u"];
const snd = ["gor", "gris", "un", "bane", "ruk",
"oth", "ul", "z", "thos", "akh", "hai"];
const iend = rn1(2, 3);
let vstart = rn2(2);
let s = '';
for (let i = 0; i < iend; ++i) {
vstart = 1 - vstart;
const sep = (i > 0 && !rn2(30)) ? "-" : "";
const part = vstart ? v[rn2(v.length)] : snd[rn2(snd.length)];
s += sep + part;
}
return s;
}
// ── christen_orc (C: christen_orc) ──
export function christen_orc(mtmp, gang, other) {
const orcname = rndorcname();
let sz = orcname.length;
if (gang) sz += gang.length + 4; // " of "
else if (other) sz += other.length;
if (sz < BUFSZ) {
let buf;
if (gang) {
buf = `${upstart(orcname)} of ${upstart(gang)}`;
mtmp = christen_monst(mtmp, buf);
} else if (other) {
buf = `${upstart(orcname)}${other}`;
mtmp = christen_monst(mtmp, buf);
}
}
return mtmp;
}
// ── noveltitle (C: noveltitle) ──
export function noveltitle(novidxRef) {
const k = sir_Terry_novels.length;
let j = rn2(k);
if (novidxRef) {
if (novidxRef.value === -1) {
novidxRef.value = j;
} else if (novidxRef.value >= 0 && novidxRef.value < k) {
j = novidxRef.value;
}
}
return sir_Terry_novels[j];
}
// ── lookup_novel (C: lookup_novel) ──
export function lookup_novel(lookname, idxRef) {
// variant spellings
if (The(lookname).toLowerCase() === "the color of magic")
lookname = sir_Terry_novels[NVL_COLOUR_OF_MAGIC];
else if (lookname.toLowerCase() === "sorcery")
lookname = sir_Terry_novels[NVL_SOURCERY];
else if (lookname.toLowerCase() === "masquerade")
lookname = sir_Terry_novels[NVL_MASKERADE];
else if (The(lookname).toLowerCase() === "the amazing maurice")
lookname = sir_Terry_novels[NVL_AMAZING_MAURICE];
else if (lookname.toLowerCase() === "thud")
lookname = sir_Terry_novels[NVL_THUD];
for (let k = 0; k < sir_Terry_novels.length; ++k) {
if (lookname.toLowerCase() === sir_Terry_novels[k].toLowerCase()
|| The(lookname).toLowerCase() === sir_Terry_novels[k].toLowerCase()) {
if (idxRef) idxRef.value = k;
return sir_Terry_novels[k];
}
}
if (idxRef && idxRef.value >= 0 && idxRef.value < sir_Terry_novels.length)
return sir_Terry_novels[idxRef.value];
return null;
}
|