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 | 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 27x 27x 12x 12x 12x 12x 27x 15x 15x 15x 15x 15x 27x 73x 73x 27x 27x 27x 27x 27x 27x 15x 15x 2x 2x 15x 13x 13x 13x 13x 13x 13x 13x 13x 15x 15x 15x 15x 3x 3x 15x 12x 12x 12x 12x 12x 12x 12x 15x 27x 12x 12x 2x 2x 12x 10x 10x 10x 10x 10x 10x 10x 12x 12x 12x 12x 1x 1x 12x 11x 11x 11x 11x 11x 11x 11x 12x 12x 27x 73x 73x 30x 30x 30x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 27x 27x 57x 57x 57x 57x 57x 27x 27x 30x 73x 73x 73x 3x 3x 3x 9x 27x 27x 9x 3x 3x 3x 3x 3x 9x 27x 5x 5x 5x 5x 27x 22x 22x 22x 22x 22x 22x 22x 22x 27x 27x 9x 3x 3x 3x 3x 3x 9x 27x 22x 22x 22x 22x 22x 22x 22x 22x 27x 9x 3x 3x 3x 9x 27x 27x 27x 9x 3x 73x 73x 73x 383x 383x 383x 383x 73x 73x 73x 73x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x | // extralev.js — Rogue-style level generation (port of extralev.c)
// Creates the rogue dungeon level with a 3x3 grid of rooms.
import { game } from './gstate.js';
import { rn1, rn2, rnd } from './rng.js';
import { CORR, SCORR, IS_WALL, D_NODOOR } from './const.js';
import { FOOD_RATION, MACE, TWO_HANDED_SWORD, BOW, ARROW,
RING_MAIL, PLATE_MAIL, FAKE_AMULET_OF_YENDOR,
} from './objects.js';
import { PM_GHOST } from './monsters.js';
import { mksobj_at, curse, weight } from './mkobj.js';
import { makemon } from './makemon.js';
import { mons } from './monsters.js';
import { add_room, dodoor } from './mklev.js';
import { roguename } from './do_name.js';
import { somex, somey } from './mkroom.js';
const XL_UP = 1, XL_DOWN = 2, XL_LEFT = 4, XL_RIGHT = 8;
// C ref: extralev.c:19 roguejoin — connect two points with corridors
function roguejoin(x1, y1, x2, y2, horiz) {
if (horiz) {
const middle = x1 + rn2(x2 - x1 + 1);
for (let x = Math.min(x1, middle); x <= Math.max(x1, middle); x++) corr(x, y1);
for (let y = Math.min(y1, y2); y <= Math.max(y1, y2); y++) corr(middle, y);
for (let x = Math.min(middle, x2); x <= Math.max(middle, x2); x++) corr(x, y2);
} else {
const middle = y1 + rn2(y2 - y1 + 1);
for (let y = Math.min(y1, middle); y <= Math.max(y1, middle); y++) corr(x1, y);
for (let x = Math.min(x1, x2); x <= Math.max(x1, x2); x++) corr(x, middle);
for (let y = Math.min(middle, y2); y <= Math.max(middle, y2); y++) corr(x2, y);
}
}
// C ref: extralev.c:44 roguecorr — create corridor between adjacent grid cells
async function roguecorr(x, y, dir) {
const r = game._rogueRooms;
const map = game.level;
let fromx, fromy, tox, toy;
if (dir === XL_DOWN) {
r[x][y].doortable &= ~XL_DOWN;
if (!r[x][y].real) {
fromx = r[x][y].rlx + 1 + 26 * x;
fromy = r[x][y].rly + 7 * y;
} else {
fromx = r[x][y].rlx + rn2(r[x][y].dx) + 1 + 26 * x;
fromy = r[x][y].rly + r[x][y].dy + 7 * y;
// C ref: extralev.c:63-64 — create door then override to D_NODOOR
await dodoor(fromx, fromy, game.level?.rooms?.[r[x][y].nroom]);
const loc = map.at(fromx, fromy);
if (loc) { loc.doormask = D_NODOOR; }
fromy++;
}
if (y >= 2) return;
y++;
r[x][y].doortable &= ~XL_UP;
if (!r[x][y].real) {
tox = r[x][y].rlx + 1 + 26 * x;
toy = r[x][y].rly + 7 * y;
} else {
tox = r[x][y].rlx + rn2(r[x][y].dx) + 1 + 26 * x;
toy = r[x][y].rly - 1 + 7 * y;
await dodoor(tox, toy, game.level?.rooms?.[r[x][y].nroom]);
const loc = map.at(tox, toy);
if (loc) { loc.doormask = D_NODOOR; }
toy--;
}
roguejoin(fromx, fromy, tox, toy, false);
} else if (dir === XL_RIGHT) {
r[x][y].doortable &= ~XL_RIGHT;
if (!r[x][y].real) {
fromx = r[x][y].rlx + 1 + 26 * x;
fromy = r[x][y].rly + 7 * y;
} else {
fromx = r[x][y].rlx + r[x][y].dx + 1 + 26 * x;
fromy = r[x][y].rly + rn2(r[x][y].dy) + 7 * y;
await dodoor(fromx, fromy, game.level?.rooms?.[r[x][y].nroom]);
const loc = map.at(fromx, fromy);
if (loc) { loc.doormask = D_NODOOR; }
fromx++;
}
if (x >= 2) return;
x++;
r[x][y].doortable &= ~XL_LEFT;
if (!r[x][y].real) {
tox = r[x][y].rlx + 1 + 26 * x;
toy = r[x][y].rly + 7 * y;
} else {
tox = r[x][y].rlx - 1 + 1 + 26 * x;
toy = r[x][y].rly + rn2(r[x][y].dy) + 7 * y;
await dodoor(tox, toy, game.level?.rooms?.[r[x][y].nroom]);
const loc = map.at(tox, toy);
if (loc) { loc.doormask = D_NODOOR; }
tox--;
}
roguejoin(fromx, fromy, tox, toy, true);
}
}
// C ref: extralev.c:138 miniwalk — connect grid cells via random walk
function miniwalk(x, y) {
const r = game._rogueRooms;
while (true) {
let q = 0;
const dirs = [];
const doorhere = () => r[x][y].doortable;
const setDoor = (flag) => { r[x][y].doortable |= flag; };
if (x > 0 && !(doorhere() & XL_LEFT)
&& (!r[x - 1][y].doortable || !rn2(10)))
dirs[q++] = 0;
if (x < 2 && !(doorhere() & XL_RIGHT)
&& (!r[x + 1][y].doortable || !rn2(10)))
dirs[q++] = 1;
if (y > 0 && !(doorhere() & XL_UP)
&& (!r[x][y - 1].doortable || !rn2(10)))
dirs[q++] = 2;
if (y < 2 && !(doorhere() & XL_DOWN)
&& (!r[x][y + 1].doortable || !rn2(10)))
dirs[q++] = 3;
if (!q) return;
const dir = dirs[rn2(q)];
switch (dir) {
case 0: setDoor(XL_LEFT); x--; r[x][y].doortable |= XL_RIGHT; break;
case 1: setDoor(XL_RIGHT); x++; r[x][y].doortable |= XL_LEFT; break;
case 2: setDoor(XL_UP); y--; r[x][y].doortable |= XL_DOWN; break;
case 3: setDoor(XL_DOWN); y++; r[x][y].doortable |= XL_UP; break;
}
miniwalk(x, y);
}
}
// C ref: extralev.c:192 makeroguerooms — create rogue-style 3x3 room grid
export async function makeroguerooms() {
const g = game;
// Initialize 3x3 grid of room descriptors
const r = Array.from({ length: 3 }, () =>
Array.from({ length: 3 }, () => ({
real: false, rlx: 0, rly: 0, dx: 0, dy: 0,
doortable: 0, nroom: -1,
}))
);
g._rogueRooms = r;
g.level.nroom = 0;
for (let y = 0; y < 3; y++) {
for (let x = 0; x < 3; x++) {
if (!rn2(5) && (g.level.nroom || (x < 2 && y < 2))) {
// Dummy room (intersection)
r[x][y].real = false;
r[x][y].rlx = rn1(22, 2);
r[x][y].rly = rn1((y === 2) ? 4 : 3, 2);
} else {
// Real room
r[x][y].real = true;
r[x][y].dx = rn1(22, 2);
r[x][y].dy = rn1((y === 2) ? 4 : 3, 2);
r[x][y].rlx = rnd(23 - r[x][y].dx + 1);
r[x][y].rly = rnd(((y === 2) ? 5 : 4) - r[x][y].dy + 1);
g.level.nroom++;
}
r[x][y].doortable = 0;
}
}
miniwalk(rn2(3), rn2(3));
g.level.nroom = 0;
for (let y = 0; y < 3; y++) {
for (let x = 0; x < 3; x++) {
if (r[x][y].real) {
r[x][y].nroom = g.level.nroom;
if (g.smeq) g.smeq[g.level.nroom] = g.level.nroom;
const lowx = 1 + 26 * x + r[x][y].rlx;
const lowy = 7 * y + r[x][y].rly;
const hix = 1 + 26 * x + r[x][y].rlx + r[x][y].dx - 1;
const hiy = 7 * y + r[x][y].rly + r[x][y].dy - 1;
add_room(lowx, lowy, hix, hiy, !rn2(7), 0/*OROOM*/, false);
}
}
}
// Connect rooms with corridors
for (let y = 0; y < 3; y++) {
for (let x = 0; x < 3; x++) {
if (r[x][y].doortable & XL_DOWN) await roguecorr(x, y, XL_DOWN);
if (r[x][y].doortable & XL_RIGHT) await roguecorr(x, y, XL_RIGHT);
}
}
}
// C ref: extralev.c:278 corr — place corridor or secret corridor
export function corr(x, y) {
const loc = game.level?.at(x, y);
if (!loc) return;
loc.typ = rn2(50) ? CORR : SCORR;
}
// C ref: extralev.c:287 makerogueghost — place ghost with items
// C ref: sp_lev.c makerogueghost() — create ghost with items on Rogue level
export async function makerogueghost() {
const g = game;
if (!g.level.nroom) return;
const croom = g.level.rooms[rn2(g.level.nroom)];
if (!croom) return;
const x = somex(croom);
const y = somey(croom);
const ghost = await makemon(mons[PM_GHOST], x, y, 0);
if (!ghost) return;
ghost.msleeping = 1;
ghost.mname = roguename();
let ghostobj;
if (rn2(4)) {
ghostobj = mksobj_at(FOOD_RATION, x, y, false, false);
if (ghostobj) {
ghostobj.quan = rnd(7);
ghostobj.owt = weight(ghostobj);
}
}
if (rn2(2)) {
ghostobj = mksobj_at(MACE, x, y, false, false);
if (ghostobj) {
ghostobj.spe = rnd(3);
if (rn2(4)) curse(ghostobj);
}
} else {
ghostobj = mksobj_at(TWO_HANDED_SWORD, x, y, false, false);
if (ghostobj) {
ghostobj.spe = rnd(5) - 2;
if (rn2(4)) curse(ghostobj);
}
}
ghostobj = mksobj_at(BOW, x, y, false, false);
if (ghostobj) {
ghostobj.spe = 1;
if (rn2(4)) curse(ghostobj);
}
ghostobj = mksobj_at(ARROW, x, y, false, false);
if (ghostobj) {
ghostobj.spe = 0;
ghostobj.quan = rn1(10, 25);
ghostobj.owt = weight(ghostobj);
if (rn2(4)) curse(ghostobj);
}
if (rn2(2)) {
ghostobj = mksobj_at(RING_MAIL, x, y, false, false);
if (ghostobj) {
ghostobj.spe = rn2(3);
if (!rn2(3)) ghostobj.oerodeproof = true;
if (rn2(4)) curse(ghostobj);
}
} else {
ghostobj = mksobj_at(PLATE_MAIL, x, y, false, false);
if (ghostobj) {
ghostobj.spe = rnd(5) - 2;
if (!rn2(3)) ghostobj.oerodeproof = true;
if (rn2(4)) curse(ghostobj);
}
}
if (rn2(2)) {
ghostobj = mksobj_at(FAKE_AMULET_OF_YENDOR, x, y, true, false);
if (ghostobj) ghostobj.known = true;
}
}
|