Source:NetHack 3.6.2/src/detect.c
Jump to navigation
Jump to search
Below is the full text to detect.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/detect.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 detect.c $NHDT-Date: 1544437284 2018/12/10 10:21:24 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.91 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2018. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. /* 7. * Detection routines, including crystal ball, magic mapping, and search 8. * command. 9. */ 10. 11. #include "hack.h" 12. #include "artifact.h" 13. 14. extern boolean known; /* from read.c */ 15. 16. STATIC_DCL boolean NDECL(unconstrain_map); 17. STATIC_DCL void NDECL(reconstrain_map); 18. STATIC_DCL void FDECL(browse_map, (int, const char *)); 19. STATIC_DCL void FDECL(map_monst, (struct monst *, BOOLEAN_P)); 20. STATIC_DCL void FDECL(do_dknown_of, (struct obj *)); 21. STATIC_DCL boolean FDECL(check_map_spot, (int, int, CHAR_P, unsigned)); 22. STATIC_DCL boolean FDECL(clear_stale_map, (CHAR_P, unsigned)); 23. STATIC_DCL void FDECL(sense_trap, (struct trap *, XCHAR_P, XCHAR_P, int)); 24. STATIC_DCL int FDECL(detect_obj_traps, (struct obj *, BOOLEAN_P, int)); 25. STATIC_DCL void FDECL(show_map_spot, (int, int)); 26. STATIC_PTR void FDECL(findone, (int, int, genericptr_t)); 27. STATIC_PTR void FDECL(openone, (int, int, genericptr_t)); 28. STATIC_DCL int FDECL(mfind0, (struct monst *, BOOLEAN_P)); 29. STATIC_DCL int FDECL(reveal_terrain_getglyph, (int, int, int, 30. unsigned, int, int)); 31. 32. /* bring hero out from underwater or underground or being engulfed; 33. return True iff any change occurred */ 34. STATIC_OVL boolean 35. unconstrain_map() 36. { 37. boolean res = u.uinwater || u.uburied || u.uswallow; 38. 39. /* bring Underwater, buried, or swallowed hero to normal map */ 40. iflags.save_uinwater = u.uinwater, u.uinwater = 0; 41. iflags.save_uburied = u.uburied, u.uburied = 0; 42. iflags.save_uswallow = u.uswallow, u.uswallow = 0; 43. 44. return res; 45. } 46. 47. /* put hero back underwater or underground or engulfed */ 48. STATIC_OVL void 49. reconstrain_map() 50. { 51. u.uinwater = iflags.save_uinwater, iflags.save_uinwater = 0; 52. u.uburied = iflags.save_uburied, iflags.save_uburied = 0; 53. u.uswallow = iflags.save_uswallow, iflags.save_uswallow = 0; 54. } 55. 56. /* use getpos()'s 'autodescribe' to view whatever is currently shown on map */ 57. STATIC_DCL void 58. browse_map(ter_typ, ter_explain) 59. int ter_typ; 60. const char *ter_explain; 61. { 62. coord dummy_pos; /* don't care whether player actually picks a spot */ 63. boolean save_autodescribe; 64. 65. dummy_pos.x = u.ux, dummy_pos.y = u.uy; /* starting spot for getpos() */ 66. save_autodescribe = iflags.autodescribe; 67. iflags.autodescribe = TRUE; 68. iflags.terrainmode = ter_typ; 69. getpos(&dummy_pos, FALSE, ter_explain); 70. iflags.terrainmode = 0; 71. iflags.autodescribe = save_autodescribe; 72. } 73. 74. /* extracted from monster_detection() so can be shared by do_vicinity_map() */ 75. STATIC_DCL void 76. map_monst(mtmp, showtail) 77. struct monst *mtmp; 78. boolean showtail; 79. { 80. if (def_monsyms[(int) mtmp->data->mlet].sym == ' ') 81. show_glyph(mtmp->mx, mtmp->my, 82. detected_mon_to_glyph(mtmp, newsym_rn2)); 83. else 84. show_glyph(mtmp->mx, mtmp->my, mtmp->mtame 85. ? pet_to_glyph(mtmp, newsym_rn2) 86. : mon_to_glyph(mtmp, newsym_rn2)); 87. 88. if (showtail && mtmp->data == &mons[PM_LONG_WORM]) 89. detect_wsegs(mtmp, 0); 90. } 91. 92. /* this is checking whether a trap symbol represents a trapped chest, 93. not whether a trapped chest is actually present */ 94. boolean 95. trapped_chest_at(ttyp, x, y) 96. int ttyp; 97. int x, y; 98. { 99. struct monst *mtmp; 100. struct obj *otmp; 101. 102. if (!glyph_is_trap(glyph_at(x, y))) 103. return FALSE; 104. if (ttyp != BEAR_TRAP || (Hallucination && rn2(20))) 105. return FALSE; 106. 107. /* 108. * TODO? We should check containers recursively like the trap 109. * detecting routine does. Chests and large boxes do not nest in 110. * themselves or each other, but could be contained inside statues. 111. * 112. * For farlook, we should also check for buried containers, but 113. * for '^' command to examine adjacent trap glyph, we shouldn't. 114. */ 115. 116. /* on map, presence of any trappable container will do */ 117. if (sobj_at(CHEST, x, y) || sobj_at(LARGE_BOX, x, y)) 118. return TRUE; 119. /* in inventory, we need to find one which is actually trapped */ 120. if (x == u.ux && y == u.uy) { 121. for (otmp = invent; otmp; otmp = otmp->nobj) 122. if (Is_box(otmp) && otmp->otrapped) 123. return TRUE; 124. if (u.usteed) { /* steed isn't on map so won't be found by m_at() */ 125. for (otmp = u.usteed->minvent; otmp; otmp = otmp->nobj) 126. if (Is_box(otmp) && otmp->otrapped) 127. return TRUE; 128. } 129. } 130. if ((mtmp = m_at(x, y)) != 0) 131. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 132. if (Is_box(otmp) && otmp->otrapped) 133. return TRUE; 134. return FALSE; 135. } 136. 137. /* this is checking whether a trap symbol represents a trapped door, 138. not whether the door here is actually trapped */ 139. boolean 140. trapped_door_at(ttyp, x, y) 141. int ttyp; 142. int x, y; 143. { 144. struct rm *lev; 145. 146. if (!glyph_is_trap(glyph_at(x, y))) 147. return FALSE; 148. if (ttyp != BEAR_TRAP || (Hallucination && rn2(20))) 149. return FALSE; 150. lev = &levl[x][y]; 151. if (!IS_DOOR(lev->typ)) 152. return FALSE; 153. if ((lev->doormask & (D_NODOOR | D_BROKEN | D_ISOPEN)) != 0 154. && trapped_chest_at(ttyp, x, y)) 155. return FALSE; 156. return TRUE; 157. } 158. 159. /* recursively search obj for an object in class oclass, return 1st found */ 160. struct obj * 161. o_in(obj, oclass) 162. struct obj *obj; 163. char oclass; 164. { 165. register struct obj *otmp; 166. struct obj *temp; 167. 168. if (obj->oclass == oclass) 169. return obj; 170. /* 171. * Note: we exclude SchroedingersBox because the corpse it contains 172. * isn't necessarily a corpse yet. Resolving the status would lead 173. * to complications if it turns out to be a live cat. We know that 174. * that Box can't contain anything else because putting something in 175. * would resolve the cat/corpse situation and convert to ordinary box. 176. */ 177. if (Has_contents(obj) && !SchroedingersBox(obj)) { 178. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) 179. if (otmp->oclass == oclass) 180. return otmp; 181. else if (Has_contents(otmp) && (temp = o_in(otmp, oclass)) != 0) 182. return temp; 183. } 184. return (struct obj *) 0; 185. } 186. 187. /* Recursively search obj for an object made of specified material. 188. * Return first found. 189. */ 190. struct obj * 191. o_material(obj, material) 192. struct obj *obj; 193. unsigned material; 194. { 195. register struct obj *otmp; 196. struct obj *temp; 197. 198. if (objects[obj->otyp].oc_material == material) 199. return obj; 200. 201. if (Has_contents(obj)) { 202. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) 203. if (objects[otmp->otyp].oc_material == material) 204. return otmp; 205. else if (Has_contents(otmp) 206. && (temp = o_material(otmp, material)) != 0) 207. return temp; 208. } 209. return (struct obj *) 0; 210. } 211. 212. STATIC_OVL void 213. do_dknown_of(obj) 214. struct obj *obj; 215. { 216. struct obj *otmp; 217. 218. obj->dknown = 1; 219. if (Has_contents(obj)) { 220. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) 221. do_dknown_of(otmp); 222. } 223. } 224. 225. /* Check whether the location has an outdated object displayed on it. */ 226. STATIC_OVL boolean 227. check_map_spot(x, y, oclass, material) 228. int x, y; 229. char oclass; 230. unsigned material; 231. { 232. int glyph; 233. register struct obj *otmp; 234. register struct monst *mtmp; 235. 236. glyph = glyph_at(x, y); 237. if (glyph_is_object(glyph)) { 238. /* there's some object shown here */ 239. if (oclass == ALL_CLASSES) { 240. return (boolean) !(level.objects[x][y] /* stale if nothing here */ 241. || ((mtmp = m_at(x, y)) != 0 && mtmp->minvent)); 242. } else { 243. if (material 244. && objects[glyph_to_obj(glyph)].oc_material == material) { 245. /* object shown here is of interest because material matches */ 246. for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) 247. if (o_material(otmp, GOLD)) 248. return FALSE; 249. /* didn't find it; perhaps a monster is carrying it */ 250. if ((mtmp = m_at(x, y)) != 0) { 251. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 252. if (o_material(otmp, GOLD)) 253. return FALSE; 254. } 255. /* detection indicates removal of this object from the map */ 256. return TRUE; 257. } 258. if (oclass && objects[glyph_to_obj(glyph)].oc_class == oclass) { 259. /* obj shown here is of interest because its class matches */ 260. for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) 261. if (o_in(otmp, oclass)) 262. return FALSE; 263. /* didn't find it; perhaps a monster is carrying it */ 264. if ((mtmp = m_at(x, y)) != 0) { 265. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 266. if (o_in(otmp, oclass)) 267. return FALSE; 268. } 269. /* detection indicates removal of this object from the map */ 270. return TRUE; 271. } 272. } 273. } 274. return FALSE; 275. } 276. 277. /* 278. * When doing detection, remove stale data from the map display (corpses 279. * rotted away, objects carried away by monsters, etc) so that it won't 280. * reappear after the detection has completed. Return true if noticeable 281. * change occurs. 282. */ 283. STATIC_OVL boolean 284. clear_stale_map(oclass, material) 285. char oclass; 286. unsigned material; 287. { 288. register int zx, zy; 289. boolean change_made = FALSE; 290. 291. for (zx = 1; zx < COLNO; zx++) 292. for (zy = 0; zy < ROWNO; zy++) 293. if (check_map_spot(zx, zy, oclass, material)) { 294. unmap_object(zx, zy); 295. change_made = TRUE; 296. } 297. 298. return change_made; 299. } 300. 301. /* look for gold, on the floor or in monsters' possession */ 302. int 303. gold_detect(sobj) 304. register struct obj *sobj; 305. { 306. register struct obj *obj; 307. register struct monst *mtmp; 308. struct obj gold, *temp = 0; 309. boolean stale, ugold = FALSE, steedgold = FALSE; 310. int ter_typ = TER_DETECT | TER_OBJ; 311. 312. known = stale = clear_stale_map(COIN_CLASS, 313. (unsigned) (sobj->blessed ? GOLD : 0)); 314. 315. /* look for gold carried by monsters (might be in a container) */ 316. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 317. if (DEADMONSTER(mtmp)) 318. continue; /* probably not needed in this case but... */ 319. if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) { 320. if (mtmp == u.usteed) { 321. steedgold = TRUE; 322. } else { 323. known = TRUE; 324. goto outgoldmap; /* skip further searching */ 325. } 326. } else { 327. for (obj = mtmp->minvent; obj; obj = obj->nobj) 328. if ((sobj->blessed && o_material(obj, GOLD)) 329. || o_in(obj, COIN_CLASS)) { 330. if (mtmp == u.usteed) { 331. steedgold = TRUE; 332. } else { 333. known = TRUE; 334. goto outgoldmap; /* skip further searching */ 335. } 336. } 337. } 338. } 339. 340. /* look for gold objects */ 341. for (obj = fobj; obj; obj = obj->nobj) { 342. if (sobj->blessed && o_material(obj, GOLD)) { 343. known = TRUE; 344. if (obj->ox != u.ux || obj->oy != u.uy) 345. goto outgoldmap; 346. } else if (o_in(obj, COIN_CLASS)) { 347. known = TRUE; 348. if (obj->ox != u.ux || obj->oy != u.uy) 349. goto outgoldmap; 350. } 351. } 352. 353. if (!known) { 354. /* no gold found on floor or monster's inventory. 355. adjust message if you have gold in your inventory */ 356. if (sobj) { 357. char buf[BUFSZ]; 358. 359. if (youmonst.data == &mons[PM_GOLD_GOLEM]) 360. Sprintf(buf, "You feel like a million %s!", currency(2L)); 361. else if (money_cnt(invent) || hidden_gold()) 362. Strcpy(buf, 363. "You feel worried about your future financial situation."); 364. else if (steedgold) 365. Sprintf(buf, "You feel interested in %s financial situation.", 366. s_suffix(x_monnam(u.usteed, 367. u.usteed->mtame ? ARTICLE_YOUR 368. : ARTICLE_THE, 369. (char *) 0, 370. SUPPRESS_SADDLE, FALSE))); 371. else 372. Strcpy(buf, "You feel materially poor."); 373. 374. strange_feeling(sobj, buf); 375. } 376. return 1; 377. } 378. /* only under me - no separate display required */ 379. if (stale) 380. docrt(); 381. You("notice some gold between your %s.", makeplural(body_part(FOOT))); 382. return 0; 383. 384. outgoldmap: 385. cls(); 386. 387. (void) unconstrain_map(); 388. /* Discover gold locations. */ 389. for (obj = fobj; obj; obj = obj->nobj) { 390. if (sobj->blessed && (temp = o_material(obj, GOLD)) != 0) { 391. if (temp != obj) { 392. temp->ox = obj->ox; 393. temp->oy = obj->oy; 394. } 395. map_object(temp, 1); 396. } else if ((temp = o_in(obj, COIN_CLASS)) != 0) { 397. if (temp != obj) { 398. temp->ox = obj->ox; 399. temp->oy = obj->oy; 400. } 401. map_object(temp, 1); 402. } 403. if (temp && temp->ox == u.ux && temp->oy == u.uy) 404. ugold = TRUE; 405. } 406. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 407. if (DEADMONSTER(mtmp)) 408. continue; /* probably overkill here */ 409. temp = 0; 410. if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) { 411. gold = zeroobj; /* ensure oextra is cleared too */ 412. gold.otyp = GOLD_PIECE; 413. gold.quan = (long) rnd(10); /* usually more than 1 */ 414. gold.ox = mtmp->mx; 415. gold.oy = mtmp->my; 416. map_object(&gold, 1); 417. temp = &gold; 418. } else { 419. for (obj = mtmp->minvent; obj; obj = obj->nobj) 420. if (sobj->blessed && (temp = o_material(obj, GOLD)) != 0) { 421. temp->ox = mtmp->mx; 422. temp->oy = mtmp->my; 423. map_object(temp, 1); 424. break; 425. } else if ((temp = o_in(obj, COIN_CLASS)) != 0) { 426. temp->ox = mtmp->mx; 427. temp->oy = mtmp->my; 428. map_object(temp, 1); 429. break; 430. } 431. } 432. if (temp && temp->ox == u.ux && temp->oy == u.uy) 433. ugold = TRUE; 434. } 435. if (!ugold) { 436. newsym(u.ux, u.uy); 437. ter_typ |= TER_MON; /* so autodescribe will recognize hero */ 438. } 439. You_feel("very greedy, and sense gold!"); 440. exercise(A_WIS, TRUE); 441. 442. browse_map(ter_typ, "gold"); 443. 444. reconstrain_map(); 445. docrt(); 446. if (Underwater) 447. under_water(2); 448. if (u.uburied) 449. under_ground(2); 450. return 0; 451. } 452. 453. /* returns 1 if nothing was detected, 0 if something was detected */ 454. int 455. food_detect(sobj) 456. register struct obj *sobj; 457. { 458. register struct obj *obj; 459. register struct monst *mtmp; 460. register int ct = 0, ctu = 0; 461. boolean confused = (Confusion || (sobj && sobj->cursed)), stale; 462. char oclass = confused ? POTION_CLASS : FOOD_CLASS; 463. const char *what = confused ? something : "food"; 464. 465. stale = clear_stale_map(oclass, 0); 466. if (u.usteed) /* some situations leave steed with stale coordinates */ 467. u.usteed->mx = u.ux, u.usteed->my = u.uy; 468. 469. for (obj = fobj; obj; obj = obj->nobj) 470. if (o_in(obj, oclass)) { 471. if (obj->ox == u.ux && obj->oy == u.uy) 472. ctu++; 473. else 474. ct++; 475. } 476. for (mtmp = fmon; mtmp && (!ct || !ctu); mtmp = mtmp->nmon) { 477. /* no DEADMONSTER(mtmp) check needed -- dmons never have inventory */ 478. for (obj = mtmp->minvent; obj; obj = obj->nobj) 479. if (o_in(obj, oclass)) { 480. if (mtmp->mx == u.ux && mtmp->my == u.uy) 481. ctu++; /* steed or an engulfer with inventory */ 482. else 483. ct++; 484. break; 485. } 486. } 487. 488. if (!ct && !ctu) { 489. known = stale && !confused; 490. if (stale) { 491. docrt(); 492. You("sense a lack of %s nearby.", what); 493. if (sobj && sobj->blessed) { 494. if (!u.uedibility) 495. Your("%s starts to tingle.", body_part(NOSE)); 496. u.uedibility = 1; 497. } 498. } else if (sobj) { 499. char buf[BUFSZ]; 500. 501. Sprintf(buf, "Your %s twitches%s.", body_part(NOSE), 502. (sobj->blessed && !u.uedibility) 503. ? " then starts to tingle" 504. : ""); 505. if (sobj->blessed && !u.uedibility) { 506. boolean savebeginner = flags.beginner; 507. 508. flags.beginner = FALSE; /* prevent non-delivery of message */ 509. strange_feeling(sobj, buf); 510. flags.beginner = savebeginner; 511. u.uedibility = 1; 512. } else 513. strange_feeling(sobj, buf); 514. } 515. return !stale; 516. } else if (!ct) { 517. known = TRUE; 518. You("%s %s nearby.", sobj ? "smell" : "sense", what); 519. if (sobj && sobj->blessed) { 520. if (!u.uedibility) 521. pline("Your %s starts to tingle.", body_part(NOSE)); 522. u.uedibility = 1; 523. } 524. } else { 525. struct obj *temp; 526. int ter_typ = TER_DETECT | TER_OBJ; 527. 528. known = TRUE; 529. cls(); 530. (void) unconstrain_map(); 531. for (obj = fobj; obj; obj = obj->nobj) 532. if ((temp = o_in(obj, oclass)) != 0) { 533. if (temp != obj) { 534. temp->ox = obj->ox; 535. temp->oy = obj->oy; 536. } 537. map_object(temp, 1); 538. } 539. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) 540. /* no DEADMONSTER() check needed -- dmons never have inventory */ 541. for (obj = mtmp->minvent; obj; obj = obj->nobj) 542. if ((temp = o_in(obj, oclass)) != 0) { 543. temp->ox = mtmp->mx; 544. temp->oy = mtmp->my; 545. map_object(temp, 1); 546. break; /* skip rest of this monster's inventory */ 547. } 548. if (!ctu) { 549. newsym(u.ux, u.uy); 550. ter_typ |= TER_MON; /* for autodescribe of self */ 551. } 552. if (sobj) { 553. if (sobj->blessed) { 554. Your("%s %s to tingle and you smell %s.", body_part(NOSE), 555. u.uedibility ? "continues" : "starts", what); 556. u.uedibility = 1; 557. } else 558. Your("%s tingles and you smell %s.", body_part(NOSE), what); 559. } else 560. You("sense %s.", what); 561. exercise(A_WIS, TRUE); 562. 563. browse_map(ter_typ, "food"); 564. 565. reconstrain_map(); 566. docrt(); 567. if (Underwater) 568. under_water(2); 569. if (u.uburied) 570. under_ground(2); 571. } 572. return 0; 573. } 574. 575. /* 576. * Used for scrolls, potions, spells, and crystal balls. Returns: 577. * 578. * 1 - nothing was detected 579. * 0 - something was detected 580. */ 581. int 582. object_detect(detector, class) 583. struct obj *detector; /* object doing the detecting */ 584. int class; /* an object class, 0 for all */ 585. { 586. register int x, y; 587. char stuff[BUFSZ]; 588. int is_cursed = (detector && detector->cursed); 589. int do_dknown = (detector && (detector->oclass == POTION_CLASS 590. || detector->oclass == SPBOOK_CLASS) 591. && detector->blessed); 592. int ct = 0, ctu = 0; 593. register struct obj *obj, *otmp = (struct obj *) 0; 594. register struct monst *mtmp; 595. int sym, boulder = 0, ter_typ = TER_DETECT | TER_OBJ; 596. 597. if (class < 0 || class >= MAXOCLASSES) { 598. impossible("object_detect: illegal class %d", class); 599. class = 0; 600. } 601. 602. /* Special boulder symbol check - does the class symbol happen 603. * to match iflags.bouldersym which is a user-defined? 604. * If so, that means we aren't sure what they really wanted to 605. * detect. Rather than trump anything, show both possibilities. 606. * We can exclude checking the buried obj chain for boulders below. 607. */ 608. sym = class ? def_oc_syms[class].sym : 0; 609. if (sym && iflags.bouldersym && sym == iflags.bouldersym) 610. boulder = ROCK_CLASS; 611. 612. if (Hallucination || (Confusion && class == SCROLL_CLASS)) 613. Strcpy(stuff, something); 614. else 615. Strcpy(stuff, class ? def_oc_syms[class].name : "objects"); 616. if (boulder && class != ROCK_CLASS) 617. Strcat(stuff, " and/or large stones"); 618. 619. if (do_dknown) 620. for (obj = invent; obj; obj = obj->nobj) 621. do_dknown_of(obj); 622. 623. for (obj = fobj; obj; obj = obj->nobj) { 624. if ((!class && !boulder) || o_in(obj, class) || o_in(obj, boulder)) { 625. if (obj->ox == u.ux && obj->oy == u.uy) 626. ctu++; 627. else 628. ct++; 629. } 630. if (do_dknown) 631. do_dknown_of(obj); 632. } 633. 634. for (obj = level.buriedobjlist; obj; obj = obj->nobj) { 635. if (!class || o_in(obj, class)) { 636. if (obj->ox == u.ux && obj->oy == u.uy) 637. ctu++; 638. else 639. ct++; 640. } 641. if (do_dknown) 642. do_dknown_of(obj); 643. } 644. 645. if (u.usteed) 646. u.usteed->mx = u.ux, u.usteed->my = u.uy; 647. 648. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 649. if (DEADMONSTER(mtmp)) 650. continue; 651. for (obj = mtmp->minvent; obj; obj = obj->nobj) { 652. if ((!class && !boulder) || o_in(obj, class) 653. || o_in(obj, boulder)) 654. ct++; 655. if (do_dknown) 656. do_dknown_of(obj); 657. } 658. if ((is_cursed && M_AP_TYPE(mtmp) == M_AP_OBJECT 659. && (!class || class == objects[mtmp->mappearance].oc_class)) 660. || (findgold(mtmp->minvent) && (!class || class == COIN_CLASS))) { 661. ct++; 662. break; 663. } 664. } 665. 666. if (!clear_stale_map(!class ? ALL_CLASSES : class, 0) && !ct) { 667. if (!ctu) { 668. if (detector) 669. strange_feeling(detector, "You feel a lack of something."); 670. return 1; 671. } 672. 673. You("sense %s nearby.", stuff); 674. return 0; 675. } 676. 677. cls(); 678. 679. (void) unconstrain_map(); 680. /* 681. * Map all buried objects first. 682. */ 683. for (obj = level.buriedobjlist; obj; obj = obj->nobj) 684. if (!class || (otmp = o_in(obj, class)) != 0) { 685. if (class) { 686. if (otmp != obj) { 687. otmp->ox = obj->ox; 688. otmp->oy = obj->oy; 689. } 690. map_object(otmp, 1); 691. } else 692. map_object(obj, 1); 693. } 694. /* 695. * If we are mapping all objects, map only the top object of a pile or 696. * the first object in a monster's inventory. Otherwise, go looking 697. * for a matching object class and display the first one encountered 698. * at each location. 699. * 700. * Objects on the floor override buried objects. 701. */ 702. for (x = 1; x < COLNO; x++) 703. for (y = 0; y < ROWNO; y++) 704. for (obj = level.objects[x][y]; obj; obj = obj->nexthere) 705. if ((!class && !boulder) || (otmp = o_in(obj, class)) != 0 706. || (otmp = o_in(obj, boulder)) != 0) { 707. if (class || boulder) { 708. if (otmp != obj) { 709. otmp->ox = obj->ox; 710. otmp->oy = obj->oy; 711. } 712. map_object(otmp, 1); 713. } else 714. map_object(obj, 1); 715. break; 716. } 717. 718. /* Objects in the monster's inventory override floor objects. */ 719. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 720. if (DEADMONSTER(mtmp)) 721. continue; 722. for (obj = mtmp->minvent; obj; obj = obj->nobj) 723. if ((!class && !boulder) || (otmp = o_in(obj, class)) != 0 724. || (otmp = o_in(obj, boulder)) != 0) { 725. if (!class && !boulder) 726. otmp = obj; 727. otmp->ox = mtmp->mx; /* at monster location */ 728. otmp->oy = mtmp->my; 729. map_object(otmp, 1); 730. break; 731. } 732. /* Allow a mimic to override the detected objects it is carrying. */ 733. if (is_cursed && M_AP_TYPE(mtmp) == M_AP_OBJECT 734. && (!class || class == objects[mtmp->mappearance].oc_class)) { 735. struct obj temp; 736. 737. temp = zeroobj; 738. temp.otyp = mtmp->mappearance; /* needed for obj_to_glyph() */ 739. temp.quan = 1L; 740. temp.ox = mtmp->mx; 741. temp.oy = mtmp->my; 742. temp.corpsenm = PM_TENGU; /* if mimicing a corpse */ 743. map_object(&temp, 1); 744. } else if (findgold(mtmp->minvent) 745. && (!class || class == COIN_CLASS)) { 746. struct obj gold; 747. 748. gold = zeroobj; /* ensure oextra is cleared too */ 749. gold.otyp = GOLD_PIECE; 750. gold.quan = (long) rnd(10); /* usually more than 1 */ 751. gold.ox = mtmp->mx; 752. gold.oy = mtmp->my; 753. map_object(&gold, 1); 754. } 755. } 756. if (!glyph_is_object(glyph_at(u.ux, u.uy))) { 757. newsym(u.ux, u.uy); 758. ter_typ |= TER_MON; 759. } 760. You("detect the %s of %s.", ct ? "presence" : "absence", stuff); 761. 762. if (!ct) 763. display_nhwindow(WIN_MAP, TRUE); 764. else 765. browse_map(ter_typ, "object"); 766. 767. reconstrain_map(); 768. docrt(); /* this will correctly reset vision */ 769. if (Underwater) 770. under_water(2); 771. if (u.uburied) 772. under_ground(2); 773. return 0; 774. } 775. 776. /* 777. * Used by: crystal balls, potions, fountains 778. * 779. * Returns 1 if nothing was detected. 780. * Returns 0 if something was detected. 781. */ 782. int 783. monster_detect(otmp, mclass) 784. register struct obj *otmp; /* detecting object (if any) */ 785. int mclass; /* monster class, 0 for all */ 786. { 787. register struct monst *mtmp; 788. int mcnt = 0; 789. 790. /* Note: This used to just check fmon for a non-zero value 791. * but in versions since 3.3.0 fmon can test TRUE due to the 792. * presence of dmons, so we have to find at least one 793. * with positive hit-points to know for sure. 794. */ 795. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) 796. if (!DEADMONSTER(mtmp)) { 797. mcnt++; 798. break; 799. } 800. 801. if (!mcnt) { 802. if (otmp) 803. strange_feeling(otmp, Hallucination 804. ? "You get the heebie jeebies." 805. : "You feel threatened."); 806. return 1; 807. } else { 808. boolean unconstrained, woken = FALSE; 809. unsigned swallowed = u.uswallow; /* before unconstrain_map() */ 810. 811. cls(); 812. unconstrained = unconstrain_map(); 813. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 814. if (DEADMONSTER(mtmp)) 815. continue; 816. if (!mclass || mtmp->data->mlet == mclass 817. || (mtmp->data == &mons[PM_LONG_WORM] 818. && mclass == S_WORM_TAIL)) 819. map_monst(mtmp, TRUE); 820. 821. if (otmp && otmp->cursed 822. && (mtmp->msleeping || !mtmp->mcanmove)) { 823. mtmp->msleeping = mtmp->mfrozen = 0; 824. mtmp->mcanmove = 1; 825. woken = TRUE; 826. } 827. } 828. if (!swallowed) 829. display_self(); 830. You("sense the presence of monsters."); 831. if (woken) 832. pline("Monsters sense the presence of you."); 833. 834. if ((otmp && otmp->blessed) && !unconstrained) { 835. /* persistent detection--just show updated map */ 836. display_nhwindow(WIN_MAP, TRUE); 837. } else { 838. /* one-shot detection--allow player to move cursor around and 839. get autodescribe feedback */ 840. EDetect_monsters |= I_SPECIAL; 841. browse_map(TER_DETECT | TER_MON, "monster of interest"); 842. EDetect_monsters &= ~I_SPECIAL; 843. } 844. 845. reconstrain_map(); 846. docrt(); /* redraw the screen to remove unseen monsters from map */ 847. if (Underwater) 848. under_water(2); 849. if (u.uburied) 850. under_ground(2); 851. } 852. return 0; 853. } 854. 855. STATIC_OVL void 856. sense_trap(trap, x, y, src_cursed) 857. struct trap *trap; 858. xchar x, y; 859. int src_cursed; 860. { 861. if (Hallucination || src_cursed) { 862. struct obj obj; /* fake object */ 863. 864. obj = zeroobj; 865. if (trap) { 866. obj.ox = trap->tx; 867. obj.oy = trap->ty; 868. } else { 869. obj.ox = x; 870. obj.oy = y; 871. } 872. obj.otyp = !Hallucination ? GOLD_PIECE : random_object(rn2); 873. obj.quan = (long) ((obj.otyp == GOLD_PIECE) ? rnd(10) 874. : objects[obj.otyp].oc_merge ? rnd(2) : 1); 875. obj.corpsenm = random_monster(rn2); /* if otyp == CORPSE */ 876. map_object(&obj, 1); 877. } else if (trap) { 878. map_trap(trap, 1); 879. trap->tseen = 1; 880. } else { /* trapped door or trapped chest */ 881. struct trap temp_trap; /* fake trap */ 882. 883. (void) memset((genericptr_t) &temp_trap, 0, sizeof temp_trap); 884. temp_trap.tx = x; 885. temp_trap.ty = y; 886. temp_trap.ttyp = BEAR_TRAP; /* some kind of trap */ 887. map_trap(&temp_trap, 1); 888. } 889. } 890. 891. #define OTRAP_NONE 0 /* nothing found */ 892. #define OTRAP_HERE 1 /* found at hero's location */ 893. #define OTRAP_THERE 2 /* found at any other location */ 894. 895. /* check a list of objects for chest traps; return 1 if found at <ux,uy>, 896. 2 if found at some other spot, 3 if both, 0 otherwise; optionally 897. update the map to show where such traps were found */ 898. STATIC_OVL int 899. detect_obj_traps(objlist, show_them, how) 900. struct obj *objlist; 901. boolean show_them; 902. int how; /* 1 for misleading map feedback */ 903. { 904. struct obj *otmp; 905. xchar x, y; 906. int result = OTRAP_NONE; 907. 908. /* 909. * TODO? Display locations of unarmed land mine and beartrap objects. 910. * If so, should they be displayed as objects or as traps? 911. */ 912. 913. for (otmp = objlist; otmp; otmp = otmp->nobj) { 914. if (Is_box(otmp) && otmp->otrapped 915. && get_obj_location(otmp, &x, &y, BURIED_TOO | CONTAINED_TOO)) { 916. result |= (x == u.ux && y == u.uy) ? OTRAP_HERE : OTRAP_THERE; 917. if (show_them) 918. sense_trap((struct trap *) 0, x, y, how); 919. } 920. if (Has_contents(otmp)) 921. result |= detect_obj_traps(otmp->cobj, show_them, how); 922. } 923. return result; 924. } 925. 926. /* the detections are pulled out so they can 927. * also be used in the crystal ball routine 928. * returns 1 if nothing was detected 929. * returns 0 if something was detected 930. */ 931. int 932. trap_detect(sobj) 933. struct obj *sobj; /* null if crystal ball, *scroll if gold detection scroll */ 934. { 935. register struct trap *ttmp; 936. struct monst *mon; 937. int door, glyph, tr, ter_typ = TER_DETECT | TER_TRP; 938. int cursed_src = sobj && sobj->cursed; 939. boolean found = FALSE; 940. coord cc; 941. 942. if (u.usteed) 943. u.usteed->mx = u.ux, u.usteed->my = u.uy; 944. 945. /* floor/ceiling traps */ 946. for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { 947. if (ttmp->tx != u.ux || ttmp->ty != u.uy) 948. goto outtrapmap; 949. else 950. found = TRUE; 951. } 952. /* chest traps (might be buried or carried) */ 953. if ((tr = detect_obj_traps(fobj, FALSE, 0)) != OTRAP_NONE) { 954. if (tr & OTRAP_THERE) 955. goto outtrapmap; 956. else 957. found = TRUE; 958. } 959. if ((tr = detect_obj_traps(level.buriedobjlist, FALSE, 0)) != OTRAP_NONE) { 960. if (tr & OTRAP_THERE) 961. goto outtrapmap; 962. else 963. found = TRUE; 964. } 965. for (mon = fmon; mon; mon = mon->nmon) { 966. if (DEADMONSTER(mon)) 967. continue; 968. if ((tr = detect_obj_traps(mon->minvent, FALSE, 0)) != OTRAP_NONE) { 969. if (tr & OTRAP_THERE) 970. goto outtrapmap; 971. else 972. found = TRUE; 973. } 974. } 975. if (detect_obj_traps(invent, FALSE, 0) != OTRAP_NONE) 976. found = TRUE; 977. /* door traps */ 978. for (door = 0; door < doorindex; door++) { 979. cc = doors[door]; 980. if (levl[cc.x][cc.y].doormask & D_TRAPPED) { 981. if (cc.x != u.ux || cc.y != u.uy) 982. goto outtrapmap; 983. else 984. found = TRUE; 985. } 986. } 987. if (!found) { 988. char buf[BUFSZ]; 989. 990. Sprintf(buf, "Your %s stop itching.", makeplural(body_part(TOE))); 991. strange_feeling(sobj, buf); 992. return 1; 993. } 994. /* traps exist, but only under me - no separate display required */ 995. Your("%s itch.", makeplural(body_part(TOE))); 996. return 0; 997. 998. outtrapmap: 999. cls(); 1000. 1001. (void) unconstrain_map(); 1002. /* show chest traps first, so that subsequent floor trap display 1003. will override if both types are present at the same location */ 1004. (void) detect_obj_traps(fobj, TRUE, cursed_src); 1005. (void) detect_obj_traps(level.buriedobjlist, TRUE, cursed_src); 1006. for (mon = fmon; mon; mon = mon->nmon) { 1007. if (DEADMONSTER(mon)) 1008. continue; 1009. (void) detect_obj_traps(mon->minvent, TRUE, cursed_src); 1010. } 1011. (void) detect_obj_traps(invent, TRUE, cursed_src); 1012. 1013. for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) 1014. sense_trap(ttmp, 0, 0, cursed_src); 1015. 1016. for (door = 0; door < doorindex; door++) { 1017. cc = doors[door]; 1018. if (levl[cc.x][cc.y].doormask & D_TRAPPED) 1019. sense_trap((struct trap *) 0, cc.x, cc.y, cursed_src); 1020. } 1021. 1022. /* redisplay hero unless sense_trap() revealed something at <ux,uy> */ 1023. glyph = glyph_at(u.ux, u.uy); 1024. if (!(glyph_is_trap(glyph) || glyph_is_object(glyph))) { 1025. newsym(u.ux, u.uy); 1026. ter_typ |= TER_MON; /* for autodescribe at <u.ux,u.uy> */ 1027. } 1028. You_feel("%s.", cursed_src ? "very greedy" : "entrapped"); 1029. 1030. browse_map(ter_typ, "trap of interest"); 1031. 1032. reconstrain_map(); 1033. docrt(); /* redraw the screen to remove unseen traps from the map */ 1034. if (Underwater) 1035. under_water(2); 1036. if (u.uburied) 1037. under_ground(2); 1038. return 0; 1039. } 1040. 1041. const char * 1042. level_distance(where) 1043. d_level *where; 1044. { 1045. register schar ll = depth(&u.uz) - depth(where); 1046. register boolean indun = (u.uz.dnum == where->dnum); 1047. 1048. if (ll < 0) { 1049. if (ll < (-8 - rn2(3))) 1050. if (!indun) 1051. return "far away"; 1052. else 1053. return "far below"; 1054. else if (ll < -1) 1055. if (!indun) 1056. return "away below you"; 1057. else 1058. return "below you"; 1059. else if (!indun) 1060. return "in the distance"; 1061. else 1062. return "just below"; 1063. } else if (ll > 0) { 1064. if (ll > (8 + rn2(3))) 1065. if (!indun) 1066. return "far away"; 1067. else 1068. return "far above"; 1069. else if (ll > 1) 1070. if (!indun) 1071. return "away above you"; 1072. else 1073. return "above you"; 1074. else if (!indun) 1075. return "in the distance"; 1076. else 1077. return "just above"; 1078. } else if (!indun) 1079. return "in the distance"; 1080. else 1081. return "near you"; 1082. } 1083. 1084. static const struct { 1085. const char *what; 1086. d_level *where; 1087. } level_detects[] = { 1088. { "Delphi", &oracle_level }, 1089. { "Medusa's lair", &medusa_level }, 1090. { "a castle", &stronghold_level }, 1091. { "the Wizard of Yendor's tower", &wiz1_level }, 1092. }; 1093. 1094. void 1095. use_crystal_ball(optr) 1096. struct obj **optr; 1097. { 1098. char ch; 1099. int oops; 1100. struct obj *obj = *optr; 1101. 1102. if (Blind) { 1103. pline("Too bad you can't see %s.", the(xname(obj))); 1104. return; 1105. } 1106. oops = (rnd(20) > ACURR(A_INT) || obj->cursed); 1107. if (oops && (obj->spe > 0)) { 1108. switch (rnd(obj->oartifact ? 4 : 5)) { 1109. case 1: 1110. pline("%s too much to comprehend!", Tobjnam(obj, "are")); 1111. break; 1112. case 2: 1113. pline("%s you!", Tobjnam(obj, "confuse")); 1114. make_confused((HConfusion & TIMEOUT) + (long) rnd(100), FALSE); 1115. break; 1116. case 3: 1117. if (!resists_blnd(&youmonst)) { 1118. pline("%s your vision!", Tobjnam(obj, "damage")); 1119. make_blinded((Blinded & TIMEOUT) + (long) rnd(100), FALSE); 1120. if (!Blind) 1121. Your1(vision_clears); 1122. } else { 1123. pline("%s your vision.", Tobjnam(obj, "assault")); 1124. You("are unaffected!"); 1125. } 1126. break; 1127. case 4: 1128. pline("%s your mind!", Tobjnam(obj, "zap")); 1129. (void) make_hallucinated( 1130. (HHallucination & TIMEOUT) + (long) rnd(100), FALSE, 0L); 1131. break; 1132. case 5: 1133. pline("%s!", Tobjnam(obj, "explode")); 1134. useup(obj); 1135. *optr = obj = 0; /* it's gone */ 1136. /* physical damage cause by the shards and force */ 1137. losehp(Maybe_Half_Phys(rnd(30)), "exploding crystal ball", 1138. KILLED_BY_AN); 1139. break; 1140. } 1141. if (obj) 1142. consume_obj_charge(obj, TRUE); 1143. return; 1144. } 1145. 1146. if (Hallucination) { 1147. if (!obj->spe) { 1148. pline("All you see is funky %s haze.", hcolor((char *) 0)); 1149. } else { 1150. switch (rnd(6)) { 1151. case 1: 1152. You("grok some groovy globs of incandescent lava."); 1153. break; 1154. case 2: 1155. pline("Whoa! Psychedelic colors, %s!", 1156. poly_gender() == 1 ? "babe" : "dude"); 1157. break; 1158. case 3: 1159. pline_The("crystal pulses with sinister %s light!", 1160. hcolor((char *) 0)); 1161. break; 1162. case 4: 1163. You_see("goldfish swimming above fluorescent rocks."); 1164. break; 1165. case 5: 1166. You_see( 1167. "tiny snowflakes spinning around a miniature farmhouse."); 1168. break; 1169. default: 1170. pline("Oh wow... like a kaleidoscope!"); 1171. break; 1172. } 1173. consume_obj_charge(obj, TRUE); 1174. } 1175. return; 1176. } 1177. 1178. /* read a single character */ 1179. if (flags.verbose) 1180. You("may look for an object or monster symbol."); 1181. ch = yn_function("What do you look for?", (char *) 0, '\0'); 1182. /* Don't filter out ' ' here; it has a use */ 1183. if ((ch != def_monsyms[S_GHOST].sym) && index(quitchars, ch)) { 1184. if (flags.verbose) 1185. pline1(Never_mind); 1186. return; 1187. } 1188. You("peer into %s...", the(xname(obj))); 1189. nomul(-rnd(10)); 1190. multi_reason = "gazing into a crystal ball"; 1191. nomovemsg = ""; 1192. if (obj->spe <= 0) { 1193. pline_The("vision is unclear."); 1194. } else { 1195. int class, i; 1196. int ret = 0; 1197. 1198. makeknown(CRYSTAL_BALL); 1199. consume_obj_charge(obj, TRUE); 1200. 1201. /* special case: accept ']' as synonym for mimic 1202. * we have to do this before the def_char_to_objclass check 1203. */ 1204. if (ch == DEF_MIMIC_DEF) 1205. ch = DEF_MIMIC; 1206. 1207. if ((class = def_char_to_objclass(ch)) != MAXOCLASSES) 1208. ret = object_detect((struct obj *) 0, class); 1209. else if ((class = def_char_to_monclass(ch)) != MAXMCLASSES) 1210. ret = monster_detect((struct obj *) 0, class); 1211. else if (iflags.bouldersym && (ch == iflags.bouldersym)) 1212. ret = object_detect((struct obj *) 0, ROCK_CLASS); 1213. else 1214. switch (ch) { 1215. case '^': 1216. ret = trap_detect((struct obj *) 0); 1217. break; 1218. default: 1219. i = rn2(SIZE(level_detects)); 1220. You_see("%s, %s.", level_detects[i].what, 1221. level_distance(level_detects[i].where)); 1222. ret = 0; 1223. break; 1224. } 1225. 1226. if (ret) { 1227. if (!rn2(100)) /* make them nervous */ 1228. You_see("the Wizard of Yendor gazing out at you."); 1229. else 1230. pline_The("vision is unclear."); 1231. } 1232. } 1233. return; 1234. } 1235. 1236. STATIC_OVL void 1237. show_map_spot(x, y) 1238. register int x, y; 1239. { 1240. struct rm *lev; 1241. struct trap *t; 1242. int oldglyph; 1243. 1244. if (Confusion && rn2(7)) 1245. return; 1246. lev = &levl[x][y]; 1247. 1248. lev->seenv = SVALL; 1249. 1250. /* Secret corridors are found, but not secret doors. */ 1251. if (lev->typ == SCORR) { 1252. lev->typ = CORR; 1253. unblock_point(x, y); 1254. } 1255. 1256. /* 1257. * Force the real background, then if it's not furniture and there's 1258. * a known trap there, display the trap, else if there was an object 1259. * shown there, redisplay the object. So during mapping, furniture 1260. * takes precedence over traps, which take precedence over objects, 1261. * opposite to how normal vision behaves. 1262. */ 1263. oldglyph = glyph_at(x, y); 1264. if (level.flags.hero_memory) { 1265. magic_map_background(x, y, 0); 1266. newsym(x, y); /* show it, if not blocked */ 1267. } else { 1268. magic_map_background(x, y, 1); /* display it */ 1269. } 1270. if (!IS_FURNITURE(lev->typ)) { 1271. if ((t = t_at(x, y)) != 0 && t->tseen) { 1272. map_trap(t, 1); 1273. } else if (glyph_is_trap(oldglyph) || glyph_is_object(oldglyph)) { 1274. show_glyph(x, y, oldglyph); 1275. if (level.flags.hero_memory) 1276. lev->glyph = oldglyph; 1277. } 1278. } 1279. } 1280. 1281. void 1282. do_mapping() 1283. { 1284. register int zx, zy; 1285. boolean unconstrained; 1286. 1287. unconstrained = unconstrain_map(); 1288. for (zx = 1; zx < COLNO; zx++) 1289. for (zy = 0; zy < ROWNO; zy++) 1290. show_map_spot(zx, zy); 1291. 1292. if (!level.flags.hero_memory || unconstrained) { 1293. flush_screen(1); /* flush temp screen */ 1294. /* browse_map() instead of display_nhwindow(WIN_MAP, TRUE) */ 1295. browse_map(TER_DETECT | TER_MAP | TER_TRP | TER_OBJ, 1296. "anything of interest"); 1297. docrt(); 1298. } 1299. reconstrain_map(); 1300. exercise(A_WIS, TRUE); 1301. } 1302. 1303. /* clairvoyance */ 1304. void 1305. do_vicinity_map(sobj) 1306. struct obj *sobj; /* scroll--actually fake spellbook--object */ 1307. { 1308. register int zx, zy; 1309. struct monst *mtmp; 1310. struct obj *otmp; 1311. long save_EDetect_mons; 1312. char save_viz_uyux; 1313. boolean unconstrained, refresh = FALSE, 1314. mdetected = FALSE, odetected = FALSE, 1315. /* fake spellbook 'sobj' implies hero has cast the spell; 1316. when book is blessed, casting is skilled or expert level; 1317. if already clairvoyant, non-skilled spell acts like skilled */ 1318. extended = (sobj && (sobj->blessed || Clairvoyant)); 1319. int newglyph, oldglyph, 1320. lo_y = ((u.uy - 5 < 0) ? 0 : u.uy - 5), 1321. hi_y = ((u.uy + 6 >= ROWNO) ? ROWNO - 1 : u.uy + 6), 1322. lo_x = ((u.ux - 9 < 1) ? 1 : u.ux - 9), /* avoid column 0 */ 1323. hi_x = ((u.ux + 10 >= COLNO) ? COLNO - 1 : u.ux + 10), 1324. ter_typ = TER_DETECT | TER_MAP | TER_TRP | TER_OBJ; 1325. 1326. /* 1327. * 3.6.0 attempted to emphasize terrain over transient map 1328. * properties (monsters and objects) but that led to problems. 1329. * Notably, known trap would be displayed instead of a monster 1330. * on or in it and then the display remained that way after the 1331. * clairvoyant snapshot finished. That could have been fixed by 1332. * issuing --More-- and then regular vision update, but we want 1333. * to avoid that when having a clairvoyant episode every N turns 1334. * (from donating to a temple priest or by carrying the Amulet). 1335. * Unlike when casting the spell, it is much too intrustive when 1336. * in the midst of walking around or combatting monsters. 1337. * 1338. * For 3.6.2, show terrain, then object, then monster like regular 1339. * map updating, except in this case the map locations get marked 1340. * as seen from every direction rather than just from direction of 1341. * hero. Skilled spell marks revealed objects as 'seen up close' 1342. * (but for piles, only the top item) and shows monsters as if 1343. * detected. Non-skilled and timed clairvoyance reveals non-visible 1344. * monsters as 'remembered, unseen'. 1345. */ 1346. 1347. /* if hero is engulfed, show engulfer at <u.ux,u.uy> */ 1348. save_viz_uyux = viz_array[u.uy][u.ux]; 1349. if (u.uswallow) 1350. viz_array[u.uy][u.ux] |= IN_SIGHT; /* <x,y> are reversed to [y][x] */ 1351. save_EDetect_mons = EDetect_monsters; 1352. /* for skilled spell, getpos() scanning of the map will display all 1353. monsters within range; otherwise, "unseen creature" will be shown */ 1354. EDetect_monsters |= I_SPECIAL; 1355. unconstrained = unconstrain_map(); 1356. for (zx = lo_x; zx <= hi_x; zx++) 1357. for (zy = lo_y; zy <= hi_y; zy++) { 1358. oldglyph = glyph_at(zx, zy); 1359. /* this will remove 'remembered, unseen mon' (and objects) */ 1360. show_map_spot(zx, zy); 1361. /* if there are any objects here, see the top one */ 1362. if (OBJ_AT(zx, zy)) { 1363. /* not vobj_at(); this is not vision-based access; 1364. unlike object detection, we don't notice buried items */ 1365. otmp = level.objects[zx][zy]; 1366. if (extended) 1367. otmp->dknown = 1; 1368. map_object(otmp, TRUE); 1369. newglyph = glyph_at(zx, zy); 1370. /* if otmp is underwater, we'll need to redisplay the water */ 1371. if (newglyph != oldglyph && covers_objects(zx, zy)) 1372. odetected = TRUE; 1373. } 1374. /* if there is a monster here, see or detect it, 1375. possibly as "remembered, unseen monster" */ 1376. if ((mtmp = m_at(zx, zy)) != 0 1377. && mtmp->mx == zx && mtmp->my == zy) { /* skip worm tails */ 1378. /* if we're going to offer browse_map()/getpos() scanning of 1379. the map and we're not doing extended/blessed clairvoyance 1380. (hence must be swallowed or underwater), show "unseen 1381. creature" unless map already displayed a monster here */ 1382. if ((unconstrained || !level.flags.hero_memory) 1383. && !extended && (zx != u.ux || zy != u.uy) 1384. && !glyph_is_monster(oldglyph)) 1385. map_invisible(zx, zy); 1386. else 1387. map_monst(mtmp, FALSE); 1388. newglyph = glyph_at(zx, zy); 1389. if (extended && newglyph != oldglyph 1390. && !glyph_is_invisible(newglyph)) 1391. mdetected = TRUE; 1392. } 1393. } 1394. 1395. if (!level.flags.hero_memory || unconstrained || mdetected || odetected) { 1396. flush_screen(1); /* flush temp screen */ 1397. /* the getpos() prompt from browse_map() is only shown when 1398. flags.verbose is set, but make this unconditional so that 1399. not-verbose users become aware of the prompting situation */ 1400. You("sense your surroundings."); 1401. if (extended || glyph_is_monster(glyph_at(u.ux, u.uy))) 1402. ter_typ |= TER_MON; 1403. browse_map(ter_typ, "anything of interest"); 1404. refresh = TRUE; 1405. } 1406. reconstrain_map(); 1407. EDetect_monsters = save_EDetect_mons; 1408. viz_array[u.uy][u.ux] = save_viz_uyux; 1409. 1410. /* replace monsters with remembered,unseen monster, then run 1411. see_monsters() to update visible ones and warned-of ones */ 1412. for (zx = lo_x; zx <= hi_x; zx++) 1413. for (zy = lo_y; zy <= hi_y; zy++) { 1414. if (zx == u.ux && zy == u.uy) 1415. continue; 1416. newglyph = glyph_at(zx, zy); 1417. if (glyph_is_monster(newglyph) 1418. && glyph_to_mon(newglyph) != PM_LONG_WORM_TAIL) 1419. map_invisible(zx, zy); 1420. } 1421. see_monsters(); 1422. 1423. if (refresh) 1424. docrt(); 1425. } 1426. 1427. /* convert a secret door into a normal door */ 1428. void 1429. cvt_sdoor_to_door(lev) 1430. struct rm *lev; 1431. { 1432. int newmask = lev->doormask & ~WM_MASK; 1433. 1434. if (Is_rogue_level(&u.uz)) 1435. /* rogue didn't have doors, only doorways */ 1436. newmask = D_NODOOR; 1437. else 1438. /* newly exposed door is closed */ 1439. if (!(newmask & D_LOCKED)) 1440. newmask |= D_CLOSED; 1441. 1442. lev->typ = DOOR; 1443. lev->doormask = newmask; 1444. } 1445. 1446. STATIC_PTR void 1447. findone(zx, zy, num) 1448. int zx, zy; 1449. genericptr_t num; 1450. { 1451. register struct trap *ttmp; 1452. register struct monst *mtmp; 1453. 1454. if (levl[zx][zy].typ == SDOOR) { 1455. cvt_sdoor_to_door(&levl[zx][zy]); /* .typ = DOOR */ 1456. magic_map_background(zx, zy, 0); 1457. newsym(zx, zy); 1458. (*(int *) num)++; 1459. } else if (levl[zx][zy].typ == SCORR) { 1460. levl[zx][zy].typ = CORR; 1461. unblock_point(zx, zy); 1462. magic_map_background(zx, zy, 0); 1463. newsym(zx, zy); 1464. (*(int *) num)++; 1465. } else if ((ttmp = t_at(zx, zy)) != 0) { 1466. if (!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) { 1467. ttmp->tseen = 1; 1468. newsym(zx, zy); 1469. (*(int *) num)++; 1470. } 1471. } else if ((mtmp = m_at(zx, zy)) != 0) { 1472. if (M_AP_TYPE(mtmp)) { 1473. seemimic(mtmp); 1474. (*(int *) num)++; 1475. } 1476. if (mtmp->mundetected 1477. && (is_hider(mtmp->data) || mtmp->data->mlet == S_EEL)) { 1478. mtmp->mundetected = 0; 1479. newsym(zx, zy); 1480. (*(int *) num)++; 1481. } 1482. if (!canspotmon(mtmp) && !glyph_is_invisible(levl[zx][zy].glyph)) 1483. map_invisible(zx, zy); 1484. } else if (unmap_invisible(zx, zy)) { 1485. (*(int *) num)++; 1486. } 1487. } 1488. 1489. STATIC_PTR void 1490. openone(zx, zy, num) 1491. int zx, zy; 1492. genericptr_t num; 1493. { 1494. register struct trap *ttmp; 1495. register struct obj *otmp; 1496. int *num_p = (int *) num; 1497. 1498. if (OBJ_AT(zx, zy)) { 1499. for (otmp = level.objects[zx][zy]; otmp; otmp = otmp->nexthere) { 1500. if (Is_box(otmp) && otmp->olocked) { 1501. otmp->olocked = 0; 1502. (*num_p)++; 1503. } 1504. } 1505. /* let it fall to the next cases. could be on trap. */ 1506. } 1507. if (levl[zx][zy].typ == SDOOR 1508. || (levl[zx][zy].typ == DOOR 1509. && (levl[zx][zy].doormask & (D_CLOSED | D_LOCKED)))) { 1510. if (levl[zx][zy].typ == SDOOR) 1511. cvt_sdoor_to_door(&levl[zx][zy]); /* .typ = DOOR */ 1512. if (levl[zx][zy].doormask & D_TRAPPED) { 1513. if (distu(zx, zy) < 3) 1514. b_trapped("door", 0); 1515. else 1516. Norep("You %s an explosion!", 1517. cansee(zx, zy) ? "see" : (!Deaf ? "hear" 1518. : "feel the shock of")); 1519. wake_nearto(zx, zy, 11 * 11); 1520. levl[zx][zy].doormask = D_NODOOR; 1521. } else 1522. levl[zx][zy].doormask = D_ISOPEN; 1523. unblock_point(zx, zy); 1524. newsym(zx, zy); 1525. (*num_p)++; 1526. } else if (levl[zx][zy].typ == SCORR) { 1527. levl[zx][zy].typ = CORR; 1528. unblock_point(zx, zy); 1529. newsym(zx, zy); 1530. (*num_p)++; 1531. } else if ((ttmp = t_at(zx, zy)) != 0) { 1532. struct monst *mon; 1533. boolean dummy; /* unneeded "you notice it arg" */ 1534. 1535. if (!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) { 1536. ttmp->tseen = 1; 1537. newsym(zx, zy); 1538. (*num_p)++; 1539. } 1540. mon = (zx == u.ux && zy == u.uy) ? &youmonst : m_at(zx, zy); 1541. if (openholdingtrap(mon, &dummy) 1542. || openfallingtrap(mon, TRUE, &dummy)) 1543. (*num_p)++; 1544. } else if (find_drawbridge(&zx, &zy)) { 1545. /* make sure it isn't an open drawbridge */ 1546. open_drawbridge(zx, zy); 1547. (*num_p)++; 1548. } 1549. } 1550. 1551. /* returns number of things found */ 1552. int 1553. findit() 1554. { 1555. int num = 0; 1556. 1557. if (u.uswallow) 1558. return 0; 1559. do_clear_area(u.ux, u.uy, BOLT_LIM, findone, (genericptr_t) &num); 1560. return num; 1561. } 1562. 1563. /* returns number of things found and opened */ 1564. int 1565. openit() 1566. { 1567. int num = 0; 1568. 1569. if (u.uswallow) { 1570. if (is_animal(u.ustuck->data)) { 1571. if (Blind) 1572. pline("Its mouth opens!"); 1573. else 1574. pline("%s opens its mouth!", Monnam(u.ustuck)); 1575. } 1576. expels(u.ustuck, u.ustuck->data, TRUE); 1577. return -1; 1578. } 1579. 1580. do_clear_area(u.ux, u.uy, BOLT_LIM, openone, (genericptr_t) &num); 1581. return num; 1582. } 1583. 1584. /* callback hack for overriding vision in do_clear_area() */ 1585. boolean 1586. detecting(func) 1587. void FDECL((*func), (int, int, genericptr_t)); 1588. { 1589. return (func == findone || func == openone); 1590. } 1591. 1592. void 1593. find_trap(trap) 1594. struct trap *trap; 1595. { 1596. int tt = what_trap(trap->ttyp, rn2); 1597. boolean cleared = FALSE; 1598. 1599. trap->tseen = 1; 1600. exercise(A_WIS, TRUE); 1601. feel_newsym(trap->tx, trap->ty); 1602. 1603. /* The "Hallucination ||" is to preserve 3.6.1 behaviour, but this 1604. behaviour might need a rework in the hallucination case 1605. (e.g. to not prompt if any trap glyph appears on the 1606. square). */ 1607. if (Hallucination || 1608. levl[trap->tx][trap->ty].glyph != 1609. trap_to_glyph(trap, rn2_on_display_rng)) { 1610. /* There's too much clutter to see your find otherwise */ 1611. cls(); 1612. map_trap(trap, 1); 1613. display_self(); 1614. cleared = TRUE; 1615. } 1616. 1617. You("find %s.", an(defsyms[trap_to_defsym(tt)].explanation)); 1618. 1619. if (cleared) { 1620. display_nhwindow(WIN_MAP, TRUE); /* wait */ 1621. docrt(); 1622. } 1623. } 1624. 1625. STATIC_OVL int 1626. mfind0(mtmp, via_warning) 1627. struct monst *mtmp; 1628. boolean via_warning; 1629. { 1630. int x = mtmp->mx, y = mtmp->my; 1631. boolean found_something = FALSE; 1632. 1633. if (via_warning && !warning_of(mtmp)) 1634. return -1; 1635. 1636. if (M_AP_TYPE(mtmp)) { 1637. seemimic(mtmp); 1638. found_something = TRUE; 1639. } else if (!canspotmon(mtmp)) { 1640. if (mtmp->mundetected 1641. && (is_hider(mtmp->data) || mtmp->data->mlet == S_EEL)) { 1642. if (via_warning) { 1643. Your("warning senses cause you to take a second %s.", 1644. Blind ? "to check nearby" : "look close by"); 1645. display_nhwindow(WIN_MESSAGE, FALSE); /* flush messages */ 1646. } 1647. mtmp->mundetected = 0; 1648. } 1649. newsym(x, y); 1650. found_something = TRUE; 1651. } 1652. 1653. if (found_something) { 1654. if (!canspotmon(mtmp) && glyph_is_invisible(levl[x][y].glyph)) 1655. return -1; /* Found invisible monster in square which already has 1656. * 'I' in it. Logically, this should still take time 1657. * and lead to `return 1', but if we did that the hero 1658. * would keep finding the same monster every turn. */ 1659. exercise(A_WIS, TRUE); 1660. if (!canspotmon(mtmp)) { 1661. map_invisible(x, y); 1662. You_feel("an unseen monster!"); 1663. } else if (!sensemon(mtmp)) { 1664. You("find %s.", mtmp->mtame ? y_monnam(mtmp) : a_monnam(mtmp)); 1665. } 1666. return 1; 1667. } 1668. return 0; 1669. } 1670. 1671. int 1672. dosearch0(aflag) 1673. register int aflag; /* intrinsic autosearch vs explicit searching */ 1674. { 1675. #ifdef GCC_BUG 1676. /* Some old versions of gcc seriously muck up nested loops. If you get 1677. * strange crashes while searching in a version compiled with gcc, try 1678. * putting #define GCC_BUG in *conf.h (or adding -DGCC_BUG to CFLAGS in 1679. * the makefile). 1680. */ 1681. volatile xchar x, y; 1682. #else 1683. register xchar x, y; 1684. #endif 1685. register struct trap *trap; 1686. register struct monst *mtmp; 1687. 1688. if (u.uswallow) { 1689. if (!aflag) 1690. pline("What are you looking for? The exit?"); 1691. } else { 1692. int fund = (uwep && uwep->oartifact 1693. && spec_ability(uwep, SPFX_SEARCH)) ? uwep->spe : 0; 1694. 1695. if (ublindf && ublindf->otyp == LENSES && !Blind) 1696. fund += 2; /* JDS: lenses help searching */ 1697. if (fund > 5) 1698. fund = 5; 1699. for (x = u.ux - 1; x < u.ux + 2; x++) 1700. for (y = u.uy - 1; y < u.uy + 2; y++) { 1701. if (!isok(x, y)) 1702. continue; 1703. if (x == u.ux && y == u.uy) 1704. continue; 1705. 1706. if (Blind && !aflag) 1707. feel_location(x, y); 1708. if (levl[x][y].typ == SDOOR) { 1709. if (rnl(7 - fund)) 1710. continue; 1711. cvt_sdoor_to_door(&levl[x][y]); /* .typ = DOOR */ 1712. exercise(A_WIS, TRUE); 1713. nomul(0); 1714. feel_location(x, y); /* make sure it shows up */ 1715. You("find a hidden door."); 1716. } else if (levl[x][y].typ == SCORR) { 1717. if (rnl(7 - fund)) 1718. continue; 1719. levl[x][y].typ = CORR; 1720. unblock_point(x, y); /* vision */ 1721. exercise(A_WIS, TRUE); 1722. nomul(0); 1723. feel_newsym(x, y); /* make sure it shows up */ 1724. You("find a hidden passage."); 1725. } else { 1726. /* Be careful not to find anything in an SCORR or SDOOR */ 1727. if ((mtmp = m_at(x, y)) != 0 && !aflag) { 1728. int mfres = mfind0(mtmp, 0); 1729. 1730. if (mfres == -1) 1731. continue; 1732. else if (mfres > 0) 1733. return mfres; 1734. } 1735. 1736. /* see if an invisible monster has moved--if Blind, 1737. * feel_location() already did it 1738. */ 1739. if (!aflag && !mtmp && !Blind) 1740. (void) unmap_invisible(x, y); 1741. 1742. if ((trap = t_at(x, y)) && !trap->tseen && !rnl(8)) { 1743. nomul(0); 1744. if (trap->ttyp == STATUE_TRAP) { 1745. if (activate_statue_trap(trap, x, y, FALSE)) 1746. exercise(A_WIS, TRUE); 1747. return 1; 1748. } else { 1749. find_trap(trap); 1750. } 1751. } 1752. } 1753. } 1754. } 1755. return 1; 1756. } 1757. 1758. /* the 's' command -- explicit searching */ 1759. int 1760. dosearch() 1761. { 1762. return dosearch0(0); 1763. } 1764. 1765. void 1766. warnreveal() 1767. { 1768. int x, y; 1769. struct monst *mtmp; 1770. 1771. for (x = u.ux - 1; x <= u.ux + 1; x++) 1772. for (y = u.uy - 1; y <= u.uy + 1; y++) { 1773. if (!isok(x, y) || (x == u.ux && y == u.uy)) 1774. continue; 1775. if ((mtmp = m_at(x, y)) != 0 1776. && warning_of(mtmp) && mtmp->mundetected) 1777. (void) mfind0(mtmp, 1); /* via_warning */ 1778. } 1779. } 1780. 1781. /* Pre-map the sokoban levels */ 1782. void 1783. sokoban_detect() 1784. { 1785. register int x, y; 1786. register struct trap *ttmp; 1787. register struct obj *obj; 1788. 1789. /* Map the background and boulders */ 1790. for (x = 1; x < COLNO; x++) 1791. for (y = 0; y < ROWNO; y++) { 1792. levl[x][y].seenv = SVALL; 1793. levl[x][y].waslit = TRUE; 1794. map_background(x, y, 1); 1795. if ((obj = sobj_at(BOULDER, x, y)) != 0) 1796. map_object(obj, 1); 1797. } 1798. 1799. /* Map the traps */ 1800. for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) { 1801. ttmp->tseen = 1; 1802. map_trap(ttmp, 1); 1803. /* set sokoban_rules when there is at least one pit or hole */ 1804. if (ttmp->ttyp == PIT || ttmp->ttyp == HOLE) 1805. Sokoban = 1; 1806. } 1807. } 1808. 1809. STATIC_DCL int 1810. reveal_terrain_getglyph(x, y, full, swallowed, default_glyph, which_subset) 1811. int x, y, full; 1812. unsigned swallowed; 1813. int default_glyph, which_subset; 1814. { 1815. int glyph, levl_glyph; 1816. uchar seenv; 1817. boolean keep_traps = (which_subset & TER_TRP) !=0, 1818. keep_objs = (which_subset & TER_OBJ) != 0, 1819. keep_mons = (which_subset & TER_MON) != 0; 1820. struct monst *mtmp; 1821. struct trap *t; 1822. 1823. /* for 'full', show the actual terrain for the entire level, 1824. otherwise what the hero remembers for seen locations with 1825. monsters, objects, and/or traps removed as caller dictates */ 1826. seenv = (full || level.flags.hero_memory) 1827. ? levl[x][y].seenv : cansee(x, y) ? SVALL : 0; 1828. if (full) { 1829. levl[x][y].seenv = SVALL; 1830. glyph = back_to_glyph(x, y); 1831. levl[x][y].seenv = seenv; 1832. } else { 1833. levl_glyph = level.flags.hero_memory 1834. ? levl[x][y].glyph 1835. : seenv ? back_to_glyph(x, y): default_glyph; 1836. /* glyph_at() returns the displayed glyph, which might 1837. be a monster. levl[][].glyph contains the remembered 1838. glyph, which will never be a monster (unless it is 1839. the invisible monster glyph, which is handled like 1840. an object, replacing any object or trap at its spot) */ 1841. glyph = !swallowed ? glyph_at(x, y) : levl_glyph; 1842. if (keep_mons && x == u.ux && y == u.uy && swallowed) 1843. glyph = mon_to_glyph(u.ustuck, rn2_on_display_rng); 1844. else if (((glyph_is_monster(glyph) 1845. || glyph_is_warning(glyph)) && !keep_mons) 1846. || glyph_is_swallow(glyph)) 1847. glyph = levl_glyph; 1848. if (((glyph_is_object(glyph) && !keep_objs) 1849. || glyph_is_invisible(glyph)) 1850. && keep_traps && !covers_traps(x, y)) { 1851. if ((t = t_at(x, y)) != 0 && t->tseen) 1852. glyph = trap_to_glyph(t, rn2_on_display_rng); 1853. } 1854. if ((glyph_is_object(glyph) && !keep_objs) 1855. || (glyph_is_trap(glyph) && !keep_traps) 1856. || glyph_is_invisible(glyph)) { 1857. if (!seenv) { 1858. glyph = default_glyph; 1859. } else if (lastseentyp[x][y] == levl[x][y].typ) { 1860. glyph = back_to_glyph(x, y); 1861. } else { 1862. /* look for a mimic here posing as furniture; 1863. if we don't find one, we'll have to fake it */ 1864. if ((mtmp = m_at(x, y)) != 0 1865. && M_AP_TYPE(mtmp) == M_AP_FURNITURE) { 1866. glyph = cmap_to_glyph(mtmp->mappearance); 1867. } else { 1868. /* we have a topology type but we want a screen 1869. symbol in order to derive a glyph; some screen 1870. symbols need the flags field of levl[][] in 1871. addition to the type (to disambiguate STAIRS to 1872. S_upstair or S_dnstair, for example; current 1873. flags might not be intended for remembered type, 1874. but we've got no other choice) */ 1875. schar save_typ = levl[x][y].typ; 1876. 1877. levl[x][y].typ = lastseentyp[x][y]; 1878. glyph = back_to_glyph(x, y); 1879. levl[x][y].typ = save_typ; 1880. } 1881. } 1882. } 1883. } 1884. if (glyph == cmap_to_glyph(S_darkroom)) 1885. glyph = cmap_to_glyph(S_room); /* FIXME: dirty hack */ 1886. return glyph; 1887. } 1888. 1889. #ifdef DUMPLOG 1890. void 1891. dump_map() 1892. { 1893. int x, y, glyph, skippedrows, lastnonblank; 1894. int subset = TER_MAP | TER_TRP | TER_OBJ | TER_MON; 1895. int default_glyph = cmap_to_glyph(level.flags.arboreal ? S_tree : S_stone); 1896. char buf[BUFSZ]; 1897. boolean blankrow, toprow; 1898. 1899. /* 1900. * Squeeze out excess vertial space when dumping the map. 1901. * If there are any blank map rows at the top, suppress them 1902. * (our caller has already printed a separator). If there is 1903. * more than one blank map row at the bottom, keep just one. 1904. * Any blank rows within the middle of the map are kept. 1905. * Note: putstr() with winid==0 is for dumplog. 1906. */ 1907. skippedrows = 0; 1908. toprow = TRUE; 1909. for (y = 0; y < ROWNO; y++) { 1910. blankrow = TRUE; /* assume blank until we discover otherwise */ 1911. lastnonblank = -1; /* buf[] index rather than map's x */ 1912. for (x = 1; x < COLNO; x++) { 1913. int ch, color; 1914. unsigned special; 1915. 1916. glyph = reveal_terrain_getglyph(x, y, FALSE, u.uswallow, 1917. default_glyph, subset); 1918. (void) mapglyph(glyph, &ch, &color, &special, x, y); 1919. buf[x - 1] = ch; 1920. if (ch != ' ') { 1921. blankrow = FALSE; 1922. lastnonblank = x - 1; 1923. } 1924. } 1925. if (!blankrow) { 1926. buf[lastnonblank + 1] = '\0'; 1927. if (toprow) { 1928. skippedrows = 0; 1929. toprow = FALSE; 1930. } 1931. for (x = 0; x < skippedrows; x++) 1932. putstr(0, 0, ""); 1933. putstr(0, 0, buf); /* map row #y */ 1934. skippedrows = 0; 1935. } else { 1936. ++skippedrows; 1937. } 1938. } 1939. if (skippedrows) 1940. putstr(0, 0, ""); 1941. } 1942. #endif /* DUMPLOG */ 1943. 1944. /* idea from crawl; show known portion of map without any monsters, 1945. objects, or traps occluding the view of the underlying terrain */ 1946. void 1947. reveal_terrain(full, which_subset) 1948. int full; /* wizard|explore modes allow player to request full map */ 1949. int which_subset; /* when not full, whether to suppress objs and/or traps */ 1950. { 1951. if ((Hallucination || Stunned || Confusion) && !full) { 1952. You("are too disoriented for this."); 1953. } else { 1954. int x, y, glyph, default_glyph; 1955. char buf[BUFSZ]; 1956. /* there is a TER_MAP bit too; we always show map regardless of it */ 1957. boolean keep_traps = (which_subset & TER_TRP) !=0, 1958. keep_objs = (which_subset & TER_OBJ) != 0, 1959. keep_mons = (which_subset & TER_MON) != 0; /* not used */ 1960. unsigned swallowed = u.uswallow; /* before unconstrain_map() */ 1961. 1962. if (unconstrain_map()) 1963. docrt(); 1964. default_glyph = cmap_to_glyph(level.flags.arboreal ? S_tree : S_stone); 1965. 1966. for (x = 1; x < COLNO; x++) 1967. for (y = 0; y < ROWNO; y++) { 1968. glyph = reveal_terrain_getglyph(x,y, full, swallowed, 1969. default_glyph, which_subset); 1970. show_glyph(x, y, glyph); 1971. } 1972. 1973. /* hero's location is not highlighted, but getpos() starts with 1974. cursor there, and after moving it anywhere '@' moves it back */ 1975. flush_screen(1); 1976. if (full) { 1977. Strcpy(buf, "underlying terrain"); 1978. } else { 1979. Strcpy(buf, "known terrain"); 1980. if (keep_traps) 1981. Sprintf(eos(buf), "%s traps", 1982. (keep_objs || keep_mons) ? "," : " and"); 1983. if (keep_objs) 1984. Sprintf(eos(buf), "%s%s objects", 1985. (keep_traps || keep_mons) ? "," : "", 1986. keep_mons ? "" : " and"); 1987. if (keep_mons) 1988. Sprintf(eos(buf), "%s and monsters", 1989. (keep_traps || keep_objs) ? "," : ""); 1990. } 1991. pline("Showing %s only...", buf); 1992. 1993. /* allow player to move cursor around and get autodescribe feedback 1994. based on what is visible now rather than what is on 'real' map */ 1995. which_subset |= TER_MAP; /* guarantee non-zero */ 1996. browse_map(which_subset, "anything of interest"); 1997. 1998. reconstrain_map(); 1999. docrt(); /* redraw the screen, restoring regular map */ 2000. if (Underwater) 2001. under_water(2); 2002. if (u.uburied) 2003. under_ground(2); 2004. } 2005. return; 2006. } 2007. 2008. /*detect.c*/