All files / js light.js

34.75% Statements 220/633
70% Branches 14/20
20% Functions 7/35
34.75% Lines 220/633

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 63473x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x             73x 73x 73x 73x 73x 73x 73x 73x 73x                 73x 73x           73x 73x   73x 73x   73x 73x 73x 73x 73x 73x 73x 73x 73x 73x         73x 73x 73x 73x 73x 14613x 14613x 14613x 14613x 73x 73x 73x 73x     73x 73x                                     73x 73x 73x 73x                                                                           73x 73x 73x 73x 14543x 14543x 14543x 14543x                                                                                                                               14543x 73x 73x 73x 73x         73x 73x 73x 73x     73x 73x 73x 73x                                                   73x 73x 73x 73x                 73x 73x 73x 73x 70x 70x 73x 73x 73x 73x                               73x 73x 73x 73x 4706x 4706x 73x 73x 73x 73x 4709x 4709x 73x 73x 73x 73x                                     73x 73x 73x 73x                         73x 73x 73x 73x                       73x 73x 73x 73x                             73x 73x 73x 73x 1943x 1877x 1943x 1943x 1943x 1877x 1877x 1943x 73x 73x 73x 73x                           73x 73x 73x 73x                   73x 73x 73x 73x                                                                                                                                                         73x 73x 73x 73x                                   73x 73x 73x                   73x 73x 73x 73x                             73x 73x 73x 73x     73x 73x 73x 73x       73x 73x 73x 73x                             73x 73x 73x 73x 108x 108x 108x 108x 108x 73x 73x 73x      
// light.js — Light sources (port of light.c)
// C ref: light.c — 985 lines
//
// Ported functions:
//   new_light_source()        — add a light source
//   del_light_source()        — remove a light source
//   do_light_sources()        — mark TEMP_LIT locations for vision
//   save_light_sources()      — save light sources (stub)
//   restore_light_sources()   — restore light sources (stub)
//   relink_light_sources()    — relink light source obj/mon pointers
//   obj_move_light_source()   — reassign light source from src to dest obj
//   any_light_source()        — return true if any light sources exist
//   snuff_light_source()      — extinguish burning light source at position
//   obj_is_burning()          — is object actively burning?
//   obj_sheds_light()         — does object shed light?
//   begin_burn()              — light an object (C: timeout.c)
//   end_burn()                — extinguish a burning object (C: timeout.c)
//   artifact_light()          — does object emit artifact/special light?
//   arti_light_description()  — adverb for artifact light
//   arti_light_radius()       — radius for artifact light
//   candle_light_range()      — compute candle/candelabrum light radius
//   obj_split_light_source()  — copy light source for split stack
//   obj_merge_light_sources() — merge light sources (candles)
//   obj_adjust_light_radius() — change light source radius
//   wiz_light_sources()       — #lightsources wizard command
//   find_mid()                — find monster by m_id
//   show_transient_light()    — show light for thrown/kicked lit object (stub)
//   transient_light_cleanup() — cleanup after transient light (stub)
 
import { game } from './gstate.js';
import {
    LS_OBJECT, LS_MONSTER, MAX_RADIUS, COLNO, ROWNO,
    COULD_SEE, TEMP_LIT, W_ARM,
    BURN_OBJECT, TIMER_OBJECT, OBJ_INVENT, OBJ_FREE, OBJ_FLOOR, OBJ_MINVENT,
    CONTAINED_TOO, BURIED_TOO,
    FM_FMON, FM_MIGRATE, FM_MYDOGS, FM_YOU, FM_EVERYWHERE,
} from './const.js';
import { impossible } from './pline.js';
import { circle_data, clear_path } from './vision.js';
import { ART_SUNSWORD, ART_NONARTIFACT } from './artifacts.js';
import { BRASS_LANTERN, CANDELABRUM_OF_INVOCATION, GOLD_DRAGON_SCALES, GOLD_DRAGON_SCALE_MAIL, Is_candle, MAGIC_LAMP, OIL_LAMP, POT_OIL, TALLOW_CANDLE, WAX_CANDLE } from './objects.js';
import { find_oid } from './shk.js';
import { start_timer, stop_timer } from './timeout.js';
import { carried } from './invent.js';
import { update_inventory } from './mon.js';
import { u_at } from './const.js';
import { xname } from './objnam.js';
import { is_art, obj_to_any } from './hacklib.js';
 
// ── Local stubs for functions not yet available as imports ──
 
import { get_obj_location } from './mkobj.js';
 
// C ref: mkobj.c get_mon_location — returns {x, y} or null
function get_mon_location(mon) {
    if (!mon) return null;
    if (mon === game.youmonst) return { x: game.u.ux, y: game.u.uy };
    if (mon.mx > 0) return { x: mon.mx, y: mon.my };
    return null;
}
 
// obj_to_any: imported from hacklib.js
 
// C ref: objnam.c — stub
 
// C ref: artifact.c is_art
 
// C ref: objclass.h Is_candle macro
// Is_candle: imported from objects.js
function ignitable(obj) {
    if (!obj) return false;
    const otyp = obj.otyp;
    return (otyp === BRASS_LANTERN || otyp === OIL_LAMP || otyp === MAGIC_LAMP
         || otyp === CANDELABRUM_OF_INVOCATION
         || otyp === TALLOW_CANDLE || otyp === WAX_CANDLE
         || otyp === POT_OIL);
}
 
// C ref: mkobj.c obj_is_local — on-level objects are local
function obj_is_local(obj) {
    if (!obj) return false;
    return obj.where === OBJ_FLOOR || obj.where === OBJ_INVENT
        || obj.where === OBJ_MINVENT;
}
 
// C ref: light.c #define mon_is_local(mon) ((mon)->mx > 0)
function mon_is_local(mon) { return mon && mon.mx > 0; }
 
// C ref: restore.c lookup_id_mapping — stub
function lookup_id_mapping(nid, out) { return false; }
 
// ── Light source flags ──
const LSF_SHOW = 0x1;
const LSF_NEEDS_FIXUP = 0x2;
const LSF_IS_PROBLEMATIC = 0x4;
 
// ── circle_start table (from vision.c) ──
const circle_start = [0, 1, 3, 6, 10, 15, 21, 38, 36, 45, 55, 66, 78, 91, 105, 120];
 
// C ref: vision.c circle_ptr
function circle_ptr(range) {
    if (range < 1 || range > 15) return null;
    return circle_data.slice(circle_start[range], circle_start[range + 1] ?? circle_data.length);
}
 
// ── Light source list ──
// C uses gl.light_base as a singly-linked list.
// JS uses game.light_base as an array of light_source objects.
 
function get_light_base() {
    if (!game.light_base) game.light_base = [];
    return game.light_base;
}
 
// ── new_light_source ──
// C ref: light.c:62
export function new_light_source(x, y, range, type, id) {
    new_light_core(x, y, range, type, id);
}
 
// C ref: light.c:69 new_light_core
function new_light_core(x, y, range, type, id) {
    if (range > MAX_RADIUS || range < 0
        || (range === 0 && (type !== LS_OBJECT || id.a_obj !== null))) {
        impossible(`new_light_source: illegal range ${range}`);
        return null;
    }

    const ls = {
        x, y,
        range,
        type,
        id: { ...id },
        flags: 0,
    };
    get_light_base().unshift(ls); // prepend like C linked list
    game.vision_full_recalc = 1;
    return ls;
}
 
// ── del_light_source ──
// C ref: light.c:99
export function del_light_source(type, id) {
    const sources = get_light_base();
    let tmp_id_uint = 0;

    switch (type) {
    case 0: // LS_NONE
        impossible('del_light_source:type=none');
        break;
    case LS_OBJECT:
        tmp_id_uint = id.a_obj ? id.a_obj.o_id : 0;
        break;
    case LS_MONSTER:
        tmp_id_uint = id.a_monst ? id.a_monst.m_id : 0;
        break;
    default:
        break;
    }

    for (let i = 0; i < sources.length; i++) {
        const curr = sources[i];
        if (curr.type !== type) continue;
        // C compares curr->id.a_obj with (needs_fixup ? tmp_id.a_obj : id->a_obj)
        if (curr.flags & LSF_NEEDS_FIXUP) {
            // During fixup, compare by numeric id
            const curr_id = curr.type === LS_OBJECT
                ? (curr.id.a_obj ? curr.id.a_obj.o_id : 0)
                : (curr.id.a_monst ? curr.id.a_monst.m_id : 0);
            if (curr_id !== tmp_id_uint) continue;
        } else {
            if (curr.id.a_obj !== id.a_obj) continue;
        }
        // delete_ls: remove from list
        sources.splice(i, 1);
        game.vision_full_recalc = 1;
        return;
    }
    impossible(`del_light_source: not found type=${type}`);
}
 
// ── do_light_sources ──
// C ref: light.c:169 — mark TEMP_LIT locations
export function do_light_sources(cs_rows) {
    const sources = get_light_base();
    let at_hero_range = 0;
 
    for (const ls of sources) {
        ls.flags &= ~LSF_SHOW;

        // Check for moved light sources — update positions
        if (ls.type === LS_OBJECT) {
            if (ls.range === 0) {
                // camera flash; caller has set ls.x, ls.y
                ls.flags |= LSF_SHOW;
            } else {
                const loc = get_obj_location(ls.id.a_obj, 0);
                if (loc) {
                    ls.x = loc.x;
                    ls.y = loc.y;
                    ls.flags |= LSF_SHOW;
                }
            }
        } else if (ls.type === LS_MONSTER) {
            const loc = get_mon_location(ls.id.a_monst);
            if (loc) {
                ls.x = loc.x;
                ls.y = loc.y;
                ls.flags |= LSF_SHOW;
            }
        }

        // minor optimization: don't bother with duplicate at hero
        if (u_at(ls.x, ls.y)) {
            if (at_hero_range >= ls.range)
                ls.flags &= ~LSF_SHOW;
            else
                at_hero_range = ls.range;
        }

        if (ls.flags & LSF_SHOW) {
            const limits = circle_ptr(ls.range);
            if (!limits) continue;
            let max_y = ls.y + ls.range;
            if (max_y >= ROWNO) max_y = ROWNO - 1;
            let y = ls.y - ls.range;
            if (y < 0) y = 0;

            for (; y <= max_y; y++) {
                const row = cs_rows[y];
                if (!row) continue;
                const offset = limits[Math.abs(y - ls.y)];
                let min_x = ls.x - offset;
                if (min_x < 1) min_x = 1;
                let max_x = ls.x + offset;
                if (max_x >= COLNO) max_x = COLNO - 1;

                if (u_at(ls.x, ls.y)) {
                    // Light at hero: use COULD_SEE bits
                    for (let x = min_x; x <= max_x; x++)
                        if (row[x] & COULD_SEE)
                            row[x] |= TEMP_LIT;
                } else {
                    for (let x = min_x; x <= max_x; x++)
                        if ((ls.x === x && ls.y === y)
                            || clear_path(ls.x, ls.y, x, y))
                            row[x] |= TEMP_LIT;
                }
            }
        }
    }
}
 
// ── save_light_sources ──
// C ref: light.c:421 — stub for save/restore
export function save_light_sources(nhfp, range) {
    // TODO: full save implementation
    discard_flashes();
    game.vision_full_recalc = 0;
}
 
// ── restore_light_sources ──
// C ref: light.c:479 — stub for save/restore
export function restore_light_sources(nhfp) {
    // TODO: full restore implementation
}
 
// ── relink_light_sources ──
// C ref: light.c:517
export function relink_light_sources(ghostly) {
    const sources = get_light_base();
    for (const ls of sources) {
        if (ls.flags & LSF_NEEDS_FIXUP) {
            if (ls.type === LS_OBJECT || ls.type === LS_MONSTER) {
                let nid = ls.id.a_uint;
                if (ghostly && !lookup_id_mapping(nid, {}))
                    throw new Error('relink_light_sources: no id mapping');

                let which = '\0';
                if (ls.type === LS_OBJECT) {
                    ls.id.a_obj = find_oid(nid);
                    if (!ls.id.a_obj) which = 'o';
                } else {
                    ls.id.a_monst = find_mid(nid, FM_EVERYWHERE);
                    if (!ls.id.a_monst) which = 'm';
                }
                if (which !== '\0')
                    throw new Error(`relink_light_sources: can't find ${which}_id ${nid}`);
            } else {
                throw new Error(`relink_light_sources: bad type (${ls.type})`);
            }
            ls.flags &= ~LSF_NEEDS_FIXUP;
        }
    }
}
 
// ── obj_move_light_source ──
// C ref: light.c:706
export function obj_move_light_source(src, dest) {
    const sources = get_light_base();
    for (const ls of sources) {
        if (ls.type === LS_OBJECT && ls.id.a_obj === src)
            ls.id.a_obj = dest;
    }
    src.lamplit = 0;
    dest.lamplit = 1;
}
 
// ── any_light_source ──
// C ref: light.c:719
export function any_light_source() {
    return get_light_base().length > 0;
}
 
// ── snuff_light_source ──
// C ref: light.c:729
export function snuff_light_source(x, y) {
    const sources = get_light_base();
    for (const ls of sources) {
        if (ls.type === LS_OBJECT && ls.x === x && ls.y === y) {
            const obj = ls.id.a_obj;
            if (obj_is_burning(obj)) {
                // Sunsword can only be snuffed by unwielding
                if (artifact_light(obj))
                    continue;
                end_burn(obj, obj.otyp !== MAGIC_LAMP);
                // ls has been removed; return (one light per object)
                return;
            }
        }
    }
}
 
// ── obj_sheds_light ──
// C ref: light.c:763
export function obj_sheds_light(obj) {
    return obj_is_burning(obj);
}
 
// ── obj_is_burning ──
// C ref: light.c:771
export function obj_is_burning(obj) {
    return !!(obj && obj.lamplit && (ignitable(obj) || artifact_light(obj)));
}
 
// ── obj_split_light_source ──
// C ref: light.c:779
export function obj_split_light_source(src, dest) {
    const sources = get_light_base();
    const len = sources.length;
    for (let i = 0; i < len; i++) {
        const ls = sources[i];
        if (ls.type === LS_OBJECT && ls.id.a_obj === src) {
            const new_ls = { ...ls, id: { ...ls.id } };
            if (Is_candle(src)) {
                ls.range = candle_light_range(src);
                new_ls.range = candle_light_range(dest);
                game.vision_full_recalc = 1;
            }
            new_ls.id.a_obj = dest;
            sources.unshift(new_ls); // prepend
            dest.lamplit = 1;
            return;
        }
    }
}
 
// ── obj_merge_light_sources ──
// C ref: light.c:808
export function obj_merge_light_sources(src, dest) {
    if (src !== dest)
        end_burn(src, true);

    const sources = get_light_base();
    for (const ls of sources) {
        if (ls.type === LS_OBJECT && ls.id.a_obj === dest) {
            ls.range = candle_light_range(dest);
            game.vision_full_recalc = 1;
            break;
        }
    }
}
 
// ── obj_adjust_light_radius ──
// C ref: light.c:825
export function obj_adjust_light_radius(obj, new_radius) {
    const sources = get_light_base();
    for (const ls of sources) {
        if (ls.type === LS_OBJECT && ls.id.a_obj === obj) {
            if (new_radius !== ls.range)
                game.vision_full_recalc = 1;
            ls.range = new_radius;
            return;
        }
    }
    impossible(`obj_adjust_light_radius: can't find ${xname(obj)}`);
}
 
// ── candle_light_range ──
// C ref: light.c:843
export function candle_light_range(obj) {
    let radius;
    if (obj.otyp === CANDELABRUM_OF_INVOCATION) {
        radius = (obj.spe < 4) ? 2 : (obj.spe < 7) ? 3 : 4;
    } else if (Is_candle(obj)) {
        const n = obj.quan;
        radius = 1;
        while (radius * radius <= n && radius < MAX_RADIUS) {
            radius++;
        }
    } else {
        radius = 3; // lamp's value
    }
    return radius;
}
 
// ── artifact_light ──
// C ref: artifact.c:2264
export function artifact_light(obj) {
    if (!obj) return false;
    // Gold dragon scale mail / scales when worn as armor
    if ((obj.otyp === GOLD_DRAGON_SCALE_MAIL || obj.otyp === GOLD_DRAGON_SCALES)
        && (obj.owornmask & W_ARM) !== 0)
        return true;
    // Sunsword
    return is_art(obj, ART_SUNSWORD);
}
 
// ── arti_light_radius ──
// C ref: light.c:881
export function arti_light_radius(obj) {
    if (!obj.lamplit || !artifact_light(obj))
        return 0;

    let res = obj.blessed ? 3 : !obj.cursed ? 2 : 1;

    // uskin: poly'd into gold dragon with embedded scales
    if (obj === game.u?.uskin)
        res = 1;
    else if (obj.otyp === GOLD_DRAGON_SCALE_MAIL)
        ++res;

    return res;
}
 
// ── arti_light_description ──
// C ref: light.c:916
export function arti_light_description(obj) {
    switch (arti_light_radius(obj)) {
    case 4: return 'radiantly';
    case 3: return 'brilliantly';
    case 2: return 'brightly';
    case 1: return 'dimly';
    default: break;
    }
    return 'strangely';
}
 
// ── begin_burn ──
// C ref: timeout.c:1712
export function begin_burn(obj, already_lit) {
    let radius = 3;
    let turns = 0;
    let do_timer = true;

    if (obj.age === 0 && obj.otyp !== MAGIC_LAMP && !artifact_light(obj))
        return;

    switch (obj.otyp) {
    case MAGIC_LAMP:
        obj.lamplit = 1;
        do_timer = false;
        break;
    case POT_OIL:
        turns = obj.age;
        if (obj.odiluted)
            turns = Math.trunc((3 * turns + 2) / 4);
        radius = 1;
        break;
    case BRASS_LANTERN:
    case OIL_LAMP:
        if (obj.age > 150)
            turns = obj.age - 150;
        else if (obj.age > 100)
            turns = obj.age - 100;
        else if (obj.age > 50)
            turns = obj.age - 50;
        else if (obj.age > 25)
            turns = obj.age - 25;
        else
            turns = obj.age;
        break;
    case CANDELABRUM_OF_INVOCATION:
    case TALLOW_CANDLE:
    case WAX_CANDLE:
        if (obj.age > 75)
            turns = obj.age - 75;
        else if (obj.age > 15)
            turns = obj.age - 15;
        else
            turns = obj.age;
        radius = candle_light_range(obj);
        break;
    default:
        if (artifact_light(obj)) {
            obj.lamplit = 1;
            do_timer = false;
            radius = arti_light_radius(obj);
        } else {
            impossible(`begin burn: unexpected ${xname(obj)}`);
            turns = obj.age;
        }
        break;
    }

    if (do_timer) {
        if (start_timer(turns, TIMER_OBJECT, BURN_OBJECT, obj_to_any(obj))) {
            obj.lamplit = 1;
            obj.age -= turns;
            if (carried(obj) && !already_lit)
                update_inventory();
        } else {
            obj.lamplit = 0;
        }
    } else {
        if (carried(obj) && !already_lit)
            update_inventory();
    }

    if (obj.lamplit && !already_lit) {
        const loc = get_obj_location(obj, CONTAINED_TOO | BURIED_TOO);
        if (loc)
            new_light_source(loc.x, loc.y, radius, LS_OBJECT, obj_to_any(obj));
        else
            impossible("begin_burn: can't get obj position");
    }
}
 
// ── end_burn ──
// C ref: timeout.c:1803
export function end_burn(obj, timer_attached) {
    if (!obj.lamplit) {
        impossible(`end_burn: obj ${xname(obj)} not lit`);
        return;
    }

    if (obj.otyp === MAGIC_LAMP || artifact_light(obj))
        timer_attached = false;

    if (!timer_attached) {
        del_light_source(LS_OBJECT, obj_to_any(obj));
        obj.lamplit = 0;
        if (obj.where === OBJ_INVENT)
            update_inventory();
    } else if (!stop_timer(BURN_OBJECT, obj_to_any(obj))) {
        impossible(`end_burn: obj ${xname(obj)} not timed!`);
    }
}
 
// ── discard_flashes ──
// C ref: light.c:361
function discard_flashes() {
    const sources = get_light_base();
    for (let i = sources.length - 1; i >= 0; i--) {
        if (sources[i].type === LS_OBJECT && !sources[i].id.a_obj) {
            sources.splice(i, 1);
            game.vision_full_recalc = 1;
        }
    }
}
 
// ── find_mid ──
// C ref: light.c:376
export function find_mid(nid, fmflags) {
    if ((fmflags & FM_YOU) && nid === 1)
        return game.youmonst;
    if (fmflags & FM_FMON)
        for (let mtmp = game.fmon; mtmp; mtmp = mtmp.nmon)
            if (!mtmp.mhp || mtmp.mhp > 0) // !DEADMONSTER
                if (mtmp.m_id === nid) return mtmp;
    if (fmflags & FM_MIGRATE)
        for (let mtmp = game.migrating_mons; mtmp; mtmp = mtmp.nmon)
            if (mtmp.m_id === nid) return mtmp;
    if (fmflags & FM_MYDOGS)
        for (let mtmp = game.mydogs; mtmp; mtmp = mtmp.nmon)
            if (mtmp.m_id === nid) return mtmp;
    return null;
}
 
// ── show_transient_light ──
// C ref: light.c:257 — stub
export function show_transient_light(obj, x, y) {
    // TODO: full implementation requires vision_recalc, place_object, etc.
}
 
// ── transient_light_cleanup ──
// C ref: light.c:330 — stub
export function transient_light_cleanup() {
    discard_flashes();
    // TODO: full implementation
}
 
// ── wiz_light_sources ──
// C ref: light.c:936
export function wiz_light_sources() {
    // TODO: requires create_nhwindow/putstr/display_nhwindow
    const sources = get_light_base();
    if (sources.length > 0) {
        for (const ls of sources) {
            const typeStr = ls.type === LS_OBJECT ? 'obj'
                          : ls.type === LS_MONSTER
                            ? (mon_is_local(ls.id.a_monst) ? 'mon'
                               : (ls.id.a_monst === game.youmonst) ? 'you' : '<m>')
                            : '???';
            // Would putstr to window; stubbed for now
        }
    }
    return 0; // ECMD_OK
}
 
// ── emits_light ──
// C ref: mondata.h — some monsters glow
export function emits_light(ptr) {
    if (!ptr) return 0;
    if (ptr.mname === 'fire elemental' || ptr.mname === 'flaming sphere')
        return 1;
    return 0;
}
 
// ── Legacy alias ──
export function obj_shines_on(obj) {
    return obj_sheds_light(obj);
}