Source:NetHack 3.6.6/src/light.c
Jump to navigation
Jump to search
Below is the full text to light.c from the source code of NetHack 3.6.6. To link to a particular line, write [[Source:NetHack 3.6.6/src/light.c#line12]], for example.
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* NetHack 3.6 light.c $NHDT-Date: 1559994625 2019/06/08 11:50:25 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.30 $ */ 2. /* Copyright (c) Dean Luick, 1994 */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #include "hack.h" 6. #include "lev.h" /* for checking save modes */ 7. 8. /* 9. * Mobile light sources. 10. * 11. * This implementation minimizes memory at the expense of extra 12. * recalculations. 13. * 14. * Light sources are "things" that have a physical position and range. 15. * They have a type, which gives us information about them. Currently 16. * they are only attached to objects and monsters. Note well: the 17. * polymorphed-player handling assumes that both youmonst.m_id and 18. * youmonst.mx will always remain 0. 19. * 20. * Light sources, like timers, either follow game play (RANGE_GLOBAL) or 21. * stay on a level (RANGE_LEVEL). Light sources are unique by their 22. * (type, id) pair. For light sources attached to objects, this id 23. * is a pointer to the object. 24. * 25. * The major working function is do_light_sources(). It is called 26. * when the vision system is recreating its "could see" array. Here 27. * we add a flag (TEMP_LIT) to the array for all locations that are lit 28. * via a light source. The bad part of this is that we have to 29. * re-calculate the LOS of each light source every time the vision 30. * system runs. Even if the light sources and any topology (vision blocking 31. * positions) have not changed. The good part is that no extra memory 32. * is used, plus we don't have to figure out how far the sources have moved, 33. * or if the topology has changed. 34. * 35. * The structure of the save/restore mechanism is amazingly similar to 36. * the timer save/restore. This is because they both have the same 37. * principals of having pointers into objects that must be recalculated 38. * across saves and restores. 39. */ 40. 41. /* flags */ 42. #define LSF_SHOW 0x1 /* display the light source */ 43. #define LSF_NEEDS_FIXUP 0x2 /* need oid fixup */ 44. 45. static light_source *light_base = 0; 46. 47. STATIC_DCL void FDECL(write_ls, (int, light_source *)); 48. STATIC_DCL int FDECL(maybe_write_ls, (int, int, BOOLEAN_P)); 49. 50. /* imported from vision.c, for small circles */ 51. extern char circle_data[]; 52. extern char circle_start[]; 53. 54. /* Create a new light source. */ 55. void 56. new_light_source(x, y, range, type, id) 57. xchar x, y; 58. int range, type; 59. anything *id; 60. { 61. light_source *ls; 62. 63. if (range > MAX_RADIUS || range < 1) { 64. impossible("new_light_source: illegal range %d", range); 65. return; 66. } 67. 68. ls = (light_source *) alloc(sizeof *ls); 69. 70. ls->next = light_base; 71. ls->x = x; 72. ls->y = y; 73. ls->range = range; 74. ls->type = type; 75. ls->id = *id; 76. ls->flags = 0; 77. light_base = ls; 78. 79. vision_full_recalc = 1; /* make the source show up */ 80. } 81. 82. /* 83. * Delete a light source. This assumes only one light source is attached 84. * to an object at a time. 85. */ 86. void 87. del_light_source(type, id) 88. int type; 89. anything *id; 90. { 91. light_source *curr, *prev; 92. anything tmp_id; 93. 94. tmp_id = zeroany; 95. /* need to be prepared for dealing a with light source which 96. has only been partially restored during a level change 97. (in particular: chameleon vs prot. from shape changers) */ 98. switch (type) { 99. case LS_OBJECT: 100. tmp_id.a_uint = id->a_obj->o_id; 101. break; 102. case LS_MONSTER: 103. tmp_id.a_uint = id->a_monst->m_id; 104. break; 105. default: 106. tmp_id.a_uint = 0; 107. break; 108. } 109. 110. for (prev = 0, curr = light_base; curr; prev = curr, curr = curr->next) { 111. if (curr->type != type) 112. continue; 113. if (curr->id.a_obj 114. == ((curr->flags & LSF_NEEDS_FIXUP) ? tmp_id.a_obj : id->a_obj)) { 115. if (prev) 116. prev->next = curr->next; 117. else 118. light_base = curr->next; 119. 120. free((genericptr_t) curr); 121. vision_full_recalc = 1; 122. return; 123. } 124. } 125. impossible("del_light_source: not found type=%d, id=%s", type, 126. fmt_ptr((genericptr_t) id->a_obj)); 127. } 128. 129. /* Mark locations that are temporarily lit via mobile light sources. */ 130. void 131. do_light_sources(cs_rows) 132. char **cs_rows; 133. { 134. int x, y, min_x, max_x, max_y, offset; 135. char *limits; 136. short at_hero_range = 0; 137. light_source *ls; 138. char *row; 139. 140. for (ls = light_base; ls; ls = ls->next) { 141. ls->flags &= ~LSF_SHOW; 142. 143. /* 144. * Check for moved light sources. It may be possible to 145. * save some effort if an object has not moved, but not in 146. * the current setup -- we need to recalculate for every 147. * vision recalc. 148. */ 149. if (ls->type == LS_OBJECT) { 150. if (get_obj_location(ls->id.a_obj, &ls->x, &ls->y, 0)) 151. ls->flags |= LSF_SHOW; 152. } else if (ls->type == LS_MONSTER) { 153. if (get_mon_location(ls->id.a_monst, &ls->x, &ls->y, 0)) 154. ls->flags |= LSF_SHOW; 155. } 156. 157. /* minor optimization: don't bother with duplicate light sources 158. at hero */ 159. if (ls->x == u.ux && ls->y == u.uy) { 160. if (at_hero_range >= ls->range) 161. ls->flags &= ~LSF_SHOW; 162. else 163. at_hero_range = ls->range; 164. } 165. 166. if (ls->flags & LSF_SHOW) { 167. /* 168. * Walk the points in the circle and see if they are 169. * visible from the center. If so, mark'em. 170. * 171. * Kevin's tests indicated that doing this brute-force 172. * method is faster for radius <= 3 (or so). 173. */ 174. limits = circle_ptr(ls->range); 175. if ((max_y = (ls->y + ls->range)) >= ROWNO) 176. max_y = ROWNO - 1; 177. if ((y = (ls->y - ls->range)) < 0) 178. y = 0; 179. for (; y <= max_y; y++) { 180. row = cs_rows[y]; 181. offset = limits[abs(y - ls->y)]; 182. if ((min_x = (ls->x - offset)) < 0) 183. min_x = 0; 184. if ((max_x = (ls->x + offset)) >= COLNO) 185. max_x = COLNO - 1; 186. 187. if (ls->x == u.ux && ls->y == u.uy) { 188. /* 189. * If the light source is located at the hero, then 190. * we can use the COULD_SEE bits already calculated 191. * by the vision system. More importantly than 192. * this optimization, is that it allows the vision 193. * system to correct problems with clear_path(). 194. * The function clear_path() is a simple LOS 195. * path checker that doesn't go out of its way to 196. * make things look "correct". The vision system 197. * does this. 198. */ 199. for (x = min_x; x <= max_x; x++) 200. if (row[x] & COULD_SEE) 201. row[x] |= TEMP_LIT; 202. } else { 203. for (x = min_x; x <= max_x; x++) 204. if ((ls->x == x && ls->y == y) 205. || clear_path((int) ls->x, (int) ls->y, x, y)) 206. row[x] |= TEMP_LIT; 207. } 208. } 209. } 210. } 211. } 212. 213. /* lit 'obj' has been thrown or kicked and is passing through x,y on the 214. way to its destination; show its light so that hero has a chance to 215. remember terrain, objects, and monsters being revealed */ 216. void 217. show_transient_light(obj, x, y) 218. struct obj *obj; 219. int x, y; 220. { 221. light_source *ls; 222. struct monst *mon; 223. int radius_squared; 224. 225. /* caller has verified obj->lamplit and that hero is not Blind; 226. validate light source and obtain its radius (for monster sightings) */ 227. for (ls = light_base; ls; ls = ls->next) { 228. if (ls->type != LS_OBJECT) 229. continue; 230. if (ls->id.a_obj == obj) 231. break; 232. } 233. if (!ls || obj->where != OBJ_FREE) { 234. impossible("transient light %s %s is not %s?", 235. obj->lamplit ? "lit" : "unlit", xname(obj), 236. !ls ? "a light source" : "free"); 237. } else { 238. /* "expensive" but rare */ 239. place_object(obj, bhitpos.x, bhitpos.y); /* temporarily put on map */ 240. vision_recalc(0); 241. flush_screen(0); 242. delay_output(); 243. remove_object(obj); /* take back off of map */ 244. 245. radius_squared = ls->range * ls->range; 246. for (mon = fmon; mon; mon = mon->nmon) { 247. if (DEADMONSTER(mon)) 248. continue; 249. /* light range is the radius of a circle and we're limiting 250. canseemon() to a square exclosing that circle, but setting 251. mtemplit 'erroneously' for a seen monster is not a problem; 252. it just flags monsters for another canseemon() check when 253. 'obj' has reached its destination after missile traversal */ 254. if (dist2(mon->mx, mon->my, x, y) <= radius_squared 255. && canseemon(mon)) 256. mon->mtemplit = 1; 257. /* [what about worm tails?] */ 258. } 259. } 260. } 261. 262. /* draw "remembered, unseen monster" glyph at locations where a monster 263. was flagged for being visible during transient light movement but can't 264. be seen now */ 265. void 266. transient_light_cleanup() 267. { 268. struct monst *mon; 269. int mtempcount = 0; 270. 271. for (mon = fmon; mon; mon = mon->nmon) { 272. if (DEADMONSTER(mon)) 273. continue; 274. if (mon->mtemplit) { 275. mon->mtemplit = 0; 276. ++mtempcount; 277. if (!canseemon(mon)) 278. map_invisible(mon->mx, mon->my); 279. } 280. } 281. if (mtempcount) { 282. vision_recalc(0); 283. flush_screen(0); 284. } 285. } 286. 287. /* (mon->mx == 0) implies migrating */ 288. #define mon_is_local(mon) ((mon)->mx > 0) 289. 290. struct monst * 291. find_mid(nid, fmflags) 292. unsigned nid; 293. unsigned fmflags; 294. { 295. struct monst *mtmp; 296. 297. if (!nid) 298. return &youmonst; 299. if (fmflags & FM_FMON) 300. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) 301. if (!DEADMONSTER(mtmp) && mtmp->m_id == nid) 302. return mtmp; 303. if (fmflags & FM_MIGRATE) 304. for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) 305. if (mtmp->m_id == nid) 306. return mtmp; 307. if (fmflags & FM_MYDOGS) 308. for (mtmp = mydogs; mtmp; mtmp = mtmp->nmon) 309. if (mtmp->m_id == nid) 310. return mtmp; 311. return (struct monst *) 0; 312. } 313. 314. /* Save all light sources of the given range. */ 315. void 316. save_light_sources(fd, mode, range) 317. int fd, mode, range; 318. { 319. int count, actual, is_global; 320. light_source **prev, *curr; 321. 322. if (perform_bwrite(mode)) { 323. count = maybe_write_ls(fd, range, FALSE); 324. bwrite(fd, (genericptr_t) &count, sizeof count); 325. actual = maybe_write_ls(fd, range, TRUE); 326. if (actual != count) 327. panic("counted %d light sources, wrote %d! [range=%d]", count, 328. actual, range); 329. } 330. 331. if (release_data(mode)) { 332. for (prev = &light_base; (curr = *prev) != 0;) { 333. if (!curr->id.a_monst) { 334. impossible("save_light_sources: no id! [range=%d]", range); 335. is_global = 0; 336. } else 337. switch (curr->type) { 338. case LS_OBJECT: 339. is_global = !obj_is_local(curr->id.a_obj); 340. break; 341. case LS_MONSTER: 342. is_global = !mon_is_local(curr->id.a_monst); 343. break; 344. default: 345. is_global = 0; 346. impossible("save_light_sources: bad type (%d) [range=%d]", 347. curr->type, range); 348. break; 349. } 350. /* if global and not doing local, or vice versa, remove it */ 351. if (is_global ^ (range == RANGE_LEVEL)) { 352. *prev = curr->next; 353. free((genericptr_t) curr); 354. } else { 355. prev = &(*prev)->next; 356. } 357. } 358. } 359. } 360. 361. /* 362. * Pull in the structures from disk, but don't recalculate the object 363. * pointers. 364. */ 365. void 366. restore_light_sources(fd) 367. int fd; 368. { 369. int count; 370. light_source *ls; 371. 372. /* restore elements */ 373. mread(fd, (genericptr_t) &count, sizeof count); 374. 375. while (count-- > 0) { 376. ls = (light_source *) alloc(sizeof(light_source)); 377. mread(fd, (genericptr_t) ls, sizeof(light_source)); 378. ls->next = light_base; 379. light_base = ls; 380. } 381. } 382. 383. /* to support '#stats' wizard-mode command */ 384. void 385. light_stats(hdrfmt, hdrbuf, count, size) 386. const char *hdrfmt; 387. char *hdrbuf; 388. long *count, *size; 389. { 390. light_source *ls; 391. 392. Sprintf(hdrbuf, hdrfmt, (long) sizeof (light_source)); 393. *count = *size = 0L; 394. for (ls = light_base; ls; ls = ls->next) { 395. ++*count; 396. *size += (long) sizeof *ls; 397. } 398. } 399. 400. /* Relink all lights that are so marked. */ 401. void 402. relink_light_sources(ghostly) 403. boolean ghostly; 404. { 405. char which; 406. unsigned nid; 407. light_source *ls; 408. 409. for (ls = light_base; ls; ls = ls->next) { 410. if (ls->flags & LSF_NEEDS_FIXUP) { 411. if (ls->type == LS_OBJECT || ls->type == LS_MONSTER) { 412. if (ghostly) { 413. if (!lookup_id_mapping(ls->id.a_uint, &nid)) 414. impossible("relink_light_sources: no id mapping"); 415. } else 416. nid = ls->id.a_uint; 417. if (ls->type == LS_OBJECT) { 418. which = 'o'; 419. ls->id.a_obj = find_oid(nid); 420. } else { 421. which = 'm'; 422. ls->id.a_monst = find_mid(nid, FM_EVERYWHERE); 423. } 424. if (!ls->id.a_monst) 425. impossible("relink_light_sources: cant find %c_id %d", 426. which, nid); 427. } else 428. impossible("relink_light_sources: bad type (%d)", ls->type); 429. 430. ls->flags &= ~LSF_NEEDS_FIXUP; 431. } 432. } 433. } 434. 435. /* 436. * Part of the light source save routine. Count up the number of light 437. * sources that would be written. If write_it is true, actually write 438. * the light source out. 439. */ 440. STATIC_OVL int 441. maybe_write_ls(fd, range, write_it) 442. int fd, range; 443. boolean write_it; 444. { 445. int count = 0, is_global; 446. light_source *ls; 447. 448. for (ls = light_base; ls; ls = ls->next) { 449. if (!ls->id.a_monst) { 450. impossible("maybe_write_ls: no id! [range=%d]", range); 451. continue; 452. } 453. switch (ls->type) { 454. case LS_OBJECT: 455. is_global = !obj_is_local(ls->id.a_obj); 456. break; 457. case LS_MONSTER: 458. is_global = !mon_is_local(ls->id.a_monst); 459. break; 460. default: 461. is_global = 0; 462. impossible("maybe_write_ls: bad type (%d) [range=%d]", ls->type, 463. range); 464. break; 465. } 466. /* if global and not doing local, or vice versa, count it */ 467. if (is_global ^ (range == RANGE_LEVEL)) { 468. count++; 469. if (write_it) 470. write_ls(fd, ls); 471. } 472. } 473. 474. return count; 475. } 476. 477. void 478. light_sources_sanity_check() 479. { 480. light_source *ls; 481. struct monst *mtmp; 482. struct obj *otmp; 483. unsigned int auint; 484. 485. for (ls = light_base; ls; ls = ls->next) { 486. if (!ls->id.a_monst) 487. panic("insane light source: no id!"); 488. if (ls->type == LS_OBJECT) { 489. otmp = (struct obj *) ls->id.a_obj; 490. auint = otmp->o_id; 491. if (find_oid(auint) != otmp) 492. panic("insane light source: can't find obj #%u!", auint); 493. } else if (ls->type == LS_MONSTER) { 494. mtmp = (struct monst *) ls->id.a_monst; 495. auint = mtmp->m_id; 496. if (find_mid(auint, FM_EVERYWHERE) != mtmp) 497. panic("insane light source: can't find mon #%u!", auint); 498. } else { 499. panic("insane light source: bad ls type %d", ls->type); 500. } 501. } 502. } 503. 504. /* Write a light source structure to disk. */ 505. STATIC_OVL void 506. write_ls(fd, ls) 507. int fd; 508. light_source *ls; 509. { 510. anything arg_save; 511. struct obj *otmp; 512. struct monst *mtmp; 513. 514. if (ls->type == LS_OBJECT || ls->type == LS_MONSTER) { 515. if (ls->flags & LSF_NEEDS_FIXUP) { 516. bwrite(fd, (genericptr_t) ls, sizeof(light_source)); 517. } else { 518. /* replace object pointer with id for write, then put back */ 519. arg_save = ls->id; 520. if (ls->type == LS_OBJECT) { 521. otmp = ls->id.a_obj; 522. ls->id = zeroany; 523. ls->id.a_uint = otmp->o_id; 524. if (find_oid((unsigned) ls->id.a_uint) != otmp) 525. impossible("write_ls: can't find obj #%u!", 526. ls->id.a_uint); 527. } else { /* ls->type == LS_MONSTER */ 528. mtmp = (struct monst *) ls->id.a_monst; 529. ls->id = zeroany; 530. ls->id.a_uint = mtmp->m_id; 531. if (find_mid((unsigned) ls->id.a_uint, FM_EVERYWHERE) != mtmp) 532. impossible("write_ls: can't find mon #%u!", 533. ls->id.a_uint); 534. } 535. ls->flags |= LSF_NEEDS_FIXUP; 536. bwrite(fd, (genericptr_t) ls, sizeof(light_source)); 537. ls->id = arg_save; 538. ls->flags &= ~LSF_NEEDS_FIXUP; 539. } 540. } else { 541. impossible("write_ls: bad type (%d)", ls->type); 542. } 543. } 544. 545. /* Change light source's ID from src to dest. */ 546. void 547. obj_move_light_source(src, dest) 548. struct obj *src, *dest; 549. { 550. light_source *ls; 551. 552. for (ls = light_base; ls; ls = ls->next) 553. if (ls->type == LS_OBJECT && ls->id.a_obj == src) 554. ls->id.a_obj = dest; 555. src->lamplit = 0; 556. dest->lamplit = 1; 557. } 558. 559. /* return true if there exist any light sources */ 560. boolean 561. any_light_source() 562. { 563. return (boolean) (light_base != (light_source *) 0); 564. } 565. 566. /* 567. * Snuff an object light source if at (x,y). This currently works 568. * only for burning light sources. 569. */ 570. void 571. snuff_light_source(x, y) 572. int x, y; 573. { 574. light_source *ls; 575. struct obj *obj; 576. 577. for (ls = light_base; ls; ls = ls->next) 578. /* 579. * Is this position check valid??? Can I assume that the positions 580. * will always be correct because the objects would have been 581. * updated with the last vision update? [Is that recent enough???] 582. */ 583. if (ls->type == LS_OBJECT && ls->x == x && ls->y == y) { 584. obj = ls->id.a_obj; 585. if (obj_is_burning(obj)) { 586. /* The only way to snuff Sunsword is to unwield it. Darkness 587. * scrolls won't affect it. (If we got here because it was 588. * dropped or thrown inside a monster, this won't matter 589. * anyway because it will go out when dropped.) 590. */ 591. if (artifact_light(obj)) 592. continue; 593. end_burn(obj, obj->otyp != MAGIC_LAMP); 594. /* 595. * The current ls element has just been removed (and 596. * ls->next is now invalid). Return assuming that there 597. * is only one light source attached to each object. 598. */ 599. return; 600. } 601. } 602. } 603. 604. /* Return TRUE if object sheds any light at all. */ 605. boolean 606. obj_sheds_light(obj) 607. struct obj *obj; 608. { 609. /* so far, only burning objects shed light */ 610. return obj_is_burning(obj); 611. } 612. 613. /* Return TRUE if sheds light AND will be snuffed by end_burn(). */ 614. boolean 615. obj_is_burning(obj) 616. struct obj *obj; 617. { 618. return (boolean) (obj->lamplit && (obj->otyp == MAGIC_LAMP 619. || ignitable(obj) 620. || artifact_light(obj))); 621. } 622. 623. /* copy the light source(s) attached to src, and attach it/them to dest */ 624. void 625. obj_split_light_source(src, dest) 626. struct obj *src, *dest; 627. { 628. light_source *ls, *new_ls; 629. 630. for (ls = light_base; ls; ls = ls->next) 631. if (ls->type == LS_OBJECT && ls->id.a_obj == src) { 632. /* 633. * Insert the new source at beginning of list. This will 634. * never interfere us walking down the list - we are already 635. * past the insertion point. 636. */ 637. new_ls = (light_source *) alloc(sizeof(light_source)); 638. *new_ls = *ls; 639. if (Is_candle(src)) { 640. /* split candles may emit less light than original group */ 641. ls->range = candle_light_range(src); 642. new_ls->range = candle_light_range(dest); 643. vision_full_recalc = 1; /* in case range changed */ 644. } 645. new_ls->id.a_obj = dest; 646. new_ls->next = light_base; 647. light_base = new_ls; 648. dest->lamplit = 1; /* now an active light source */ 649. } 650. } 651. 652. /* light source `src' has been folded into light source `dest'; 653. used for merging lit candles and adding candle(s) to lit candelabrum */ 654. void 655. obj_merge_light_sources(src, dest) 656. struct obj *src, *dest; 657. { 658. light_source *ls; 659. 660. /* src == dest implies adding to candelabrum */ 661. if (src != dest) 662. end_burn(src, TRUE); /* extinguish candles */ 663. 664. for (ls = light_base; ls; ls = ls->next) 665. if (ls->type == LS_OBJECT && ls->id.a_obj == dest) { 666. ls->range = candle_light_range(dest); 667. vision_full_recalc = 1; /* in case range changed */ 668. break; 669. } 670. } 671. 672. /* light source `obj' is being made brighter or dimmer */ 673. void 674. obj_adjust_light_radius(obj, new_radius) 675. struct obj *obj; 676. int new_radius; 677. { 678. light_source *ls; 679. 680. for (ls = light_base; ls; ls = ls->next) 681. if (ls->type == LS_OBJECT && ls->id.a_obj == obj) { 682. if (new_radius != ls->range) 683. vision_full_recalc = 1; 684. ls->range = new_radius; 685. return; 686. } 687. impossible("obj_adjust_light_radius: can't find %s", xname(obj)); 688. } 689. 690. /* Candlelight is proportional to the number of candles; 691. minimum range is 2 rather than 1 for playability. */ 692. int 693. candle_light_range(obj) 694. struct obj *obj; 695. { 696. int radius; 697. 698. if (obj->otyp == CANDELABRUM_OF_INVOCATION) { 699. /* 700. * The special candelabrum emits more light than the 701. * corresponding number of candles would. 702. * 1..3 candles, range 2 (minimum range); 703. * 4..6 candles, range 3 (normal lamp range); 704. * 7 candles, range 4 (bright). 705. */ 706. radius = (obj->spe < 4) ? 2 : (obj->spe < 7) ? 3 : 4; 707. } else if (Is_candle(obj)) { 708. /* 709. * Range is incremented by powers of 7 so that it will take 710. * wizard mode quantities of candles to get more light than 711. * from a lamp, without imposing an arbitrary limit. 712. * 1..6 candles, range 2; 713. * 7..48 candles, range 3; 714. * 49..342 candles, range 4; &c. 715. */ 716. long n = obj->quan; 717. 718. radius = 1; /* always incremented at least once */ 719. do { 720. radius++; 721. n /= 7L; 722. } while (n > 0L); 723. } else { 724. /* we're only called for lit candelabrum or candles */ 725. /* impossible("candlelight for %d?", obj->otyp); */ 726. radius = 3; /* lamp's value */ 727. } 728. return radius; 729. } 730. 731. /* light emitting artifact's range depends upon its curse/bless state */ 732. int 733. arti_light_radius(obj) 734. struct obj *obj; 735. { 736. /* 737. * Used by begin_burn() when setting up a new light source 738. * (obj->lamplit will already be set by this point) and 739. * also by bless()/unbless()/uncurse()/curse() to decide 740. * whether to call obj_adjust_light_radius(). 741. */ 742. 743. /* sanity check [simplifies usage by bless()/curse()/&c] */ 744. if (!obj->lamplit || !artifact_light(obj)) 745. return 0; 746. 747. /* cursed radius of 1 is not noticeable for an item that's 748. carried by the hero but is if it's carried by a monster 749. or left lit on the floor (not applicable for Sunsword) */ 750. return (obj->blessed ? 3 : !obj->cursed ? 2 : 1); 751. } 752. 753. /* adverb describing lit artifact's light; depends on curse/bless state */ 754. const char * 755. arti_light_description(obj) 756. struct obj *obj; 757. { 758. switch (arti_light_radius(obj)) { 759. case 3: 760. return "brilliantly"; /* blessed */ 761. case 2: 762. return "brightly"; /* uncursed */ 763. case 1: 764. return "dimly"; /* cursed */ 765. default: 766. break; 767. } 768. return "strangely"; 769. } 770. 771. int 772. wiz_light_sources() 773. { 774. winid win; 775. char buf[BUFSZ]; 776. light_source *ls; 777. 778. win = create_nhwindow(NHW_MENU); /* corner text window */ 779. if (win == WIN_ERR) 780. return 0; 781. 782. Sprintf(buf, "Mobile light sources: hero @ (%2d,%2d)", u.ux, u.uy); 783. putstr(win, 0, buf); 784. putstr(win, 0, ""); 785. 786. if (light_base) { 787. putstr(win, 0, "location range flags type id"); 788. putstr(win, 0, "-------- ----- ------ ---- -------"); 789. for (ls = light_base; ls; ls = ls->next) { 790. Sprintf(buf, " %2d,%2d %2d 0x%04x %s %s", ls->x, ls->y, 791. ls->range, ls->flags, 792. (ls->type == LS_OBJECT 793. ? "obj" 794. : ls->type == LS_MONSTER 795. ? (mon_is_local(ls->id.a_monst) 796. ? "mon" 797. : (ls->id.a_monst == &youmonst) 798. ? "you" 799. /* migrating monster */ 800. : "<m>") 801. : "???"), 802. fmt_ptr(ls->id.a_void)); 803. putstr(win, 0, buf); 804. } 805. } else 806. putstr(win, 0, "<none>"); 807. 808. display_nhwindow(win, FALSE); 809. destroy_nhwindow(win); 810. 811. return 0; 812. } 813. 814. /*light.c*/