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 | 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 129x 129x 129x 129x 73x 73x 73x 129x 129x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 610x 610x 610x 610x 73x 73x 73x 1910901x 1910901x 1910901x 1910901x 1910901x 1910901x 1910901x 1907568x 1910901x 73x 73x 73x 1917117x 1917117x 1917117x 1917117x 1917117x 1917117x 1917117x 1916933x 1917117x 73x 73x 73x 1728357x 1728357x 1726962x 1728357x 73x 73x 73x 74x 74x 74x 74x 74x 74x 74x 74x 73x 73x 73x 1907586x 1907586x 1907586x 1907586x 1907586x 1907586x 1907586x 1907586x 1907586x 1907586x 73x 73x 73x 73x 73x 73x 73x 163x 163x 163x 163x 163x 163x 91x 91x 163x 163x 91x 163x 163x 91x 163x 163x 91x 163x 163x 91x 91x 163x 73x 73x 73x 73x 73x 73x 4x 4x 73x 73x 73x 73x 73x 73x 63x 63x 63x 63x 63x 63x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 5x 1x 1x 1x 5x 3x 3x 3x 5x 5x 5x 5x 5x 5x 5x 5x 2x 2x 2x 2x 2x 5x 3x 3x 3x 3x 3x 3x 5x 5x 5x 5x 5x 5x 5x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 32x 32x 32x 32x 32x 32x 73x 73x 73x 73x | // dbridge.js -- Drawbridge management (port of dbridge.c)
import { game } from './gstate.js';
import { D_NODOOR, DB_DIR, DB_EAST, DB_ICE, DB_LAVA, DB_MOAT, DB_NORTH, DB_SOUTH, DB_UNDER, DB_WEST, DBWALL, DOOR, DRAWBRIDGE_DOWN, DRAWBRIDGE_UP, ENTITIES, ICE, ICED_MOAT, IS_DRAWBRIDGE, Is_botlevel, Is_earthlevel, Is_juiblex_level, Is_stronghold, IS_WALL, IS_WATERWALL, isok, LAVAPOOL, LAVAWALL, MAY_HIT, MOAT, OBJ_AT, POOL, ROOM, STONE, u_at, W_NONDIGGABLE, WATER } from './const.js';
import { cansee } from './vision.js';
import { rn2 } from './rng.js';
import { block_point, does_block, newsym, recalc_block_point, unblock_point } from './display.js';
import { Soundeffect } from './sounds.js';
import { Deaf, Invocation_lev, Is_airlevel, Is_waterlevel, Underwater } from './macros.js';
import { del_engr_at } from './engrave.js';
import { deltrap } from './trap.js';
import { t_at, m_at } from './map_access.js';
import { obj_extract_self, mksobj_at, sobj_at } from './mkobj.js';
import { IRON_CHAIN } from './objects.js';
import { scatter } from './explode.js';
import { minliquid, wake_nearto } from './mon.js';
import { vision_recalc } from './vision.js';
import { hliquid } from './do_name.js';
import { You, You_hear, You_see, pline, pline_The } from './pline.js';
import { flooreffects } from './do.js';
import { distu } from './hacklib.js';
// ── Level predicates (dbridge.c) ──
// C ref: dungeon.c:1643 Can_dig_down
export function Can_dig_down(uz) {
return !!(!game.level?.flags?.hardfloor
&& !Is_botlevel(uz)
&& !Invocation_lev(uz));
}
// C ref: dungeon.c:1656 Can_fall_thru — like Can_dig_down, but also
// allows falling through on the stronghold level.
export function Can_fall_thru(uz) {
return !!(Can_dig_down(uz) || Is_stronghold(uz));
}
// Invocation_lev imported from macros.js
// ── Local stubs for unported dependencies ──
// block_point: imported from display.js
// does_block: imported from display.js
// Entity-related stubs for monster interaction (complex deps not yet ported)
function set_entity(_x, _y, _etmp) { /* TODO */ }
function do_entity(_etmp) { /* TODO */ }
function nokiller() {
// C: clears killer, resets both occupants
// Stub: occupants not yet modeled
}
function revive_nasty(_x, _y, _s) { return 0; } // TODO
function delallobj(_x, _y) { /* TODO */ }
// TODO
// ── Terrain predicates (dbridge.c) ──
// C ref: dbridge.c:is_waterwall
export function is_waterwall(x, y) {
if (isok(x, y) && IS_WATERWALL(game.level.at(x, y).typ))
return true;
return false;
}
// C ref: dbridge.c:is_pool — is position a water tile?
export function is_pool(x, y) {
if (!isok(x, y))
return false;
const ltyp = game.level.at(x, y).typ;
// The ltyp == MOAT is not redundant with is_moat, because the
// Juiblex level does not have moats, although it has MOATs.
if (ltyp === POOL || ltyp === MOAT || ltyp === WATER || is_moat(x, y))
return true;
return false;
}
// C ref: dbridge.c:is_lava
export function is_lava(x, y) {
if (!isok(x, y))
return false;
const ltyp = game.level.at(x, y).typ;
if (ltyp === LAVAPOOL || ltyp === LAVAWALL
|| (ltyp === DRAWBRIDGE_UP
&& (game.level.at(x, y).drawbridgemask & DB_UNDER) === DB_LAVA))
return true;
return false;
}
// C ref: dbridge.c:is_pool_or_lava
export function is_pool_or_lava(x, y) {
if (is_pool(x, y) || is_lava(x, y))
return true;
return false;
}
// C ref: dbridge.c:is_ice
export function is_ice(x, y) {
if (!isok(x, y))
return false;
const ltyp = game.level.at(x, y).typ;
if (ltyp === ICE || (ltyp === DRAWBRIDGE_UP
&& (game.level.at(x, y).drawbridgemask & DB_UNDER) === DB_ICE))
return true;
return false;
}
// C ref: dbridge.c:is_moat
export function is_moat(x, y) {
if (!isok(x, y))
return false;
const ltyp = game.level.at(x, y).typ;
if (!Is_juiblex_level(game.u.uz)
&& (ltyp === MOAT
|| (ltyp === DRAWBRIDGE_UP
&& (game.level.at(x, y).drawbridgemask & DB_UNDER) === DB_MOAT)))
return true;
return false;
}
// C ref: dbridge.c:db_under_typ
export function db_under_typ(mask) {
switch (mask & DB_UNDER) {
case DB_ICE:
return ICE;
case DB_LAVA:
return LAVAPOOL;
case DB_MOAT:
return MOAT;
default:
return STONE;
}
}
// C ref: dbridge.c:is_drawbridge_wall
// Return the direction of the drawbridge, or -1 if not valid
export function is_drawbridge_wall(x, y) {
if (!isok(x, y))
return -1;
const lev = game.level.at(x, y);
if (lev.typ !== DOOR && lev.typ !== DBWALL)
return -1;
if (isok(x + 1, y) && IS_DRAWBRIDGE(game.level.at(x + 1, y).typ)
&& (game.level.at(x + 1, y).drawbridgemask & DB_DIR) === DB_WEST)
return DB_WEST;
if (isok(x - 1, y) && IS_DRAWBRIDGE(game.level.at(x - 1, y).typ)
&& (game.level.at(x - 1, y).drawbridgemask & DB_DIR) === DB_EAST)
return DB_EAST;
if (isok(x, y - 1) && IS_DRAWBRIDGE(game.level.at(x, y - 1).typ)
&& (game.level.at(x, y - 1).drawbridgemask & DB_DIR) === DB_SOUTH)
return DB_SOUTH;
if (isok(x, y + 1) && IS_DRAWBRIDGE(game.level.at(x, y + 1).typ)
&& (game.level.at(x, y + 1).drawbridgemask & DB_DIR) === DB_NORTH)
return DB_NORTH;
return -1;
}
// Alias requested by caller
export { is_drawbridge_wall as drawbridge_wall_direction };
// C ref: dbridge.c:is_db_wall
export function is_db_wall(x, y) {
return game.level.at(x, y).typ === DBWALL;
}
// C ref: dbridge.c:find_drawbridge
// Return true with {x, y} pointing to the drawbridge if (x, y) initially
// indicate a drawbridge or drawbridge wall.
// In JS we return { found, x, y } since we can't use pointer args.
export function find_drawbridge(x, y) {
if (IS_DRAWBRIDGE(game.level.at(x, y).typ))
return { found: true, x, y };
const dir = is_drawbridge_wall(x, y);
if (dir >= 0) {
switch (dir) {
case DB_NORTH: y++; break;
case DB_SOUTH: y--; break;
case DB_EAST: x--; break;
case DB_WEST: x++; break;
}
return { found: true, x, y };
}
return { found: false, x, y };
}
// C ref: dbridge.c:get_wall_for_db (static)
// Find the drawbridge wall associated with a drawbridge.
// Returns { x, y } with the wall coordinates.
function get_wall_for_db(x, y) {
switch (game.level.at(x, y).drawbridgemask & DB_DIR) {
case DB_NORTH: y--; break;
case DB_SOUTH: y++; break;
case DB_EAST: x++; break;
case DB_WEST: x--; break;
}
return { x, y };
}
// C ref: dbridge.c:e_at (static)
// Find entity at (x, y) in go.occupants[].
// Returns the entity or null.
function e_at(x, y) {
const occupants = game.occupants;
if (!occupants) return null;
for (let i = 0; i < ENTITIES; i++) {
if (occupants[i].edata
&& occupants[i].ex === x
&& occupants[i].ey === y)
return occupants[i];
}
return null;
}
// ── Drawbridge creation (dbridge.c:235) ──
export function create_drawbridge(x, y, dir, flag) {
const map = game.level;
const loc = map.at(x, y);
let x2 = x;
let y2 = y;
let horiz;
const lava = loc.typ === LAVAPOOL;
switch (dir) {
case DB_NORTH:
horiz = true;
y2--;
break;
case DB_SOUTH:
horiz = true;
y2++;
break;
case DB_EAST:
horiz = false;
x2++;
break;
default:
// impossible("bad direction in create_drawbridge");
// FALLTHROUGH
case DB_WEST:
horiz = false;
x2--;
break;
}
if (!IS_WALL(map.at(x2, y2).typ))
return false;
if (flag) {
// We want the bridge open
loc.typ = DRAWBRIDGE_DOWN;
const wall = map.at(x2, y2);
wall.typ = DOOR;
wall.flags = D_NODOOR;
} else {
loc.typ = DRAWBRIDGE_UP;
const wall = map.at(x2, y2);
wall.typ = DBWALL;
// Drawbridges are non-diggable.
wall.wall_info = W_NONDIGGABLE;
}
loc.horizontal = !horiz;
map.at(x2, y2).horizontal = horiz;
loc.drawbridgemask = dir;
if (lava)
loc.drawbridgemask |= DB_LAVA;
return true;
}
// ── open_drawbridge (dbridge.c:840) ──
export async function open_drawbridge(x, y) {
const lev1 = game.level.at(x, y);
if (lev1.typ !== DRAWBRIDGE_UP)
return;
let x2 = x, y2 = y;
({ x: x2, y: y2 } = get_wall_for_db(x2, y2));
if (cansee(x, y) || cansee(x2, y2)) {
await You_see(`a drawbridge ${
(distu(x2, y2) < distu(x, y)) ? "going" : "coming"} down!`);
} else {
Soundeffect(/*se_gears_turning_chains_rattling*/ 0, 100);
await You_hear("gears turning and chains rattling.");
}
lev1.typ = DRAWBRIDGE_DOWN;
const lev2 = game.level.at(x2, y2);
lev2.typ = DOOR;
lev2.flags = D_NODOOR;
set_entity(x, y, game.occupants?.[0]);
set_entity(x2, y2, game.occupants?.[1]);
do_entity(game.occupants?.[0]);
set_entity(x2, y2, game.occupants?.[1]);
do_entity(game.occupants?.[1]);
revive_nasty(x, y, null);
delallobj(x, y);
let t;
if ((t = t_at(x, y)) != null)
deltrap(t);
if ((t = t_at(x2, y2)) != null)
deltrap(t);
del_engr_at(x, y);
del_engr_at(x2, y2);
newsym(x, y);
newsym(x2, y2);
unblock_point(x2, y2);
if (Is_stronghold(game.u.uz))
game.u.uevent.uopened_dbridge = true;
nokiller();
}
// ── close_drawbridge (dbridge.c:775) ──
export async function close_drawbridge(x, y) {
const lev1 = game.level.at(x, y);
if (lev1.typ !== DRAWBRIDGE_DOWN)
return;
let x2 = x, y2 = y;
({ x: x2, y: y2 } = get_wall_for_db(x2, y2));
if (cansee(x, y) || cansee(x2, y2)) {
await You_see(`a drawbridge ${
(((game.u.ux === x || game.u.uy === y) && !Underwater())
|| distu(x2, y2) < distu(x, y))
? "coming"
: "going"} up!`);
} else {
Soundeffect(/*se_chains_rattling_gears_turning*/ 0, 75);
await You_hear("chains rattling and gears turning.");
}
lev1.typ = DRAWBRIDGE_UP;
const lev2 = game.level.at(x2, y2);
lev2.typ = DBWALL;
switch (lev1.drawbridgemask & DB_DIR) {
case DB_NORTH:
case DB_SOUTH:
lev2.horizontal = true;
break;
case DB_WEST:
case DB_EAST:
lev2.horizontal = false;
break;
}
lev2.wall_info = W_NONDIGGABLE;
set_entity(x, y, game.occupants?.[0]);
set_entity(x2, y2, game.occupants?.[1]);
do_entity(game.occupants?.[0]);
set_entity(x2, y2, game.occupants?.[1]);
do_entity(game.occupants?.[1]);
if (OBJ_AT(x, y) && !Deaf()) {
Soundeffect(/*se_smashing_and_crushing*/ 0, 75);
await You_hear("smashing and crushing.");
}
revive_nasty(x, y, null);
revive_nasty(x2, y2, null);
delallobj(x, y);
delallobj(x2, y2);
let t;
if ((t = t_at(x, y)) != null)
deltrap(t);
if ((t = t_at(x2, y2)) != null)
deltrap(t);
del_engr_at(x, y);
del_engr_at(x2, y2);
newsym(x, y);
newsym(x2, y2);
block_point(x2, y2);
nokiller();
}
// ── destroy_drawbridge (dbridge.c:888) ──
export async function destroy_drawbridge(x, y) {
const lev1 = game.level.at(x, y);
if (!IS_DRAWBRIDGE(lev1.typ))
return;
let x2 = x, y2 = y;
({ x: x2, y: y2 } = get_wall_for_db(x2, y2));
const lev2 = game.level.at(x2, y2);
if ((lev1.drawbridgemask & DB_UNDER) === DB_MOAT
|| (lev1.drawbridgemask & DB_UNDER) === DB_LAVA) {
const lava = (lev1.drawbridgemask & DB_UNDER) === DB_LAVA;
Soundeffect(/*se_loud_splash*/ 0, 100);
if (lev1.typ === DRAWBRIDGE_UP) {
if (cansee(x2, y2) || u_at(x2, y2))
await pline_The(`portcullis of the drawbridge falls into the ${
lava ? hliquid("lava") : "moat"}!`);
else
await You_hear("a loud *SPLASH*!");
} else {
if (cansee(x, y) || u_at(x, y))
await pline_The(`drawbridge collapses into the ${
lava ? hliquid("lava") : "moat"}!`);
else
await You_hear("a loud *SPLASH*!");
}
lev1.typ = lava ? LAVAPOOL : MOAT;
lev1.drawbridgemask = 0;
const otmp2 = sobj_at(/* BOULDER */ 6, x, y); // TODO: import BOULDER
if (otmp2) {
obj_extract_self(otmp2);
await flooreffects(otmp2, x, y, "fall");
}
} else {
// no moat beneath
Soundeffect(/*se_loud_crash*/ 0, 100);
if (cansee(x, y) || u_at(x, y))
await pline_The("drawbridge disintegrates!");
else
await You_hear("a loud *CRASH*!");
lev1.typ = ((lev1.drawbridgemask & DB_ICE) ? ICE : ROOM);
lev1.icedpool = ((lev1.drawbridgemask & DB_ICE) ? ICED_MOAT : 0);
}
wake_nearto(x, y, 500);
lev2.typ = DOOR;
lev2.flags = D_NODOOR;
let t;
if ((t = t_at(x, y)) != null)
deltrap(t);
if ((t = t_at(x2, y2)) != null)
deltrap(t);
del_engr_at(x, y);
del_engr_at(x2, y2);
// scatter some debris
const debrisCount = rn2(6);
for (let i = debrisCount; i > 0; --i) {
const ox = rn2(2) ? x : x2;
const oy = rn2(2) ? y : y2;
const otmp = mksobj_at(IRON_CHAIN, ox, oy, true, false);
if (otmp) await scatter(otmp.ox, otmp.oy, 1, MAY_HIT, otmp);
}
newsym(x, y);
newsym(x2, y2);
if (!does_block(x2, y2, lev2))
unblock_point(x2, y2);
vision_recalc(0);
if (Is_stronghold(game.u.uz))
game.u.uevent.uopened_dbridge = true;
// Entity handling for destroy (stub - entity system not fully ported)
// C: set_entity, automiss, e_missed, e_died for etmp1/etmp2
// TODO: port entity system for full destroy_drawbridge monster handling
nokiller();
if (Is_stronghold(game.u.uz))
game.u.uevent.uheard_tune = 3; // bridge is gone so tune is useless
}
// ── Dungeon level predicates (from dungeon.h, kept here for import convenience) ──
// Level predicates: canonical versions in const.js
|