Source:NetHack 5.0.0/src/detect.c
Jump to navigation
Jump to search
Below is the full text to detect.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/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 5.0 detect.c $NHDT-Date: 1763708572 2025/11/20 23:02:52 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.191 $ */ 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. #ifndef FOUND_FLASH_COUNT 15. /* for screen alert shown to player when secret door detection or ^E 16. finds stuff; to use tmp_at() instead of flash_glyph_at(), define as 0; 17. extra code for tmp_at() will be included and the flash_glyph_at() 18. calls will execute but won't do anything */ 19. #define FOUND_FLASH_COUNT 6 20. #endif 21. 22. struct found_things; 23. 24. staticfn boolean unconstrain_map(void); 25. staticfn void reconstrain_map(void); 26. staticfn void map_redisplay(void); 27. staticfn void browse_map(unsigned, const char *); 28. staticfn void map_monst(struct monst *, boolean); 29. staticfn void observe_recursively(struct obj *); 30. staticfn boolean check_map_spot(coordxy, coordxy, char, unsigned); 31. staticfn boolean clear_stale_map(char, unsigned); 32. staticfn void sense_trap(struct trap *, coordxy, coordxy, int); 33. staticfn int detect_obj_traps(struct obj *, boolean, int, 34. struct found_things *) NO_NNARGS; 35. staticfn void display_trap_map(int); 36. staticfn int furniture_detect(void); 37. staticfn void foundone(coordxy, coordxy, int); 38. staticfn void findone(coordxy, coordxy, genericptr_t); 39. staticfn void openone(coordxy, coordxy, genericptr_t); 40. staticfn int mfind0(struct monst *, boolean); 41. staticfn boolean skip_premap_detect(coordxy, coordxy); 42. staticfn int reveal_terrain_getglyph(coordxy, coordxy, unsigned, int, 43. unsigned); 44. 45. /* dummytrap: used when detecting traps finds a door or chest trap; the 46. couple of fields that matter are always re-initialized during use so 47. this does not need to be part of 'struct instance_globals g'; fields 48. that aren't used are compile-/link-/load-time initialized to 0 */ 49. static struct trap dummytrap; 50. 51. /* data for enhanced feedback from findone() */ 52. struct found_things { 53. coord ft_cc; /* for passing extra info to detect_obj_traps() */ 54. uchar num_sdoors; 55. uchar num_scorrs; 56. uchar num_traps; 57. uchar num_mons; 58. uchar num_invis; 59. uchar num_cleared_invis; 60. uchar num_kept_invis; 61. }; 62. 63. /* wildcard class for clear_stale_map - this used to be used as a getobj() 64. input but it's no longer used for that function */ 65. #define ALL_CLASSES (MAXOCLASSES + 1) 66. 67. /* bring hero out from underwater or underground or being engulfed; 68. return True iff any change occurred */ 69. staticfn boolean 70. unconstrain_map(void) 71. { 72. boolean res = u.uinwater || u.uburied || u.uswallow; 73. 74. /* bring Underwater, buried, or swallowed hero to normal map; 75. bypass set_uinwater() */ 76. iflags.save_uinwater = u.uinwater, u.uinwater = 0; 77. iflags.save_uburied = u.uburied, u.uburied = 0; 78. iflags.save_uswallow = u.uswallow, u.uswallow = 0; 79. 80. return res; 81. } 82. 83. /* put hero back underwater or underground or engulfed */ 84. staticfn void 85. reconstrain_map(void) 86. { 87. /* if was in water and taken out, put back; bypass set_uinwater() */ 88. u.uinwater = iflags.save_uinwater, iflags.save_uinwater = 0; 89. u.uburied = iflags.save_uburied, iflags.save_uburied = 0; 90. u.uswallow = iflags.save_uswallow, iflags.save_uswallow = 0; 91. } 92. 93. staticfn void 94. map_redisplay(void) 95. { 96. reconstrain_map(); 97. docrt(); /* redraw the screen to remove unseen traps from the map */ 98. if (Underwater) 99. under_water(2); 100. if (u.uburied) 101. under_ground(2); 102. } 103. 104. /* use getpos()'s 'autodescribe' to view whatever is currently shown on map */ 105. staticfn void 106. browse_map(unsigned ter_typ, const char *ter_explain) 107. { 108. coord dummy_pos; /* don't care whether player actually picks a spot */ 109. boolean save_autodescribe; 110. 111. dummy_pos.x = u.ux, dummy_pos.y = u.uy; /* starting spot for getpos() */ 112. save_autodescribe = iflags.autodescribe; 113. iflags.autodescribe = TRUE; 114. iflags.terrainmode = ter_typ; 115. (void) getpos(&dummy_pos, FALSE, ter_explain); 116. iflags.terrainmode = 0; 117. iflags.autodescribe = save_autodescribe; 118. } 119. 120. /* extracted from monster_detection() so can be shared by do_vicinity_map() */ 121. staticfn void 122. map_monst(struct monst *mtmp, boolean showtail) 123. { 124. int glyph = (monsym(mtmp->data) == ' ') 125. ? detected_mon_to_glyph(mtmp, newsym_rn2) 126. : mtmp->mtame 127. ? pet_to_glyph(mtmp, newsym_rn2) 128. : mon_to_glyph(mtmp, newsym_rn2); 129. 130. show_glyph(mtmp->mx, mtmp->my, glyph); 131. 132. if (showtail && mtmp->data == &mons[PM_LONG_WORM]) 133. detect_wsegs(mtmp, 0); 134. } 135. 136. /* this is checking whether a trap symbol represents a trapped chest, 137. not whether a trapped chest is actually present */ 138. boolean 139. trapped_chest_at(int ttyp, coordxy x, coordxy y) 140. { 141. struct monst *mtmp; 142. struct obj *otmp; 143. 144. if (!glyph_is_trap(glyph_at(x, y))) 145. return FALSE; 146. if (ttyp != TRAPPED_CHEST || (Hallucination && rn2(20))) 147. return FALSE; 148. 149. /* 150. * TODO? We should check containers recursively like the trap 151. * detecting routine does. Chests and large boxes do not nest in 152. * themselves or each other, but could be contained inside statues. 153. * 154. * For farlook, we should also check for buried containers, but 155. * for '^' command to examine adjacent trap glyph, we shouldn't. 156. */ 157. 158. /* on map, presence of any trappable container will do */ 159. if (sobj_at(CHEST, x, y) || sobj_at(LARGE_BOX, x, y)) 160. return TRUE; 161. /* in inventory, we need to find one which is actually trapped */ 162. if (u_at(x, y)) { 163. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 164. if (Is_box(otmp) && otmp->otrapped) 165. return TRUE; 166. if (u.usteed) { /* steed isn't on map so won't be found by m_at() */ 167. for (otmp = u.usteed->minvent; otmp; otmp = otmp->nobj) 168. if (Is_box(otmp) && otmp->otrapped) 169. return TRUE; 170. } 171. } 172. if ((mtmp = m_at(x, y)) != 0) 173. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 174. if (Is_box(otmp) && otmp->otrapped) 175. return TRUE; 176. return FALSE; 177. } 178. 179. /* this is checking whether a trap symbol represents a trapped door, 180. not whether the door here is actually trapped */ 181. boolean 182. trapped_door_at(int ttyp, coordxy x, coordxy y) 183. { 184. struct rm *lev; 185. 186. if (!glyph_is_trap(glyph_at(x, y))) 187. return FALSE; 188. if (ttyp != TRAPPED_DOOR || (Hallucination && rn2(20))) 189. return FALSE; 190. lev = &levl[x][y]; 191. if (!IS_DOOR(lev->typ)) 192. return FALSE; 193. if ((lev->doormask & (D_NODOOR | D_BROKEN | D_ISOPEN)) != 0 194. && trapped_chest_at(ttyp, x, y)) 195. return FALSE; 196. return TRUE; 197. } 198. 199. /* recursively search obj for an object in class oclass, return 1st found */ 200. struct obj * 201. o_in(struct obj *obj, char oclass) 202. { 203. struct obj *otmp; 204. struct obj *temp; 205. 206. if (obj->oclass == oclass) 207. return obj; 208. /* 209. * Note: we exclude SchroedingersBox because the corpse it contains 210. * isn't necessarily a corpse yet. Resolving the status would lead 211. * to complications if it turns out to be a live cat. We know that 212. * that Box can't contain anything else because putting something in 213. * would resolve the cat/corpse situation and convert to ordinary box. 214. */ 215. if (Has_contents(obj) && !SchroedingersBox(obj)) { 216. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) 217. if (otmp->oclass == oclass) 218. return otmp; 219. else if (Has_contents(otmp) && (temp = o_in(otmp, oclass)) != 0) 220. return temp; 221. } 222. return (struct obj *) 0; 223. } 224. 225. /* Recursively search obj for an object made of specified material. 226. * Return first found. 227. */ 228. struct obj * 229. o_material(struct obj *obj, unsigned material) 230. { 231. struct obj *otmp; 232. struct obj *temp; 233. 234. if (objects[obj->otyp].oc_material == material) 235. return obj; 236. 237. if (Has_contents(obj)) { 238. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) 239. if (objects[otmp->otyp].oc_material == material) 240. return otmp; 241. else if (Has_contents(otmp) 242. && (temp = o_material(otmp, material)) != 0) 243. return temp; 244. } 245. return (struct obj *) 0; 246. } 247. 248. staticfn void 249. observe_recursively(struct obj *obj) 250. { 251. struct obj *otmp; 252. 253. observe_object(obj); 254. if (Has_contents(obj)) { 255. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) 256. observe_recursively(otmp); 257. } 258. } 259. 260. /* Check whether the location has an outdated object displayed on it. */ 261. staticfn boolean 262. check_map_spot(coordxy x, coordxy y, char oclass, unsigned material) 263. { 264. int glyph; 265. struct obj *otmp; 266. struct monst *mtmp; 267. 268. glyph = glyph_at(x, y); 269. if (glyph_is_object(glyph)) { 270. /* there's some object shown here */ 271. if (oclass == ALL_CLASSES) { 272. return !(svl.level.objects[x][y] /* stale if nothing here */ 273. || ((mtmp = m_at(x, y)) != 0 && mtmp->minvent)); 274. } else { 275. if (material 276. && objects[glyph_to_obj(glyph)].oc_material == material) { 277. /* object shown here is of interest because material matches */ 278. for (otmp = svl.level.objects[x][y]; otmp; 279. otmp = otmp->nexthere) 280. if (o_material(otmp, GOLD)) 281. return FALSE; 282. /* didn't find it; perhaps a monster is carrying it */ 283. if ((mtmp = m_at(x, y)) != 0) { 284. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 285. if (o_material(otmp, GOLD)) 286. return FALSE; 287. } 288. /* detection indicates removal of this object from the map */ 289. return TRUE; 290. } 291. if (oclass && objects[glyph_to_obj(glyph)].oc_class == oclass) { 292. /* obj shown here is of interest because its class matches */ 293. for (otmp = svl.level.objects[x][y]; otmp; 294. otmp = otmp->nexthere) 295. if (o_in(otmp, oclass)) 296. return FALSE; 297. /* didn't find it; perhaps a monster is carrying it */ 298. if ((mtmp = m_at(x, y)) != 0) { 299. for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) 300. if (o_in(otmp, oclass)) 301. return FALSE; 302. } 303. /* detection indicates removal of this object from the map */ 304. return TRUE; 305. } 306. } 307. } 308. return FALSE; 309. } 310. 311. /* 312. * When doing detection, remove stale data from the map display (corpses 313. * rotted away, objects carried away by monsters, etc) so that it won't 314. * reappear after the detection has completed. Return true if noticeable 315. * change occurs. 316. */ 317. staticfn boolean 318. clear_stale_map(char oclass, unsigned material) 319. { 320. coordxy zx, zy; 321. boolean change_made = FALSE; 322. 323. for (zx = 1; zx < COLNO; zx++) 324. for (zy = 0; zy < ROWNO; zy++) 325. if (check_map_spot(zx, zy, oclass, material)) { 326. unmap_object(zx, zy); 327. change_made = TRUE; 328. } 329. 330. return change_made; 331. } 332. 333. /* look for gold, on the floor or in monsters' possession */ 334. int 335. gold_detect(struct obj *sobj) 336. { 337. struct obj *obj; 338. struct monst *mtmp; 339. struct obj gold, *temp = 0; 340. boolean stale, ugold = FALSE, steedgold = FALSE; 341. int ter_typ = TER_DETECT | TER_OBJ; 342. 343. gk.known = stale = clear_stale_map(COIN_CLASS, 344. (unsigned) (sobj->blessed ? GOLD : 0)); 345. 346. /* look for gold carried by monsters (might be in a container) */ 347. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 348. if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx)) 349. continue; 350. if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) { 351. if (mtmp == u.usteed) { 352. steedgold = TRUE; 353. } else { 354. gk.known = TRUE; 355. goto outgoldmap; /* skip further searching */ 356. } 357. } else { 358. for (obj = mtmp->minvent; obj; obj = obj->nobj) 359. if ((sobj->blessed && o_material(obj, GOLD)) 360. || o_in(obj, COIN_CLASS)) { 361. if (mtmp == u.usteed) { 362. steedgold = TRUE; 363. } else { 364. gk.known = TRUE; 365. goto outgoldmap; /* skip further searching */ 366. } 367. } 368. } 369. } 370. 371. /* look for gold objects */ 372. for (obj = fobj; obj; obj = obj->nobj) { 373. if (sobj->blessed && o_material(obj, GOLD)) { 374. gk.known = TRUE; 375. if (obj->ox != u.ux || obj->oy != u.uy) 376. goto outgoldmap; 377. } else if (o_in(obj, COIN_CLASS)) { 378. gk.known = TRUE; 379. if (obj->ox != u.ux || obj->oy != u.uy) 380. goto outgoldmap; 381. } 382. } 383. 384. if (!gk.known) { 385. /* no gold found on floor or monster's inventory. 386. adjust message if you have gold in your inventory */ 387. char buf[BUFSZ]; 388. 389. if (gy.youmonst.data == &mons[PM_GOLD_GOLEM]) 390. Sprintf(buf, "You feel like a million %s!", currency(2L)); 391. else if (money_cnt(gi.invent) || hidden_gold(TRUE)) 392. Strcpy(buf, 393. "You feel worried about your future financial situation."); 394. else if (steedgold) 395. Sprintf(buf, "You feel interested in %s financial situation.", 396. s_suffix(x_monnam(u.usteed, 397. u.usteed->mtame ? ARTICLE_YOUR 398. : ARTICLE_THE, 399. (char *) 0, 400. SUPPRESS_SADDLE, FALSE))); 401. else 402. Strcpy(buf, "You feel materially poor."); 403. 404. strange_feeling(sobj, buf); 405. return 1; 406. } 407. /* only under me - no separate display required */ 408. if (stale) 409. docrt(); 410. You("notice some gold between your %s.", makeplural(body_part(FOOT))); 411. return 0; 412. 413. outgoldmap: 414. cls(); 415. 416. (void) unconstrain_map(); 417. /* Discover gold locations. */ 418. for (obj = fobj; obj; obj = obj->nobj) { 419. if (sobj->blessed && (temp = o_material(obj, GOLD)) != 0) { 420. if (temp != obj) { 421. temp->ox = obj->ox; 422. temp->oy = obj->oy; 423. } 424. map_object(temp, 1); 425. } else if ((temp = o_in(obj, COIN_CLASS)) != 0) { 426. if (temp != obj) { 427. temp->ox = obj->ox; 428. temp->oy = obj->oy; 429. } 430. map_object(temp, 1); 431. } 432. if (temp && u_at(temp->ox, temp->oy)) 433. ugold = TRUE; 434. } 435. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 436. if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx)) 437. continue; 438. temp = 0; 439. if (findgold(mtmp->minvent) || monsndx(mtmp->data) == PM_GOLD_GOLEM) { 440. gold = cg.zeroobj; /* ensure oextra is cleared too */ 441. gold.otyp = GOLD_PIECE; 442. gold.quan = (long) rnd(10); /* usually more than 1 */ 443. gold.ox = mtmp->mx; 444. gold.oy = mtmp->my; 445. map_object(&gold, 1); 446. temp = &gold; 447. } else { 448. for (obj = mtmp->minvent; obj; obj = obj->nobj) 449. if (sobj->blessed && (temp = o_material(obj, GOLD)) != 0) { 450. temp->ox = mtmp->mx; 451. temp->oy = mtmp->my; 452. map_object(temp, 1); 453. break; 454. } else if ((temp = o_in(obj, COIN_CLASS)) != 0) { 455. temp->ox = mtmp->mx; 456. temp->oy = mtmp->my; 457. map_object(temp, 1); 458. break; 459. } 460. } 461. if (temp && u_at(temp->ox, temp->oy)) 462. ugold = TRUE; 463. } 464. if (!ugold) { 465. newsym(u.ux, u.uy); 466. ter_typ |= TER_MON; /* so autodescribe will recognize hero */ 467. } 468. You_feel("very greedy, and sense gold!"); 469. exercise(A_WIS, TRUE); 470. 471. browse_map(ter_typ, "gold"); 472. 473. map_redisplay(); 474. return 0; 475. } 476. 477. /* returns 1 if nothing was detected, 0 if something was detected */ 478. int 479. food_detect(struct obj *sobj) 480. { 481. struct obj *obj; 482. struct monst *mtmp; 483. int ct = 0, ctu = 0; 484. boolean confused = (Confusion || (sobj && sobj->cursed)), stale; 485. char oclass = confused ? POTION_CLASS : FOOD_CLASS; 486. const char *what = confused ? something : "food"; 487. 488. stale = clear_stale_map(oclass, 0); 489. if (u.usteed) /* some situations leave steed with stale coordinates */ 490. u.usteed->mx = u.ux, u.usteed->my = u.uy; 491. 492. for (obj = fobj; obj; obj = obj->nobj) 493. if (o_in(obj, oclass)) { 494. if (u_at(obj->ox, obj->oy)) 495. ctu++; 496. else 497. ct++; 498. } 499. for (mtmp = fmon; mtmp && (!ct || !ctu); mtmp = mtmp->nmon) { 500. if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx)) 501. continue; 502. for (obj = mtmp->minvent; obj; obj = obj->nobj) 503. if (o_in(obj, oclass)) { 504. if (u_at(mtmp->mx, mtmp->my)) 505. ctu++; /* steed or an engulfer with inventory */ 506. else 507. ct++; 508. break; 509. } 510. } 511. 512. if (!ct && !ctu) { 513. gk.known = stale && !confused; 514. if (stale) { 515. docrt(); 516. You("sense a lack of %s nearby.", what); 517. if (sobj && sobj->blessed) { 518. if (!u.uedibility) 519. Your("%s starts to tingle.", body_part(NOSE)); 520. u.uedibility = 1; 521. } 522. } else if (sobj) { 523. char buf[BUFSZ]; 524. 525. Sprintf(buf, "Your %s twitches%s.", body_part(NOSE), 526. (sobj->blessed && !u.uedibility) 527. ? " then starts to tingle" 528. : ""); 529. if (sobj->blessed && !u.uedibility) { 530. boolean savebeginner = flags.beginner; 531. 532. flags.beginner = FALSE; /* prevent non-delivery of message */ 533. strange_feeling(sobj, buf); 534. flags.beginner = savebeginner; 535. u.uedibility = 1; 536. } else 537. strange_feeling(sobj, buf); 538. } 539. return !stale; 540. } else if (!ct) { 541. gk.known = TRUE; 542. You("%s %s nearby.", sobj ? "smell" : "sense", what); 543. if (sobj && sobj->blessed) { 544. if (!u.uedibility) 545. Your("%s starts to tingle.", body_part(NOSE)); 546. u.uedibility = 1; 547. } 548. } else { 549. struct obj *temp; 550. int ter_typ = TER_DETECT | TER_OBJ; 551. 552. gk.known = TRUE; 553. cls(); 554. (void) unconstrain_map(); 555. for (obj = fobj; obj; obj = obj->nobj) 556. if ((temp = o_in(obj, oclass)) != 0) { 557. if (temp != obj) { 558. temp->ox = obj->ox; 559. temp->oy = obj->oy; 560. } 561. map_object(temp, 1); 562. } 563. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 564. if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx)) 565. continue; 566. for (obj = mtmp->minvent; obj; obj = obj->nobj) 567. if ((temp = o_in(obj, oclass)) != 0) { 568. temp->ox = mtmp->mx; 569. temp->oy = mtmp->my; 570. map_object(temp, 1); 571. break; /* skip rest of this monster's inventory */ 572. } 573. } 574. if (!ctu) { 575. newsym(u.ux, u.uy); 576. ter_typ |= TER_MON; /* for autodescribe of self */ 577. } 578. if (sobj) { 579. if (sobj->blessed) { 580. Your("%s %s to tingle and you smell %s.", body_part(NOSE), 581. u.uedibility ? "continues" : "starts", what); 582. u.uedibility = 1; 583. } else 584. Your("%s tingles and you smell %s.", body_part(NOSE), what); 585. } else 586. You("sense %s.", what); 587. exercise(A_WIS, TRUE); 588. 589. browse_map(ter_typ, "food"); 590. 591. map_redisplay(); 592. } 593. return 0; 594. } 595. 596. /* 597. * Used for scrolls, potions, spells, and crystal balls. Returns: 598. * 599. * 1 - nothing was detected 600. * 0 - something was detected 601. */ 602. int 603. object_detect(struct obj *detector, /* object doing the detecting */ 604. int class) /* an object class, 0 for all */ 605. { 606. coordxy x, y; 607. char stuff[BUFSZ]; 608. int is_cursed = (detector && detector->cursed); 609. int do_dknown = (detector && (detector->oclass == POTION_CLASS 610. || detector->oclass == SPBOOK_CLASS) 611. && detector->blessed); 612. int ct = 0, ctu = 0; 613. struct obj *obj, *otmp = (struct obj *) 0; 614. struct monst *mtmp; 615. int sym, boulder = 0, ter_typ = TER_DETECT | TER_OBJ; 616. 617. if (class < 0 || class >= MAXOCLASSES) { 618. impossible("object_detect: illegal class %d", class); 619. class = 0; 620. } 621. 622. /* Special boulder symbol check - does the class symbol happen 623. * to match showsyms[SYM_BOULDER + SYM_OFF_X] which is user-defined. 624. * If so, that means we aren't sure what they really wanted to 625. * detect. Rather than trump anything, show both possibilities. 626. * We can exclude checking the buried obj chain for boulders below. 627. */ 628. sym = class ? def_oc_syms[class].sym : 0; 629. if (sym && sym == gs.showsyms[SYM_BOULDER + SYM_OFF_X]) 630. boulder = ROCK_CLASS; 631. 632. if (Hallucination || (Confusion && class == SCROLL_CLASS)) 633. Strcpy(stuff, something); 634. else 635. Strcpy(stuff, class ? def_oc_syms[class].name : "objects"); 636. if (boulder && class != ROCK_CLASS) 637. Strcat(stuff, " and/or large stones"); 638. 639. if (do_dknown) 640. for (obj = gi.invent; obj; obj = obj->nobj) 641. observe_recursively(obj); 642. 643. for (obj = fobj; obj; obj = obj->nobj) { 644. if ((!class && !boulder) || o_in(obj, class) || o_in(obj, boulder)) { 645. if (u_at(obj->ox, obj->oy)) 646. ctu++; 647. else 648. ct++; 649. } 650. if (do_dknown) 651. observe_recursively(obj); 652. } 653. 654. for (obj = svl.level.buriedobjlist; obj; obj = obj->nobj) { 655. if (!class || o_in(obj, class)) { 656. if (u_at(obj->ox, obj->oy)) 657. ctu++; 658. else 659. ct++; 660. } 661. if (do_dknown) 662. observe_recursively(obj); 663. } 664. 665. if (u.usteed) 666. u.usteed->mx = u.ux, u.usteed->my = u.uy; 667. 668. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 669. if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx)) 670. continue; 671. for (obj = mtmp->minvent; obj; obj = obj->nobj) { 672. if ((!class && !boulder) || o_in(obj, class) 673. || o_in(obj, boulder)) 674. ct++; 675. if (do_dknown) 676. observe_recursively(obj); 677. } 678. if ((is_cursed && M_AP_TYPE(mtmp) == M_AP_OBJECT 679. && (!class || class == objects[mtmp->mappearance].oc_class)) 680. || (findgold(mtmp->minvent) && (!class || class == COIN_CLASS))) { 681. ct++; 682. break; 683. } 684. } 685. 686. if (!clear_stale_map(!class ? ALL_CLASSES : class, 0) && !ct) { 687. if (!ctu) { 688. if (detector) 689. strange_feeling(detector, "You feel a lack of something."); 690. return 1; 691. } 692. You("sense %s nearby.", stuff); 693. return 0; 694. } 695. 696. cls(); 697. 698. (void) unconstrain_map(); 699. /* 700. * Map all buried objects first. 701. */ 702. for (obj = svl.level.buriedobjlist; obj; obj = obj->nobj) 703. if (!class || (otmp = o_in(obj, class)) != 0) { 704. if (class) { 705. if (otmp != obj) { 706. otmp->ox = obj->ox; 707. otmp->oy = obj->oy; 708. } 709. map_object(otmp, 1); 710. } else 711. map_object(obj, 1); 712. } 713. /* 714. * If we are mapping all objects, map only the top object of a pile or 715. * the first object in a monster's inventory. Otherwise, go looking 716. * for a matching object class and display the first one encountered 717. * at each location. 718. * 719. * Objects on the floor override buried objects. 720. */ 721. for (x = 1; x < COLNO; x++) 722. for (y = 0; y < ROWNO; y++) 723. for (obj = svl.level.objects[x][y]; obj; obj = obj->nexthere) 724. if ((!class && !boulder) || (otmp = o_in(obj, class)) != 0 725. || (otmp = o_in(obj, boulder)) != 0) { 726. if (class || boulder) { 727. if (otmp != obj) { 728. otmp->ox = obj->ox; 729. otmp->oy = obj->oy; 730. } 731. map_object(otmp, 1); 732. } else 733. map_object(obj, 1); 734. break; 735. } 736. 737. /* Objects in the monster's inventory override floor objects. */ 738. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 739. if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx)) 740. continue; 741. for (obj = mtmp->minvent; obj; obj = obj->nobj) 742. if ((!class && !boulder) || (otmp = o_in(obj, class)) != 0 743. || (otmp = o_in(obj, boulder)) != 0) { 744. if (!class && !boulder) 745. otmp = obj; 746. otmp->ox = mtmp->mx; /* at monster location */ 747. otmp->oy = mtmp->my; 748. map_object(otmp, 1); 749. break; 750. } 751. /* Allow a mimic to override the detected objects it is carrying. */ 752. if (is_cursed && M_AP_TYPE(mtmp) == M_AP_OBJECT 753. && (!class || class == objects[mtmp->mappearance].oc_class)) { 754. struct obj temp; 755. 756. temp = cg.zeroobj; 757. temp.otyp = mtmp->mappearance; /* needed for obj_to_glyph() */ 758. temp.quan = 1L; 759. temp.ox = mtmp->mx; 760. temp.oy = mtmp->my; 761. /* used for mimicking a corpse or statue */ 762. temp.corpsenm = has_mcorpsenm(mtmp) ? MCORPSENM(mtmp) : PM_TENGU; 763. map_object(&temp, 1); 764. } else if (findgold(mtmp->minvent) 765. && (!class || class == COIN_CLASS)) { 766. struct obj gold; 767. 768. gold = cg.zeroobj; /* ensure oextra is cleared too */ 769. gold.otyp = GOLD_PIECE; 770. gold.quan = (long) rnd(10); /* usually more than 1 */ 771. gold.ox = mtmp->mx; 772. gold.oy = mtmp->my; 773. map_object(&gold, 1); 774. } 775. } 776. if (!glyph_is_object(glyph_at(u.ux, u.uy))) { 777. newsym(u.ux, u.uy); 778. ter_typ |= TER_MON; 779. } 780. You("detect the %s of %s.", ct ? "presence" : "absence", stuff); 781. 782. if (!ct) 783. display_nhwindow(WIN_MAP, TRUE); 784. else 785. browse_map(ter_typ, "object"); 786. 787. map_redisplay(); 788. return 0; 789. } 790. 791. /* 792. * Used by: crystal balls, potions, fountains 793. * 794. * Returns 1 if nothing was detected. 795. * Returns 0 if something was detected. 796. */ 797. int 798. monster_detect(struct obj *otmp, /* detecting object (if any) */ 799. int mclass) /* monster class, 0 for all */ 800. { 801. struct monst *mtmp; 802. int mcnt = 0; 803. 804. /* Note: This used to just check fmon for a non-zero value 805. * but in versions since 3.3.0 fmon can test TRUE due to the 806. * presence of dmons, so we have to find at least one 807. * with positive hit-points to know for sure. 808. */ 809. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 810. if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx)) 811. continue; 812. ++mcnt; 813. break; /* no need for full count, just 1 or more vs 0 */ 814. } 815. 816. if (!mcnt) { 817. if (otmp) 818. strange_feeling(otmp, Hallucination 819. ? "You get the heebie jeebies." 820. : "You feel threatened."); 821. return 1; 822. } else { 823. boolean unconstrained, woken = FALSE; 824. unsigned swallowed = u.uswallow; /* before unconstrain_map() */ 825. 826. cls(); 827. unconstrained = unconstrain_map(); 828. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 829. if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx)) 830. continue; 831. if (!mclass || mtmp->data->mlet == mclass 832. || (mtmp->data == &mons[PM_LONG_WORM] 833. && mclass == S_WORM_TAIL)) 834. map_monst(mtmp, TRUE); 835. 836. if (otmp && otmp->cursed && helpless(mtmp)) { 837. mtmp->msleeping = mtmp->mfrozen = 0; 838. mtmp->mcanmove = 1; 839. woken = TRUE; 840. } 841. } 842. if (!swallowed) 843. display_self(); 844. You("sense the presence of monsters."); 845. if (woken) 846. pline("Monsters sense the presence of you."); 847. 848. if ((otmp && otmp->blessed) && !unconstrained) { 849. /* persistent detection--just show updated map */ 850. display_nhwindow(WIN_MAP, TRUE); 851. } else { 852. /* one-shot detection--allow player to move cursor around and 853. get autodescribe feedback */ 854. EDetect_monsters |= I_SPECIAL; 855. browse_map(TER_DETECT | TER_MON, "monster of interest"); 856. EDetect_monsters &= ~I_SPECIAL; 857. } 858. 859. map_redisplay(); 860. } 861. return 0; 862. } 863. 864. staticfn void 865. sense_trap(struct trap *trap, coordxy x, coordxy y, int src_cursed) 866. { 867. if (Hallucination || src_cursed) { 868. struct obj obj; /* fake object */ 869. 870. obj = cg.zeroobj; 871. if (trap) { 872. obj.ox = trap->tx; 873. obj.oy = trap->ty; 874. } else { 875. obj.ox = x; 876. obj.oy = y; 877. } 878. obj.otyp = !Hallucination ? GOLD_PIECE : random_object(rn2); 879. obj.quan = (long) ((obj.otyp == GOLD_PIECE) ? rnd(10) 880. : objects[obj.otyp].oc_merge ? rnd(2) : 1); 881. obj.corpsenm = random_monster(rn2); /* if otyp == CORPSE */ 882. map_object(&obj, 1); 883. } else if (trap) { 884. map_trap(trap, 1); 885. trap->tseen = 1; 886. } else { 887. /* 888. * OBSOLETE; this was for trapped door or trapped chest 889. * but those are handled by 'if (trap) {map_trap()}' now 890. * and this block of code shouldn't be reachable anymore. 891. */ 892. dummytrap.tx = x; 893. dummytrap.ty = y; 894. dummytrap.ttyp = BEAR_TRAP; /* some kind of trap */ 895. map_trap(&dummytrap, 1); 896. } 897. } 898. 899. #define OTRAP_NONE 0 /* nothing found */ 900. #define OTRAP_HERE 1 /* found at hero's location */ 901. #define OTRAP_THERE 2 /* found at any other location */ 902. 903. /* check a list of objects for chest traps; return 1 if found at <ux,uy>, 904. 2 if found at some other spot, 3 if both, 0 otherwise; optionally 905. update the map to show where such traps were found */ 906. staticfn int 907. detect_obj_traps( 908. struct obj *objlist, 909. boolean show_them, 910. int how, /* 1 for misleading map feedback */ 911. struct found_things *ft) /* being called by findone() when non-Null */ 912. { 913. struct obj *otmp; 914. coordxy x, y; 915. int trapglyph, result = OTRAP_NONE; 916. 917. /* 918. * TODO? Display locations of unarmed land mine and beartrap objects. 919. * If so, should they be displayed as objects or as traps? 920. */ 921. 922. dummytrap.ttyp = TRAPPED_CHEST; 923. trapglyph = ft ? trap_to_glyph(&dummytrap) : GLYPH_NOTHING; 924. for (otmp = objlist; otmp; otmp = otmp->nobj) { 925. x = y = 0; /* lint suppression */ 926. if ((Is_box(otmp) && otmp->otrapped) || Has_contents(otmp)) { 927. /* !get_obj_location and !isok should both be impossible here */ 928. if (!get_obj_location(otmp, &x, &y, BURIED_TOO | CONTAINED_TOO) 929. || !isok(x, y) 930. || (ft && (x != ft->ft_cc.x || y != ft->ft_cc.y))) 931. continue; 932. } 933. if (Is_box(otmp) && otmp->otrapped) { 934. otmp->tknown = 1; 935. observe_object(otmp); 936. result |= u_at(x, y) ? OTRAP_HERE : OTRAP_THERE; 937. if (ft) { 938. flash_glyph_at(x, y, trapglyph, FOUND_FLASH_COUNT); 939. } 940. if (show_them) { 941. dummytrap.tx = x, dummytrap.ty = y; 942. sense_trap(&dummytrap, x, y, how); 943. } 944. if (ft) { 945. foundone(x, y, trapglyph); 946. ft->num_traps++; 947. } 948. } 949. if (Has_contents(otmp)) 950. result |= detect_obj_traps(otmp->cobj, show_them, how, ft); 951. } 952. return result; 953. } 954. 955. staticfn void 956. display_trap_map(int cursed_src) 957. { 958. struct monst *mon; 959. struct trap *ttmp; 960. int door, glyph, ter_typ = TER_DETECT | (cursed_src ? TER_OBJ : TER_TRP); 961. coord cc; 962. 963. cls(); 964. 965. (void) unconstrain_map(); 966. /* show chest traps first, first buried chests then floor chests, so 967. that subsequent floor trap display will override if both types are 968. present at the same location */ 969. (void) detect_obj_traps(svl.level.buriedobjlist, TRUE, cursed_src, NULL); 970. (void) detect_obj_traps(fobj, TRUE, cursed_src, NULL); 971. for (mon = fmon; mon; mon = mon->nmon) { 972. if (DEADMONSTER(mon) || (mon->isgd && !mon->mx)) 973. continue; 974. (void) detect_obj_traps(mon->minvent, TRUE, cursed_src, NULL); 975. } 976. (void) detect_obj_traps(gi.invent, TRUE, cursed_src, NULL); 977. 978. for (ttmp = gf.ftrap; ttmp; ttmp = ttmp->ntrap) 979. sense_trap(ttmp, 0, 0, cursed_src); 980. 981. dummytrap.ttyp = TRAPPED_DOOR; 982. for (door = 0; door < gd.doorindex; door++) { 983. cc = svd.doors[door]; 984. if (levl[cc.x][cc.y].typ == SDOOR) /* can't be trapped; see above */ 985. continue; 986. if (levl[cc.x][cc.y].doormask & D_TRAPPED) { 987. dummytrap.tx = cc.x, dummytrap.ty = cc.y; 988. sense_trap(&dummytrap, cc.x, cc.y, cursed_src); 989. } 990. } 991. 992. /* redisplay hero unless sense_trap() revealed something at <ux,uy> */ 993. glyph = glyph_at(u.ux, u.uy); 994. if (!(glyph_is_trap(glyph) || glyph_is_object(glyph))) { 995. newsym(u.ux, u.uy); 996. ter_typ |= TER_MON; /* for autodescribe at <u.ux,u.uy> */ 997. } 998. You_feel("%s.", cursed_src ? "very greedy" : "entrapped"); 999. 1000. browse_map(ter_typ, cursed_src ? "gold" : "trap of interest"); 1001. 1002. map_redisplay(); 1003. } 1004. 1005. /* the detections are pulled out so they can 1006. * also be used in the crystal ball routine 1007. * returns 1 if nothing was detected 1008. * returns 0 if something was detected 1009. */ 1010. int 1011. trap_detect( 1012. struct obj *sobj) /* Null if crystal ball, scroll if gold detection */ 1013. { 1014. struct trap *ttmp; 1015. struct monst *mon; 1016. int door, tr; 1017. int cursed_src = sobj && sobj->cursed; 1018. boolean found = FALSE; 1019. coord cc; 1020. 1021. if (u.usteed) 1022. u.usteed->mx = u.ux, u.usteed->my = u.uy; 1023. 1024. /* floor/ceiling traps */ 1025. for (ttmp = gf.ftrap; ttmp; ttmp = ttmp->ntrap) { 1026. if (ttmp->tx != u.ux || ttmp->ty != u.uy) { 1027. display_trap_map(cursed_src); 1028. return 0; 1029. } 1030. found = TRUE; 1031. } 1032. /* chest traps (might be buried or carried) */ 1033. if ((tr = detect_obj_traps(fobj, FALSE, 0, NULL)) != OTRAP_NONE) { 1034. if (tr & OTRAP_THERE) { 1035. display_trap_map(cursed_src); 1036. return 0; 1037. } 1038. found = TRUE; 1039. } 1040. if ((tr = detect_obj_traps(svl.level.buriedobjlist, FALSE, 0, NULL)) 1041. != OTRAP_NONE) { 1042. if (tr & OTRAP_THERE) { 1043. display_trap_map(cursed_src); 1044. return 0; 1045. } 1046. found = TRUE; 1047. } 1048. for (mon = fmon; mon; mon = mon->nmon) { 1049. if (DEADMONSTER(mon) || (mon->isgd && !mon->mx)) 1050. continue; 1051. if ((tr = detect_obj_traps(mon->minvent, FALSE, 0, NULL)) 1052. != OTRAP_NONE) { 1053. if (tr & OTRAP_THERE) { 1054. display_trap_map(cursed_src); 1055. return 0; 1056. } 1057. found = TRUE; 1058. } 1059. } 1060. if (detect_obj_traps(gi.invent, FALSE, 0, NULL) != OTRAP_NONE) 1061. found = TRUE; 1062. /* door traps */ 1063. for (door = 0; door < gd.doorindex; door++) { 1064. cc = svd.doors[door]; 1065. /* levl[][].doormask and .wall_info both overlay levl[][].flags; 1066. the bit in doormask for D_TRAPPED is also a bit in wall_info; 1067. secret doors use wall_info so can't be marked as trapped */ 1068. if (levl[cc.x][cc.y].typ == SDOOR) 1069. continue; 1070. if (levl[cc.x][cc.y].doormask & D_TRAPPED) { 1071. if (cc.x != u.ux || cc.y != u.uy) { 1072. display_trap_map(cursed_src); 1073. return 0; 1074. } 1075. found = TRUE; 1076. } 1077. } 1078. if (!found) { 1079. char buf[BUFSZ]; 1080. 1081. Sprintf(buf, "Your %s stop itching.", makeplural(body_part(TOE))); 1082. strange_feeling(sobj, buf); 1083. return 1; 1084. } 1085. /* traps exist, but only under me - no separate display required */ 1086. Your("%s itch.", makeplural(body_part(TOE))); 1087. return 0; 1088. } 1089. 1090. staticfn int 1091. furniture_detect(void) 1092. { 1093. struct monst *mon; 1094. coordxy x, y; 1095. int glyph, sym, found = 0, revealed = 0; 1096. 1097. (void) unconstrain_map(); 1098. 1099. for (y = 0; y < ROWNO; ++y) 1100. for (x = 1; x < COLNO; ++x) { 1101. glyph = glyph_at(x, y); 1102. sym = glyph_to_cmap(glyph); 1103. if (IS_FURNITURE(levl[x][y].typ)) { 1104. ++found; 1105. magic_map_background(x, y, 1); 1106. } else if (is_cmap_furniture(sym)) { 1107. ++found; 1108. if ((mon = m_at(x, y)) != 0 1109. && M_AP_TYPE(mon) == M_AP_FURNITURE) 1110. seemimic(mon); 1111. if (!mon || !canspotmon(mon)) 1112. map_invisible(x, y); 1113. } 1114. if (glyph_at(x, y) != glyph) 1115. ++revealed; 1116. } 1117. 1118. if (!found) 1119. There("seems to be nothing of interest on this level."); 1120. else if (!revealed) 1121. /* [what about clipped map with points of interest outside of the 1122. currently shown area?] */ 1123. Your("map already shows all relevant locations."); 1124. 1125. if (!revealed) 1126. display_nhwindow(WIN_MAP, TRUE); 1127. else /* we need to browse all types because we haven't redrawn the map 1128. * with only points of interest */ 1129. browse_map(TER_DETECT | TER_MAP | TER_TRP | TER_OBJ | TER_MON, 1130. "location"); 1131. 1132. map_redisplay(); 1133. return 0; 1134. } 1135. 1136. /* way back in 3.0plN and/or 2.x, you could use a crystal ball to find out 1137. where the wizard was relative to your current location; that was when the 1138. Wizard guarded the Amulet and was located on a random maze level, and you 1139. were expected to level teleport deep into Hell and hunt for him while 1140. working your way up; this isn't of much use anymore */ 1141. const char * 1142. level_distance(d_level *where) 1143. { 1144. schar ll = depth(&u.uz) - depth(where); 1145. boolean indun = (u.uz.dnum == where->dnum); 1146. const char *res = ""; /* always replaced by some other non-Null value */ 1147. 1148. if (ll < 0) { 1149. if (ll < (-8 - rn2(3))) 1150. if (!indun) 1151. res = "far away"; 1152. else 1153. res = "far below"; 1154. else if (ll < -1) 1155. if (!indun) 1156. res = "away below you"; 1157. else 1158. res = "below you"; 1159. else if (!indun) 1160. res = "in the distance"; 1161. else 1162. res = "just below"; 1163. } else if (ll > 0) { 1164. if (ll > (8 + rn2(3))) 1165. if (!indun) 1166. res = "far away"; 1167. else 1168. res = "far above"; 1169. else if (ll > 1) 1170. if (!indun) 1171. res = "away above you"; 1172. else 1173. res = "above you"; 1174. else if (!indun) 1175. res = "in the distance"; 1176. else 1177. res = "just above"; 1178. } else { /* l1 == 0 */ 1179. if (!indun) 1180. res = "in the distance"; 1181. else 1182. res = "near you"; 1183. } 1184. return res; 1185. } 1186. 1187. /* 1188. * This could be made a lot more useful. Especially now that 1189. * amnesia no longer causes levels to be forgotten. Perhaps a 1190. * menu, and it ought to include the entrance to Vlad's Tower, 1191. * one of the few things that requires active searching/mapping 1192. * to find. And once the Wizard is in play, he is easy for the 1193. * game to locate but not necessarily for the player. 1194. */ 1195. static const struct crystalballlevels { 1196. const char *what; 1197. d_level *where; 1198. } level_detects[] = { 1199. { "Delphi", &oracle_level }, 1200. { "Medusa's lair", &medusa_level }, 1201. { "a castle", &stronghold_level }, 1202. { "the Wizard of Yendor's tower", &wiz1_level }, 1203. }; 1204. 1205. void 1206. use_crystal_ball(struct obj **optr) 1207. { 1208. char ch; 1209. int oops; 1210. struct obj *obj = *optr; 1211. boolean charged = (obj->spe > 0); 1212. 1213. if (Blind) { 1214. pline("Too bad you can't see %s.", the(xname(obj))); 1215. return; 1216. } 1217. oops = is_quest_artifact(obj) ? 8 : obj->blessed ? 16 : 20; 1218. if (charged && (obj->cursed || rnd(oops) > ACURR(A_INT))) { 1219. long impair = (long) rnd(100 - 3 * ACURR(A_INT)); 1220. 1221. switch (rnd((obj->oartifact || obj->blessed) ? 4 : 5)) { 1222. case 1: 1223. pline("%s too much to comprehend!", Tobjnam(obj, "are")); 1224. break; 1225. case 2: 1226. pline("%s you!", Tobjnam(obj, "confuse")); 1227. make_confused((HConfusion & TIMEOUT) + impair, FALSE); 1228. break; 1229. case 3: 1230. if (!resists_blnd(&gy.youmonst)) { 1231. pline("%s your vision!", Tobjnam(obj, "damage")); 1232. make_blinded(BlindedTimeout + impair, FALSE); 1233. if (!Blind) 1234. Your1(vision_clears); 1235. } else { 1236. pline("%s your vision.", Tobjnam(obj, "assault")); 1237. You("are unaffected!"); 1238. } 1239. break; 1240. case 4: 1241. pline("%s your mind!", Tobjnam(obj, "zap")); 1242. (void) make_hallucinated((HHallucination & TIMEOUT) + impair, 1243. FALSE, 0L); 1244. break; 1245. case 5: 1246. pline("%s!", Tobjnam(obj, "explode")); 1247. useup(obj); 1248. *optr = obj = 0; /* it's gone */ 1249. /* physical damage cause by the shards and force */ 1250. losehp(Maybe_Half_Phys(rnd(30)), "exploding crystal ball", 1251. KILLED_BY_AN); 1252. break; 1253. } 1254. if (obj) 1255. consume_obj_charge(obj, TRUE); 1256. return; 1257. } 1258. 1259. if (Hallucination) { 1260. nomul(-rnd(charged ? 4 : 2)); 1261. gm.multi_reason = "gazing into a Magic 8-Ball (tm)"; 1262. gn.nomovemsg = ""; 1263. 1264. if (!charged) { 1265. pline("All you see is funky %s haze.", hcolor((char *) 0)); 1266. if (obj->spe < 0) 1267. goto implode; /* destroy it when it has been cancelled */ 1268. } else { 1269. switch (rnd(6)) { 1270. case 1: 1271. You("grok some groovy globs of incandescent lava."); 1272. break; 1273. case 2: 1274. pline("Whoa! Psychedelic colors, %s!", 1275. poly_gender() == 1 ? "babe" : "dude"); 1276. break; 1277. case 3: 1278. pline_The("crystal pulses with sinister %s light!", 1279. hcolor((char *) 0)); 1280. break; 1281. case 4: 1282. You_see("goldfish swimming above fluorescent rocks."); 1283. break; 1284. case 5: 1285. You_see( 1286. "tiny snowflakes spinning around a miniature farmhouse."); 1287. break; 1288. default: 1289. pline("Oh wow... like a kaleidoscope!"); 1290. break; 1291. } 1292. consume_obj_charge(obj, TRUE); 1293. } 1294. return; 1295. } 1296. 1297. /* read a single character */ 1298. if (flags.verbose) 1299. You("may look for an object, monster, or special map symbol."); 1300. ch = yn_function("What do you look for?", (char *) 0, '\0', TRUE); 1301. /* Don't filter out ' ' here; it has a use */ 1302. if ((ch != def_monsyms[S_GHOST].sym) && strchr(quitchars, ch)) { 1303. if (flags.verbose) 1304. pline1(Never_mind); 1305. return; 1306. } 1307. /* Possible extension: 1308. * If ch=='?', ask whether player wants to find scrolls or is asking 1309. * for help in using the crystal ball. 1310. */ 1311. 1312. You("peer into %s...", the(xname(obj))); 1313. nomul(-rnd(charged ? 10 : 2)); 1314. gm.multi_reason = "gazing into a crystal ball"; 1315. gn.nomovemsg = ""; 1316. 1317. if (!charged) { 1318. pline_The("vision is unclear."); 1319. 1320. if (obj->spe < 0) { /* destroy ball if used after being cancelled */ 1321. implode: /* no damage to hero but 'multi' has a small negative value */ 1322. pline("%s!", Tobjnam(obj, "implode")); 1323. useup(obj); 1324. *optr = obj = (struct obj *) 0; /* it's gone */ 1325. return; 1326. } 1327. } else { 1328. int class, i; 1329. int ret = 0; 1330. 1331. makeknown(CRYSTAL_BALL); 1332. consume_obj_charge(obj, TRUE); 1333. 1334. /* special case: accept ']' as synonym for mimic 1335. * we have to do this before the def_char_to_objclass check 1336. */ 1337. if (ch == DEF_MIMIC_DEF) 1338. ch = DEF_MIMIC; 1339. 1340. /* checking furniture before objects allows '_' to find altars 1341. (along with other furniture) instead of finding iron chains */ 1342. if (def_char_is_furniture(ch) >= 0) { 1343. ret = furniture_detect(); 1344. } else if ((class = def_char_to_objclass(ch)) != MAXOCLASSES) { 1345. ret = object_detect((struct obj *) 0, class); 1346. } else if ((class = def_char_to_monclass(ch)) != MAXMCLASSES) { 1347. ret = monster_detect((struct obj *) 0, class); 1348. } else if (gs.showsyms[SYM_BOULDER + SYM_OFF_X] 1349. && (ch == gs.showsyms[SYM_BOULDER + SYM_OFF_X])) { 1350. ret = object_detect((struct obj *) 0, ROCK_CLASS); 1351. } else if (ch == '^') { 1352. ret = trap_detect((struct obj *) 0); 1353. } else { 1354. i = rn2(SIZE(level_detects)); 1355. You_see("%s, %s.", level_detects[i].what, 1356. level_distance(level_detects[i].where)); 1357. ret = 0; 1358. } 1359. 1360. if (ret) { 1361. if (!rn2(100)) /* make them nervous */ 1362. You_see("the Wizard of Yendor gazing out at you."); 1363. else 1364. pline_The("vision is unclear."); 1365. } 1366. } 1367. return; 1368. } 1369. 1370. /* used by magic mapping, clairvoyance, and wand of probing */ 1371. void 1372. show_map_spot(coordxy x, coordxy y, boolean cnf) 1373. { 1374. struct rm *lev; 1375. struct trap *t; 1376. struct engr *ep; 1377. int oldglyph; 1378. 1379. if (cnf && rn2(7)) 1380. return; 1381. lev = &levl[x][y]; 1382. 1383. lev->seenv = SVALL; 1384. 1385. /* Secret corridors are found, but not secret doors. */ 1386. if (lev->typ == SCORR) { 1387. lev->typ = CORR; 1388. unblock_point(x, y); 1389. } 1390. 1391. /* 1392. * Force the real background, then if it's not furniture and there's 1393. * a known trap there, display the trap, else if there was an object 1394. * shown there, redisplay the object. So during mapping, furniture 1395. * takes precedence over traps, which take precedence over objects, 1396. * opposite to how normal vision behaves. 1397. */ 1398. oldglyph = glyph_at(x, y); 1399. if (svl.level.flags.hero_memory) { 1400. magic_map_background(x, y, 0); 1401. newsym(x, y); /* show it, if not blocked */ 1402. } else { 1403. magic_map_background(x, y, 1); /* display it */ 1404. } 1405. if (!IS_FURNITURE(lev->typ)) { 1406. if ((t = t_at(x, y)) != 0 && t->tseen) { 1407. map_trap(t, 1); 1408. } else if ((ep = engr_at(x, y)) != 0 && !cnf) { 1409. map_engraving(ep, 1); 1410. } else if (glyph_is_trap(oldglyph) || glyph_is_object(oldglyph)) { 1411. show_glyph(x, y, oldglyph); 1412. if (svl.level.flags.hero_memory) 1413. lev->glyph = oldglyph; 1414. } 1415. } 1416. /* possibly update #overview */ 1417. if (!cnf && lev->roomno >= ROOMOFFSET) 1418. room_discovered(lev->roomno - ROOMOFFSET); 1419. } 1420. 1421. void 1422. do_mapping(void) 1423. { 1424. int zx, zy; 1425. boolean unconstrained; 1426. 1427. unconstrained = unconstrain_map(); 1428. for (zx = 1; zx < COLNO; zx++) 1429. for (zy = 0; zy < ROWNO; zy++) 1430. show_map_spot(zx, zy, Confusion); 1431. 1432. if (!svl.level.flags.hero_memory || unconstrained) { 1433. flush_screen(1); /* flush temp screen */ 1434. /* browse_map() instead of display_nhwindow(WIN_MAP, TRUE) */ 1435. browse_map(TER_DETECT | TER_MAP | TER_TRP | TER_OBJ, 1436. "anything of interest"); 1437. map_redisplay(); /* calls reconstrain_map() and docrt() */ 1438. } else { 1439. /* we only get here when unconstrained is False, so reconstrain_map 1440. will be a no-op; call it anyway */ 1441. reconstrain_map(); 1442. } 1443. exercise(A_WIS, TRUE); 1444. } 1445. 1446. /* clairvoyance */ 1447. void 1448. do_vicinity_map( 1449. struct obj *sobj) /* scroll--actually fake spellbook--object */ 1450. { 1451. int zx, zy; 1452. struct monst *mtmp; 1453. struct obj *otmp; 1454. long save_EDetect_mons; 1455. char save_viz_uyux; 1456. boolean unconstrained, refresh = FALSE, 1457. mdetected = FALSE, odetected = FALSE, 1458. /* fake spellbook 'sobj' implies hero has cast the spell; 1459. when book is blessed, casting is skilled or expert level; 1460. if already clairvoyant, non-skilled spell acts like skilled */ 1461. extended = (sobj && (sobj->blessed || Clairvoyant)), 1462. random_farsight = !sobj; 1463. int newglyph, oldglyph, 1464. lo_y = ((u.uy - 5 < 0) ? 0 : u.uy - 5), 1465. hi_y = ((u.uy + 6 >= ROWNO) ? ROWNO - 1 : u.uy + 6), 1466. lo_x = ((u.ux - 9 < 1) ? 1 : u.ux - 9), /* avoid column 0 */ 1467. hi_x = ((u.ux + 10 >= COLNO) ? COLNO - 1 : u.ux + 10), 1468. ter_typ = TER_DETECT | TER_MAP | TER_TRP | TER_OBJ; 1469. 1470. /* 1471. * 3.6.0 attempted to emphasize terrain over transient map 1472. * properties (monsters and objects) but that led to problems. 1473. * Notably, known trap would be displayed instead of a monster 1474. * on or in it and then the display remained that way after the 1475. * clairvoyant snapshot finished. That could have been fixed by 1476. * issuing --More-- and then regular vision update, but we want 1477. * to avoid that when having a clairvoyant episode every N turns 1478. * (from donating to a temple priest or by carrying the Amulet). 1479. * Unlike when casting the spell, it is much too intrusive when 1480. * in the midst of walking around or combatting monsters. 1481. * 1482. * As of 3.6.2, show terrain, then object, then monster like regular 1483. * map updating, except in this case the map locations get marked 1484. * as seen from every direction rather than just from direction of 1485. * hero. Skilled spell marks revealed objects as 'seen up close' 1486. * (but for piles, only the top item) and shows monsters as if 1487. * detected. Non-skilled and timed clairvoyance reveals non-visible 1488. * monsters as 'remembered, unseen'. 1489. */ 1490. 1491. /* if hero is engulfed, show engulfer at <u.ux,u.uy> */ 1492. save_viz_uyux = gv.viz_array[u.uy][u.ux]; 1493. if (u.uswallow) 1494. gv.viz_array[u.uy][u.ux] |= IN_SIGHT; /* <x,y> are reversed, [y][x] */ 1495. save_EDetect_mons = EDetect_monsters; 1496. /* for skilled spell, getpos() scanning of the map will display all 1497. monsters within range; otherwise, "unseen creature" will be shown */ 1498. EDetect_monsters |= I_SPECIAL; 1499. unconstrained = unconstrain_map(); 1500. for (zx = lo_x; zx <= hi_x; zx++) 1501. for (zy = lo_y; zy <= hi_y; zy++) { 1502. oldglyph = glyph_at(zx, zy); 1503. /* this will remove 'remembered, unseen mon' (and objects) */ 1504. show_map_spot(zx, zy, Confusion); 1505. /* if there are any objects here, see the top one */ 1506. if (OBJ_AT(zx, zy)) { 1507. /* not vobj_at(); this is not vision-based access; 1508. unlike object detection, we don't notice buried items */ 1509. otmp = svl.level.objects[zx][zy]; 1510. if (extended) 1511. observe_object(otmp); 1512. map_object(otmp, TRUE); 1513. newglyph = glyph_at(zx, zy); 1514. /* if otmp is underwater, we'll need to redisplay the water */ 1515. if (newglyph != oldglyph && covers_objects(zx, zy)) 1516. odetected = TRUE; 1517. } 1518. /* if there is a monster here, see or detect it, 1519. possibly as "remembered, unseen monster" */ 1520. if ((mtmp = m_at(zx, zy)) != 0 1521. && mtmp->mx == zx && mtmp->my == zy) { /* skip worm tails */ 1522. /* if we're going to offer browse_map()/getpos() scanning of 1523. the map and we're not doing extended/blessed clairvoyance 1524. (hence must be swallowed or underwater), show "unseen 1525. creature" unless map already displayed a monster here */ 1526. if ((unconstrained || !svl.level.flags.hero_memory) 1527. && !extended && (zx != u.ux || zy != u.uy) 1528. && !glyph_is_monster(oldglyph)) 1529. map_invisible(zx, zy); 1530. else 1531. map_monst(mtmp, FALSE); 1532. newglyph = glyph_at(zx, zy); 1533. if (extended && newglyph != oldglyph 1534. && !glyph_is_invisible(newglyph)) 1535. mdetected = TRUE; 1536. } 1537. } 1538. 1539. /* when this instance of clairvoyance is random (see allmain()) and 1540. the only reason to browse the map is that previously undetected 1541. monster(s) or object(s) have been revealed, player can prevent 1542. the you-sense-your-surroundings message and browse operation from 1543. happening by setting 'quick_farsight' option; for clairvoyance 1544. spell, that option is ignored because the message and the pause 1545. for map browsing isn't as intrusive in that circumstance */ 1546. if (random_farsight && flags.quick_farsight) 1547. mdetected = odetected = FALSE; 1548. 1549. if (!svl.level.flags.hero_memory || unconstrained 1550. || mdetected || odetected) { 1551. flush_screen(1); /* flush temp screen */ 1552. /* the getpos() prompt from browse_map() is only shown when 1553. flags.verbose is set, but make this unconditional so that 1554. not-verbose users become aware of the prompting situation */ 1555. You("sense your surroundings."); 1556. if (extended || glyph_is_monster(glyph_at(u.ux, u.uy))) 1557. ter_typ |= TER_MON; 1558. browse_map(ter_typ, "anything of interest"); 1559. refresh = TRUE; 1560. } 1561. reconstrain_map(); 1562. EDetect_monsters = save_EDetect_mons; 1563. gv.viz_array[u.uy][u.ux] = save_viz_uyux; 1564. 1565. /* replace monsters with remembered,unseen monster, then run 1566. see_monsters() to update visible ones and warned-of ones */ 1567. for (zx = lo_x; zx <= hi_x; zx++) 1568. for (zy = lo_y; zy <= hi_y; zy++) { 1569. if (u_at(zx, zy)) 1570. continue; 1571. newglyph = glyph_at(zx, zy); 1572. if (glyph_is_monster(newglyph) 1573. && glyph_to_mon(newglyph) != PM_LONG_WORM_TAIL) { 1574. /* map_invisible() was unconditional here but that made 1575. remembered objects be forgotten for the case where a 1576. monster is immediately redrawn by see_monsters() */ 1577. if ((mtmp = m_at(zx, zy)) == 0 || !canspotmon(mtmp)) 1578. map_invisible(zx, zy); 1579. } 1580. } 1581. see_monsters(); 1582. 1583. if (refresh) 1584. docrt(); 1585. } 1586. 1587. /* convert a secret door into a normal door; it might be trapped */ 1588. void 1589. cvt_sdoor_to_door(struct rm *lev) 1590. { 1591. int newmask = lev->doormask & ~WM_MASK; 1592. 1593. if (Is_rogue_level(&u.uz)) { 1594. /* rogue didn't have doors, only doorways */ 1595. newmask = D_NODOOR; 1596. } else { 1597. /* newly exposed door is closed */ 1598. if (!(newmask & D_LOCKED)) 1599. newmask |= D_CLOSED; 1600. } 1601. lev->typ = DOOR; 1602. lev->doormask = newmask; 1603. lev->arboreal_sdoor = 0; /* clears 'candig' */ 1604. } 1605. 1606. /* update the map for something which has just been found by wand of secret 1607. door detection or wizard mode ^E; will be called multiple times during a 1608. single operation if multiple things of interest are discovered */ 1609. staticfn void 1610. foundone(coordxy zx, coordxy zy, int glyph) 1611. { 1612. if (glyph_is_cmap(glyph) || glyph_is_unexplored(glyph)) 1613. levl[zx][zy].seenv = SVALL; 1614. 1615. { 1616. seenV save_viz = gv.viz_array[zy][zx]; 1617. 1618. if (!Blind) 1619. gv.viz_array[zy][zx] = COULD_SEE | IN_SIGHT; 1620. newsym(zx, zy); 1621. gv.viz_array[zy][zx] = save_viz; 1622. } 1623. 1624. #if FOUND_FLASH_COUNT == 0 1625. /* 1626. * This works [for non-monsters at present] but flash_glyph_at() 1627. * seems preferrable because the tmp_at() variation requires that 1628. * the player respond to --More-- at the end, the flash_glyph 1629. * variation doesn't. 1630. */ 1631. tmp_at(DISP_CHANGE, glyph); 1632. tmp_at(zx, zy); 1633. #endif 1634. } 1635. 1636. /* find something at one location; this should find all somethings there 1637. since it is used for magical detection rather than physical searching */ 1638. staticfn void 1639. findone(coordxy zx, coordxy zy, genericptr_t whatfound) 1640. { 1641. struct rm *lev = &levl[zx][zy]; 1642. struct trap *ttmp = t_at(zx, zy); 1643. struct monst *mtmp = m_at(zx, zy); 1644. struct found_things *found_p = (struct found_things *) whatfound; 1645. 1646. if (mtmp && (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx))) 1647. mtmp = (struct monst *) NULL; 1648. found_p->ft_cc.x = zx; /* needed by detect_obj_traps() */ 1649. found_p->ft_cc.y = zy; 1650. 1651. if (lev->typ == SDOOR) { 1652. nhsym sym = lev->horizontal ? S_hcdoor : S_vcdoor; 1653. 1654. flash_glyph_at(zx, zy, cmap_to_glyph(sym), FOUND_FLASH_COUNT); 1655. cvt_sdoor_to_door(lev); /* set lev->typ = DOOR */ 1656. recalc_block_point(zx, zy); 1657. magic_map_background(zx, zy, 0); 1658. foundone(zx, zy, back_to_glyph(zx, zy)); 1659. found_p->num_sdoors++; 1660. } else if (lev->typ == SCORR) { 1661. flash_glyph_at(zx, zy, cmap_to_glyph(S_corr), FOUND_FLASH_COUNT); 1662. lev->typ = CORR; 1663. unblock_point(zx, zy); 1664. magic_map_background(zx, zy, 0); 1665. foundone(zx, zy, cmap_to_glyph(S_corr)); 1666. found_p->num_scorrs++; 1667. } 1668. 1669. if (ttmp && !ttmp->tseen 1670. /* [shouldn't successful 'find' reveal and activate statue traps?] */ 1671. && ttmp->ttyp != STATUE_TRAP) { 1672. flash_glyph_at(zx, zy, trap_to_glyph(ttmp), FOUND_FLASH_COUNT); 1673. ttmp->tseen = 1; 1674. sense_trap(ttmp, zx, zy, 0); /* handles Hallucination */ 1675. foundone(zx, zy, trap_to_glyph(ttmp)); 1676. found_p->num_traps++; 1677. } 1678. if (closed_door(zx, zy) && (lev->doormask & D_TRAPPED) != 0) { 1679. dummytrap.ttyp = TRAPPED_DOOR; 1680. dummytrap.tx = zx, dummytrap.ty = zy; 1681. flash_glyph_at(zx, zy, trap_to_glyph(&dummytrap), FOUND_FLASH_COUNT); 1682. dummytrap.tseen = 1; 1683. sense_trap(&dummytrap, zx, zy, 0); /* handles Hallucination */ 1684. foundone(zx, zy, trap_to_glyph(&dummytrap)); 1685. found_p->num_traps++; 1686. } 1687. /* trapped chests */ 1688. (void) detect_obj_traps(svl.level.buriedobjlist, TRUE, 0, found_p); 1689. (void) detect_obj_traps(fobj, TRUE, 0, found_p); 1690. if (mtmp) 1691. (void) detect_obj_traps(mtmp->minvent, TRUE, 0, found_p); 1692. if (u_at(zx, zy)) 1693. (void) detect_obj_traps(gi.invent, TRUE, 0, found_p); 1694. 1695. if (mtmp && (!canspotmon(mtmp) || mtmp->mundetected || M_AP_TYPE(mtmp))) { 1696. if (M_AP_TYPE(mtmp)) { 1697. flash_glyph_at(zx, zy, mon_to_glyph(mtmp, rn2_on_display_rng), 1698. FOUND_FLASH_COUNT); 1699. seemimic(mtmp); 1700. /*foundone(zx, zy, mon_to_glyph(mtmp, rn2_on_display_rng);*/ 1701. found_p->num_mons++; 1702. } else if (mtmp->mundetected && (is_hider(mtmp->data) 1703. || hides_under(mtmp->data) 1704. || mtmp->data->mlet == S_EEL)) { 1705. flash_glyph_at(zx, zy, mon_to_glyph(mtmp, rn2_on_display_rng), 1706. FOUND_FLASH_COUNT); 1707. mtmp->mundetected = 0; 1708. /*foundone(zx, zy, mon_to_glyph(mtmp, rn2_on_display_rng);*/ 1709. newsym(zx, zy); 1710. found_p->num_mons++; 1711. } 1712. if (!glyph_is_invisible(lev->glyph)) { 1713. if (!canspotmon(mtmp)) { 1714. flash_glyph_at(zx, zy, GLYPH_INVISIBLE, FOUND_FLASH_COUNT); 1715. map_invisible(zx, zy); 1716. found_p->num_invis++; 1717. } 1718. } else { 1719. found_p->num_kept_invis++; 1720. } 1721. } else if (unmap_invisible(zx, zy)) { 1722. /* flash the invisible monster glyph because it is already gone */ 1723. flash_glyph_at(zx, zy, GLYPH_INVISIBLE, FOUND_FLASH_COUNT); 1724. found_p->num_cleared_invis++; 1725. } 1726. } 1727. 1728. staticfn void 1729. openone(coordxy zx, coordxy zy, genericptr_t num) 1730. { 1731. struct trap *ttmp; 1732. struct obj *otmp; 1733. int *num_p = (int *) num; 1734. 1735. if (OBJ_AT(zx, zy)) { 1736. for (otmp = svl.level.objects[zx][zy]; otmp; otmp = otmp->nexthere) { 1737. if (Is_box(otmp) && otmp->olocked) { 1738. otmp->olocked = 0; 1739. (*num_p)++; 1740. } 1741. } 1742. /* let it fall to the next cases. could be on trap. */ 1743. } 1744. /* note: secret doors can't be trapped; they use levl[][].wall_info; 1745. see rm.h for the troublesome overlay of doormask and wall_info */ 1746. if (levl[zx][zy].typ == SDOOR 1747. || (levl[zx][zy].typ == DOOR 1748. && (levl[zx][zy].doormask & (D_CLOSED | D_LOCKED)))) { 1749. if (levl[zx][zy].typ == SDOOR) 1750. cvt_sdoor_to_door(&levl[zx][zy]); /* .typ = DOOR */ 1751. if (levl[zx][zy].doormask & D_TRAPPED) { 1752. if (distu(zx, zy) < 3) 1753. b_trapped("door", NO_PART); 1754. else 1755. Norep("You %s an explosion!", 1756. cansee(zx, zy) ? "see" : (!Deaf ? "hear" 1757. : "feel the shock of")); 1758. wake_nearto(zx, zy, 11 * 11); 1759. levl[zx][zy].doormask = D_NODOOR; 1760. } else 1761. levl[zx][zy].doormask = D_ISOPEN; 1762. unblock_point(zx, zy); 1763. newsym(zx, zy); 1764. (*num_p)++; 1765. } else if (levl[zx][zy].typ == SCORR) { 1766. levl[zx][zy].typ = CORR; 1767. unblock_point(zx, zy); 1768. newsym(zx, zy); 1769. (*num_p)++; 1770. } else if ((ttmp = t_at(zx, zy)) != 0) { 1771. struct monst *mon; 1772. boolean dummy; /* unneeded "you notice it arg" */ 1773. 1774. if (!ttmp->tseen && ttmp->ttyp != STATUE_TRAP) { 1775. ttmp->tseen = 1; 1776. newsym(zx, zy); 1777. (*num_p)++; 1778. } 1779. mon = u_at(zx, zy) ? &gy.youmonst : m_at(zx, zy); 1780. if (openholdingtrap(mon, &dummy) 1781. || openfallingtrap(mon, TRUE, &dummy)) 1782. (*num_p)++; 1783. } else if (find_drawbridge(&zx, &zy)) { 1784. /* make sure it isn't an open drawbridge */ 1785. open_drawbridge(zx, zy); 1786. (*num_p)++; 1787. } 1788. } 1789. 1790. /* returns number of things found */ 1791. int 1792. findit(void) 1793. { 1794. int num = 0, k; 1795. char buf[BUFSZ]; 1796. struct found_things found; 1797. 1798. /* 1799. * findit() -> do_clear_area(findone) -> findone() -> foundone() 1800. * is used to notify player where various things have been found. 1801. * Changing FOUND_FLASH_COUNT to 0 will switch to tmp_at() to 1802. * highlight all discoveries for the current operation, but requires 1803. * player to respond to --More-- when done. Neither allows browsing 1804. * the map via getpos() autodescribe (until after it has reverted to 1805. * normal display, where found traps might be covered by objects). 1806. */ 1807. 1808. if (u.uswallow) 1809. return 0; 1810. 1811. #if FOUND_FLASH_COUNT == 0 /* _COUNT > 0 doesn't need to init tmp_at() */ 1812. tmp_at(DISP_ALL, GLYPH_NOTHING); 1813. #endif 1814. (void) memset((genericptr_t) &found, 0, sizeof found); 1815. do_clear_area(u.ux, u.uy, BOLT_LIM, findone, (genericptr_t) &found); 1816. /* count that controls "reveal" punctuation; 0..4 */ 1817. k = !!found.num_sdoors + !!found.num_scorrs + !!found.num_traps 1818. + !!found.num_mons; 1819. 1820. buf[0] = '\0'; 1821. if (found.num_sdoors) { 1822. if (found.num_sdoors > 1) 1823. Sprintf(eos(buf), "%d secret doors", found.num_sdoors); 1824. else 1825. Strcat(buf, "a secret door"); 1826. num += found.num_sdoors; 1827. } 1828. /* note: non-\0 *buf implies that at least one previous type is present */ 1829. if (found.num_scorrs) { 1830. if (*buf) /* "doors and corrs" or "doors, corrs ..." */ 1831. Strcat(buf, (k == 2) ? " and " : ", "); 1832. if (found.num_scorrs > 1) 1833. Sprintf(eos(buf), "%d secret corridors", found.num_scorrs); 1834. else 1835. Strcat(buf, "a secret corridor"); 1836. num += found.num_scorrs; 1837. } 1838. if (found.num_traps) { 1839. if (*buf) /* "doors, corrs, and traps" or "{doors|corrs} and traps" 1840. * or "..., traps ..." */ 1841. Strcat(buf, (k == 3 && !found.num_mons) ? ", and " 1842. : (k == 2) ? " and " : ", "); 1843. if (found.num_traps > 1) 1844. Sprintf(eos(buf), "%d traps", found.num_traps); 1845. else 1846. Strcat(buf, "a trap"); 1847. num += found.num_traps; 1848. } 1849. 1850. #if FOUND_FLASH_COUNT == 0 1851. int tmp_num; 1852. tmp_num = num; /* sdoors, scorrs, and traps call tmp_at() */ 1853. #endif 1854. 1855. if (found.num_mons) { 1856. if (*buf) 1857. Strcat(buf, (k > 2) ? ", and " : " and "); 1858. if (found.num_mons > 1) 1859. Sprintf(eos(buf), "%d hidden monsters", found.num_mons); 1860. else 1861. Strcat(buf, "a hidden monster"); 1862. num += found.num_mons; 1863. } 1864. if (*buf) 1865. You("reveal %s!", buf); 1866. 1867. if (found.num_invis) { 1868. if (found.num_invis > 1) 1869. Sprintf(buf, "%d%s unseen monsters", found.num_invis, 1870. found.num_kept_invis ? " other" : ""); 1871. else 1872. Sprintf(buf, "%s unseen monster", 1873. found.num_kept_invis ? "another" : "an"); 1874. You("detect %s!", buf); 1875. num += found.num_invis; 1876. } 1877. 1878. if (found.num_cleared_invis) { 1879. /* at least 1 "remembered, unseen monster" marker has been removed */ 1880. if (!num) 1881. You_feel("%sless paranoid.", 1882. found.num_kept_invis ? "somewhat " : ""); 1883. num += found.num_cleared_invis; 1884. } 1885. /* note: num_kept_invis is not included in the final result */ 1886. 1887. if (!num) 1888. You("don't find anything."); 1889. #if FOUND_FLASH_COUNT == 0 1890. else if (tmp_num) { 1891. flush_screen(1); 1892. display_nhwindow(WIN_MAP, TRUE); 1893. } 1894. tmp_at(DISP_END, GLYPH_NOTHING); /* note: outside of 'if (tmp_num) { }' */ 1895. #endif 1896. 1897. return num; 1898. } 1899. 1900. /* returns number of things found and opened */ 1901. int 1902. openit(void) 1903. { 1904. int num = 0; 1905. 1906. if (u.uswallow) { 1907. if (digests(u.ustuck->data)) { 1908. /* purple worm */ 1909. if (Blind) 1910. pline("Its mouth opens!"); 1911. else 1912. pline("%s opens its mouth!", Monnam(u.ustuck)); 1913. #if 0 /* expels() will take care of this */ 1914. } else if (enfolds(u.ustuck->data)) { 1915. /* trapper or lurker above */ 1916. pline("%s unfolds!", Monnam(u.ustuck)); 1917. #endif 1918. } 1919. expels(u.ustuck, u.ustuck->data, TRUE); 1920. return -1; 1921. } 1922. 1923. do_clear_area(u.ux, u.uy, BOLT_LIM, openone, (genericptr_t) &num); 1924. return num; 1925. } 1926. 1927. /* callback hack for overriding vision in do_clear_area() */ 1928. boolean 1929. detecting(void (*func)(coordxy, coordxy, genericptr_t)) 1930. { 1931. return (func == findone || func == openone); 1932. } 1933. 1934. void 1935. find_trap(struct trap *trap) 1936. { 1937. boolean cleared = FALSE; 1938. 1939. trap->tseen = 1; 1940. exercise(A_WIS, TRUE); 1941. feel_newsym(trap->tx, trap->ty); 1942. 1943. /* The "Hallucination ||" is to preserve 3.6.1 behavior, but this 1944. behavior might need a rework in the hallucination case 1945. (e.g. to not prompt if any trap glyph appears on the square). */ 1946. if (Hallucination || 1947. levl[trap->tx][trap->ty].glyph != trap_to_glyph(trap)) { 1948. /* There's too much clutter to see your find otherwise */ 1949. cls(); 1950. map_trap(trap, 1); 1951. display_self(); 1952. cleared = TRUE; 1953. } 1954. 1955. set_msg_xy(trap->tx, trap->ty); 1956. You("find %s.", an(trapname(trap->ttyp, FALSE))); 1957. 1958. if (cleared) { 1959. display_nhwindow(WIN_MAP, TRUE); /* wait */ 1960. docrt(); 1961. } 1962. } 1963. 1964. staticfn int 1965. mfind0(struct monst *mtmp, boolean via_warning) 1966. { 1967. coordxy x = mtmp->mx, y = mtmp->my; 1968. boolean found_something = FALSE; 1969. 1970. if (via_warning && !warning_of(mtmp)) 1971. return -1; 1972. 1973. if (M_AP_TYPE(mtmp)) { 1974. seemimic(mtmp); 1975. found_something = TRUE; 1976. } else { 1977. /* this used to only be executed if a !canspotmon() test passed 1978. but that failed to bring sensed monsters out of hiding */ 1979. found_something = !canspotmon(mtmp); 1980. if (mtmp->mundetected && (is_hider(mtmp->data) 1981. || hides_under(mtmp->data) 1982. || mtmp->data->mlet == S_EEL)) { 1983. if (via_warning && found_something) { 1984. set_msg_xy(x, y); 1985. Your("danger sense causes you to take a second %s.", 1986. Blind ? "to check nearby" : "look close by"); 1987. display_nhwindow(WIN_MESSAGE, FALSE); /* flush messages */ 1988. } 1989. mtmp->mundetected = 0; 1990. found_something = TRUE; 1991. } 1992. newsym(x, y); 1993. } 1994. 1995. if (found_something) { 1996. if (!canspotmon(mtmp) && glyph_is_invisible(levl[x][y].glyph)) 1997. return -1; /* Found invisible monster in square which already has 1998. * 'I' in it. Logically, this should still take time 1999. * and lead to `return 1', but if we did that the hero 2000. * would keep finding the same monster every turn. */ 2001. exercise(A_WIS, TRUE); 2002. if (!canspotmon(mtmp)) { 2003. map_invisible(x, y); 2004. set_msg_xy(x, y); 2005. You_feel("an unseen monster!"); 2006. } else if (!sensemon(mtmp)) { 2007. set_msg_xy(x, y); 2008. You("find %s.", mtmp->mtame ? y_monnam(mtmp) : a_monnam(mtmp)); 2009. } 2010. return 1; 2011. } 2012. return 0; 2013. } 2014. 2015. int 2016. dosearch0(int aflag) /* intrinsic autosearch vs explicit searching */ 2017. { 2018. coordxy x, y; 2019. struct trap *trap; 2020. struct monst *mtmp; 2021. 2022. if (u.uswallow) { 2023. if (!aflag) 2024. Norep("What are you looking for? The exit?"); 2025. } else { 2026. int fund = (uwep && uwep->oartifact 2027. && spec_ability(uwep, SPFX_SEARCH)) ? uwep->spe : 0; 2028. 2029. if (ublindf && ublindf->otyp == LENSES && !Blind) 2030. fund += 2; /* JDS: lenses help searching */ 2031. if (fund > 5) 2032. fund = 5; 2033. for (x = u.ux - 1; x < u.ux + 2; x++) 2034. for (y = u.uy - 1; y < u.uy + 2; y++) { 2035. if (!isok(x, y)) 2036. continue; 2037. if (u_at(x, y)) 2038. continue; 2039. 2040. if (!aflag && (Blind || visible_region_at(x, y))) 2041. feel_location(x, y); 2042. if (levl[x][y].typ == SDOOR) { 2043. if (rnl(7 - fund)) 2044. continue; 2045. cvt_sdoor_to_door(&levl[x][y]); /* .typ = DOOR */ 2046. recalc_block_point(x, y); 2047. exercise(A_WIS, TRUE); 2048. nomul(0); 2049. feel_location(x, y); /* make sure it shows up */ 2050. set_msg_xy(x, y); 2051. You("find a hidden door."); 2052. } else if (levl[x][y].typ == SCORR) { 2053. if (rnl(7 - fund)) 2054. continue; 2055. levl[x][y].typ = CORR; 2056. unblock_point(x, y); /* vision */ 2057. exercise(A_WIS, TRUE); 2058. nomul(0); 2059. feel_newsym(x, y); /* make sure it shows up */ 2060. set_msg_xy(x, y); 2061. You("find a hidden passage."); 2062. } else { 2063. /* Be careful not to find anything in an SCORR or SDOOR */ 2064. if ((mtmp = m_at(x, y)) != 0 && !aflag) { 2065. int mfres = mfind0(mtmp, 0); 2066. 2067. if (mfres == -1) 2068. continue; 2069. else if (mfres > 0) 2070. return mfres; 2071. } 2072. 2073. /* see if an invisible monster has moved--if Blind, 2074. * feel_location() already did it 2075. */ 2076. if (!aflag && !mtmp && !Blind) 2077. (void) unmap_invisible(x, y); 2078. 2079. if ((trap = t_at(x, y)) && !trap->tseen && !rnl(8)) { 2080. nomul(0); 2081. if (trap->ttyp == STATUE_TRAP) { 2082. if (activate_statue_trap(trap, x, y, FALSE)) 2083. exercise(A_WIS, TRUE); 2084. return 1; 2085. } else { 2086. find_trap(trap); 2087. } 2088. } 2089. } 2090. } 2091. } 2092. return 1; 2093. } 2094. 2095. /* the #search command -- explicit searching */ 2096. int 2097. dosearch(void) 2098. { 2099. if (cmd_safety_prevention("Searching", "another search", 2100. "You already found a monster.", 2101. &ga.already_found_flag)) 2102. return ECMD_OK; 2103. return dosearch0(0) ? ECMD_TIME : ECMD_OK; 2104. } 2105. 2106. void 2107. warnreveal(void) 2108. { 2109. coordxy x, y; 2110. struct monst *mtmp; 2111. 2112. for (x = u.ux - 1; x <= u.ux + 1; x++) 2113. for (y = u.uy - 1; y <= u.uy + 1; y++) { 2114. if (!isok(x, y) || u_at(x, y)) 2115. continue; 2116. if ((mtmp = m_at(x, y)) != 0 2117. && warning_of(mtmp) && mtmp->mundetected) 2118. (void) mfind0(mtmp, 1); /* via_warning */ 2119. } 2120. } 2121. 2122. /* skip premap detection of areas outside Sokoban map */ 2123. staticfn boolean 2124. skip_premap_detect(coordxy x, coordxy y) 2125. { 2126. if ((levl[x][y].typ == STONE) 2127. && (levl[x][y].wall_info & (W_NONDIGGABLE | W_NONPASSWALL)) != 0) 2128. return TRUE; 2129. return FALSE; 2130. } 2131. 2132. /* Pre-map (the sokoban) levels */ 2133. void 2134. premap_detect(void) 2135. { 2136. coordxy x, y; 2137. struct trap *ttmp; 2138. struct obj *obj; 2139. 2140. /* Map the background and boulders */ 2141. for (x = 1; x < COLNO; x++) 2142. for (y = 0; y < ROWNO; y++) { 2143. if (skip_premap_detect(x, y)) 2144. continue; 2145. levl[x][y].seenv = SVALL; 2146. levl[x][y].waslit = TRUE; 2147. if (levl[x][y].typ == SDOOR) 2148. levl[x][y].wall_info = 0; /* see rm.h for explanation */ 2149. map_background(x, y, 1); 2150. if ((obj = sobj_at(BOULDER, x, y)) != 0) 2151. map_object(obj, 1); 2152. } 2153. 2154. /* Map the traps */ 2155. for (ttmp = gf.ftrap; ttmp; ttmp = ttmp->ntrap) { 2156. ttmp->tseen = 1; 2157. map_trap(ttmp, 1); 2158. } 2159. } 2160. 2161. /* used to see under visible gas/cloud regions; caller must declare cmaptmp */ 2162. #define glyph_is_gascloud(glyph) \ 2163. (glyph_is_cmap(glyph) && ((cmaptmp = glyph_to_cmap(glyph)) == S_cloud \ 2164. || cmaptmp == S_poisoncloud)) 2165. 2166. staticfn int 2167. reveal_terrain_getglyph( 2168. coordxy x, coordxy y, 2169. unsigned swallowed, 2170. int default_glyph, 2171. unsigned which_subset) 2172. { 2173. struct trap *t; 2174. struct monst *mtmp; 2175. int glyph, levl_glyph; 2176. uchar seenv; 2177. boolean keep_traps = (which_subset & TER_TRP) != 0, 2178. keep_objs = (which_subset & TER_OBJ) != 0, 2179. keep_mons = (which_subset & TER_MON) != 0, 2180. full = (which_subset & TER_FULL) != 0; 2181. 2182. /* 2183. * FIXME: 2184. * travel treats discovered vibrating square as if it were terrain 2185. * rather than a trap so this should do so too. 2186. */ 2187. 2188. /* for 'full', show the actual terrain for the entire level, 2189. otherwise what the hero remembers for seen locations with 2190. monsters, objects, and/or traps removed as caller dictates */ 2191. seenv = (full || svl.level.flags.hero_memory) 2192. ? levl[x][y].seenv : cansee(x, y) ? SVALL : 0; 2193. if (full) { 2194. levl[x][y].seenv = SVALL; 2195. glyph = back_to_glyph(x, y); 2196. levl[x][y].seenv = seenv; 2197. } else { 2198. int cmaptmp = 0; /* used by glyph_is_gascloud() macro */ 2199. NhRegion *reg = visible_region_at(x, y); 2200. boolean was_mon = FALSE; 2201. 2202. levl_glyph = svl.level.flags.hero_memory ? levl[x][y].glyph 2203. : seenv ? back_to_glyph(x, y) 2204. : default_glyph; 2205. /* glyph_at() returns the displayed glyph, which might 2206. be a monster. levl[][].glyph contains the remembered 2207. glyph, which will never be a monster (unless it is 2208. the invisible monster glyph, which is handled like 2209. an object, replacing any object or trap at its spot) */ 2210. glyph = !swallowed ? glyph_at(x, y) : levl_glyph; 2211. if (keep_mons && u_at(x, y) && swallowed) { 2212. glyph = mon_to_glyph(u.ustuck, rn2_on_display_rng); 2213. } else if ((!keep_mons && (glyph_is_monster(glyph) 2214. || glyph_is_warning(glyph))) 2215. || glyph_is_swallow(glyph)) { 2216. glyph = levl_glyph; 2217. was_mon = TRUE; 2218. } 2219. if (((!keep_objs && glyph_is_object(glyph)) 2220. || glyph_is_invisible(glyph)) 2221. && keep_traps && !covers_traps(x, y)) { 2222. if ((t = t_at(x, y)) != 0 && t->tseen) 2223. glyph = trap_to_glyph(t); 2224. } 2225. if ((!keep_objs && glyph_is_object(glyph)) 2226. /* we either show both traps and visible regions (trap if both 2227. are present at the same spot) or neither traps nor regions */ 2228. || (!keep_traps && (glyph_is_trap(glyph) 2229. || (reg && glyph_is_gascloud(glyph)))) 2230. || (reg && was_mon) 2231. || glyph_is_invisible(glyph)) { 2232. if (!seenv) { 2233. /* it's possible to have a visible region shown at an 2234. otherwise unexplored location (cast stinking cloud 2235. through unexplored corridor into lit room, then approach 2236. far enough to be adjacent to the cloud without having 2237. seen the corridor underneath it) */ 2238. glyph = !reg ? default_glyph : GLYPH_UNEXPLORED; 2239. } else if (keep_traps && reg 2240. && (glyph_is_gascloud(glyph) || was_mon)) { 2241. t = t_at(x, y); 2242. /* we need reg->glyph here when there's a monster shown 2243. at a region spot; the region glyph isn't the remembered 2244. background glyph or the current glyph */ 2245. glyph = (t && t->tseen) ? trap_to_glyph(t) : reg->glyph; 2246. /* FIXME? what about objects temporarily hidden by regions? 2247. when objects are being shown, shouldn't showing them take 2248. precedence over showing the region, just like traps? */ 2249. } else if (svl.lastseentyp[x][y] == levl[x][y].typ) { 2250. glyph = back_to_glyph(x, y); 2251. } else { 2252. /* look for a mimic here posing as furniture; 2253. if we don't find one, we'll have to fake it */ 2254. if ((mtmp = m_at(x, y)) != 0 2255. && M_AP_TYPE(mtmp) == M_AP_FURNITURE) { 2256. glyph = cmap_to_glyph(mtmp->mappearance); 2257. } else { 2258. struct rm save_spot; 2259. 2260. /* 2261. * We have a topology type but we want a screen symbol 2262. * in order to derive a glyph. Some screen symbols need 2263. * the flags field of levl[][] in addition to the type 2264. * (to disambiguate STAIRS to S_upstair or S_dnstair, 2265. * for example). Current flags might not be intended 2266. * for remembered type, but we've got no other choice. 2267. * An exception is wall_info which can be recalculated and 2268. * needs to be. Otherwise back_to_glyph() -> wall_angle() 2269. * might issue an impossible() for it if it is currently 2270. * doormask==D_OPEN for an open door remembered as a wall. 2271. */ 2272. save_spot = levl[x][y]; 2273. levl[x][y].typ = svl.lastseentyp[x][y]; 2274. if (IS_WALL(levl[x][y].typ) || levl[x][y].typ == SDOOR) 2275. xy_set_wall_state(x, y); /* levl[x][y].wall_info */ 2276. glyph = back_to_glyph(x, y); 2277. levl[x][y] = save_spot; 2278. } 2279. } 2280. } 2281. } 2282. /* FIXME: dirty hack */ 2283. if (glyph == cmap_to_glyph(S_darkroom)) 2284. glyph = cmap_to_glyph(S_room); 2285. else if (glyph == cmap_to_glyph(S_litcorr)) 2286. glyph = cmap_to_glyph(S_corr); 2287. return glyph; 2288. } 2289. 2290. #undef glyph_is_gascloud 2291. 2292. #ifdef DUMPLOG 2293. void 2294. dump_map(void) 2295. { 2296. char buf[COLBUFSZ]; 2297. coordxy x, y; 2298. int glyph, skippedrows, lastnonblank; 2299. boolean blankrow, toprow; 2300. unsigned subset = TER_MAP | TER_TRP | TER_OBJ | TER_MON; 2301. /* cmap_to_glyph() evaluates its argument multiple times, so pull the 2302. tree vs stone conditional out of it */ 2303. nhsym default_sym = svl.level.flags.arboreal ? S_tree : S_stone; 2304. int default_glyph = cmap_to_glyph(default_sym); 2305. 2306. /* 2307. * Squeeze out excess vertical space when dumping the map. 2308. * If there are any blank map rows at the top, suppress them 2309. * (our caller has already printed a separator). If there is 2310. * more than one blank map row at the bottom, keep just one. 2311. * Any blank rows within the middle of the map are kept. 2312. * Note: putstr() with winid==0 is for dumplog. 2313. */ 2314. skippedrows = 0; 2315. toprow = TRUE; 2316. for (y = 0; y < ROWNO; y++) { 2317. blankrow = TRUE; /* assume blank until we discover otherwise */ 2318. lastnonblank = -1; /* buf[] index rather than map's x */ 2319. for (x = 1; x < COLNO; x++) { 2320. int ch; 2321. glyph_info glyphinfo; 2322. 2323. glyph = reveal_terrain_getglyph(x, y, u.uswallow, 2324. default_glyph, subset); 2325. map_glyphinfo(x, y, glyph, 0, &glyphinfo); 2326. ch = glyphinfo.ttychar; 2327. buf[x - 1] = ch; 2328. if (ch != ' ') { 2329. blankrow = FALSE; 2330. lastnonblank = x - 1; 2331. } 2332. } 2333. if (!blankrow) { 2334. buf[lastnonblank + 1] = '\0'; 2335. if (toprow) { 2336. skippedrows = 0; 2337. toprow = FALSE; 2338. } 2339. for (x = 0; x < skippedrows; x++) 2340. putstr(0, 0, ""); 2341. putstr(0, 0, buf); /* map row #y */ 2342. skippedrows = 0; 2343. } else { 2344. ++skippedrows; 2345. } 2346. } 2347. if (skippedrows) 2348. putstr(0, 0, ""); 2349. } 2350. #endif /* DUMPLOG */ 2351. 2352. /* idea from crawl; show known portion of map without any monsters, 2353. objects, or traps occluding the view of the underlying terrain; 2354. in explore or wizard modes, can also display unexplored portion */ 2355. void 2356. reveal_terrain( 2357. unsigned which_subset) /* TER_TRP | TER_OBJ | TER_MON | TER_FULL */ 2358. { 2359. /* 'full' overrides impairment and implies no-traps, no-objs, no-mons */ 2360. boolean full = (which_subset & TER_FULL) != 0; /* show whole map */ 2361. 2362. if ((Hallucination || Stunned || Confusion) && !full) { 2363. You("are too disoriented for this."); 2364. } else { 2365. coordxy x, y; 2366. int glyph, default_glyph; 2367. char buf[BUFSZ]; 2368. /* there is a TER_MAP bit too; we always show map regardless of it */ 2369. boolean keep_traps = (which_subset & TER_TRP) != 0, 2370. keep_objs = (which_subset & TER_OBJ) != 0, 2371. keep_mons = (which_subset & TER_MON) != 0; /* not used */ 2372. unsigned swallowed = u.uswallow; /* before unconstrain_map() */ 2373. nhsym default_sym = svl.level.flags.arboreal ? S_tree : S_stone; 2374. 2375. if (unconstrain_map()) 2376. docrt(); 2377. default_glyph = cmap_to_glyph(default_sym); 2378. 2379. for (x = 1; x < COLNO; x++) 2380. for (y = 0; y < ROWNO; y++) { 2381. glyph = reveal_terrain_getglyph(x, y, swallowed, 2382. default_glyph, which_subset); 2383. show_glyph(x, y, glyph); 2384. } 2385. 2386. /* hero's location is not highlighted, but getpos() starts with 2387. cursor there, and after moving it anywhere '@' moves it back */ 2388. flush_screen(1); 2389. if (full) { 2390. Strcpy(buf, "underlying terrain"); 2391. } else { 2392. Strcpy(buf, "known terrain"); 2393. if (keep_traps) 2394. Sprintf(eos(buf), "%s traps", 2395. (keep_objs || keep_mons) ? "," : " and"); 2396. if (keep_objs) 2397. Sprintf(eos(buf), "%s%s objects", 2398. (keep_traps || keep_mons) ? "," : "", 2399. keep_mons ? "" : " and"); 2400. if (keep_mons) 2401. Sprintf(eos(buf), "%s and monsters", 2402. (keep_traps || keep_objs) ? "," : ""); 2403. } 2404. pline("Showing %s only...", buf); 2405. 2406. /* allow player to move cursor around and get autodescribe feedback 2407. based on what is visible now rather than what is on 'real' map */ 2408. which_subset |= TER_MAP; /* guarantee non-zero */ 2409. browse_map(which_subset, "anything of interest"); 2410. 2411. map_redisplay(); 2412. } 2413. return; 2414. } 2415. 2416. #undef FOUND_FLASH_COUNT 2417. 2418. /*detect.c*/