Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 | 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 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 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 1x 73x 73x 73x 73x 73x 73x 2x 2x 2x 2x 2x 58x 58x 58x 58x 58x 58x 58x 58x 73x 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 73x 73x 73x 73x 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 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 753x 753x 73x 73x 73x 73x 73x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 3x 3x 73x 73x 73x 73x 73x 2x 2x 2x 2x 1x 1x 1x 1x 1x 2x 4x 4x 4x 4x 4x 2x 1x 2x 2x 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 73x 73x 73x 73x 73x 73x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 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 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 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 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 9x 9x 9x 9x 3x 3x 3x 9x 9x 73x 90x 90x 90x 90x 6x 90x 90x 12x 12x 72x 90x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 6x 6x 6x 6x 6x 3x 3x 6x 6x 3x 3x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 90x 90x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 24x 24x 78x 90x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 73x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 2x 2x 2x 2x 3x 2x 2x 2x 2x 73x 73x 73x 126x 3x 3x 126x 126x | /**
* themerms - NetHack themed room library
* Converted from: themerms.lua
*
* This is a LIBRARY module (not a level generator).
* Exports theme room definitions and callback functions used by dungeon.js
*
* GLOBALS EXPECTED AT RUNTIME (provided by dungeon.js execution context):
* - align: Array of alignment strings (shuffled at level generation)
* - nh: NetHack game state interface (nh.level_difficulty, nh.rn2, etc.)
* - pline: Print line function for debug messages
* - obj: Object creation interface (obj.new)
*/
import * as des from '../sp_lev.js';
import { selection, percent, shuffle, levelState, nh as nhGlobal, initLuaMT } from '../sp_lev.js';
import { rn2, rnd, lua_d as d, getRngLog, getRngCallCount } from '../rng.js';
import { setMtInitialized } from '../dungeon.js';
import { start_timer, spot_stop_timers } from '../timeout.js';
import { impossible, pline } from '../pline.js';
import { readobjnam } from '../objnam.js';
import { GLASS } from '../objects.js';
import { MELT_ICE_AWAY, TIMER_LEVEL, isok } from '../const.js';
import { envFlag } from '../runtime_env.js';
import { game } from '../gstate.js';
// Module-level state for postprocessing callbacks
let postprocess = [];
// Module-level depth tracking (set by themerooms_generate)
let _levelDepth = 1;
// NetHack global functions (Lua nh.* replacements)
// Use the global nh from sp_lev.js, but override level_difficulty to use our local depth tracking
// Note: Use getter to avoid circular dependency issues at module load time
const nh = {
get debug_themerm() { return nhGlobal.debug_themerm; },
level_difficulty: () => _levelDepth,
rn2: (n) => rn2(n),
// C ref: nhlua.c:1612-1635 nhl_timer_start_at
start_timer_at: (x, y, type, time) => {
if (type !== 'melt-ice') return;
if (!isok(x, y)) return;
if (!(time > 0)) return;
const where = (x << 16) | y;
spot_stop_timers(x, y, MELT_ICE_AWAY);
start_timer(time, TIMER_LEVEL, MELT_ICE_AWAY, where);
},
impossible: (msg) => impossible(msg),
};
// Stub other globals
const align = ['law', 'neutral', 'chaos']; // nhlib.lua default before shuffle
function currentAlign() {
const dnum = game.u?.uz?.dnum ?? 0;
const fromMklev = game._luathemes_align?.[dnum];
return (Array.isArray(fromMklev) && fromMklev.length >= 3) ? fromMklev : align;
}
const obj = {
// C ref: nhlobj.c l_obj_new_readobjnam() — obj.new("...") uses readobjnam.
new: async (id) => {
const name = String(id || '');
const otmp = await readobjnam(name, null);
if (!otmp) return null;
otmp.class = () => ({
material: (game.objects[otmp.otyp]?.oc_material === GLASS) ? 'glass' : 'unknown',
});
return otmp;
},
};
// Reset state between level generations
export function reset_state() {
postprocess = [];
_initialized = false;
themeroom_failed = false;
// CRITICAL: Reset debug mode flags between levels
debug_rm_idx = null;
debug_fill_idx = null;
}
// Themeroom failure flag (set when room creation fails in themed rooms)
// C ref: mklev.c themeroom_failed global
let themeroom_failed = false;
export function set_themeroom_failed() {
themeroom_failed = true;
}
export function get_themeroom_failed() {
return themeroom_failed;
}
// themeroom_fills: Contents that can fill any room shape
// Each entry defines "name", optional "frequency"/"mindiff"/"maxdiff"/"eligible", and "contents" function
export const themeroom_fills = [
{
name: "Ice room",
contents: async function(rm) {
const ice = selection.room();
await des.terrain(ice, "I");
if (percent(25)) {
const mintime = 1000 - (nh.level_difficulty() * 100);
const ice_melter = function(x,y) {
nh.start_timer_at(x,y, "melt-ice", mintime + nh.rn2(1000));
};
await ice.iterate(ice_melter);
}
},
},
{
name: "Cloud room",
contents: async function(rm) {
const fog = selection.room();
for (let i = 1; i <= Math.floor(fog.numpoints() / 4); i++) {
await des.monster({ id: "fog cloud", asleep: true });
}
await des.gas_cloud({ selection: fog });
},
},
{
name: "Boulder room",
mindiff: 4,
contents: async function(rm) {
const locs = selection.room().percentage(30);
const func = async function(x,y) {
if (percent(50)) {
await des.object("boulder", x, y);
} else {
await des.trap("rolling boulder", x, y);
}
};
await locs.iterate(func);
},
},
{
name: "Spider nest",
contents: async function(rm) {
const spooders = nh.level_difficulty() > 8;
const locs = selection.room().percentage(30);
const func = async function(x,y) {
await des.trap({ type: "web", x: x, y: y,
spider_on_web: spooders && percent(80) });
};
await locs.iterate(func);
},
},
{
name: "Trap room",
contents: async function(rm) {
const traps = [ "arrow", "dart", "falling rock", "bear",
"land mine", "sleep gas", "rust",
"anti magic" ];
shuffle(traps);
const locs = selection.room().percentage(30);
const func = async function(x,y) {
await des.trap(traps[0], x, y);
};
await locs.iterate(func);
},
},
{
name: "Garden",
eligible: function(rm) { return rm.lit === true; },
contents: async function(rm) {
const s = selection.room();
const npts = Math.floor(s.numpoints() / 6);
for (let i = 1; i <= npts; i++) {
await des.monster({ id: "wood nymph", asleep: true });
if (percent(30)) {
await des.feature("fountain");
}
}
postprocess.push({ handler: make_garden_walls,
data: { sel: selection.room() } });
}
},
{
name: "Buried treasure",
contents: async function(rm) {
await des.object({ id: "chest", buried: true, contents: async function(otmp) {
const xobj = otmp.totable ? otmp.totable() : otmp;
// keep track of the last buried treasure
if (xobj.NO_OBJ === undefined) {
postprocess.push({ handler: make_dig_engraving,
data: { x: xobj.ox, y: xobj.oy }});
}
const numObjects = d(3,4); // Evaluate once, not on every iteration
for (let i = 1; i <= numObjects; i++) {
await des.object();
}
} });
},
},
{
name: "Buried zombies",
contents: async function(rm) {
const diff = nh.level_difficulty()
// start with [1..4] for low difficulty
const zombifiable = [ "kobold", "gnome", "orc", "dwarf" ];
if (diff > 3) { // medium difficulty
zombifiable[4] = "elf";
zombifiable[5] = "human";
if (diff > 6) { // high difficulty (relatively speaking)
zombifiable[6] = "ettin";
zombifiable[7] = "giant";
}
}
for (let i = 1; i <= Math.floor((rm.width * rm.height) / 2); i++) {
shuffle(zombifiable);
const o = await des.object({ id: "corpse", montype: zombifiable[0],
buried: true });
if (o) {
o.stop_timer("rot-corpse");
o.start_timer("zombify-mon", rn2(21) + 990);
}
}
},
},
{
name: "Massacre",
contents: async function(rm) {
const mon = [ "apprentice", "warrior", "ninja", "thug",
"hunter", "acolyte", "abbot", "page",
"attendant", "neanderthal", "chieftain",
"student", "wizard", "valkyrie", "tourist",
"samurai", "rogue", "ranger", "priestess",
"priest", "monk", "knight", "healer",
"cavewoman", "caveman", "barbarian",
"archeologist" ];
let idx = rn2(mon.length);
const numCorpses = d(5,5); // Evaluate once, not on every iteration
for (let i = 1; i <= numCorpses; i++) {
if (percent(10)) { idx = rn2(mon.length); }
await des.object({ id: "corpse", montype: mon[idx] });
}
},
},
{
name: "Statuary",
contents: async function(rm) {
const numStatues = d(5,5); // Evaluate once, not on every iteration
for (let i = 1; i <= numStatues; i++) {
await des.object({ id: "statue" });
}
const numTraps = d(1, 3); // Evaluate once, not on every iteration
for (let i = 1; i <= numTraps; i++) {
await des.trap("statue");
}
},
},
{
name: "Light source",
eligible: function(rm) { return rm.lit === false; },
contents: async function(rm) {
await des.object({ id: "oil lamp", lit: true });
}
},
{
name: "Temple of the gods",
contents: async function(rm) {
const a = currentAlign();
await des.altar({ align: a[0] });
await des.altar({ align: a[1] });
await des.altar({ align: a[2] });
},
},
{
name: "Ghost of an Adventurer",
contents: async function(rm) {
const loc = selection.room().rndcoord(0);
await des.monster({ id: "ghost", asleep: true, waiting: true,
coord: loc });
if (percent(65)) {
await des.object({ id: "dagger", coord: loc, buc: "not-blessed" });
}
if (percent(55)) {
await des.object({ class: ")", coord: loc, buc: "not-blessed" });
}
if (percent(45)) {
await des.object({ id: "bow", coord: loc, buc: "not-blessed" });
await des.object({ id: "arrow", coord: loc, buc: "not-blessed" });
}
if (percent(65)) {
await des.object({ class: "[", coord: loc, buc: "not-blessed" });
}
if (percent(20)) {
await des.object({ class: "=", coord: loc, buc: "not-blessed" });
}
if (percent(20)) {
await des.object({ class: "?", coord: loc, buc: "not-blessed" });
}
},
},
{
name: "Storeroom",
contents: async function(rm) {
const locs = selection.room().percentage(30);
const func = async function(x,y) {
if (percent(25)) {
await des.object("chest");
} else {
await des.monster({ class: "m", appear_as: "obj:chest" });
}
};
await locs.iterate(func);
},
},
{
name: "Teleportation hub",
contents: async function(rm) {
const locs = selection.room().filter_mapchar(".");
// Lua numeric-for evaluates the upper bound once at loop entry.
const trapCount = 2 + rn2(3);
for (let i = 1; i <= trapCount; i++) {
const pos = locs.rndcoord(1);
if (pos && pos.x > 0) {
// C/Lua parity: themerms.lua uses rm.region.x1 - 1 for X and
// rm.region.y1 for Y when converting room-relative rndcoord().
const lx = Number.isFinite(rm?.lx)
? rm.lx
: (Number.isFinite(rm?.region?.x1) ? rm.region.x1 : 0);
const ly = Number.isFinite(rm?.ly)
? rm.ly
: (Number.isFinite(rm?.region?.y1) ? rm.region.y1 : 0);
pos.x = pos.x + lx - 1;
pos.y = pos.y + ly;
postprocess.push({ handler: make_a_trap,
data: { type: "teleport", seen: true,
coord: pos, teledest: 1 } });
}
}
},
},
]; // End themeroom_fills
// themerooms: Complete room definitions (shape + contents)
// Each entry defines "name", optional "frequency"/"mindiff"/"maxdiff"/"eligible", and "contents" function
export const themerooms = [
{
name: "default",
frequency: 1000,
contents: async function() {
await des.makeRoom({ type: "ordinary", filled: 1 });
}
},
{
name: "Fake Delphi",
contents: async function() {
await des.makeRoom({ type: "ordinary", w: 11, h: 9, filled: 1,
contents: async function() {
await des.makeRoom({ type: "ordinary", x: 4, y: 3, w: 3, h: 3,
filled: 1,
contents: async function() {
await des.door({ state: "random", wall: "all" });
}
});
}
});
},
},
{
name: "Room in a room",
contents: async function() {
await des.makeRoom({ type: "ordinary", filled: 1,
contents: async function() {
await des.makeRoom({ type: "ordinary",
contents: async function() {
await des.door({ state: "random", wall: "all" });
}
});
}
});
},
},
{
name: "Huge room with another room inside",
contents: async function() {
await des.makeRoom({ type: "ordinary", w: rn2(10)+11, h: rn2(5)+8,
filled: 1,
contents: async function() {
if (percent(90)) {
await des.makeRoom({ type: "ordinary", filled: 1,
contents: async function() {
await des.door({ state: "random", wall: "all" });
if (percent(50)) {
await des.door({ state: "random", wall: "all" });
}
}
});
}
}
});
},
},
{
name: "Nesting rooms",
contents: async function() {
await des.makeRoom({ type: "ordinary", w: 9 + rn2(4), h: 9 + rn2(4),
filled: 1,
contents: async function(rm) {
// Lua: math.random(floor(rm.width/2), rm.width-2) -> rn2(range)+min
const minWid = Math.floor(rm.width / 2);
const maxWid = rm.width - 2;
const wid = rn2(maxWid - minWid + 1) + minWid;
const minHei = Math.floor(rm.height / 2);
const maxHei = rm.height - 2;
const hei = rn2(maxHei - minHei + 1) + minHei;
await des.makeRoom({ type: "ordinary", w: wid, h: hei, filled: 1,
contents: async function() {
if (percent(90)) {
await des.makeRoom({ type: "ordinary", filled: 1,
contents: async function() {
await des.door({ state: "random", wall: "all" });
if (percent(15)) {
await des.door({ state: "random", wall: "all" });
}
}
});
}
await des.door({ state: "random", wall: "all" });
if (percent(15)) {
await des.door({ state: "random", wall: "all" });
}
}
});
}
});
},
},
{
name: "Default room with themed fill",
frequency: 6,
contents: async function() {
await des.makeRoom({ type: "themed", contents: themeroom_fill });
}
},
{
name: "Unlit room with themed fill",
frequency: 2,
contents: async function() {
await des.makeRoom({ type: "themed", lit: 0, contents: themeroom_fill });
}
},
{
name: "Room with both normal contents and themed fill",
frequency: 2,
contents: async function() {
await des.makeRoom({ type: "themed", filled: 1, contents: themeroom_fill });
}
},
{
name: 'Pillars',
contents: async function() {
const DEBUG = envFlag('DEBUG_THEMEROOMS');
if (DEBUG) console.log('Pillars: outer contents() called, about to call await des.makeRoom()');
await des.makeRoom({ type: "themed", w: 10, h: 10,
contents: async function(rm) {
if (DEBUG) console.log(`Pillars: inner contents() called for room at (${rm.lx},${rm.ly}), about to shuffle`);
const terr = [ "-", "-", "-", "-", "L", "P", "T" ];
shuffle(terr);
if (DEBUG) console.log('Pillars: shuffle complete, terr=', terr);
for (let x = 0; x < Math.floor(rm.width / 4); x++) {
for (let y = 0; y < Math.floor(rm.height / 4); y++) {
await des.terrain({ x: x * 4 + 2, y: y * 4 + 2, typ: terr[0], lit: -2 });
await des.terrain({ x: x * 4 + 3, y: y * 4 + 2, typ: terr[0], lit: -2 });
await des.terrain({ x: x * 4 + 2, y: y * 4 + 3, typ: terr[0], lit: -2 });
await des.terrain({ x: x * 4 + 3, y: y * 4 + 3, typ: terr[0], lit: -2 });
}
}
}
});
if (DEBUG) console.log('Pillars: outer contents() returning');
},
},
{
name: 'Mausoleum',
contents: async function() {
await des.makeRoom({ type: "themed", w: 5 + rn2(3)*2, h: 5 + rn2(3)*2,
contents: async function(rm) {
await des.makeRoom({ type: "themed",
x: Math.floor((rm.width - 1) / 2), y: Math.floor((rm.height - 1) / 2),
w: 1, h: 1, joined: false,
contents: async function() {
if (percent(50)) {
const mons = [ "M", "V", "L", "Z" ];
shuffle(mons);
await des.monster({ class: mons[0], x: 0, y: 0, waiting: 1 });
} else {
await des.object({ id: "corpse", montype: "@", coord: [0, 0] });
}
if (percent(20)) {
await des.door({ state: "secret", wall: "all" });
}
}
});
}
});
},
},
{
name: 'Random dungeon feature in the middle of an odd-sized room',
contents: async function() {
const wid = 3 + (rn2(3) * 2);
const hei = 3 + (rn2(3) * 2);
await des.makeRoom({ type: "ordinary", filled: 1, w: wid, h: hei,
contents: async function(rm) {
const feature = [ "C", "L", "I", "P", "T" ];
shuffle(feature);
await des.terrain(Math.floor((rm.width - 1) / 2), Math.floor((rm.height - 1) / 2),
feature[0]);
}
});
},
},
{
name: 'L-shaped',
contents: async function() {
await des.map({ map: `
-----xxx
|...|xxx
|...|xxx
|...----
|......|
|......|
|......|
--------
`, contents: async function(m) { await filler_region(1, 1); } });
},
},
{
name: 'L-shaped, rot 1',
contents: async function() {
await des.map({ map: `
xxx-----
xxx|...|
xxx|...|
----...|
|......|
|......|
|......|
--------
`, contents: async function(m) { await filler_region(5, 1); } });
},
},
{
name: 'L-shaped, rot 2',
contents: async function() {
await des.map({ map: `
--------
|......|
|......|
|......|
----...|
xxx|...|
xxx|...|
xxx-----
`, contents: async function(m) { await filler_region(1, 1); } });
},
},
{
name: 'L-shaped, rot 3',
contents: async function() {
await des.map({ map: `
--------
|......|
|......|
|......|
|...----
|...|xxx
|...|xxx
-----xxx
`, contents: async function(m) { await filler_region(1, 1); } });
},
},
{
name: 'Blocked center',
contents: async function() {
await des.map({ map: `
-----------
|.........|
|.........|
|.........|
|...LLL...|
|...LLL...|
|...LLL...|
|.........|
|.........|
|.........|
-----------
`, contents: async function(m) {
if (percent(30)) {
const terr = [ "-", "P" ];
shuffle(terr);
await des.replace_terrain({ region: [1, 1, 9, 9],
fromterrain: "L",
toterrain: terr[0] });
}
await filler_region(1, 1);
} });
},
},
{
name: 'Circular, small',
contents: async function() {
await des.map({ map: `
xx---xx
x--.--x
--...--
|.....|
--...--
x--.--x
xx---xx
`, contents: async function(m) { await filler_region(3, 3); } });
},
},
{
name: 'Circular, medium',
contents: async function() {
await des.map({ map: `
xx-----xx
x--...--x
--.....--
|.......|
|.......|
|.......|
--.....--
x--...--x
xx-----xx
`, contents: async function(m) { await filler_region(4, 4); } });
},
},
{
name: 'Circular, big',
contents: async function() {
await des.map({ map: `
xxx-----xxx
x---...---x
x-.......-x
--.......--
|.........|
|.........|
|.........|
--.......--
x-.......-x
x---...---x
xxx-----xxx
`, contents: async function(m) { await filler_region(5, 5); } });
},
},
{
name: 'T-shaped',
contents: async function() {
await des.map({ map: `
xxx-----xxx
xxx|...|xxx
xxx|...|xxx
----...----
|.........|
|.........|
|.........|
-----------
`, contents: async function(m) { await filler_region(5, 5); } });
},
},
{
name: 'T-shaped, rot 1',
contents: async function() {
await des.map({ map: `
-----xxx
|...|xxx
|...|xxx
|...----
|......|
|......|
|......|
|...----
|...|xxx
|...|xxx
-----xxx
`, contents: async function(m) { await filler_region(2, 2); } });
},
},
{
name: 'T-shaped, rot 2',
contents: async function() {
await des.map({ map: `
-----------
|.........|
|.........|
|.........|
----...----
xxx|...|xxx
xxx|...|xxx
xxx-----xxx
`, contents: async function(m) { await filler_region(2, 2); } });
},
},
{
name: 'T-shaped, rot 3',
contents: async function() {
await des.map({ map: `
xxx-----
xxx|...|
xxx|...|
----...|
|......|
|......|
|......|
----...|
xxx|...|
xxx|...|
xxx-----
`, contents: async function(m) { await filler_region(5, 5); } });
},
},
{
name: 'S-shaped',
contents: async function() {
await des.map({ map: `
-----xxx
|...|xxx
|...|xxx
|...----
|......|
|......|
|......|
----...|
xxx|...|
xxx|...|
xxx-----
`, contents: async function(m) { await filler_region(2, 2); } });
},
},
{
name: 'S-shaped, rot 1',
contents: async function() {
await des.map({ map: `
xxx--------
xxx|......|
xxx|......|
----......|
|......----
|......|xxx
|......|xxx
--------xxx
`, contents: async function(m) { await filler_region(5, 5); } });
},
},
{
name: 'Z-shaped',
contents: async function() {
await des.map({ map: `xxx-----
xxx|...|
xxx|...|
----...|
|......|
|......|
|......|
|...----
|...|xxx
|...|xxx
-----xxx
`, contents: async function(m) { await filler_region(5, 5); } });
},
},
{
name: 'Z-shaped, rot 1',
contents: async function() {
await des.map({ map: `
--------xxx
|......|xxx
|......|xxx
|......----
----......|
xxx|......|
xxx|......|
xxx--------
`, contents: async function(m) { await filler_region(2, 2); } });
},
},
{
name: 'Cross',
contents: async function() {
await des.map({ map: `
xxx-----xxx
xxx|...|xxx
xxx|...|xxx
----...----
|.........|
|.........|
|.........|
----...----
xxx|...|xxx
xxx|...|xxx
xxx-----xxx
`, contents: async function(m) { await filler_region(6, 6); } });
},
},
{
name: 'Four-leaf clover',
contents: async function() {
await des.map({ map: `
-----x-----
|...|x|...|
|...---...|
|.........|
---.....---
xx|.....|xx
---.....---
|.........|
|...---...|
|...|x|...|
-----x-----
`, contents: async function(m) { await filler_region(6, 6); } });
},
},
{
name: 'Water-surrounded vault',
contents: async function() {
await des.map({ map: `
}}}}}}
}----}
}|..|}
}|..|}
}----}
}}}}}}
`, contents: async function(m) {
await des.region({ region: [3, 3, 3, 3], type: "themed", irregular: true,
filled: 0, joined: false });
const nasty_undead = [ "giant zombie", "ettin zombie", "vampire lord" ];
const chest_spots = [ [ 2, 2 ], [ 3, 2 ], [ 2, 3 ], [ 3, 3 ] ];
shuffle(chest_spots)
// Guarantee an escape item inside one of the chests, to prevent
// the hero falling in from above and becoming permanently stuck
// [cf. generate_way_out_method(sp_lev.c)].
// If the escape item is made of glass or crystal, make sure that
// the chest isn't locked so that kicking it to gain access to its
// contents won't be necessary; otherwise retain lock state from
// random creation.
// "pick-axe", "dwarvish mattock" could be included in the list of
// escape items but don't normally generate in containers.
const escape_items = [
"scroll of teleportation", "ring of teleportation",
"wand of teleportation", "wand of digging"
];
// C ref: themerms.lua uses obj.new(...) here, then box:addcontent(itm).
// This consumes readobjnam RNG before chest creation.
const itm = await obj.new(escape_items[rn2(escape_items.length)]);
const box = await des.object({
id: "chest",
coord: chest_spots[0],
});
if (box && itm) {
if (!Array.isArray(box.contents)) box.contents = [];
box.contents.push(itm);
}
for (let i = 1; i < chest_spots.length; i++) {
await des.object({ id: "chest", coord: chest_spots[i] });
}
shuffle(nasty_undead);
await des.monster(nasty_undead[0], 2, 2);
await des.exclusion({ type: "teleport", region: [ 2, 2, 3, 3 ] });
} });
},
},
{
name: 'Twin businesses',
mindiff: 4, // arbitrary
contents: async function() {
// Due to the way room connections work in mklev.c, we must guarantee
// that the "aisle" between the shops touches all four walls of the
// larger room. Thus it has an extra width and height.
await des.makeRoom({ type: "themed", w: 9, h: 5, contents: async function() {
// There are eight possible placements of the two shops, four of
// which have the vertical aisle in the center.
const southeast = function() { return percent(50) ? "south" : "east"; }
const northeast = function() { return percent(50) ? "north" : "east"; }
const northwest = function() { return percent(50) ? "north" : "west"; }
const southwest = function() { return percent(50) ? "south" : "west"; }
const placements = [
{ lx: 1, ly: 1, rx: 4, ry: 1, lwall: "south", rwall: southeast() },
{ lx: 1, ly: 2, rx: 4, ry: 2, lwall: "north", rwall: northeast() },
{ lx: 1, ly: 1, rx: 5, ry: 1, lwall: southeast(), rwall: southwest() },
{ lx: 1, ly: 1, rx: 5, ry: 2, lwall: southeast(), rwall: northwest() },
{ lx: 1, ly: 2, rx: 5, ry: 1, lwall: northeast(), rwall: southwest() },
{ lx: 1, ly: 2, rx: 5, ry: 2, lwall: northeast(), rwall: northwest() },
{ lx: 2, ly: 1, rx: 5, ry: 1, lwall: southwest(), rwall: "south" },
{ lx: 2, ly: 2, rx: 5, ry: 2, lwall: northwest(), rwall: "north" }
];
let ltype = "weapon shop", rtype = "armor shop";
if (percent(50)) {
[ltype, rtype] = [rtype, ltype];
}
const shopdoorstate = function() {
if (percent(1)) {
return "locked";
} else if (percent(50)) {
return "closed";
} else {
return "open";
}
}
const p = placements[d(1, placements.length) - 1];
await des.makeRoom({ type: ltype, x: p["lx"], y: p["ly"], w: 3, h: 3, filled: 1, joined: false,
contents: async function() {
await des.door({ state: shopdoorstate(), wall: p["lwall"] })
}
});
await des.makeRoom({ type: rtype, x: p["rx"], y: p["ry"], w: 3, h: 3, filled: 1, joined: false,
contents: async function() {
await des.door({ state: shopdoorstate(), wall: p["rwall"] })
}
});
}
});
}
},
]; // End themerooms
// Store these at module scope, they will be reinitialized in pre_themerooms_generate
let debug_rm_idx = null;
let debug_fill_idx = null;
// Track whether themerms has been initialized for current level
let _initialized = false;
// Given a point in a themed room, ensure that themed room is stocked with
// regular room contents.
// With 30% chance, also give it a random themed fill.
async function filler_region(x, y) {
let rmtyp = "ordinary";
let func = null;
if (percent(30)) {
rmtyp = "themed";
func = themeroom_fill;
}
await des.region({ region: [x, y, x, y], type: rmtyp, irregular: true, filled: 1, contents: func });
}
function is_eligible(room, mkrm) {
const t = typeof room;
const diff = nh.level_difficulty();
if (room.mindiff !== undefined && diff < room.mindiff) {
return false;
} else if (room.maxdiff !== undefined && diff > room.maxdiff) {
return false;
}
if (mkrm !== undefined && room.eligible !== undefined) {
return room.eligible(mkrm);
}
return true;
}
// given the name of a themed room or fill, return its index in that array
function lookup_by_name(name, checkfills) {
if (name === undefined || name === null) {
return null;
}
if (checkfills) {
for (let i = 0; i < themeroom_fills.length; i++) {
if (themeroom_fills[i].name === name) {
return i;
}
}
} else {
for (let i = 0; i < themerooms.length; i++) {
if (themerooms[i].name === name) {
return i;
}
}
}
return null;
}
// called repeatedly until the core decides there are enough rooms
export async function themerooms_generate(map, depth) {
_levelDepth = depth; // Update module-level depth for nh.level_difficulty()
// C ref: In Lua, the MT init pattern (rn2(1000-1004), rn2(1010), etc.) is NOT a separate
// initialization - it's the reservoir sampling itself! Each eligible room calls
// rn2(total_frequency), which naturally produces the 1000, 1001, 1002, ... sequence.
// NO separate initLuaMT() call needed here.
// C ref: mklev.c:404 — reset failure flag before calling Lua themerooms_generate
themeroom_failed = false;
// First-time initialization for this level: shuffle align and init Lua MT RNG
if (!_initialized) {
await pre_themerooms_generate();
_initialized = true;
}
if (debug_rm_idx !== null) {
// room may not be suitable for stairs/portals, so create the "default"
// room half of the time
// (if the user specified BOTH a room and a fill, presumably they are
// interested in what happens when that room gets that fill, so don't
// bother generating default-with-fill rooms as happens below)
let actualrm = lookup_by_name("default", false);
if (percent(50)) {
if (is_eligible(themerooms[debug_rm_idx])) {
actualrm = debug_rm_idx;
} else {
await pline("Warning: themeroom '" + themerooms[debug_rm_idx].name
+ "' is ineligible");
}
}
await themerooms[actualrm].contents();
return true;
} else if (debug_fill_idx !== null) {
// when a fill is requested but not a room, still create the "default"
// room half of the time, and "default with themed fill" half of the time
// (themeroom_fill will take care of guaranteeing the fill in it)
const actualrm = lookup_by_name(percent(50) ? "Default room with themed fill"
: "default", false);
await themerooms[actualrm].contents();
return true;
}
let pick = null;
let total_frequency = 0;
const themerooms_count = themerooms.length;
let eligible_count = 0;
for (let i = 0; i < themerooms.length; i++) {
if (typeof themerooms[i] !== "object") {
nh.impossible('themed room ' + i + ' is not a table');
} else if (is_eligible(themerooms[i], null)) {
eligible_count++;
// Reservoir sampling: select one room from the set of eligible rooms,
// which may change on different levels because of level difficulty.
let this_frequency;
if (themerooms[i].frequency !== undefined) {
this_frequency = themerooms[i].frequency;
} else {
this_frequency = 1;
}
total_frequency = total_frequency + this_frequency;
// C ref: Lua themerms.lua:969 uses nh.rn2() for reservoir sampling (LOGGED, not invisible)
// Algorithm: if (rn2(total_frequency) < this_frequency) pick = i
// This is mathematically equivalent to: if (random() < this_frequency / total_frequency)
// but uses integer RNG so it appears in the RNG trace
if (this_frequency > 0) {
const randValue = rn2(total_frequency);
const DEBUG_RESERVOIR = envFlag('DEBUG_RESERVOIR');
if (DEBUG_RESERVOIR) {
console.log(` Room ${i} (${themerooms[i].name || 'unnamed'}): rn2(${total_frequency})=${randValue}, this_freq=${this_frequency}, total=${total_frequency}, pick=${randValue < this_frequency ? 'YES' : 'no'}`);
}
if (randValue < this_frequency) {
pick = i;
}
}
}
}
if (themerooms_count > 100) {
console.log(`themerooms_generate: ${themerooms_count} total themerooms, ${eligible_count} eligible`);
}
if (pick === null) {
nh.impossible('no eligible themed rooms?');
return false;
}
// Mark MT as initialized after reservoir sampling to prevent lazy init
// The reservoir sampling consumed the MT init pattern (rn2(1000-1036) calls)
// Set luaRngCounter=37 to match C's state after MT init (see sp_lev.js:237)
if (levelState && levelState.luaRngCounter === 0) {
levelState.luaRngCounter = 37;
}
const DEBUG_THEME = envFlag('DEBUG_THEMEROOMS');
if (DEBUG_THEME) {
console.log(`Selected themed room [${pick}]: "${themerooms[pick].name}"`);
}
const rngLog = getRngLog();
const rngBefore = rngLog ? rngLog.length : 0;
// Set up failure callback so await des.makeRoom() can signal when it can't create a room
// This bridges the sp_lev → themerms communication without circular dependency
levelState.roomFailureCallback = () => { themeroom_failed = true; };
// Debug: Log which themed room was selected
const DEBUG_SELECTION = envFlag('DEBUG_THEMERM_SELECT');
if (DEBUG_SELECTION) {
const rngCount = typeof getRngCallCount === 'function' ? getRngCallCount() : '?';
console.log(`\n[RNG ${rngCount}] Selected themed room #${pick}: ${themerooms[pick].name || 'default'}`);
}
try {
await themerooms[pick].contents();
} finally {
// Always clear the callback after contents() completes
levelState.roomFailureCallback = null;
}
const rngAfter = rngLog ? getRngLog().length : 0;
// Disabled: too spammy during investigation
// if (rngLog && rngAfter - rngBefore > 100) {
// console.log(`themerooms[${pick}].contents() consumed ${rngAfter - rngBefore} RNG calls (name: ${themerooms[pick].name})`);
// }
// C ref: mklev.c:408 — return failure if theme room creation failed
// The contents() function calls await des.makeRoom() which sets themeroom_failed flag on failure
return !themeroom_failed;
}
// called before any rooms are generated
let _mtInitCount = 0;
export async function pre_themerooms_generate() {
const DEBUG = envFlag('DEBUG_LUA_RNG');
// C ref: MT initialization happens lazily on first Lua RNG call (des.object/des.monster),
// NOT here in pre_themerooms_generate(). Removing MT init from here to match C timing.
// Theme selection happens BEFORE MT init in C (calls 260-261 vs 263-292 in seed 4).
_mtInitCount++;
if (DEBUG) {
console.log(`\n[pre_themerooms_generate] luaRngCounter: ${levelState ? levelState.luaRngCounter : 'no levelState'}`);
}
// NOTE: MT init removed - now handled lazily in sp_lev.js des.object/des.monster
const debug_themerm = nh.debug_themerm(false);
const debug_fill = nh.debug_themerm(true);
let xtrainfo = "";
debug_rm_idx = lookup_by_name(debug_themerm, false);
debug_fill_idx = lookup_by_name(debug_fill, true);
if (debug_themerm !== null && debug_rm_idx === null) {
if (lookup_by_name(debug_themerm, true) !== null) {
xtrainfo = "; it is a fill type";
}
await pline("Warning: themeroom '" + debug_themerm
+ "' not found in themerooms" + xtrainfo, true);
}
if (debug_fill !== null && debug_fill_idx === null) {
if (lookup_by_name(debug_fill, false) !== null) {
xtrainfo = "; it is a room type";
}
await pline("Warning: themeroom fill '" + debug_fill
+ "' not found in themeroom_fills" + xtrainfo, true);
}
}
// called after all rooms have been generated
// but before creating connecting corridors/doors, or filling rooms
export function post_themerooms_generate() {
}
export async function themeroom_fill(rm) {
const DEBUG = envFlag('DEBUG_THEMEROOMS');
// C parity: Lua mkroom table exposes room dimensions; ensure callbacks
// relying on rm.width/rm.height/lit behave consistently.
if (rm && !Number.isFinite(rm.width)
&& Number.isFinite(rm.lx) && Number.isFinite(rm.hx)) {
rm.width = (rm.hx - rm.lx + 1);
}
if (rm && !Number.isFinite(rm.height)
&& Number.isFinite(rm.ly) && Number.isFinite(rm.hy)) {
rm.height = (rm.hy - rm.ly + 1);
}
if (rm && typeof rm.lit !== 'boolean') {
if (rm.rlit === 0 || rm.rlit === false) {
rm.lit = false;
} else if (rm.rlit === 1 || rm.rlit === true) {
rm.lit = true;
}
}
if (DEBUG) {
console.log(`themeroom_fill() called for room at (${rm.lx},${rm.ly})`);
}
if (debug_fill_idx !== null) {
if (is_eligible(themeroom_fills[debug_fill_idx], rm)) {
des.setCurrentRoom(rm);
await themeroom_fills[debug_fill_idx].contents(rm);
des.setCurrentRoom(null);
} else{
// ideally this would be a debugpline, not a full pline, and offer
// some more context on whether it failed because of difficulty or
// because of eligible function returning false; the warning doesn't
// necessarily mean anything.
await pline("Warning: fill '" + themeroom_fills[debug_fill_idx].name
+ "' is not eligible in room that generated it");
}
return;
}
let pick = null;
let total_frequency = 0;
let eligible_count = 0;
for (let i = 0; i < themeroom_fills.length; i++) {
if (typeof themeroom_fills[i] !== "object") {
nh.impossible('themeroom fill ' + i + ' must be a table');
} else if (is_eligible(themeroom_fills[i], rm)) {
eligible_count++;
// Reservoir sampling: select one room from the set of eligible rooms,
// which may change on different levels because of level difficulty.
let this_frequency;
if (themeroom_fills[i].frequency !== undefined) {
this_frequency = themeroom_fills[i].frequency;
} else {
this_frequency = 1;
}
total_frequency = total_frequency + this_frequency;
// avoid rn2(0) if a fill has freq 0
if (this_frequency > 0 && rn2(total_frequency) < this_frequency) {
pick = i;
}
}
}
if (pick === null) {
nh.impossible('no eligible themed room fills?');
return;
}
// Debug: Log which themed room was selected
if (envFlag('DEBUG_THEMERM_EXEC')) {
console.log(`\n=== Executing themed room fill: ${themeroom_fills[pick].name} ===`);
}
des.setCurrentRoom(rm);
await themeroom_fills[pick].contents(rm);
des.setCurrentRoom(null);
}
// postprocess callback: create an engraving pointing at a location
async function make_dig_engraving(data) {
const floors = selection.negate().filter_mapchar(".");
const pos = floors.rndcoord(0);
const tx = data.x - pos.x - 1;
const ty = data.y - pos.y;
let dig = "";
if (tx === 0 && ty === 0) {
dig = " here";
} else {
if (tx < 0 || tx > 0) {
dig = ` ${Math.abs(tx)} ${(tx > 0) ? "east" : "west"}`;
}
if (ty < 0 || ty > 0) {
dig = dig + ` ${Math.abs(ty)} ${(ty > 0) ? "south" : "north"}`;
}
}
await des.engraving({ coord: pos, type: "burn", text: "Dig" + dig });
}
// postprocess callback: turn room walls into trees
async function make_garden_walls(data) {
const sel = data.sel.grow();
// change walls to trees
await des.replace_terrain({ selection: sel, fromterrain: "w", toterrain: "T" });
// update secret doors; attempting to change to AIR will set arboreal flag
await des.replace_terrain({ selection: sel, fromterrain: "S", toterrain: "A" });
}
// postprocess callback: make a trap
async function make_a_trap(data) {
if (data.teledest === 1 && data.type === "teleport") {
const locs = selection.negate().filter_mapchar(".");
do {
data.teledest = locs.rndcoord(1);
} while (data.teledest.x === data.coord.x || data.teledest.y === data.coord.y);
}
await des.trap(data);
}
// called once after the whole level has been generated
export async function themerooms_post_level_generate() {
for (const v of postprocess) {
await v.handler(v.data);
}
postprocess = [];
}
|