Source:NetHack 5.0.0/src/apply.c
Jump to navigation
Jump to search
Below is the full text to apply.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/apply.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 apply.c $NHDT-Date: 1769342601 2026/01/25 04:03:21 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.475 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2012. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. staticfn int use_camera(struct obj *); 9. staticfn int use_towel(struct obj *); 10. staticfn boolean its_dead(coordxy, coordxy, int *); 11. staticfn int use_stethoscope(struct obj *); 12. staticfn void use_whistle(struct obj *); 13. staticfn void use_magic_whistle(struct obj *); 14. staticfn void magic_whistled(struct obj *); 15. staticfn int use_leash(struct obj *); 16. staticfn void use_leash_core(struct obj *, struct monst *, coord *, int); 17. staticfn boolean mleashed_next2u(struct monst *); 18. staticfn int use_mirror(struct obj *); 19. staticfn void use_bell(struct obj **); 20. staticfn void use_candelabrum(struct obj *); 21. staticfn void use_candle(struct obj **); 22. staticfn void use_lamp(struct obj *); 23. staticfn void light_cocktail(struct obj **); 24. staticfn int rub_ok(struct obj *); 25. staticfn void display_jump_positions(boolean); 26. staticfn void use_tinning_kit(struct obj *); 27. staticfn int use_figurine(struct obj **); 28. staticfn int grease_ok(struct obj *); 29. staticfn int use_grease(struct obj *); 30. staticfn void use_trap(struct obj *); 31. staticfn int touchstone_ok(struct obj *); 32. staticfn int use_stone(struct obj *); 33. staticfn int set_trap(void); /* occupation callback */ 34. staticfn void display_polearm_positions(boolean); 35. staticfn void calc_pole_range(int *, int *); 36. staticfn boolean snickersnee_used_dist_attk(struct obj *); 37. staticfn int use_cream_pie(struct obj *); 38. staticfn int jelly_ok(struct obj *); 39. staticfn int use_royal_jelly(struct obj **); 40. staticfn int grapple_range(void); 41. staticfn boolean can_grapple_location(coordxy, coordxy); 42. staticfn void display_grapple_positions(boolean); 43. staticfn int use_grapple(struct obj *); 44. staticfn void discard_broken_wand(void); 45. staticfn void broken_wand_explode(struct obj *, int, int); 46. staticfn int do_break_wand(struct obj *); 47. staticfn int apply_ok(struct obj *); 48. staticfn int flip_through_book(struct obj *); 49. staticfn int flip_coin(struct obj *); 50. staticfn boolean figurine_location_checks(struct obj *, coord *, boolean); 51. staticfn boolean check_jump(genericptr_t, coordxy, coordxy); 52. staticfn boolean is_valid_jump_pos(coordxy, coordxy, int, boolean); 53. staticfn boolean get_valid_jump_position(coordxy, coordxy); 54. staticfn boolean get_valid_polearm_position(coordxy, coordxy); 55. staticfn boolean find_poleable_mon(coord *); 56. 57. static const char 58. no_elbow_room[] = "don't have enough elbow-room to maneuver."; 59. 60. void 61. do_blinding_ray(struct obj *obj) 62. { 63. struct monst *mtmp = bhit(u.dx, u.dy, COLNO, FLASHED_LIGHT, 64. (int (*) (MONST_P, OBJ_P)) 0, 65. (int (*) (OBJ_P, OBJ_P)) 0, &obj); 66. 67. obj->ox = u.ux, obj->oy = u.uy; /* flash_hits_mon() wants this */ 68. if (mtmp) { 69. (void) flash_hits_mon(mtmp, obj); 70. if (obj->otyp == EXPENSIVE_CAMERA) 71. see_monster_closeup(mtmp, TRUE); /* TRUE for photo */ 72. } 73. /* normally bhit() would do this but for FLASHED_LIGHT we want it 74. to be deferred until after flash_hits_mon() */ 75. transient_light_cleanup(); 76. } 77. 78. staticfn int 79. use_camera(struct obj *obj) 80. { 81. if (Underwater) { 82. pline("Using your camera underwater would void the warranty."); 83. return ECMD_OK; 84. } 85. if (!getdir((char *) 0)) 86. return ECMD_CANCEL; 87. 88. if (obj->spe <= 0) { 89. pline1(nothing_happens); 90. return ECMD_TIME; 91. } 92. consume_obj_charge(obj, TRUE); 93. 94. if (obj->cursed && !rn2(2)) { 95. (void) zapyourself(obj, TRUE); 96. } else if (u.uswallow) { 97. You("take a picture of %s %s.", s_suffix(mon_nam(u.ustuck)), 98. mbodypart(u.ustuck, STOMACH)); 99. } else if (u.dz) { 100. You("take a picture of the %s.", 101. (u.dz > 0) ? surface(u.ux, u.uy) : ceiling(u.ux, u.uy)); 102. } else if (!u.dx && !u.dy) { 103. /* TODO: we ought to have a "selfie" joke here... */ 104. (void) zapyourself(obj, TRUE); 105. } else { 106. do_blinding_ray(obj); 107. } 108. return ECMD_TIME; 109. } 110. 111. staticfn int 112. use_towel(struct obj *obj) 113. { 114. boolean drying_feedback = (obj == uwep); 115. 116. if (!freehand()) { 117. You("have no free %s!", body_part(HAND)); 118. return ECMD_OK; 119. } else if (obj == ublindf) { 120. You("cannot use it while you're wearing it!"); 121. return ECMD_OK; 122. } else if (obj->cursed) { 123. long old; 124. 125. switch (rn2(3)) { 126. case 2: 127. old = (Glib & TIMEOUT); 128. make_glib((int) old + rn1(10, 3)); /* + 3..12 */ 129. Your("%s %s!", makeplural(body_part(HAND)), 130. (old ? "are filthier than ever" : "get slimy")); 131. if (is_wet_towel(obj)) 132. dry_a_towel(obj, -1, drying_feedback); 133. return ECMD_TIME; 134. case 1: 135. if (!ublindf) { 136. old = u.ucreamed; 137. u.ucreamed += rn1(10, 3); 138. pline("Yecch! Your %s %s gunk on it!", body_part(FACE), 139. (old ? "has more" : "now has")); 140. make_blinded(BlindedTimeout + (long) u.ucreamed - old, TRUE); 141. } else { 142. const char *what; 143. 144. what = (ublindf->otyp == LENSES) 145. ? "lenses" 146. : (obj->otyp == ublindf->otyp) ? "other towel" 147. : "blindfold"; 148. if (ublindf->cursed) { 149. You("push your %s %s.", what, 150. rn2(2) ? "cock-eyed" : "crooked"); 151. } else { 152. struct obj *saved_ublindf = ublindf; 153. You("push your %s off.", what); 154. Blindf_off(ublindf); 155. dropx(saved_ublindf); 156. } 157. } 158. if (is_wet_towel(obj)) 159. dry_a_towel(obj, -1, drying_feedback); 160. return ECMD_TIME; 161. case 0: 162. break; 163. } 164. } 165. 166. if (Glib) { 167. make_glib(0); 168. You("wipe off your %s.", 169. !uarmg ? makeplural(body_part(HAND)) : gloves_simple_name(uarmg)); 170. if (is_wet_towel(obj)) 171. dry_a_towel(obj, -1, drying_feedback); 172. return ECMD_TIME; 173. } else if (u.ucreamed) { 174. incr_itimeout(&HBlinded, (-1 * (int) u.ucreamed)); 175. u.ucreamed = 0; 176. if (!Blinded) { 177. pline("You've got the glop off."); 178. if (!gulp_blnd_check()) { 179. set_itimeout(&HBlinded, 1L); 180. make_blinded(0L, TRUE); 181. } 182. } else { 183. Your("%s feels clean now.", body_part(FACE)); 184. } 185. if (is_wet_towel(obj)) 186. dry_a_towel(obj, -1, drying_feedback); 187. return ECMD_TIME; 188. } 189. 190. Your("%s and %s are already clean.", body_part(FACE), 191. makeplural(body_part(HAND))); 192. 193. return ECMD_OK; 194. } 195. 196. /* maybe give a stethoscope message based on floor objects */ 197. staticfn boolean 198. its_dead(coordxy rx, coordxy ry, int *resp) 199. { 200. char buf[BUFSZ]; 201. boolean more_corpses; 202. struct permonst *mptr; 203. struct obj *corpse = sobj_at(CORPSE, rx, ry), 204. *statue = sobj_at(STATUE, rx, ry); 205. 206. if (!can_reach_floor(TRUE)) { /* levitation or unskilled riding */ 207. corpse = 0; /* can't reach corpse on floor */ 208. /* you can't reach tiny statues (even though you can fight 209. tiny monsters while levitating--consistency, what's that?) */ 210. while (statue && mons[statue->corpsenm].msize == MZ_TINY) 211. statue = nxtobj(statue, STATUE, TRUE); 212. } 213. /* when both corpse and statue are present, pick the uppermost one */ 214. if (corpse && statue) { 215. if (nxtobj(statue, CORPSE, TRUE) == corpse) 216. corpse = 0; /* corpse follows statue; ignore it */ 217. else 218. statue = 0; /* corpse precedes statue; ignore statue */ 219. } 220. more_corpses = (corpse && nxtobj(corpse, CORPSE, TRUE)); 221. 222. /* additional stethoscope messages from jyoung@apanix.apana.org.au */ 223. if (!corpse && !statue) { 224. ; /* nothing to do */ 225. 226. } else if (Hallucination) { 227. if (!corpse) { 228. /* it's a statue */ 229. Strcpy(buf, "You're both stoned"); 230. } else if (corpse->quan == 1L && !more_corpses) { 231. int gndr = 2; /* neuter: "it" */ 232. struct monst *mtmp = get_mtraits(corpse, FALSE); 233. 234. /* (most corpses don't retain the monster's sex, so 235. we're usually forced to use generic pronoun here) */ 236. if (mtmp) { 237. mtmp->data = &mons[mtmp->mnum]; 238. gndr = pronoun_gender(mtmp, PRONOUN_NO_IT); 239. } else { 240. mptr = &mons[corpse->corpsenm]; 241. if (is_female(mptr)) 242. gndr = 1; 243. else if (is_male(mptr)) 244. gndr = 0; 245. } 246. Sprintf(buf, "%s's dead", genders[gndr].he); /* "he"/"she"/"it" */ 247. buf[0] = highc(buf[0]); 248. } else { /* plural */ 249. Strcpy(buf, "They're dead"); 250. } 251. /* variations on "He's dead, Jim." (Star Trek's Dr McCoy) */ 252. You_hear("a voice say, \"%s, Jim.\"", buf); 253. *resp = ECMD_TIME; 254. return TRUE; 255. 256. } else if (corpse) { 257. boolean here = u_at(rx, ry), 258. one = (corpse->quan == 1L && !more_corpses), reviver = FALSE; 259. int visglyph, corpseglyph; 260. 261. visglyph = glyph_at(rx, ry); 262. corpseglyph = obj_to_glyph(corpse, rn2); 263. 264. if (Blind && (visglyph != corpseglyph)) 265. map_object(corpse, TRUE); 266. 267. if (Role_if(PM_HEALER)) { 268. /* ok to reset `corpse' here; we're done with it */ 269. do { 270. if (obj_has_timer(corpse, REVIVE_MON)) 271. reviver = TRUE; 272. else 273. corpse = nxtobj(corpse, CORPSE, TRUE); 274. } while (corpse && !reviver); 275. } 276. You("determine that %s unfortunate being%s %s%s dead.", 277. one ? (here ? "this" : "that") : (here ? "these" : "those"), 278. one ? "" : "s", one ? "is" : "are", reviver ? " mostly" : ""); 279. return TRUE; 280. 281. } else { /* statue */ 282. const char *what, *how; 283. 284. mptr = &mons[statue->corpsenm]; 285. if (Blind) { /* ignore statue->dknown; it'll always be set */ 286. Sprintf(buf, "%s %s", 287. u_at(rx, ry) ? "This" : "That", 288. humanoid(mptr) ? "person" : "creature"); 289. what = buf; 290. } else { 291. what = obj_pmname(statue); 292. if (!type_is_pname(mptr)) 293. what = The(what); 294. } 295. how = "fine"; 296. if (Role_if(PM_HEALER)) { 297. struct trap *ttmp = t_at(rx, ry); 298. 299. if (ttmp && ttmp->ttyp == STATUE_TRAP) 300. how = "extraordinary"; 301. else if (Has_contents(statue)) 302. how = "remarkable"; 303. } 304. 305. pline("%s is in %s health for a statue.", what, how); 306. return TRUE; 307. } 308. return FALSE; /* no corpse or statue */ 309. } 310. 311. static const char hollow_str[] = "a hollow sound. This must be a secret %s!"; 312. 313. /* Strictly speaking it makes no sense for usage of a stethoscope to 314. not take any time; however, unless it did, the stethoscope would be 315. almost useless. As a compromise, one use per turn is free, another 316. uses up the turn; this makes curse status have a tangible effect. */ 317. staticfn int 318. use_stethoscope(struct obj *obj) 319. { 320. struct monst *mtmp; 321. struct rm *lev; 322. int res; 323. coordxy rx, ry; 324. boolean interference = (u.uswallow && is_whirly(u.ustuck->data) 325. && !rn2(Role_if(PM_HEALER) ? 10 : 3)); 326. 327. if (nohands(gy.youmonst.data)) { 328. You("have no hands!"); /* not `body_part(HAND)' */ 329. return ECMD_OK; 330. } else if (Deaf) { 331. You_cant("hear anything!"); 332. return ECMD_OK; 333. } else if (!freehand()) { 334. You("have no free %s.", body_part(HAND)); 335. return ECMD_OK; 336. } 337. if (!getdir((char *) 0)) 338. return ECMD_CANCEL; 339. 340. res = (gh.hero_seq == svc.context.stethoscope_seq) ? ECMD_TIME : ECMD_OK; 341. svc.context.stethoscope_seq = gh.hero_seq; 342. 343. gb.bhitpos.x = u.ux, gb.bhitpos.y = u.uy; /* tentative, reset below */ 344. gn.notonhead = u.uswallow; 345. if (u.usteed && u.dz > 0) { 346. if (interference) { 347. pline("%s interferes.", Monnam(u.ustuck)); 348. mstatusline(u.ustuck); 349. } else 350. mstatusline(u.usteed); 351. return res; 352. } else if (u.uswallow && (u.dx || u.dy || u.dz)) { 353. mstatusline(u.ustuck); 354. return res; 355. } else if (u.uswallow && interference) { 356. pline("%s interferes.", Monnam(u.ustuck)); 357. mstatusline(u.ustuck); 358. return res; 359. } else if (u.dz) { 360. if (Underwater) { 361. Soundeffect(se_faint_splashing, 35); 362. You_hear("faint splashing."); 363. } else if (u.dz < 0 || !can_reach_floor(TRUE)) { 364. cant_reach_floor(u.ux, u.uy, (u.dz < 0), TRUE, FALSE); 365. } else if (its_dead(u.ux, u.uy, &res)) { 366. ; /* message already given */ 367. } else if (Is_stronghold(&u.uz)) { 368. Soundeffect(se_crackling_of_hellfire, 35); 369. You_hear("the crackling of hellfire."); 370. } else { 371. pline_The("%s seems healthy enough.", surface(u.ux, u.uy)); 372. } 373. return res; 374. } else if (obj->cursed && !rn2(2)) { 375. Soundeffect(se_heart_beat, 100); 376. You_hear("your heart beat."); 377. return res; 378. } 379. confdir(FALSE); 380. if (!u.dx && !u.dy) { 381. ustatusline(); 382. return res; 383. } 384. rx = u.ux + u.dx; 385. ry = u.uy + u.dy; 386. if (!isok(rx, ry)) { 387. Soundeffect(se_typing_noise, 100); 388. You_hear("a faint typing noise."); 389. return ECMD_OK; 390. } 391. if ((mtmp = m_at(rx, ry)) != 0) { 392. const char *mnm = x_monnam(mtmp, ARTICLE_A, (const char *) 0, 393. SUPPRESS_IT | SUPPRESS_INVISIBLE, FALSE); 394. 395. /* gb.bhitpos needed by mstatusline() iff mtmp is a long worm */ 396. gb.bhitpos.x = rx, gb.bhitpos.y = ry; 397. gn.notonhead = (mtmp->mx != rx || mtmp->my != ry); 398. 399. if (mtmp->mundetected) { 400. if (!canspotmon(mtmp)) 401. There("is %s hidden there.", mnm); 402. mtmp->mundetected = 0; 403. newsym(mtmp->mx, mtmp->my); 404. } else if (mtmp->mappearance) { 405. const char *what = "thing"; 406. boolean use_plural = FALSE; 407. struct obj dummyobj, *odummy; 408. 409. switch (M_AP_TYPE(mtmp)) { 410. case M_AP_OBJECT: 411. /* FIXME? 412. * we should probably be using object_from_map() here 413. */ 414. odummy = init_dummyobj(&dummyobj, mtmp->mappearance, 1L); 415. /* simple_typename() yields "fruit" for any named fruit; 416. we want the same thing '//' or ';' shows: "slime mold" 417. or "grape" or "slice of pizza" */ 418. if (odummy->otyp == SLIME_MOLD && has_mcorpsenm(mtmp)) { 419. odummy->spe = MCORPSENM(mtmp); 420. what = simpleonames(odummy); 421. } else { 422. what = simple_typename(odummy->otyp); 423. } 424. use_plural = (is_boots(odummy) || is_gloves(odummy) 425. || odummy->otyp == LENSES); 426. break; 427. case M_AP_MONSTER: /* ignore Hallucination here */ 428. what = pmname(&mons[mtmp->mappearance], Mgender(mtmp)); 429. break; 430. case M_AP_FURNITURE: 431. what = defsyms[mtmp->mappearance].explanation; 432. break; 433. } 434. seemimic(mtmp); 435. pline("%s %s %s really %s.", 436. use_plural ? "Those" : "That", what, 437. use_plural ? "are" : "is", mnm); 438. } else if (flags.verbose && !canspotmon(mtmp)) { 439. There("is %s there.", mnm); 440. } 441. 442. mstatusline(mtmp); 443. if (!canspotmon(mtmp)) 444. map_invisible(rx, ry); 445. return res; 446. } 447. if (unmap_invisible(rx,ry)) 448. pline_The("invisible monster must have moved."); 449. 450. lev = &levl[rx][ry]; 451. switch (lev->typ) { 452. case SDOOR: 453. Soundeffect(se_hollow_sound, 100); 454. You_hear(hollow_str, "door"); 455. cvt_sdoor_to_door(lev); /* ->typ = DOOR */ 456. recalc_block_point(rx, ry); 457. feel_newsym(rx, ry); 458. return res; 459. case SCORR: 460. You_hear(hollow_str, "passage"); 461. lev->typ = CORR, lev->flags = 0; 462. unblock_point(rx, ry); 463. feel_newsym(rx, ry); 464. return res; 465. } 466. 467. if (!its_dead(rx, ry, &res)) 468. You("hear nothing special."); /* not You_hear() */ 469. return res; 470. } 471. 472. static const char whistle_str[] = "produce a %s whistling sound.", 473. alt_whistle_str[] = "produce a %s, sharp vibration."; 474. 475. staticfn void 476. use_whistle(struct obj *obj) 477. { 478. if (!can_blow(&gy.youmonst)) { 479. You("are incapable of using the whistle."); 480. } else if (Underwater) { 481. You("blow bubbles through %s.", yname(obj)); 482. } else { 483. if (Deaf) 484. You_feel("rushing air tickle your %s.", body_part(NOSE)); 485. else 486. You(whistle_str, obj->cursed ? "shrill" : "high"); 487. Soundeffect(se_shrill_whistle, 50); 488. wake_nearby(TRUE); 489. if (obj->cursed) 490. vault_summon_gd(); 491. } 492. } 493. 494. staticfn void 495. use_magic_whistle(struct obj *obj) 496. { 497. if (!can_blow(&gy.youmonst)) { 498. You("are incapable of using the whistle."); 499. } else if (obj->cursed && !rn2(2)) { 500. You("produce a %shigh-%s.", Underwater ? "very " : "", 501. Deaf ? "frequency vibration" : "pitched humming noise"); 502. wake_nearby(TRUE); 503. if (!rn2(2) && !noteleport_level(&gy.youmonst)) 504. tele_to_rnd_pet(); 505. } else { 506. /* it's magic! it works underwater too (at a higher pitch) */ 507. You(Deaf ? alt_whistle_str : whistle_str, 508. Hallucination ? "normal" 509. : (Underwater && !Deaf) ? "strange, high-pitched" 510. : "strange"); 511. Soundeffect(se_shrill_whistle, 80); 512. magic_whistled(obj); 513. } 514. } 515. 516. /* 'obj' is assumed to be a magic whistle */ 517. staticfn void 518. magic_whistled(struct obj *obj) 519. { 520. struct monst *mtmp, *nextmon; 521. char buf[BUFSZ], *mnam = 0, 522. shiftbuf[BUFSZ + sizeof "shifts location"], 523. appearbuf[BUFSZ + sizeof "appears"], 524. disappearbuf[BUFSZ + sizeof "disappears"]; 525. boolean oseen, nseen, 526. already_discovered = objects[obj->otyp].oc_name_known != 0; 527. int omx, omy, shift = 0, appear = 0, disappear = 0, trapped = 0; 528. 529. /* stasis prevents magic-whistling */ 530. if (svl.level.flags.stasis_until >= svm.moves) 531. return; 532. 533. /* need to copy (up to 3) names as they're collected rather than just 534. save pointers to them, otherwise churning through every mbuf[] might 535. clobber the ones we care about */ 536. shiftbuf[0] = appearbuf[0] = disappearbuf[0] = '\0'; 537. 538. for (mtmp = fmon; mtmp; mtmp = nextmon) { 539. nextmon = mtmp->nmon; /* trap might kill mon */ 540. if (DEADMONSTER(mtmp)) 541. continue; 542. /* only tame monsters are affected; 543. steed is already at your location, so not affected; 544. this avoids trap issues if you're on a trap location */ 545. if (!mtmp->mtame || mtmp == u.usteed) 546. continue; 547. if (mtmp->mtrapped) { 548. /* no longer in previous trap (affects mintrap) */ 549. mtmp->mtrapped = 0; 550. fill_pit(mtmp->mx, mtmp->my); 551. } 552. 553. oseen = canspotmon(mtmp); /* old 'seen' status */ 554. if (oseen) /* get name in case it's one we'll remember */ 555. mnam = y_monnam(mtmp); /* before mnexto(); it might disappear */ 556. /* mimic must be revealed before we know whether it 557. actually moves because line-of-sight may change */ 558. if (M_AP_TYPE(mtmp)) 559. seemimic(mtmp); 560. omx = mtmp->mx, omy = mtmp->my; 561. mnexto(mtmp, !already_discovered ? RLOC_MSG : RLOC_NONE); 562. 563. if (mtmp->mx != omx || mtmp->my != omy) { 564. if (mtmp->mundetected) { /* reveal non-mimic hider that moved */ 565. mtmp->mundetected = 0; 566. newsym(mtmp->mx, mtmp->my); 567. } 568. /* 569. * FIXME: 570. * All relocated monsters should change positions essentially 571. * simultaneously but we're dealing with them sequentially. 572. * That could kill some off in the process, each time leaving 573. * their target position (which should be occupied at least 574. * momentarily) available as a potential death trap for others. 575. * 576. * Also, teleporting onto a trap introduces message sequencing 577. * issues. We try to avoid the most obvious non sequiturs by 578. * checking whether pline() got called during mintrap(). 579. * iflags.last_msg will be changed from the value we set here 580. * to PLNMSG_UNKNOWN in that situation. 581. */ 582. iflags.last_msg = PLNMSG_enum; /* not a specific message */ 583. if (mintrap(mtmp, NO_TRAP_FLAGS) == Trap_Killed_Mon) 584. change_luck(-1); 585. if (iflags.last_msg != PLNMSG_enum) { 586. ++trapped; 587. continue; 588. } 589. /* dying while seen would have issued a message and not get here; 590. being sent to an unseen location and dying there should be 591. included in the disappeared case */ 592. nseen = DEADMONSTER(mtmp) ? FALSE : canspotmon(mtmp); 593. 594. if (nseen) { 595. mnam = y_monnam(mtmp); 596. if (oseen) { 597. if (++shift == 1) 598. Sprintf(shiftbuf, "%s shifts location", mnam); 599. } else { 600. if (++appear == 1) 601. Sprintf(appearbuf, "%s appears", mnam); 602. } 603. } else if (oseen) { 604. if (++disappear == 1) 605. Sprintf(disappearbuf, "%s disappears", mnam); 606. } 607. } 608. } 609. 610. /* 611. * If any pets changed location, (1) they might have been in view 612. * before and still in view after, (2) out of view before but in 613. * view after, (3) in view before but out of view after (perhaps 614. * on the far side of a boulder/door/wall), or (4) out of view 615. * before and still out of view after. The first two cases are 616. * the usual ones; the fourth will happen if the hero can't see. 617. * 618. * If the magic whistle hasn't been discovered yet, rloc() issued 619. * any applicable vanishing and/or appearing messages, and we make 620. * it become discovered now if any pets moved within or into view. 621. * If it has already been discovered, we told rloc() not to issue 622. * messages and will issue one cumulative message now (for any of 623. * the first three cases, not the fourth) to reduce verbosity for 624. * the first case of a single pet (avoid "vanishes and reappears") 625. * and greatly reduce verbosity for multiple pets regardless of 626. * each one's case. 627. */ 628. buf[0] = '\0'; 629. if (!already_discovered) { 630. /* message(s) were handled by rloc(); if only noticeable change was 631. pet(s) disappearing, the magic whistle won't become discovered */ 632. if (shift + appear + trapped > 0) 633. makeknown(obj->otyp); 634. } else { 635. /* could use array of cardinal number names like wishcmdassist() but 636. extra precision above 3 or 4 seems pedantic; not used for 0 or 1 */ 637. #define HowMany(n) (((n) < 2) ? "sqrt(-1)" \ 638. : ((n) == 2) ? "two" \ 639. : ((n) == 3) ? "three" \ 640. : ((n) == 4) ? "four" \ 641. : ((n) <= 7) ? "several" \ 642. : "many") 643. /* magic whistle is already discovered so rloc() message(s) 644. were suppressed above; if any discernible relocation occurred, 645. construct a message now and issue it below */ 646. if (shift > 0) { 647. if (shift > 1) 648. Sprintf(shiftbuf, "%s creatures shift locations", 649. HowMany(shift)); 650. copynchars(buf, upstart(shiftbuf), (int) sizeof buf - 1); 651. } 652. if (appear > 0) { 653. if (appear > 1) 654. /* shift==0: N creatures appear; 655. shift==1: Foo shifts location and N other creatures appear; 656. shift >1: M creatures shift locations and N others appear */ 657. Sprintf(appearbuf, "%s %s appear", HowMany(appear), 658. (shift == 0) ? "creatures" 659. : (shift == 1) ? "other creatures" 660. : "others"); 661. if (shift == 0) 662. copynchars(buf, upstart(appearbuf), (int) sizeof buf - 1); 663. else 664. Snprintf(eos(buf), sizeof buf - strlen(buf), "%s %s", 665. /* to get here: appear > 0 and shift != 0, 666. so "shifters, appearers" if disappear != 0 667. with ", and disappearers" yet to be appended, 668. or "shifters and appearers" otherwise */ 669. disappear ? "," : " and", appearbuf); 670. } 671. if (disappear > 0) { 672. if (disappear > 1) 673. Sprintf(disappearbuf, "%s %s disappear", HowMany(disappear), 674. (shift == 0 && appear == 0) ? "creatures" 675. : (shift < 2 && appear < 2) ? "other creatures" 676. : "others"); 677. if (shift + appear == 0) 678. copynchars(buf, upstart(disappearbuf), (int) sizeof buf - 1); 679. else 680. Snprintf(eos(buf), sizeof buf - strlen(buf), "%s and %s", 681. (shift && appear) ? "," : "", disappearbuf); 682. } 683. } 684. if (*buf) 685. pline("%s.", buf); 686. return; 687. } 688. 689. #undef HowMany 690. 691. boolean 692. um_dist(coordxy x, coordxy y, xint16 n) 693. { 694. return (boolean) (abs(u.ux - x) > n || abs(u.uy - y) > n); 695. } 696. 697. int 698. number_leashed(void) 699. { 700. int i = 0; 701. struct obj *obj; 702. 703. for (obj = gi.invent; obj; obj = obj->nobj) 704. if (obj->otyp == LEASH && obj->leashmon != 0) 705. i++; 706. return i; 707. } 708. 709. /* otmp is about to be destroyed or stolen */ 710. void 711. o_unleash(struct obj *otmp) 712. { 713. struct monst *mtmp; 714. 715. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) 716. if (mtmp->m_id == (unsigned) otmp->leashmon) { 717. mtmp->mleashed = 0; 718. break; 719. } 720. otmp->leashmon = 0; 721. update_inventory(); 722. } 723. 724. /* mtmp is about to die, or become untame */ 725. void 726. m_unleash(struct monst *mtmp, boolean feedback) 727. { 728. struct obj *otmp; 729. 730. if (feedback) { 731. if (canseemon(mtmp)) 732. pline_mon(mtmp, "%s pulls free of %s leash!", 733. Monnam(mtmp), mhis(mtmp)); 734. else 735. Your("leash falls slack."); 736. } 737. if ((otmp = get_mleash(mtmp)) != 0) { 738. otmp->leashmon = 0; 739. update_inventory(); 740. } 741. mtmp->mleashed = 0; 742. } 743. 744. /* player is about to die (for bones) */ 745. void 746. unleash_all(void) 747. { 748. struct obj *otmp; 749. struct monst *mtmp; 750. 751. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 752. if (otmp->otyp == LEASH) 753. otmp->leashmon = 0; 754. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) 755. mtmp->mleashed = 0; 756. } 757. 758. #define MAXLEASHED 2 759. 760. boolean 761. leashable(struct monst *mtmp) 762. { 763. return (boolean) (mtmp->mnum != PM_LONG_WORM 764. && !unsolid(mtmp->data) 765. && (!nolimbs(mtmp->data) || has_head(mtmp->data))); 766. } 767. 768. staticfn int 769. use_leash(struct obj *obj) 770. { 771. coord cc; 772. struct monst *mtmp; 773. 774. if (u.uswallow) { 775. /* if the leash isn't in use, assume we're trying to leash 776. the engulfer; if it is use, distinguish between removing 777. it from the engulfer versus from some other creature 778. (note: the two in-use cases can't actually occur; all 779. leashes are released when the hero gets engulfed) */ 780. You_cant((!obj->leashmon 781. ? "leash %s from inside." 782. : (obj->leashmon == (int) u.ustuck->m_id) 783. ? "unleash %s from inside." 784. : "unleash anything from inside %s."), 785. noit_mon_nam(u.ustuck)); 786. return ECMD_OK; 787. } 788. if (!obj->leashmon && number_leashed() >= MAXLEASHED) { 789. You("cannot leash any more pets."); 790. return ECMD_OK; 791. } 792. 793. if (!get_adjacent_loc((char *) 0, (char *) 0, u.ux, u.uy, &cc)) 794. return ECMD_OK; 795. 796. if (u_at(cc.x, cc.y)) { 797. if (u.usteed && u.dz > 0) { 798. mtmp = u.usteed; 799. use_leash_core(obj, mtmp, &cc, 1); 800. return ECMD_TIME; 801. } 802. pline("Leash yourself? Very funny..."); 803. return ECMD_OK; 804. } 805. 806. /* 807. * From here on out, return value is 1 == a move is used. 808. */ 809. 810. if (!(mtmp = m_at(cc.x, cc.y))) { 811. There("is no creature there."); 812. (void) unmap_invisible(cc.x, cc.y); 813. return ECMD_TIME; 814. } 815. 816. use_leash_core(obj, mtmp, &cc, canspotmon(mtmp)); 817. return ECMD_TIME; 818. } 819. 820. staticfn void 821. use_leash_core(struct obj *obj, struct monst *mtmp, coord *cc, int spotmon) 822. { 823. if (!spotmon && !glyph_is_invisible(levl[cc->x][cc->y].glyph)) { 824. /* for the unleash case, we don't verify whether this unseen 825. monster is the creature attached to the current leash */ 826. You("fail to %sleash something.", obj->leashmon ? "un" : ""); 827. /* trying again will work provided the monster is tame 828. (and also that it doesn't change location by retry time) */ 829. map_invisible(cc->x, cc->y); 830. } else if (!mtmp->mtame) { 831. pline("%s %s leashed!", Monnam(mtmp), 832. (!obj->leashmon) ? "cannot be" : "is not"); 833. } else if (!obj->leashmon) { 834. /* applying a leash which isn't currently in use */ 835. if (mtmp->mleashed) { 836. pline("This %s is already leashed.", 837. spotmon ? l_monnam(mtmp) : "creature"); 838. } else if (unsolid(mtmp->data)) { 839. pline("The leash would just fall off."); 840. } else if (nolimbs(mtmp->data) && !has_head(mtmp->data)) { 841. pline("%s has no extremities the leash would fit.", 842. Monnam(mtmp)); 843. } else if (!leashable(mtmp)) { 844. char lmonbuf[BUFSZ]; 845. char *lmonnam = l_monnam(mtmp); 846. 847. if (cc->x != mtmp->mx || cc->y != mtmp->my) { 848. Sprintf(lmonbuf, "%s tail", s_suffix(lmonnam)); 849. lmonnam = lmonbuf; 850. } 851. pline("The leash won't fit onto %s%s.", spotmon ? "your " : "", 852. lmonnam); 853. } else { 854. You("slip the leash around %s%s.", spotmon ? "your " : "", 855. l_monnam(mtmp)); 856. mtmp->mleashed = 1; 857. obj->leashmon = (int) mtmp->m_id; 858. mtmp->msleeping = 0; 859. update_inventory(); 860. } 861. } else { 862. /* applying a leash which is currently in use */ 863. if (obj->leashmon != (int) mtmp->m_id) { 864. pline("This leash is not attached to that creature."); 865. } else if (obj->cursed) { 866. pline_The("leash would not come off!"); 867. set_bknown(obj, 1); 868. } else { 869. mtmp->mleashed = 0; 870. obj->leashmon = 0; 871. update_inventory(); 872. You("remove the leash from %s%s.", 873. spotmon ? "your " : "", l_monnam(mtmp)); 874. } 875. } 876. } 877. 878. /* assuming mtmp->mleashed has been checked */ 879. struct obj * 880. get_mleash(struct monst *mtmp) 881. { 882. struct obj *otmp; 883. 884. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 885. if (otmp->otyp == LEASH && (unsigned) otmp->leashmon == mtmp->m_id) 886. break; 887. return otmp; 888. } 889. 890. staticfn boolean 891. mleashed_next2u(struct monst *mtmp) 892. { 893. if (mtmp->mleashed) { 894. if (!m_next2u(mtmp)) 895. mnexto(mtmp, RLOC_NOMSG); 896. if (!m_next2u(mtmp)) { 897. struct obj *otmp = get_mleash(mtmp); 898. 899. if (!otmp) { 900. impossible("leashed-unleashed mon?"); 901. return TRUE; 902. } 903. 904. if (otmp->cursed) 905. return TRUE; 906. mtmp->mleashed = 0; 907. otmp->leashmon = 0; 908. update_inventory(); 909. You_feel("%s leash go slack.", 910. (number_leashed() > 1) ? "a" : "the"); 911. } 912. } 913. return FALSE; 914. } 915. 916. #undef MAXLEASHED 917. 918. boolean 919. next_to_u(void) 920. { 921. if (get_iter_mons(mleashed_next2u)) 922. return FALSE; 923. 924. /* no pack mules for the Amulet */ 925. if (u.usteed && mon_has_amulet(u.usteed)) 926. return FALSE; 927. return TRUE; 928. } 929. 930. void 931. check_leash(coordxy x, coordxy y) 932. { 933. struct obj *otmp; 934. struct monst *mtmp; 935. 936. for (otmp = gi.invent; otmp; otmp = otmp->nobj) { 937. if (otmp->otyp != LEASH || otmp->leashmon == 0) 938. continue; 939. mtmp = find_mid(otmp->leashmon, FM_FMON); 940. if (!mtmp) { 941. impossible("leash in use isn't attached to anything?"); 942. otmp->leashmon = 0; 943. continue; 944. } 945. if (dist2(u.ux, u.uy, mtmp->mx, mtmp->my) 946. > dist2(x, y, mtmp->mx, mtmp->my)) { 947. if (!um_dist(mtmp->mx, mtmp->my, 3)) { 948. ; /* still close enough */ 949. } else if (otmp->cursed && !breathless(mtmp->data)) { 950. if (um_dist(mtmp->mx, mtmp->my, 5) 951. || (mtmp->mhp -= rnd(2)) <= 0) { 952. long save_pacifism = u.uconduct.killer; 953. 954. Your("leash chokes %s to death!", mon_nam(mtmp)); 955. /* hero might not have intended to kill pet, but 956. that's the result of his actions; gain experience, 957. lose pacifism, take alignment and luck hit, make 958. corpse less likely to remain tame after revival */ 959. xkilled(mtmp, XKILL_NOMSG); 960. /* life-saving doesn't ordinarily reset this */ 961. if (!DEADMONSTER(mtmp)) 962. u.uconduct.killer = save_pacifism; 963. } else { 964. pline_mon(mtmp, "%s is choked by the leash!", 965. Monnam(mtmp)); 966. /* tameness eventually drops to 1 here (never 0) */ 967. if (mtmp->mtame && rn2(mtmp->mtame)) 968. mtmp->mtame--; 969. } 970. } else { 971. if (um_dist(mtmp->mx, mtmp->my, 5)) { 972. pline("%s leash snaps loose!", s_suffix(Monnam(mtmp))); 973. m_unleash(mtmp, FALSE); 974. } else { 975. You("pull on the leash."); 976. if (mtmp->data->msound != MS_SILENT) 977. switch (rn2(3)) { 978. case 0: 979. growl(mtmp); 980. break; 981. case 1: 982. yelp(mtmp); 983. break; 984. default: 985. whimper(mtmp); 986. break; 987. } 988. } 989. } 990. } 991. } 992. } 993. 994. /* charisma is supposed to include qualities like leadership and personal 995. magnetism rather than just appearance, but it has devolved to this... */ 996. const char * 997. beautiful(void) 998. { 999. const char *res; 1000. int cha = ACURR(A_CHA); 1001. 1002. /* don't bother complaining about the sexism; NetHack is not real life */ 1003. res = ((cha >= 25) ? "sublime" /* 25 is the maximum possible */ 1004. : (cha >= 19) ? "splendorous" /* note: not "splendiferous" */ 1005. : (cha >= 16) ? ((poly_gender() == 1) ? "beautiful" : "handsome") 1006. : (cha >= 14) ? ((poly_gender() == 1) ? "winsome" : "amiable") 1007. : (cha >= 11) ? "cute" 1008. : (cha >= 9) ? "plain" 1009. : (cha >= 6) ? "homely" 1010. : (cha >= 4) ? "ugly" 1011. : "hideous"); /* 3 is the minimum possible */ 1012. return res; 1013. } 1014. 1015. static const char look_str[] = "look %s."; 1016. 1017. staticfn int 1018. use_mirror(struct obj *obj) 1019. { 1020. const char *mirror, *uvisage; 1021. struct monst *mtmp; 1022. unsigned how_seen; 1023. char mlet; 1024. boolean vis, invis_mirror, useeit, monable; 1025. 1026. if (!getdir((char *) 0)) 1027. return ECMD_CANCEL; 1028. invis_mirror = Invis; 1029. useeit = !Blind && (!invis_mirror || See_invisible); 1030. uvisage = beautiful(); 1031. mirror = simpleonames(obj); /* "mirror" or "looking glass" */ 1032. if (obj->cursed && !rn2(2)) { 1033. if (!Blind) 1034. pline_The("%s fogs up and doesn't reflect!", mirror); 1035. else 1036. pline("%s", nothing_seems_to_happen); 1037. return ECMD_TIME; 1038. } 1039. if (!u.dx && !u.dy && !u.dz) { 1040. if (!useeit) { 1041. You_cant("see your %s %s.", uvisage, body_part(FACE)); 1042. } else { 1043. if (u.umonnum == PM_FLOATING_EYE) { 1044. if (Free_action) { 1045. You("stiffen momentarily under your gaze."); 1046. } else { 1047. if (Hallucination) 1048. pline("Yow! The %s stares back!", mirror); 1049. else 1050. pline("Yikes! You've frozen yourself!"); 1051. if (!Hallucination || !rn2(4)) { 1052. nomul(-rnd(MAXULEV + 6 - u.ulevel)); 1053. gm.multi_reason = "gazing into a mirror"; 1054. } 1055. gn.nomovemsg = 0; /* default, "you can move again" */ 1056. } 1057. } else if (is_vampire(gy.youmonst.data) 1058. || is_vampshifter(&gy.youmonst)) { 1059. You("don't have a reflection."); 1060. } else if (u.umonnum == PM_UMBER_HULK) { 1061. pline("Huh? That doesn't look like you!"); 1062. make_confused(HConfusion + d(3, 4), FALSE); 1063. } else if (Hallucination) { 1064. You(look_str, hcolor((char *) 0)); 1065. } else if (Sick) { 1066. You(look_str, "peaked"); 1067. } else if (u.uhs >= WEAK) { 1068. You(look_str, "undernourished"); 1069. } else if (Upolyd) { 1070. You("look like %s.", an(pmname(&mons[u.umonnum], Ugender))); 1071. } else { 1072. You("look as %s as ever.", uvisage); 1073. } 1074. } 1075. return ECMD_TIME; 1076. } 1077. if (u.uswallow) { 1078. if (useeit) 1079. You("reflect %s %s.", s_suffix(mon_nam(u.ustuck)), 1080. mbodypart(u.ustuck, STOMACH)); 1081. return ECMD_TIME; 1082. } 1083. if (Underwater) { 1084. if (useeit) 1085. You("%s.", 1086. Hallucination ? "give the fish a chance to fix their makeup" 1087. : "reflect the murky water"); 1088. return ECMD_TIME; 1089. } 1090. if (u.dz) { 1091. if (useeit) 1092. You("reflect the %s.", 1093. (u.dz > 0) ? surface(u.ux, u.uy) : ceiling(u.ux, u.uy)); 1094. return ECMD_TIME; 1095. } 1096. mtmp = bhit(u.dx, u.dy, COLNO, INVIS_BEAM, 1097. (int (*) (MONST_P, OBJ_P)) 0, 1098. (int (*) (OBJ_P, OBJ_P)) 0, &obj); 1099. if (!mtmp || !haseyes(mtmp->data) || gn.notonhead) 1100. return ECMD_TIME; 1101. 1102. /* couldsee(mtmp->mx, mtmp->my) is implied by the fact that bhit() 1103. targeted it, so we can ignore possibility of X-ray vision */ 1104. vis = canseemon(mtmp); 1105. /* ways to directly see monster (excludes X-ray vision, telepathy, 1106. extended detection, type-specific warning) */ 1107. #define SEENMON (MONSEEN_NORMAL | MONSEEN_SEEINVIS | MONSEEN_INFRAVIS) 1108. how_seen = vis ? howmonseen(mtmp) : 0; 1109. /* whether monster is able to use its vision-based capabilities */ 1110. monable = !mtmp->mcan && (!mtmp->minvis || perceives(mtmp->data)); 1111. mlet = mtmp->data->mlet; 1112. if (mtmp->msleeping) { 1113. if (vis) 1114. pline("%s is too tired to look at your %s.", Monnam(mtmp), 1115. mirror); 1116. } else if (!mtmp->mcansee) { 1117. if (vis) 1118. pline("%s can't see anything right now.", Monnam(mtmp)); 1119. } else if (invis_mirror && !perceives(mtmp->data)) { 1120. if (vis) 1121. pline("%s fails to notice your %s.", Monnam(mtmp), mirror); 1122. /* infravision doesn't produce an image in the mirror */ 1123. } else if ((how_seen & SEENMON) == MONSEEN_INFRAVIS) { 1124. if (vis) /* (redundant) */ 1125. pline("%s in the dark.", 1126. monverbself(mtmp, Monnam(mtmp), "are", 1127. "too far away to see")); 1128. /* some monsters do special things */ 1129. } else if (mlet == S_VAMPIRE || mlet == S_GHOST || is_vampshifter(mtmp)) { 1130. if (vis) 1131. pline("%s doesn't have a reflection.", Monnam(mtmp)); 1132. } else if (monable && mtmp->data == &mons[PM_MEDUSA]) { 1133. if (mon_reflects(mtmp, "The gaze is reflected away by %s %s!")) 1134. return ECMD_TIME; 1135. if (vis) 1136. pline("%s is turned to stone!", Monnam(mtmp)); 1137. gs.stoned = TRUE; 1138. killed(mtmp); 1139. } else if (monable && mtmp->data == &mons[PM_FLOATING_EYE]) { 1140. int tmp = d((int) mtmp->m_lev, (int) mtmp->data->mattk[0].damd); 1141. if (!rn2(4)) 1142. tmp = 120; 1143. if (vis) 1144. pline("%s is frozen by its reflection.", Monnam(mtmp)); 1145. else 1146. You_hear("%s stop moving.", something); 1147. paralyze_monst(mtmp, (int) mtmp->mfrozen + tmp); 1148. } else if (monable && mtmp->data == &mons[PM_UMBER_HULK]) { 1149. if (vis) 1150. pline("%s confuses itself!", Monnam(mtmp)); 1151. mtmp->mconf = 1; 1152. } else if (monable && (mlet == S_NYMPH 1153. || mtmp->data == &mons[PM_AMOROUS_DEMON])) { 1154. if (vis) { 1155. char buf[BUFSZ]; /* "She" or "He" */ 1156. 1157. pline("%s in your %s.", /* "<mon> admires self in your mirror " */ 1158. monverbself(mtmp, Monnam(mtmp), "admire", (char *) 0), 1159. mirror); 1160. pline("%s takes it!", upstart(strcpy(buf, mhe(mtmp)))); 1161. } else 1162. pline("It steals your %s!", mirror); 1163. setnotworn(obj); /* in case mirror was wielded */ 1164. freeinv(obj); 1165. (void) mpickobj(mtmp, obj); 1166. if (!tele_restrict(mtmp)) 1167. (void) rloc(mtmp, RLOC_MSG); 1168. } else if (!is_unicorn(mtmp->data) && !humanoid(mtmp->data) 1169. && !is_demon(mtmp->data) 1170. && (!mtmp->minvis || perceives(mtmp->data)) && rn2(5)) { 1171. boolean do_react = TRUE; 1172. 1173. if (mtmp->mfrozen) { 1174. if (vis) 1175. You("discern no obvious reaction from %s.", mon_nam(mtmp)); 1176. else 1177. You_feel( 1178. "a bit silly gesturing the mirror in that direction."); 1179. do_react = FALSE; 1180. } 1181. if (do_react) { 1182. if (vis) 1183. pline("%s is frightened by its reflection.", Monnam(mtmp)); 1184. monflee(mtmp, d(2, 4), FALSE, FALSE); 1185. } 1186. } else if (!Blind) { 1187. if (mtmp->minvis && !See_invisible) 1188. ; 1189. else if ((mtmp->minvis && !perceives(mtmp->data)) 1190. /* redundant: can't get here if these are true */ 1191. || !haseyes(mtmp->data) || gn.notonhead || !mtmp->mcansee) 1192. pline("%s doesn't seem to notice %s reflection.", Monnam(mtmp), 1193. mhis(mtmp)); 1194. else 1195. pline("%s ignores %s reflection.", Monnam(mtmp), mhis(mtmp)); 1196. } 1197. return ECMD_TIME; 1198. #undef SEENMON 1199. } 1200. 1201. staticfn void 1202. use_bell(struct obj **optr) 1203. { 1204. struct obj *obj = *optr; 1205. struct monst *mtmp; 1206. boolean wakem = FALSE, learno = FALSE, 1207. ordinary = (obj->otyp != BELL_OF_OPENING || !obj->spe), 1208. invoking = (obj->otyp == BELL_OF_OPENING 1209. && invocation_pos(u.ux, u.uy) 1210. && !On_stairs(u.ux, u.uy)); 1211. 1212. Hero_playnotes(obj_to_instr(obj), "C", 100); 1213. You("ring %s.", the(xname(obj))); 1214. 1215. if (Underwater || (u.uswallow && ordinary)) { 1216. pline("But the sound is muffled."); 1217. 1218. } else if (invoking && ordinary) { 1219. /* needs to be recharged... */ 1220. pline("But it makes no sound."); 1221. learno = TRUE; /* help player figure out why */ 1222. 1223. } else if (ordinary) { 1224. if (obj->cursed && !rn2(4) 1225. /* note: once any of them are gone, we stop all of them */ 1226. && !(svm.mvitals[PM_WOOD_NYMPH].mvflags & G_GONE) 1227. && !(svm.mvitals[PM_WATER_NYMPH].mvflags & G_GONE) 1228. && !(svm.mvitals[PM_MOUNTAIN_NYMPH].mvflags & G_GONE) 1229. && (mtmp = makemon(mkclass(S_NYMPH, 0), u.ux, u.uy, 1230. NO_MINVENT | MM_NOMSG)) != 0) { 1231. You("summon %s!", a_monnam(mtmp)); 1232. if (!obj_resists(obj, 93, 100)) { 1233. pline("%s shattered!", Tobjnam(obj, "have")); 1234. useup(obj); 1235. *optr = 0; 1236. } else 1237. switch (rn2(3)) { 1238. default: 1239. break; 1240. case 1: 1241. mon_adjust_speed(mtmp, 2, (struct obj *) 0); 1242. break; 1243. case 2: /* no explanation; it just happens... */ 1244. gn.nomovemsg = ""; 1245. gm.multi_reason = NULL; 1246. nomul(-rnd(2)); 1247. break; 1248. } 1249. } 1250. wakem = TRUE; 1251. 1252. } else { 1253. /* charged Bell of Opening */ 1254. consume_obj_charge(obj, TRUE); 1255. 1256. if (u.uswallow) { 1257. if (!obj->cursed) 1258. (void) openit(); 1259. else 1260. pline1(nothing_happens); 1261. 1262. } else if (obj->cursed) { 1263. coord mm; 1264. 1265. mm.x = u.ux; 1266. mm.y = u.uy; 1267. mkundead(&mm, FALSE, NO_MINVENT); 1268. wakem = TRUE; 1269. 1270. } else if (invoking) { 1271. pline("%s an unsettling shrill sound...", Tobjnam(obj, "issue")); 1272. obj->age = svm.moves; 1273. learno = TRUE; 1274. wakem = TRUE; 1275. 1276. } else if (obj->blessed) { 1277. int res = 0; 1278. 1279. if (uchain) { 1280. unpunish(); 1281. res = 1; 1282. } else if (u.utrap && u.utraptype == TT_BURIEDBALL) { 1283. buried_ball_to_freedom(); 1284. res = 1; 1285. } 1286. res += openit(); 1287. switch (res) { 1288. case 0: 1289. pline1(nothing_happens); 1290. break; 1291. case 1: 1292. pline("%s opens...", Something); 1293. learno = TRUE; 1294. break; 1295. default: 1296. pline("Things open around you..."); 1297. learno = TRUE; 1298. break; 1299. } 1300. 1301. } else { /* uncursed */ 1302. if (findit() != 0) 1303. learno = TRUE; 1304. else 1305. pline1(nothing_happens); 1306. } 1307. 1308. } /* charged BofO */ 1309. 1310. if (learno) { 1311. makeknown(BELL_OF_OPENING); 1312. obj->known = 1; 1313. } 1314. if (wakem) 1315. wake_nearby(TRUE); 1316. } 1317. 1318. staticfn void 1319. use_candelabrum(struct obj *obj) 1320. { 1321. const char *s = (obj->spe != 1) ? "candles" : "candle"; 1322. 1323. if (obj->lamplit) { 1324. You("snuff the %s.", s); 1325. end_burn(obj, TRUE); 1326. return; 1327. } 1328. if (obj->spe <= 0) { 1329. struct obj *otmp; 1330. 1331. pline("This %s has no %s.", xname(obj), s); 1332. /* only output tip if candles are in inventory */ 1333. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 1334. if (Is_candle(otmp)) 1335. break; 1336. if (otmp) 1337. pline("To attach candles, apply them instead of the %s.", 1338. xname(obj)); 1339. return; 1340. } 1341. if (Underwater) { 1342. You("cannot make fire under water."); 1343. return; 1344. } 1345. if (u.uswallow || obj->cursed) { 1346. if (!Blind) 1347. pline_The("%s %s for a moment, then %s.", s, vtense(s, "flicker"), 1348. vtense(s, "die")); 1349. return; 1350. } 1351. if (obj->spe < 7) { 1352. There("%s only %d %s in %s.", vtense(s, "are"), obj->spe, s, 1353. the(xname(obj))); 1354. if (!Blind) 1355. pline("%s lit. %s dimly.", obj->spe == 1 ? "It is" : "They are", 1356. Tobjnam(obj, "shine")); 1357. } else { 1358. pline("%s's %s burn%s", The(xname(obj)), s, 1359. (Blind ? "." : " brightly!")); 1360. } 1361. if (!invocation_pos(u.ux, u.uy) || On_stairs(u.ux, u.uy)) { 1362. pline_The("%s %s being rapidly consumed!", s, vtense(s, "are")); 1363. /* this used to be obj->age /= 2, rounding down; an age of 1364. 1 would yield 0, confusing begin_burn() and producing an 1365. unlightable, unrefillable candelabrum; round up instead */ 1366. obj->age = (obj->age + 1L) / 2L; 1367. 1368. /* to make absolutely sure the game doesn't become unwinnable as 1369. a consequence of a broken candelabrum */ 1370. if (obj->age == 0) { 1371. impossible("Candelabrum with candles but no fuel?"); 1372. obj->age = 1; 1373. } 1374. } else { 1375. if (obj->spe == 7) { 1376. if (Blind) 1377. pline("%s a strange warmth!", Tobjnam(obj, "radiate")); 1378. else 1379. pline("%s with a strange light!", Tobjnam(obj, "glow")); 1380. } 1381. obj->known = 1; 1382. } 1383. begin_burn(obj, FALSE); 1384. } 1385. 1386. staticfn void 1387. use_candle(struct obj **optr) 1388. { 1389. struct obj *obj = *optr; 1390. struct obj *otmp; 1391. const char *s = (obj->quan != 1) ? "candles" : "candle"; 1392. char qbuf[QBUFSZ], qsfx[QBUFSZ], *q; 1393. boolean was_lamplit; 1394. 1395. if (u.uswallow) { 1396. You(no_elbow_room); 1397. return; 1398. } 1399. 1400. /* obj is the candle; otmp is the candelabrum */ 1401. otmp = carrying(CANDELABRUM_OF_INVOCATION); 1402. if (!otmp || otmp->spe == 7) { 1403. use_lamp(obj); 1404. return; 1405. } 1406. 1407. /* first, minimal candelabrum suffix for formatting candles */ 1408. Sprintf(qsfx, " to\033%s?", thesimpleoname(otmp)); 1409. /* next, format the candles as a prefix for the candelabrum */ 1410. (void) safe_qbuf(qbuf, "Attach ", qsfx, obj, yname, thesimpleoname, s); 1411. /* strip temporary candelabrum suffix */ 1412. if ((q = strstri(qbuf, " to\033")) != 0) 1413. Strcpy(q, " to "); 1414. /* last, format final "attach candles to candelabrum?" query */ 1415. if (y_n(safe_qbuf(qbuf, qbuf, "?", otmp, yname, thesimpleoname, "it")) 1416. == 'n') { 1417. use_lamp(obj); 1418. return; 1419. } else { 1420. if ((long) otmp->spe + obj->quan > 7L) { 1421. obj = splitobj(obj, 7L - (long) otmp->spe); 1422. /* avoid a grammatical error if obj->quan gets 1423. reduced to 1 candle from more than one */ 1424. s = (obj->quan != 1) ? "candles" : "candle"; 1425. } else 1426. *optr = 0; 1427. 1428. /* The candle's age field doesn't correctly reflect the amount 1429. of fuel in it while it's lit, because the fuel is measured 1430. by the timer. So to get accurate age updating, we need to 1431. end the burn temporarily while attaching the candle. */ 1432. was_lamplit = obj->lamplit; 1433. if (was_lamplit) 1434. end_burn(obj, TRUE); 1435. 1436. You("attach %ld%s %s to %s.", obj->quan, !otmp->spe ? "" : " more", s, 1437. the(xname(otmp))); 1438. if (!otmp->spe || otmp->age > obj->age) 1439. otmp->age = obj->age; 1440. otmp->spe += (int) obj->quan; 1441. if (otmp->lamplit && !was_lamplit) 1442. pline_The("new %s magically %s!", s, vtense(s, "ignite")); 1443. else if (!otmp->lamplit && was_lamplit) 1444. pline("%s out.", (obj->quan > 1L) ? "They go" : "It goes"); 1445. if (obj->unpaid) { 1446. struct monst *shkp VOICEONLY 1447. = shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE)); 1448. 1449. SetVoice(shkp, 0, 80, 0); 1450. verbalize("You %s %s, you bought %s!", 1451. otmp->lamplit ? "burn" : "use", 1452. (obj->quan > 1L) ? "them" : "it", 1453. (obj->quan > 1L) ? "them" : "it"); 1454. } 1455. if (obj->quan < 7L && otmp->spe == 7) 1456. pline("%s now has seven%s candles attached.", The(xname(otmp)), 1457. otmp->lamplit ? " lit" : ""); 1458. /* candelabrum's light range might increase */ 1459. if (otmp->lamplit) 1460. obj_merge_light_sources(otmp, otmp); 1461. /* candles are no longer a separate light source */ 1462. /* candles are now gone */ 1463. useupall(obj); 1464. /* candelabrum's weight is changing */ 1465. otmp->owt = weight(otmp); 1466. update_inventory(); 1467. } 1468. } 1469. 1470. /* call in drop, throw, and put in box, etc. */ 1471. boolean 1472. snuff_candle(struct obj *otmp) 1473. { 1474. boolean candle = Is_candle(otmp); 1475. 1476. if ((candle || otmp->otyp == CANDELABRUM_OF_INVOCATION) 1477. && otmp->lamplit) { 1478. char buf[BUFSZ]; 1479. coordxy x, y; 1480. boolean many = candle ? (otmp->quan > 1L) : (otmp->spe > 1); 1481. 1482. (void) get_obj_location(otmp, &x, &y, 0); 1483. if (otmp->where == OBJ_MINVENT ? cansee(x, y) : !Blind) 1484. pline("%s%scandle%s flame%s extinguished.", Shk_Your(buf, otmp), 1485. (candle ? "" : "candelabrum's "), (many ? "s'" : "'s"), 1486. (many ? "s are" : " is")); 1487. end_burn(otmp, TRUE); 1488. return TRUE; 1489. } 1490. return FALSE; 1491. } 1492. 1493. /* called when lit lamp is hit by water or put into a container or 1494. you've been swallowed by a monster; obj might be in transit while 1495. being thrown or dropped so don't assume that its location is valid */ 1496. boolean 1497. snuff_lit(struct obj *obj) 1498. { 1499. coordxy x, y; 1500. 1501. if (obj->lamplit) { 1502. if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP 1503. || obj->otyp == BRASS_LANTERN || obj->otyp == POT_OIL) { 1504. (void) get_obj_location(obj, &x, &y, 0); 1505. if (obj->where == OBJ_MINVENT ? cansee(x, y) : !Blind) 1506. pline("%s %s out!", Yname2(obj), otense(obj, "go")); 1507. end_burn(obj, TRUE); 1508. return TRUE; 1509. } 1510. if (snuff_candle(obj)) 1511. return TRUE; 1512. } 1513. return FALSE; 1514. } 1515. 1516. /* called when lit object is hit by water */ 1517. boolean 1518. splash_lit(struct obj *obj) 1519. { 1520. boolean result, dunk = FALSE; 1521. 1522. /* lantern won't be extinguished by a rust trap or rust monster attack 1523. but will be if submerged or placed into a container or swallowed by 1524. a monster (for mobile light source handling, not because it ought 1525. to stop being lit in all those situations...) */ 1526. if (obj->lamplit && obj->otyp == BRASS_LANTERN) { 1527. struct monst *mtmp; 1528. boolean useeit = FALSE, uhearit = FALSE, snuff = TRUE; 1529. 1530. if (obj->where == OBJ_INVENT) { 1531. useeit = !Blind; 1532. uhearit = !Deaf; 1533. /* underwater light sources aren't allowed but if hero 1534. is just entering water, Underwater won't be set yet */ 1535. dunk = (is_pool(u.ux, u.uy) 1536. && ((!Levitation && !Flying && !Wwalking) 1537. || Is_waterlevel(&u.uz))); 1538. snuff = FALSE; 1539. } else if (obj->where == OBJ_MINVENT 1540. /* don't assume that lit lantern has been swallowed; 1541. a nymph might have stolen it or picked it up */ 1542. && ((mtmp = obj->ocarry), humanoid(mtmp->data))) { 1543. coordxy x, y; 1544. 1545. useeit = get_obj_location(obj, &x, &y, 0) && cansee(x, y); 1546. uhearit = couldsee(x, y) && distu(x, y) < 5 * 5; 1547. dunk = (is_pool(mtmp->mx, mtmp->my) 1548. && ((!is_flyer(mtmp->data) && !is_floater(mtmp->data)) 1549. || Is_waterlevel(&u.uz))); 1550. snuff = FALSE; 1551. if (useeit) 1552. set_msg_xy(x, y); 1553. } 1554. 1555. if (useeit || uhearit) 1556. pline("%s %s%s%s.", Yname2(obj), 1557. uhearit ? "crackles" : "", 1558. (uhearit && useeit) ? " and " : "", 1559. useeit ? "flickers" : ""); 1560. if (!dunk && !snuff) 1561. return FALSE; 1562. } 1563. 1564. result = snuff_lit(obj); 1565. 1566. /* this is simpler when we wait until after lantern has been snuffed */ 1567. if (dunk) { 1568. /* drain some of the battery but don't short it out entirely */ 1569. obj->age -= (obj->age > 200L) ? 100L : (obj->age / 2L); 1570. } 1571. return result; 1572. } 1573. 1574. /* Called when potentially lightable object is affected by fire_damage(). 1575. Return TRUE if object becomes lit and FALSE otherwise --ALI */ 1576. boolean 1577. catch_lit(struct obj *obj) 1578. { 1579. coordxy x, y; 1580. 1581. if (!obj->lamplit && ignitable(obj) && get_obj_location(obj, &x, &y, 0)) { 1582. if (((obj->otyp == MAGIC_LAMP /* spe==0 => no djinni inside */ 1583. /* spe==0 => no candles attached */ 1584. || obj->otyp == CANDELABRUM_OF_INVOCATION) && obj->spe == 0) 1585. /* age_is_relative && age==0 && still-exists means out of fuel */ 1586. || (age_is_relative(obj) && obj->age == 0) 1587. /* lantern is classified as ignitable() but not by fire */ 1588. || obj->otyp == BRASS_LANTERN) 1589. return FALSE; 1590. if (obj->otyp == CANDELABRUM_OF_INVOCATION && obj->cursed) 1591. return FALSE; 1592. if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP) 1593. /* once lit, cursed lamp is as good as non-cursed one, so failure 1594. to light is a minor inconvenience to make cursed be worse */ 1595. && obj->cursed && !rn2(2)) 1596. return FALSE; 1597. 1598. if (obj->where == OBJ_INVENT || cansee(x, y)) { 1599. if (obj->where == OBJ_FLOOR && cansee(x, y)) 1600. set_msg_xy(x, y); 1601. pline("%s %s %s", Yname2(obj), 1602. /* "catches light!" or "feels warm." */ 1603. otense(obj, Blind ? "feel" : "catch"), 1604. Blind ? "warm." : "light!"); 1605. } 1606. if (obj->otyp == POT_OIL) 1607. makeknown(obj->otyp); 1608. if (carried(obj) && obj->unpaid && costly_spot(u.ux, u.uy)) { 1609. struct monst *shkp VOICEONLY 1610. = shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE)); 1611. 1612. /* if it catches while you have it, then it's your tough luck */ 1613. check_unpaid(obj); 1614. SetVoice(shkp, 0, 80, 0); 1615. verbalize("That's in addition to the cost of %s %s, of course.", 1616. yname(obj), 1617. (obj->quan == 1L) ? "itself" : "themselves"); 1618. bill_dummy_object(obj); 1619. } 1620. begin_burn(obj, FALSE); 1621. return TRUE; 1622. } 1623. return FALSE; 1624. } 1625. 1626. /* light a lamp or candle */ 1627. staticfn void 1628. use_lamp(struct obj *obj) 1629. { 1630. char buf[BUFSZ]; 1631. const char *lamp = (obj->otyp == OIL_LAMP 1632. || obj->otyp == MAGIC_LAMP) ? "lamp" 1633. : (obj->otyp == BRASS_LANTERN) ? "lantern" 1634. : NULL; 1635. 1636. /* 1637. * When blind, lamps' and candles' on/off state can be distinguished 1638. * by heat. For brass lantern assume that there is an on/off switch 1639. * that can be felt. 1640. */ 1641. 1642. if (obj->lamplit) { 1643. if (lamp) /* lamp or lantern */ 1644. pline("%s%s is now off.", Shk_Your(buf, obj), lamp); 1645. else 1646. You("snuff out %s.", yname(obj)); 1647. end_burn(obj, TRUE); 1648. return; 1649. } 1650. if (Underwater) { 1651. pline("%s.", 1652. !Is_candle(obj) ? "This is not a diving lamp" 1653. : "Sorry, fire and water don't mix"); 1654. return; 1655. } 1656. /* magic lamps with an spe == 0 (wished for) cannot be lit */ 1657. if ((!Is_candle(obj) && obj->age == 0) 1658. || (obj->otyp == MAGIC_LAMP && obj->spe == 0)) { 1659. if (obj->otyp == BRASS_LANTERN) { 1660. if (!Blind) 1661. Your("lantern is out of power."); 1662. else 1663. pline("%s", nothing_seems_to_happen); 1664. } else { 1665. pline("This %s has no oil.", xname(obj)); 1666. } 1667. return; 1668. } 1669. if (obj->cursed && !rn2(2)) { 1670. if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP) && !rn2(3)) { 1671. pline_The("lamp spills and covers your %s with oil.", 1672. fingers_or_gloves(TRUE)); 1673. make_glib((int) (Glib & TIMEOUT) + d(2, 10)); 1674. } else if (!Blind) { 1675. pline("%s for a moment, then %s.", Tobjnam(obj, "flicker"), 1676. otense(obj, "die")); 1677. } else { 1678. pline("%s", nothing_seems_to_happen); 1679. } 1680. } else { 1681. if (lamp) { /* lamp or lantern */ 1682. check_unpaid(obj); 1683. pline("%s%s is now on.", Shk_Your(buf, obj), lamp); 1684. } else { /* candle(s) */ 1685. pline("%s flame%s %s%s", s_suffix(Yname2(obj)), plur(obj->quan), 1686. otense(obj, "burn"), Blind ? "." : " brightly!"); 1687. if (obj->unpaid && costly_spot(u.ux, u.uy) 1688. && obj->age == 20L * (long) objects[obj->otyp].oc_cost) { 1689. const char *ithem = (obj->quan > 1L) ? "them" : "it"; 1690. struct monst *shkp VOICEONLY 1691. = shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE)); 1692. 1693. SetVoice(shkp, 0, 80, 0); 1694. verbalize("You burn %s, you bought %s!", ithem, ithem); 1695. bill_dummy_object(obj); 1696. } 1697. } 1698. begin_burn(obj, FALSE); 1699. } 1700. } 1701. 1702. staticfn void 1703. light_cocktail(struct obj **optr) 1704. { 1705. struct obj *obj = *optr; /* obj is a potion of oil */ 1706. char buf[BUFSZ]; 1707. boolean split1off; 1708. 1709. if (u.uswallow) { 1710. You(no_elbow_room); 1711. return; 1712. } 1713. 1714. if (obj->lamplit) { 1715. You("snuff the lit potion."); 1716. end_burn(obj, TRUE); 1717. /* 1718. * Free & add to re-merge potion. This will average the 1719. * age of the potions. Not exactly the best solution, 1720. * but its easy. Don't do that unless obj is not worn (uwep, 1721. * uswapwep, or uquiver) because if wielded and other oil is 1722. * quivered a "null obj after quiver merge" panic will occur. 1723. */ 1724. if (!obj->owornmask) { 1725. freeinv(obj); 1726. *optr = addinv(obj); 1727. } 1728. return; 1729. } else if (Underwater) { 1730. There("is not enough oxygen to sustain a fire."); 1731. return; 1732. } 1733. 1734. split1off = (obj->quan > 1L); 1735. if (split1off) 1736. obj = splitobj(obj, 1L); 1737. 1738. You("light %spotion.%s", shk_your(buf, obj), 1739. Blind ? "" : " It gives off a dim light."); 1740. 1741. if (obj->unpaid && costly_spot(u.ux, u.uy)) { 1742. struct monst *shkp VOICEONLY = shop_keeper(*in_rooms(u.ux, u.uy, 1743. SHOPBASE)); 1744. 1745. /* Normally, we shouldn't both partially and fully charge 1746. * for an item, but (Yendorian Fuel) Taxes are inevitable... 1747. */ 1748. check_unpaid(obj); 1749. SetVoice(shkp, 0, 80, 0); 1750. verbalize("That's in addition to the cost of the potion, of course."); 1751. bill_dummy_object(obj); 1752. } 1753. makeknown(obj->otyp); 1754. 1755. begin_burn(obj, FALSE); /* after shop billing */ 1756. if (split1off) { 1757. obj_extract_self(obj); /* free from inv */ 1758. obj->nomerge = 1; 1759. obj = hold_another_object(obj, "You drop %s!", doname(obj), 1760. (const char *) 0); 1761. if (obj) 1762. obj->nomerge = 0; 1763. } 1764. *optr = obj; 1765. } 1766. 1767. /* getobj callback for object to be rubbed - not selecting a secondary object 1768. to rub on a gray stone or rub jelly on */ 1769. staticfn int 1770. rub_ok(struct obj *obj) 1771. { 1772. if (!obj) 1773. return GETOBJ_EXCLUDE; 1774. 1775. if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP 1776. || obj->otyp == BRASS_LANTERN || is_graystone(obj) 1777. || obj->otyp == LUMP_OF_ROYAL_JELLY) 1778. return GETOBJ_SUGGEST; 1779. 1780. return GETOBJ_EXCLUDE; 1781. } 1782. 1783. /* the #rub command */ 1784. int 1785. dorub(void) 1786. { 1787. struct obj *obj; 1788. 1789. if (nohands(gy.youmonst.data)) { 1790. You("aren't able to rub anything without hands."); 1791. return ECMD_OK; 1792. } 1793. obj = getobj("rub", rub_ok, GETOBJ_NOFLAGS); 1794. if (!obj) 1795. return ECMD_CANCEL; 1796. if (obj->oclass == GEM_CLASS || obj->oclass == FOOD_CLASS) { 1797. if (is_graystone(obj)) { 1798. return use_stone(obj); 1799. } else if (obj->otyp == LUMP_OF_ROYAL_JELLY) { 1800. return use_royal_jelly(&obj); 1801. } else { 1802. pline("Sorry, I don't know how to use that."); 1803. return ECMD_OK; 1804. } 1805. } 1806. if (obj != uwep) { 1807. if (wield_tool(obj, "rub")) { 1808. cmdq_add_ec(CQ_CANNED, dorub); 1809. cmdq_add_key(CQ_CANNED, obj->invlet); 1810. return ECMD_TIME; 1811. } 1812. return ECMD_OK; 1813. } 1814. 1815. /* now uwep is obj */ 1816. if (uwep->otyp == MAGIC_LAMP) { 1817. if (uwep->spe > 0 && !rn2(3)) { 1818. check_unpaid_usage(uwep, TRUE); /* unusual item use */ 1819. /* bones preparation: perform the lamp transformation 1820. before releasing the djinni in case the latter turns out 1821. to be fatal (a hostile djinni has no chance to attack yet, 1822. but an indebted one who grants a wish might bestow an 1823. artifact which blasts the hero with lethal results) */ 1824. uwep->otyp = OIL_LAMP; 1825. uwep->spe = 0; /* for safety */ 1826. uwep->age = rn1(500, 1000); 1827. if (uwep->lamplit) 1828. begin_burn(uwep, TRUE); 1829. djinni_from_bottle(uwep); 1830. makeknown(MAGIC_LAMP); 1831. update_inventory(); 1832. } else if (rn2(2)) { 1833. You("%s smoke.", !Blind ? "see a puff of" : "smell"); 1834. } else 1835. pline1(nothing_happens); 1836. } else if (obj->otyp == BRASS_LANTERN) { 1837. /* message from Adventure */ 1838. pline("Rubbing the electric lamp is not particularly rewarding."); 1839. pline("Anyway, nothing exciting happens."); 1840. } else 1841. pline1(nothing_happens); 1842. return ECMD_TIME; 1843. } 1844. 1845. /* the #jump command */ 1846. int 1847. dojump(void) 1848. { 1849. /* Physical jump */ 1850. return jump(0); 1851. } 1852. 1853. enum jump_trajectory { 1854. jAny = 0, /* any direction => magical jump */ 1855. jHorz = 1, 1856. jVert = 2, 1857. jDiag = 3 /* jHorz|jVert */ 1858. }; 1859. 1860. /* callback routine for walk_path() */ 1861. staticfn boolean 1862. check_jump(genericptr arg, coordxy x, coordxy y) 1863. { 1864. int traj = *(int *) arg; 1865. struct rm *lev = &levl[x][y]; 1866. 1867. if (Passes_walls) 1868. return TRUE; 1869. if (IS_STWALL(lev->typ)) 1870. return FALSE; 1871. if (IS_DOOR(lev->typ)) { 1872. if (closed_door(x, y)) 1873. return FALSE; 1874. if ((lev->doormask & D_ISOPEN) != 0 && traj != jAny 1875. /* reject diagonal jump into or out-of or through open door */ 1876. && (traj == jDiag 1877. /* reject horizontal jump through horizontal open door 1878. and non-horizontal (ie, vertical) jump through 1879. non-horizontal (vertical) open door */ 1880. || ((traj & jHorz) != 0) == (lev->horizontal != 0))) 1881. return FALSE; 1882. /* empty doorways aren't restricted */ 1883. } 1884. /* let giants jump over boulders (what about Flying? 1885. and is there really enough head room for giants to jump 1886. at all, let alone over something tall?) */ 1887. if (sobj_at(BOULDER, x, y) && !throws_rocks(gy.youmonst.data)) 1888. return FALSE; 1889. return TRUE; 1890. } 1891. 1892. staticfn boolean 1893. is_valid_jump_pos(coordxy x, coordxy y, int magic, boolean showmsg) 1894. { 1895. if (!magic && !(HJumping & ~INTRINSIC) && !EJumping && distu(x, y) != 5) { 1896. /* The Knight jumping restriction still applies when riding a 1897. * horse. After all, what shape is the knight piece in chess? 1898. */ 1899. if (showmsg) 1900. pline("Illegal move!"); 1901. return FALSE; 1902. } else if (distu(x, y) > (magic ? 6 + magic * 3 : 9)) { 1903. if (showmsg) 1904. pline("Too far!"); 1905. return FALSE; 1906. } else if (!isok(x, y)) { 1907. if (showmsg) 1908. You("cannot jump there!"); 1909. return FALSE; 1910. } else if (!cansee(x, y)) { 1911. if (showmsg) 1912. You("cannot see where to land!"); 1913. return FALSE; 1914. } else { 1915. coord uc, tc; 1916. struct rm *lev = &levl[u.ux][u.uy]; 1917. /* we want to categorize trajectory for use in determining 1918. passage through doorways: horizontal, vertical, or diagonal; 1919. since knight's jump and other irregular directions are 1920. possible, we flatten those out to simplify door checks */ 1921. int diag, traj; 1922. coordxy dx = x - u.ux, dy = y - u.uy, 1923. ax = abs(dx), ay = abs(dy); 1924. 1925. /* diag: any non-orthogonal destination classified as diagonal */ 1926. diag = (magic || Passes_walls || (!dx && !dy)) ? jAny 1927. : !dy ? jHorz : !dx ? jVert : jDiag; 1928. /* traj: flatten out the trajectory => some diagonals re-classified */ 1929. if (ax >= 2 * ay) 1930. ay = 0; 1931. else if (ay >= 2 * ax) 1932. ax = 0; 1933. traj = (magic || Passes_walls || (!ax && !ay)) ? jAny 1934. : !ay ? jHorz : !ax ? jVert : jDiag; 1935. /* walk_path doesn't process the starting spot; 1936. this is iffy: if you're starting on a closed door spot, 1937. you _can_ jump diagonally from doorway (without needing 1938. Passes_walls); that's intentional but is it correct? */ 1939. if (diag == jDiag && IS_DOOR(lev->typ) 1940. && (lev->doormask & D_ISOPEN) != 0 1941. && (traj == jDiag 1942. || ((traj & jHorz) != 0) == (lev->horizontal != 0))) { 1943. if (showmsg) 1944. You_cant("jump diagonally out of a doorway."); 1945. return FALSE; 1946. } 1947. uc.x = u.ux, uc.y = u.uy; 1948. tc.x = x, tc.y = y; /* target */ 1949. if (!walk_path(&uc, &tc, check_jump, (genericptr_t) &traj)) { 1950. if (showmsg) 1951. There("is an obstacle preventing that jump."); 1952. return FALSE; 1953. } 1954. } 1955. return TRUE; 1956. } 1957. 1958. staticfn boolean 1959. get_valid_jump_position(coordxy x, coordxy y) 1960. { 1961. return (isok(x, y) 1962. && (ACCESSIBLE(levl[x][y].typ) || Passes_walls) 1963. && is_valid_jump_pos(x, y, gj.jumping_is_magic, FALSE)); 1964. } 1965. 1966. staticfn void 1967. display_jump_positions(boolean on_off) 1968. { 1969. coordxy x, y, dx, dy; 1970. 1971. if (on_off) { 1972. /* on */ 1973. tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos)); 1974. for (dx = -4; dx <= 4; dx++) 1975. for (dy = -4; dy <= 4; dy++) { 1976. x = dx + u.ux; 1977. y = dy + u.uy; 1978. if (get_valid_jump_position(x, y) && !u_at(x, y)) 1979. tmp_at(x, y); 1980. } 1981. } else { 1982. /* off */ 1983. tmp_at(DISP_END, 0); 1984. } 1985. } 1986. 1987. int 1988. jump(int magic) /* 0=Physical, otherwise skill level */ 1989. { 1990. coord cc; 1991. 1992. /* attempt "jumping" spell if hero has no innate jumping ability */ 1993. if (!magic && !Jumping && known_spell(SPE_JUMPING) >= spe_Fresh) 1994. return spelleffects(SPE_JUMPING, FALSE, FALSE); 1995. 1996. if (!magic && (nolimbs(gy.youmonst.data) || slithy(gy.youmonst.data))) { 1997. /* normally (nolimbs || slithy) implies !Jumping, 1998. but that isn't necessarily the case for knights */ 1999. You_cant("jump; you have no legs!"); 2000. return ECMD_OK; 2001. } else if (!magic && !Jumping) { 2002. You_cant("jump very far."); 2003. return ECMD_OK; 2004. 2005. /* if steed is immobile, can't do physical jump but can do spell one */ 2006. } else if (!magic && u.usteed && stucksteed(FALSE)) { 2007. /* stucksteed gave "<steed> won't move" message */ 2008. return ECMD_OK; 2009. } else if (u.uswallow) { 2010. if (magic) { 2011. You("bounce around a little."); 2012. return ECMD_TIME; 2013. } 2014. pline("You've got to be kidding!"); 2015. return ECMD_OK; 2016. } else if (u.uinwater) { 2017. if (magic) { 2018. You("swish around a little."); 2019. return ECMD_TIME; 2020. } 2021. pline("This calls for swimming, not jumping!"); 2022. return ECMD_OK; 2023. } else if (u.ustuck) { 2024. if (u.ustuck->mtame && !Conflict && !u.ustuck->mconf) { 2025. struct monst *mtmp = u.ustuck; 2026. 2027. set_ustuck((struct monst *) 0); 2028. You("pull free from %s.", mon_nam(mtmp)); 2029. return ECMD_TIME; 2030. } 2031. if (magic) { 2032. You("writhe a little in the grasp of %s!", mon_nam(u.ustuck)); 2033. return ECMD_TIME; 2034. } 2035. You("cannot escape from %s!", mon_nam(u.ustuck)); 2036. return ECMD_OK; 2037. } else if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { 2038. if (magic) { 2039. You("flail around a little."); 2040. return ECMD_TIME; 2041. } 2042. You("don't have enough traction to jump."); 2043. return ECMD_OK; 2044. } else if (!magic && near_capacity() > UNENCUMBERED) { 2045. You("are carrying too much to jump!"); 2046. return ECMD_OK; 2047. } else if (!magic && (u.uhunger <= 100 || ACURR(A_STR) < 6)) { 2048. You("lack the strength to jump!"); 2049. return ECMD_OK; 2050. } else if (!magic && Wounded_legs) { 2051. legs_in_no_shape("jumping", u.usteed != 0); 2052. return ECMD_OK; 2053. } else if (u.usteed && u.utrap) { 2054. pline("%s is stuck in a trap.", Monnam(u.usteed)); 2055. return ECMD_OK; 2056. } 2057. 2058. pline("Where do you want to jump?"); 2059. cc.x = u.ux; 2060. cc.y = u.uy; 2061. gj.jumping_is_magic = magic; 2062. getpos_sethilite(display_jump_positions, get_valid_jump_position); 2063. if (getpos(&cc, TRUE, "the desired position") < 0) 2064. return ECMD_CANCEL; /* user pressed ESC */ 2065. if (!is_valid_jump_pos(cc.x, cc.y, magic, TRUE)) { 2066. return ECMD_FAIL; 2067. } else if (u.usteed && u_at(cc.x, cc.y)) { 2068. pline("%s isn't capable of jumping in place.", YMonnam(u.usteed)); 2069. return ECMD_FAIL; 2070. } else { 2071. coord uc; 2072. long side; 2073. int range, temp; 2074. boolean wastrapped = FALSE; 2075. 2076. if (u.utrap) { 2077. wastrapped = TRUE; 2078. switch (u.utraptype) { 2079. case TT_BEARTRAP: 2080. side = rn2(3) ? LEFT_SIDE : RIGHT_SIDE; 2081. You("rip yourself free of the bear trap! Ouch!"); 2082. losehp(Maybe_Half_Phys(rnd(10)), "jumping out of a bear trap", 2083. KILLED_BY); 2084. set_wounded_legs(side, rn1(1000, 500)); 2085. break; 2086. case TT_PIT: 2087. You("leap from the pit!"); 2088. break; 2089. case TT_WEB: 2090. You("tear the web apart as you pull yourself free!"); 2091. deltrap(t_at(u.ux, u.uy)); 2092. break; 2093. case TT_LAVA: 2094. You("pull yourself above the %s!", hliquid("lava")); 2095. cc.x = u.ux, cc.y = u.uy; /* take u_at() 'if' below */ 2096. break; 2097. case TT_BURIEDBALL: 2098. case TT_INFLOOR: 2099. You("strain your %s, but you're still %s.", 2100. makeplural(body_part(LEG)), 2101. (u.utraptype == TT_INFLOOR) 2102. ? "stuck in the floor" 2103. : "attached to the buried ball"); 2104. set_wounded_legs(LEFT_SIDE, rn1(10, 11)); 2105. set_wounded_legs(RIGHT_SIDE, rn1(10, 11)); 2106. return ECMD_TIME; 2107. default: 2108. impossible("Jumping out of strange trap (%d)?", u.utraptype); 2109. break; 2110. } 2111. /* if we reach here, hero is no longer trapped */ 2112. reset_utrap(TRUE); 2113. } 2114. /* jumping on hero's same spot doesn't use walk_path() and isn't 2115. allowed when riding (handled above) */ 2116. if (u_at(cc.x, cc.y)) { 2117. struct trap *t; 2118. 2119. /* escaping from a trap takes precedence over jumping in place */ 2120. if (wastrapped) { 2121. morehungry(rnd(10)); 2122. return ECMD_TIME; 2123. } 2124. /* jumping in place on a trap will trigger it */ 2125. if ((t = t_at(cc.x, cc.y)) != 0) { 2126. You("jump up and %s back down.", !Flying ? "come" : "fly"); 2127. dotrap(t, FORCETRAP | TOOKPLUNGE); 2128. return ECMD_TIME; 2129. } 2130. /* jumping in place takes no time and doesn't exercise anything */ 2131. You("%s.", Hallucination ? "hop up and down a bit" 2132. : "decide not to jump after all"); 2133. return ECMD_OK; 2134. } 2135. 2136. /* 2137. * Check the path from uc to cc, calling hurtle_step at each 2138. * location. The final position actually reached will be 2139. * in cc. 2140. */ 2141. uc.x = u.ux; 2142. uc.y = u.uy; 2143. /* calculate max(abs(dx), abs(dy)) as the range */ 2144. range = cc.x - uc.x; 2145. if (range < 0) 2146. range = -range; 2147. temp = cc.y - uc.y; 2148. if (temp < 0) 2149. temp = -temp; 2150. if (range < temp) 2151. range = temp; 2152. (void) walk_path(&uc, &cc, hurtle_jump, (genericptr_t) &range); 2153. /* hurtle_jump -> hurtle_step results in <u.ux,u.uy> == <cc.x,cc.y> 2154. * and usually moves the ball if punished, but does not handle all 2155. * the effects of landing on the final position. 2156. */ 2157. teleds(cc.x, cc.y, TELEDS_NO_FLAGS); 2158. nomul(-1); 2159. gm.multi_reason = "jumping around"; 2160. gn.nomovemsg = ""; 2161. morehungry(rnd(25)); 2162. return ECMD_TIME; 2163. } 2164. } 2165. 2166. boolean 2167. tinnable(struct obj *corpse) 2168. { 2169. if (corpse->oeaten) 2170. return 0; 2171. if (!mons[corpse->corpsenm].cnutrit) 2172. return 0; 2173. return 1; 2174. } 2175. 2176. staticfn void 2177. use_tinning_kit(struct obj *obj) 2178. { 2179. struct obj *corpse, *can; 2180. struct permonst *mptr; 2181. 2182. /* This takes only 1 move. If this is to be changed to take many 2183. * moves, we've got to deal with decaying corpses... 2184. */ 2185. if (obj->spe <= 0) { 2186. You("seem to be out of tins."); 2187. return; 2188. } 2189. if (!(corpse = floorfood("tin", 2))) 2190. return; 2191. if (corpse->oeaten) { 2192. You("cannot tin %s which is partly eaten.", something); 2193. return; 2194. } 2195. mptr = &mons[corpse->corpsenm]; 2196. if (touch_petrifies(mptr) && !Stone_resistance && !uarmg) { 2197. char kbuf[BUFSZ]; 2198. const char *corpse_name = an(cxname(corpse)); 2199. 2200. if (poly_when_stoned(gy.youmonst.data)) { 2201. You("tin %s without wearing gloves.", corpse_name); 2202. kbuf[0] = '\0'; 2203. } else { 2204. pline("Tinning %s without wearing gloves is a fatal mistake...", 2205. corpse_name); 2206. Sprintf(kbuf, "trying to tin %s without gloves", corpse_name); 2207. } 2208. instapetrify(kbuf); 2209. } 2210. if (is_rider(mptr)) { 2211. if (revive_corpse(corpse)) 2212. verbalize("Yes... But War does not preserve its enemies..."); 2213. else 2214. pline_The("corpse evades your grasp."); 2215. return; 2216. } 2217. if (mptr->cnutrit == 0) { 2218. pline("That's too insubstantial to tin."); 2219. return; 2220. } 2221. consume_obj_charge(obj, TRUE); 2222. 2223. if ((can = mksobj(TIN, FALSE, FALSE)) != 0) { 2224. static const char you_buy_it[] = "You tin it, you bought it!"; 2225. 2226. can->corpsenm = corpse->corpsenm; 2227. can->cursed = obj->cursed; 2228. can->blessed = obj->blessed; 2229. can->owt = weight(can); 2230. can->known = 1; 2231. /* Mark tinned tins. No spinach allowed... */ 2232. set_tin_variety(can, HOMEMADE_TIN); 2233. if (carried(corpse)) { 2234. if (corpse->unpaid) { 2235. struct monst *shkp VOICEONLY = shop_keeper(*in_rooms( 2236. u.ux, u.uy, SHOPBASE)); 2237. 2238. SetVoice(shkp, 0, 80, 0); 2239. verbalize(you_buy_it); 2240. } 2241. useup(corpse); 2242. } else { 2243. if (costly_spot(corpse->ox, corpse->oy) && !corpse->no_charge) { 2244. struct monst *shkp VOICEONLY 2245. = shop_keeper(*in_rooms(corpse->ox, corpse->oy, SHOPBASE)); 2246. 2247. SetVoice(shkp, 0, 80, 0); 2248. verbalize(you_buy_it); 2249. } 2250. useupf(corpse, 1L); 2251. } 2252. (void) hold_another_object(can, "You make, but cannot pick up, %s.", 2253. doname(can), (const char *) 0); 2254. } else 2255. impossible("Tinning failed."); 2256. } 2257. 2258. void 2259. use_unicorn_horn(struct obj **optr) 2260. { 2261. #define PROP_COUNT 7 /* number of properties we're dealing with */ 2262. int idx, val, val_limit, trouble_count, unfixable_trbl, did_prop; 2263. int trouble_list[PROP_COUNT]; 2264. struct obj *obj = (optr ? *optr : (struct obj *) 0); 2265. 2266. if (obj && obj->cursed) { 2267. long lcount = (long) rn1(90, 10); 2268. 2269. switch (rn2(13) / 2) { /* case 6 is half as likely as the others */ 2270. case 0: 2271. make_sick((Sick & TIMEOUT) ? (Sick & TIMEOUT) / 3L + 1L 2272. : (long) rn1(ACURR(A_CON), 20), 2273. xname(obj), TRUE, SICK_NONVOMITABLE); 2274. break; 2275. case 1: 2276. make_blinded(BlindedTimeout + lcount, TRUE); 2277. break; 2278. case 2: 2279. if (!Confusion) 2280. You("suddenly feel %s.", 2281. Hallucination ? "trippy" : "confused"); 2282. make_confused((HConfusion & TIMEOUT) + lcount, TRUE); 2283. break; 2284. case 3: 2285. make_stunned((HStun & TIMEOUT) + lcount, TRUE); 2286. break; 2287. case 4: 2288. if (Vomiting) 2289. vomit(); 2290. else 2291. make_vomiting(14L, FALSE); 2292. break; 2293. case 5: 2294. (void) make_hallucinated((HHallucination & TIMEOUT) + lcount, 2295. TRUE, 0L); 2296. break; 2297. case 6: 2298. if (Deaf) /* make_deaf() won't give feedback when already deaf */ 2299. pline("%s", nothing_seems_to_happen); 2300. make_deaf((HDeaf & TIMEOUT) + lcount, TRUE); 2301. break; 2302. } 2303. return; 2304. } 2305. 2306. #define prop_trouble(X) trouble_list[trouble_count++] = (X) 2307. #define TimedTrouble(P) (((P) && !((P) & ~TIMEOUT)) ? ((P) & TIMEOUT) : 0L) 2308. 2309. trouble_count = unfixable_trbl = did_prop = 0; 2310. 2311. /* collect property troubles */ 2312. if (TimedTrouble(Sick)) 2313. prop_trouble(SICK); 2314. if (TimedTrouble(HBlinded) > (long) u.ucreamed 2315. && !(u.uswallow 2316. && attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND))) 2317. prop_trouble(BLINDED); 2318. if (TimedTrouble(HHallucination)) 2319. prop_trouble(HALLUC); 2320. if (TimedTrouble(Vomiting)) 2321. prop_trouble(VOMITING); 2322. if (TimedTrouble(HConfusion)) 2323. prop_trouble(CONFUSION); 2324. if (TimedTrouble(HStun)) 2325. prop_trouble(STUNNED); 2326. if (TimedTrouble(HDeaf)) 2327. prop_trouble(DEAF); 2328. 2329. if (trouble_count == 0) { 2330. pline1(nothing_happens); 2331. return; 2332. } else if (trouble_count > 1) 2333. shuffle_int_array(trouble_list, trouble_count); 2334. 2335. /* 2336. * Chances for number of troubles to be fixed 2337. * 0 1 2 3 4 5 6 7 2338. * blessed: 22.7% 22.7% 19.5% 15.4% 10.7% 5.7% 2.6% 0.8% 2339. * uncursed: 35.4% 35.4% 22.9% 6.3% 0 0 0 0 2340. */ 2341. val_limit = rn2(d(2, (obj && obj->blessed) ? 4 : 2)); 2342. if (val_limit > trouble_count) 2343. val_limit = trouble_count; 2344. 2345. /* fix [some of] the troubles */ 2346. for (val = 0; val < val_limit; val++) { 2347. idx = trouble_list[val]; 2348. 2349. switch (idx) { 2350. case SICK: 2351. make_sick(0L, (char *) 0, TRUE, SICK_ALL); 2352. did_prop++; 2353. break; 2354. case BLINDED: 2355. make_blinded((long) u.ucreamed, TRUE); 2356. did_prop++; 2357. break; 2358. case HALLUC: 2359. (void) make_hallucinated(0L, TRUE, 0L); 2360. did_prop++; 2361. break; 2362. case VOMITING: 2363. make_vomiting(0L, TRUE); 2364. did_prop++; 2365. break; 2366. case CONFUSION: 2367. make_confused(0L, TRUE); 2368. did_prop++; 2369. break; 2370. case STUNNED: 2371. make_stunned(0L, TRUE); 2372. did_prop++; 2373. break; 2374. case DEAF: 2375. make_deaf(0L, TRUE); 2376. did_prop++; 2377. break; 2378. default: 2379. impossible("use_unicorn_horn: bad trouble? (%d)", idx); 2380. break; 2381. } 2382. } 2383. 2384. if (did_prop) 2385. disp.botl = TRUE; 2386. else 2387. pline("%s", nothing_seems_to_happen); 2388. 2389. #undef PROP_COUNT 2390. #undef prop_trouble 2391. #undef TimedTrouble 2392. } 2393. 2394. /* 2395. * Timer callback routine: turn figurine into monster 2396. */ 2397. void 2398. fig_transform(anything *arg, long timeout) 2399. { 2400. struct obj *figurine = arg->a_obj; 2401. struct monst *mtmp; 2402. coord cc; 2403. boolean cansee_spot, silent, okay_spot; 2404. boolean redraw = FALSE; 2405. boolean suppress_see = FALSE; 2406. char monnambuf[BUFSZ], carriedby[BUFSZ]; 2407. 2408. if (!figurine) { 2409. impossible("null figurine in fig_transform()"); 2410. return; 2411. } 2412. silent = (timeout != svm.moves); /* happened while away */ 2413. okay_spot = get_obj_location(figurine, &cc.x, &cc.y, 0); 2414. if (figurine->where == OBJ_INVENT || figurine->where == OBJ_MINVENT) 2415. okay_spot = enexto(&cc, cc.x, cc.y, &mons[figurine->corpsenm]); 2416. if (!okay_spot || !figurine_location_checks(figurine, &cc, TRUE)) { 2417. /* reset the timer to try again later */ 2418. (void) start_timer((long) rnd(5000), TIMER_OBJECT, FIG_TRANSFORM, 2419. obj_to_any(figurine)); 2420. return; 2421. } 2422. 2423. cansee_spot = cansee(cc.x, cc.y); 2424. mtmp = make_familiar(figurine, cc.x, cc.y, TRUE); 2425. if (mtmp) { 2426. char and_vanish[BUFSZ]; 2427. struct obj *mshelter = svl.level.objects[mtmp->mx][mtmp->my]; 2428. 2429. /* [m_monnam() yields accurate mon type, overriding hallucination] */ 2430. Sprintf(monnambuf, "%s", an(m_monnam(mtmp))); 2431. and_vanish[0] = '\0'; 2432. if ((mtmp->minvis && !See_invisible) 2433. || (mtmp->data->mlet == S_MIMIC 2434. && M_AP_TYPE(mtmp) != M_AP_NOTHING)) 2435. suppress_see = TRUE; 2436. 2437. if (mtmp->mundetected) { 2438. if (hides_under(mtmp->data) && mshelter) { 2439. Sprintf(and_vanish, " and %s under %s", 2440. locomotion(mtmp->data, "crawl"), doname(mshelter)); 2441. } else if (mtmp->data->mlet == S_MIMIC 2442. || mtmp->data->mlet == S_EEL) { 2443. suppress_see = TRUE; 2444. } else 2445. Strcpy(and_vanish, " and vanish"); 2446. } 2447. 2448. switch (figurine->where) { 2449. case OBJ_INVENT: 2450. if (Blind || suppress_see) 2451. You_feel("%s %s from your pack!", something, 2452. locomotion(mtmp->data, "drop")); 2453. else 2454. You_see("%s %s out of your pack%s!", monnambuf, 2455. locomotion(mtmp->data, "drop"), and_vanish); 2456. break; 2457. 2458. case OBJ_FLOOR: 2459. if (cansee_spot && !silent) { 2460. set_msg_xy(cc.x, cc.y); 2461. if (suppress_see) 2462. pline("%s suddenly vanishes!", an(xname(figurine))); 2463. else 2464. You_see("a figurine transform into %s%s!", monnambuf, 2465. and_vanish); 2466. redraw = TRUE; /* update figurine's map location */ 2467. } 2468. break; 2469. 2470. case OBJ_MINVENT: 2471. if (cansee_spot && !silent && !suppress_see) { 2472. struct monst *mon; 2473. 2474. mon = figurine->ocarry; 2475. /* figurine carrying monster might be invisible */ 2476. if (canseemon(figurine->ocarry) 2477. && (!mon->wormno || cansee(mon->mx, mon->my))) 2478. Sprintf(carriedby, "%s pack", s_suffix(a_monnam(mon))); 2479. else if (is_pool(mon->mx, mon->my)) 2480. Strcpy(carriedby, "empty water"); 2481. else 2482. Strcpy(carriedby, "thin air"); 2483. You_see("%s %s out of %s%s!", monnambuf, 2484. locomotion(mtmp->data, "drop"), carriedby, 2485. and_vanish); 2486. } 2487. break; 2488. #if 0 2489. case OBJ_MIGRATING: 2490. break; 2491. #endif 2492. 2493. default: 2494. impossible("figurine came to life where? (%d)", 2495. (int) figurine->where); 2496. break; 2497. } 2498. } 2499. /* free figurine now */ 2500. if (carried(figurine)) { 2501. useup(figurine); 2502. } else { 2503. obj_extract_self(figurine); 2504. obfree(figurine, (struct obj *) 0); 2505. } 2506. if (redraw) 2507. newsym(cc.x, cc.y); 2508. } 2509. 2510. staticfn boolean 2511. figurine_location_checks(struct obj *obj, coord *cc, boolean quietly) 2512. { 2513. coordxy x, y; 2514. 2515. if (carried(obj) && u.uswallow) { 2516. if (!quietly) 2517. You("don't have enough room in here."); 2518. return FALSE; 2519. } 2520. x = cc ? cc->x : u.ux; 2521. y = cc ? cc->y : u.uy; 2522. if (!isok(x, y)) { 2523. if (!quietly) 2524. You("cannot put the figurine there."); 2525. return FALSE; 2526. } 2527. if (IS_OBSTRUCTED(levl[x][y].typ) 2528. && !(passes_walls(&mons[obj->corpsenm]) && may_passwall(x, y))) { 2529. if (!quietly) 2530. You("cannot place a figurine in %s!", 2531. IS_TREE(levl[x][y].typ) ? "a tree" : "solid rock"); 2532. return FALSE; 2533. } 2534. if (sobj_at(BOULDER, x, y) && !passes_walls(&mons[obj->corpsenm]) 2535. && !throws_rocks(&mons[obj->corpsenm])) { 2536. if (!quietly) 2537. You("cannot fit the figurine on the boulder."); 2538. return FALSE; 2539. } 2540. return TRUE; 2541. } 2542. 2543. staticfn int 2544. use_figurine(struct obj **optr) 2545. { 2546. struct obj *obj = *optr; 2547. coordxy x, y; 2548. coord cc; 2549. 2550. if (u.uswallow) { 2551. /* can't activate a figurine while swallowed */ 2552. if (!figurine_location_checks(obj, (coord *) 0, FALSE)) 2553. return ECMD_OK; 2554. } 2555. if (!getdir((char *) 0)) { 2556. svc.context.move = gm.multi = 0; 2557. return ECMD_CANCEL; 2558. } 2559. x = u.ux + u.dx; 2560. y = u.uy + u.dy; 2561. cc.x = x; 2562. cc.y = y; 2563. /* Passing FALSE arg here will result in messages displayed */ 2564. if (!figurine_location_checks(obj, &cc, FALSE)) 2565. return ECMD_TIME; 2566. You("%s and it %stransforms.", 2567. (u.dx || u.dy) ? "set the figurine beside you" 2568. : (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) 2569. || is_pool(cc.x, cc.y)) 2570. ? "release the figurine" 2571. : (u.dz < 0 ? "toss the figurine into the air" 2572. : "set the figurine on the ground"), 2573. Blind ? "supposedly " : ""); 2574. (void) make_familiar(obj, cc.x, cc.y, FALSE); 2575. (void) stop_timer(FIG_TRANSFORM, obj_to_any(obj)); 2576. useup(obj); 2577. if (Blind) 2578. map_invisible(cc.x, cc.y); 2579. *optr = 0; 2580. return ECMD_TIME; 2581. } 2582. 2583. /* getobj callback for object to apply grease to */ 2584. staticfn int 2585. grease_ok(struct obj *obj) 2586. { 2587. if (!obj) 2588. return GETOBJ_SUGGEST; 2589. 2590. /* note: if changing the list of ungreasable objects, also change 2591. special_throne_effect in sit.c */ 2592. if (obj->oclass == COIN_CLASS) 2593. return GETOBJ_EXCLUDE; 2594. 2595. if (inaccessible_equipment(obj, (const char *) 0, FALSE)) 2596. return GETOBJ_EXCLUDE_INACCESS; 2597. 2598. /* Possible extension: don't suggest greasing objects which are already 2599. * greased. */ 2600. return GETOBJ_SUGGEST; 2601. } 2602. 2603. staticfn int 2604. use_grease(struct obj *obj) 2605. { 2606. struct obj *otmp; 2607. 2608. if (Glib) { 2609. pline("%s from your %s.", Tobjnam(obj, "slip"), 2610. fingers_or_gloves(FALSE)); 2611. dropx(obj); 2612. return ECMD_TIME; 2613. } 2614. 2615. if (obj->spe > 0) { 2616. int oldglib; 2617. 2618. if ((obj->cursed || Fumbling) && !rn2(2)) { 2619. consume_obj_charge(obj, TRUE); 2620. 2621. pline("%s from your %s.", Tobjnam(obj, "slip"), 2622. fingers_or_gloves(FALSE)); 2623. dropx(obj); 2624. return ECMD_TIME; 2625. } 2626. otmp = getobj("grease", grease_ok, GETOBJ_PROMPT); 2627. if (!otmp) 2628. return ECMD_CANCEL; 2629. if (inaccessible_equipment(otmp, "grease", FALSE)) 2630. return ECMD_OK; 2631. consume_obj_charge(obj, TRUE); 2632. 2633. oldglib = (int) (Glib & TIMEOUT); 2634. if (otmp != &hands_obj) { 2635. You("cover %s with a thick layer of grease.", yname(otmp)); 2636. otmp->greased = 1; 2637. if (obj->cursed && !nohands(gy.youmonst.data)) { 2638. make_glib(oldglib + rn1(6, 10)); /* + 10..15 */ 2639. pline("Some of the grease gets all over your %s.", 2640. fingers_or_gloves(TRUE)); 2641. } 2642. } else { 2643. make_glib(oldglib + rn1(11, 5)); /* + 5..15 */ 2644. You("coat your %s with grease.", fingers_or_gloves(TRUE)); 2645. } 2646. } else { 2647. if (obj->known) 2648. pline("%s empty.", Tobjnam(obj, "are")); 2649. else 2650. pline("%s to be empty.", Tobjnam(obj, "seem")); 2651. } 2652. update_inventory(); 2653. return ECMD_TIME; 2654. } 2655. 2656. /* getobj callback for object to rub on a known touchstone */ 2657. staticfn int 2658. touchstone_ok(struct obj *obj) 2659. { 2660. if (!obj) 2661. return GETOBJ_EXCLUDE; 2662. 2663. /* Gold being suggested as a rub target is questionable - it fits the 2664. * real-world historic use of touchstones, but doesn't do anything 2665. * significant in the game. */ 2666. if (obj->oclass == COIN_CLASS) 2667. return GETOBJ_SUGGEST; 2668. 2669. /* don't suggest identified gems */ 2670. if (obj->oclass == GEM_CLASS 2671. && !(obj->dknown && objects[obj->otyp].oc_name_known)) 2672. return GETOBJ_SUGGEST; 2673. 2674. return GETOBJ_DOWNPLAY; 2675. } 2676. 2677. 2678. /* touchstones - by Ken Arnold */ 2679. staticfn int 2680. use_stone(struct obj *tstone) 2681. { 2682. static const char scritch[] = "\"scritch, scritch\""; 2683. struct obj *obj; 2684. boolean do_scratch; 2685. const char *streak_color; 2686. char stonebuf[QBUFSZ]; 2687. int oclass; 2688. boolean known; 2689. 2690. /* in case it was acquired while blinded */ 2691. if (!Blind) 2692. observe_object(tstone); 2693. known = (tstone->otyp == TOUCHSTONE && tstone->dknown 2694. && objects[TOUCHSTONE].oc_name_known); 2695. Sprintf(stonebuf, "rub on the stone%s", plur(tstone->quan)); 2696. /* when the touchstone is fully known, don't bother listing extra 2697. junk as likely candidates for rubbing */ 2698. if ((obj = getobj(stonebuf, known ? touchstone_ok : any_obj_ok, 2699. GETOBJ_PROMPT)) == 0) 2700. return ECMD_CANCEL; 2701. 2702. if (obj == tstone && obj->quan == 1L) { 2703. You_cant("rub %s on itself.", the(xname(obj))); 2704. return ECMD_OK; 2705. } 2706. 2707. if (tstone->otyp == TOUCHSTONE && tstone->cursed 2708. && obj->oclass == GEM_CLASS && !is_graystone(obj) 2709. && !obj_resists(obj, 80, 100)) { 2710. if (Blind) 2711. You_feel("something shatter."); 2712. else if (Hallucination) 2713. pline("Oh, wow, look at the pretty shards."); 2714. else 2715. pline("A sharp crack shatters %s%s.", 2716. (obj->quan > 1L) ? "one of " : "", the(xname(obj))); 2717. useup(obj); 2718. return ECMD_TIME; 2719. } 2720. 2721. if (Blind) { 2722. pline(scritch); 2723. return ECMD_TIME; 2724. } else if (Hallucination) { 2725. pline("Oh wow, man: Fractals!"); 2726. return ECMD_TIME; 2727. } 2728. 2729. do_scratch = FALSE; 2730. streak_color = 0; 2731. 2732. oclass = obj->oclass; 2733. /* prevent non-gemstone rings from being treated like gems */ 2734. if (oclass == RING_CLASS 2735. && objects[obj->otyp].oc_material != GEMSTONE 2736. && objects[obj->otyp].oc_material != MINERAL) 2737. oclass = RANDOM_CLASS; /* something that's neither gem nor ring */ 2738. 2739. switch (oclass) { 2740. case GEM_CLASS: /* these have class-specific handling below */ 2741. case RING_CLASS: 2742. if (tstone->otyp != TOUCHSTONE) { 2743. do_scratch = TRUE; 2744. } else if (obj->oclass == GEM_CLASS 2745. && (tstone->blessed 2746. || (!tstone->cursed && (Role_if(PM_ARCHEOLOGIST) 2747. || Race_if(PM_GNOME))))) { 2748. makeknown(TOUCHSTONE); 2749. makeknown(obj->otyp); 2750. prinv((char *) 0, obj, 0L); 2751. return ECMD_TIME; 2752. } else { 2753. /* either a ring or the touchstone was not effective */ 2754. if (objects[obj->otyp].oc_material == GLASS) { 2755. do_scratch = TRUE; 2756. break; 2757. } 2758. } 2759. streak_color = c_obj_colors[objects[obj->otyp].oc_color]; 2760. break; /* gem or ring */ 2761. 2762. default: 2763. switch (objects[obj->otyp].oc_material) { 2764. case CLOTH: 2765. pline("%s a little more polished now.", Tobjnam(tstone, "look")); 2766. return ECMD_TIME; 2767. case LIQUID: 2768. if (!obj->known) /* note: not "whetstone" */ 2769. You("must think this is a wetstone, do you?"); 2770. else 2771. pline("%s a little wetter now.", Tobjnam(tstone, "are")); 2772. return ECMD_TIME; 2773. case WAX: 2774. streak_color = "waxy"; 2775. break; /* okay even if not touchstone */ 2776. case WOOD: 2777. streak_color = "wooden"; 2778. break; /* okay even if not touchstone */ 2779. case GOLD: 2780. do_scratch = TRUE; /* scratching and streaks */ 2781. streak_color = "golden"; 2782. break; 2783. case SILVER: 2784. do_scratch = TRUE; /* scratching and streaks */ 2785. streak_color = "silvery"; 2786. break; 2787. default: 2788. /* Objects passing the is_flimsy() test will not 2789. scratch a stone. They will leave streaks on 2790. non-touchstones and touchstones alike. */ 2791. if (is_flimsy(obj)) 2792. streak_color = c_obj_colors[objects[obj->otyp].oc_color]; 2793. else 2794. do_scratch = (tstone->otyp != TOUCHSTONE); 2795. break; 2796. } 2797. break; /* default oclass */ 2798. } 2799. 2800. Sprintf(stonebuf, "stone%s", plur(tstone->quan)); 2801. if (do_scratch) 2802. You("make %s%sscratch marks on the %s.", 2803. streak_color ? streak_color : (const char *) "", 2804. streak_color ? " " : "", stonebuf); 2805. else if (streak_color) 2806. You_see("%s streaks on the %s.", streak_color, stonebuf); 2807. else 2808. pline(scritch); 2809. return ECMD_TIME; 2810. } 2811. 2812. void 2813. reset_trapset(void) 2814. { 2815. gt.trapinfo.tobj = 0; 2816. gt.trapinfo.force_bungle = 0; 2817. } 2818. 2819. /* Place a landmine/bear trap. Helge Hafting */ 2820. staticfn void 2821. use_trap(struct obj *otmp) 2822. { 2823. int ttyp, tmp; 2824. const char *what = (char *) 0; 2825. char buf[BUFSZ]; 2826. int levtyp = levl[u.ux][u.uy].typ; 2827. const char *occutext = "setting the trap"; 2828. 2829. if (nohands(gy.youmonst.data)) 2830. what = "without hands"; 2831. else if (Stunned) 2832. what = "while stunned"; 2833. else if (u.uswallow) 2834. what = digests(u.ustuck->data) ? "while swallowed" : "while engulfed"; 2835. else if (Underwater) 2836. what = "underwater"; 2837. else if (Levitation) 2838. what = "while levitating"; 2839. else if (is_pool(u.ux, u.uy)) 2840. what = "in water"; 2841. else if (is_lava(u.ux, u.uy)) 2842. what = "in lava"; 2843. else if (On_stairs(u.ux, u.uy)) { 2844. stairway *stway = stairway_at(u.ux, u.uy); 2845. what = stway->isladder ? "on the ladder" : "on the stairs"; 2846. } else if (IS_FURNITURE(levtyp) || IS_OBSTRUCTED(levtyp) 2847. || closed_door(u.ux, u.uy) || t_at(u.ux, u.uy)) 2848. what = "here"; 2849. else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) 2850. what = (levtyp == AIR) 2851. ? "in midair" 2852. : (levtyp == CLOUD) 2853. ? "in a cloud" 2854. : "in this place"; /* Air/Water Plane catch-all */ 2855. if (what) { 2856. You_cant("set a trap %s!", what); 2857. reset_trapset(); 2858. return; 2859. } 2860. ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP; 2861. if (otmp == gt.trapinfo.tobj && u_at(gt.trapinfo.tx, gt.trapinfo.ty)) { 2862. You("resume setting %s%s.", shk_your(buf, otmp), 2863. trapname(ttyp, FALSE)); 2864. set_occupation(set_trap, occutext, 0); 2865. return; 2866. } 2867. gt.trapinfo.tobj = otmp; 2868. gt.trapinfo.tx = u.ux, gt.trapinfo.ty = u.uy; 2869. tmp = ACURR(A_DEX); 2870. gt.trapinfo.time_needed = 2871. (tmp > 17) ? 2 : (tmp > 12) ? 3 : (tmp > 7) ? 4 : 5; 2872. if (Blind) 2873. gt.trapinfo.time_needed *= 2; 2874. tmp = ACURR(A_STR); 2875. if (ttyp == BEAR_TRAP && tmp < 18) 2876. gt.trapinfo.time_needed += (tmp > 12) ? 1 : (tmp > 7) ? 2 : 4; 2877. /*[fumbling and/or confusion and/or cursed object check(s) 2878. should be incorporated here instead of in set_trap]*/ 2879. if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) { 2880. boolean chance; 2881. 2882. if (Fumbling || otmp->cursed) 2883. chance = (rnl(10) > 3); 2884. else 2885. chance = (rnl(10) > 5); 2886. You("aren't very skilled at reaching from %s.", mon_nam(u.usteed)); 2887. Sprintf(buf, "Continue your attempt to set %s?", 2888. the(trapname(ttyp, FALSE))); 2889. if (y_n(buf) == 'y') { 2890. if (chance) { 2891. switch (ttyp) { 2892. case LANDMINE: /* set it off */ 2893. gt.trapinfo.time_needed = 0; 2894. gt.trapinfo.force_bungle = TRUE; 2895. break; 2896. case BEAR_TRAP: /* drop it without arming it */ 2897. reset_trapset(); 2898. You("drop %s!", the(trapname(ttyp, FALSE))); 2899. dropx(otmp); 2900. return; 2901. } 2902. } 2903. } else { 2904. reset_trapset(); 2905. return; 2906. } 2907. } 2908. You("begin setting %s%s.", shk_your(buf, otmp), trapname(ttyp, FALSE)); 2909. use_unpaid_trapobj(otmp, u.ux, u.uy); 2910. set_occupation(set_trap, occutext, 0); 2911. return; 2912. } 2913. 2914. /* occupation routine called each turn while arming a beartrap or landmine */ 2915. staticfn int 2916. set_trap(void) 2917. { 2918. struct obj *otmp = gt.trapinfo.tobj; 2919. struct trap *ttmp; 2920. int ttyp; 2921. 2922. if (!otmp || !carried(otmp) || !u_at(gt.trapinfo.tx, gt.trapinfo.ty)) { 2923. /* trap object might have been stolen or hero teleported */ 2924. reset_trapset(); 2925. return 0; 2926. } 2927. 2928. if (--gt.trapinfo.time_needed > 0) 2929. return 1; /* still busy */ 2930. 2931. ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP; 2932. ttmp = maketrap(u.ux, u.uy, ttyp); 2933. if (ttmp) { 2934. ttmp->madeby_u = 1; 2935. feeltrap(ttmp); 2936. if (*in_rooms(u.ux, u.uy, SHOPBASE)) { 2937. add_damage(u.ux, u.uy, 0L); /* schedule removal */ 2938. } 2939. if (!gt.trapinfo.force_bungle) 2940. You("finish arming %s.", the(trapname(ttyp, FALSE))); 2941. if (((otmp->cursed || Fumbling) && (rnl(10) > 5)) 2942. || gt.trapinfo.force_bungle) 2943. dotrap(ttmp, 2944. (unsigned) (gt.trapinfo.force_bungle ? FORCEBUNGLE : 0)); 2945. } else { 2946. /* this shouldn't happen */ 2947. Your("trap setting attempt fails."); 2948. } 2949. useup(otmp); 2950. reset_trapset(); 2951. return 0; 2952. } 2953. 2954. int 2955. use_whip(struct obj *obj) 2956. { 2957. char buf[BUFSZ]; 2958. struct monst *mtmp; 2959. struct obj *otmp; 2960. int rx, ry, proficient, res = ECMD_OK; 2961. const char *msg_slipsfree = "The bullwhip slips free."; 2962. const char *msg_snap = "Snap!"; 2963. 2964. if (obj != uwep) { 2965. if (wield_tool(obj, "lash")) { 2966. cmdq_add_ec(CQ_CANNED, doapply); 2967. cmdq_add_key(CQ_CANNED, obj->invlet); 2968. return ECMD_TIME; 2969. } 2970. return ECMD_OK; 2971. } 2972. if (!getdir((char *) 0)) 2973. return (res|ECMD_CANCEL); 2974. 2975. if (u.uswallow) { 2976. mtmp = u.ustuck; 2977. rx = mtmp->mx; 2978. ry = mtmp->my; 2979. } else { 2980. confdir(FALSE); 2981. rx = u.ux + u.dx; 2982. ry = u.uy + u.dy; 2983. if (!isok(rx, ry)) { 2984. You("miss."); 2985. return res; 2986. } 2987. mtmp = m_at(rx, ry); 2988. } 2989. 2990. /* fake some proficiency checks */ 2991. proficient = 0; 2992. if (Role_if(PM_ARCHEOLOGIST)) 2993. ++proficient; 2994. if (ACURR(A_DEX) < 6) 2995. proficient--; 2996. else if (ACURR(A_DEX) >= 14) 2997. proficient += (ACURR(A_DEX) - 14); 2998. if (Fumbling) 2999. --proficient; 3000. if (proficient > 3) 3001. proficient = 3; 3002. if (proficient < 0) 3003. proficient = 0; 3004. 3005. if (u.uswallow) { 3006. There("is not enough room to flick your bullwhip."); 3007. 3008. } else if (Underwater) { 3009. There("is too much resistance to flick your bullwhip."); 3010. 3011. } else if (u.dz < 0) { 3012. You("flick a bug off of the %s.", ceiling(u.ux, u.uy)); 3013. 3014. } else if (!u.dz && (IS_WATERWALL(levl[rx][ry].typ) 3015. || levl[rx][ry].typ == LAVAWALL)) { 3016. You("cause a small splash."); 3017. if (levl[rx][ry].typ == LAVAWALL) 3018. (void) fire_damage(uwep, FALSE, rx, ry); 3019. return ECMD_TIME; 3020. } else if ((!u.dx && !u.dy) || (u.dz > 0)) { 3021. int dam; 3022. 3023. /* Sometimes you hit your steed by mistake */ 3024. if (u.usteed && !rn2(proficient + 2)) { 3025. You("whip %s!", mon_nam(u.usteed)); 3026. kick_steed(); 3027. return ECMD_TIME; 3028. } 3029. if (is_pool_or_lava(u.ux, u.uy) 3030. || IS_WATERWALL(levl[rx][ry].typ) 3031. || levl[rx][ry].typ == LAVAWALL) { 3032. You("cause a small splash."); 3033. if (is_lava(u.ux, u.uy)) 3034. (void) fire_damage(uwep, FALSE, u.ux, u.uy); 3035. return ECMD_TIME; 3036. } 3037. if (Levitation || u.usteed || Flying) { 3038. /* Have a shot at snaring something on the floor. A flyer 3039. can reach the floor so could just pick an item up, but 3040. allow snagging by whip too. */ 3041. otmp = svl.level.objects[u.ux][u.uy]; 3042. if (otmp && otmp->otyp == CORPSE 3043. && (otmp->corpsenm == PM_HORSE 3044. || otmp->corpsenm == little_to_big(PM_HORSE) /* warhorse */ 3045. || otmp->corpsenm == big_to_little(PM_HORSE))) { /* pony */ 3046. pline("Why beat a dead horse?"); 3047. return ECMD_TIME; 3048. } 3049. if (otmp && proficient) { 3050. You("wrap your bullwhip around %s on the %s.", 3051. an(singular(otmp, xname)), surface(u.ux, u.uy)); 3052. if (rnl(6) || pickup_object(otmp, 1L, TRUE) < 1) 3053. pline1(msg_slipsfree); 3054. return ECMD_TIME; 3055. } 3056. } 3057. dam = rnd(2) + dbon() + obj->spe; 3058. if (dam <= 0) 3059. dam = 1; 3060. You("hit your %s with your bullwhip.", body_part(FOOT)); 3061. Sprintf(buf, "killed %sself with %s bullwhip", uhim(), uhis()); 3062. losehp(Maybe_Half_Phys(dam), buf, NO_KILLER_PREFIX); 3063. return ECMD_TIME; 3064. 3065. } else if ((Fumbling || Glib) && !rn2(5)) { 3066. pline_The("bullwhip slips out of your %s.", body_part(HAND)); 3067. dropx(obj); 3068. 3069. } else if (u.utrap && u.utraptype == TT_PIT) { 3070. /* 3071. * Assumptions: 3072. * 3073. * if you're in a pit 3074. * - you are attempting to get out of the pit 3075. * - if there is no suitable boulder or furniture to target, 3076. * target a big monster for that, or if a small or medium 3077. * monster is present, attack it 3078. * [if both boulder and furniture are present, target the 3079. * former because it is on top of the latter] 3080. * else if you are applying it towards a monster 3081. * - if monster is concealed, reveal it and proceed; 3082. * - if it was not concealed and is wielding a weapon, attempt 3083. * to disarm it; 3084. * - otherwise attack it. 3085. * 3086. * if you're confused (and thus off the mark) 3087. * - you only end up hitting. 3088. */ 3089. const char *wrapped_what = sobj_at(BOULDER, rx, ry) ? "a boulder" 3090. : IS_FURNITURE(levl[rx][ry].typ) 3091. ? something : (char *) 0; 3092. 3093. if (mtmp) { 3094. /* if a big monster is known to be present, target it in 3095. preference to boulder or furniture; if any small or medium 3096. monster is present, or an unseen big one, use the boulder 3097. or furniture if available, otherwise attack */ 3098. if (bigmonst(mtmp->data) && canspotmon(mtmp)) 3099. wrapped_what = strcpy(buf, mon_nam(mtmp)); 3100. 3101. if (!wrapped_what) 3102. goto whipattack; 3103. } 3104. if (wrapped_what) { 3105. coord cc; 3106. 3107. cc.x = rx; 3108. cc.y = ry; 3109. You("wrap your bullwhip around %s.", wrapped_what); 3110. if (proficient && rn2(proficient + 2)) { 3111. if (!mtmp || enexto(&cc, rx, ry, gy.youmonst.data)) { 3112. You("yank yourself out of the pit!"); 3113. reset_utrap(TRUE); /* [was after teleds(); do this before 3114. * in case it has no alternative other 3115. * than to put hero in another trap] */ 3116. teleds(cc.x, cc.y, TELEDS_ALLOW_DRAG); 3117. gv.vision_full_recalc = 1; 3118. } 3119. } else { 3120. pline1(msg_slipsfree); 3121. } 3122. if (mtmp) 3123. wakeup(mtmp, TRUE); 3124. } else 3125. pline1(msg_snap); 3126. 3127. } else if (mtmp) { 3128. whipattack: 3129. otmp = 0; /* if monster is unseen, can't attempt to disarm it */ 3130. if (!canspotmon(mtmp)) { 3131. boolean spotitnow; 3132. 3133. mtmp->mundetected = 0; /* bring non-mimic hider out of hiding */ 3134. /* check visibility again after mundetected=0 in case being 3135. brought out of hiding has exposed it (might not if hero is 3136. blind or formerly hidden monster is also invisible) */ 3137. spotitnow = canspotmon(mtmp); 3138. if (spotitnow || !glyph_is_invisible(levl[rx][ry].glyph)) { 3139. pline("%s is there that you %s.", 3140. !spotitnow ? "A monster" : Amonnam(mtmp), 3141. !Blind ? "couldn't see" : "hadn't noticed"); 3142. if (!spotitnow) 3143. map_invisible(rx, ry); 3144. else 3145. newsym(rx, ry); 3146. } 3147. } else { 3148. /* monster is known so if it is wielding something, try to 3149. disarm it rather than make a direct attack */ 3150. otmp = MON_WEP(mtmp); 3151. } 3152. 3153. if (otmp) { 3154. char onambuf[BUFSZ]; 3155. const char *mon_hand; 3156. boolean gotit = proficient && (!Fumbling || !rn2(10)); 3157. 3158. Strcpy(onambuf, cxname(otmp)); 3159. if (gotit) { 3160. mon_hand = mbodypart(mtmp, HAND); 3161. if (bimanual(otmp)) 3162. mon_hand = makeplural(mon_hand); 3163. } else 3164. mon_hand = 0; /* lint suppression */ 3165. 3166. You("wrap your bullwhip around %s.", yname(otmp)); 3167. if (gotit && mwelded(otmp)) { 3168. pline("%s welded to %s %s%c", 3169. (otmp->quan == 1L) ? "It is" : "They are", mhis(mtmp), 3170. mon_hand, !otmp->bknown ? '!' : '.'); 3171. set_bknown(otmp, 1); 3172. gotit = FALSE; /* can't pull it free */ 3173. } 3174. if (gotit) { 3175. obj_extract_self(otmp); 3176. possibly_unwield(mtmp, FALSE); 3177. setmnotwielded(mtmp, otmp); 3178. 3179. switch (rn2(proficient + 1)) { 3180. case 2: 3181. /* to floor near you */ 3182. You("yank %s to the %s!", yname(otmp), 3183. surface(u.ux, u.uy)); 3184. place_object(otmp, u.ux, u.uy); 3185. stackobj(otmp); 3186. break; 3187. case 3: 3188. #if 0 3189. /* right to you */ 3190. if (!rn2(25)) { 3191. /* proficient with whip, but maybe not 3192. so proficient at catching weapons */ 3193. int dam, hitvalu, hitu; 3194. 3195. dam = dmgval(otmp, &gy.youmonst); 3196. hitvalu = 8 + otmp->spe; 3197. hitu = thitu(hitvalu, Maybe_Half_Phys(dam), 3198. &otmp, (char *) 0); 3199. if (hitu) { 3200. pline_The("%s hits you as you try to snatch it!", 3201. the(onambuf)); 3202. } 3203. place_object(otmp, u.ux, u.uy); 3204. stackobj(otmp); 3205. break; 3206. } 3207. #endif /* 0 */ 3208. /* right into your inventory */ 3209. You("snatch %s!", yname(otmp)); 3210. if (otmp->otyp == CORPSE 3211. && touch_petrifies(&mons[otmp->corpsenm]) && !uarmg 3212. && !Stone_resistance 3213. && !(poly_when_stoned(gy.youmonst.data) 3214. && polymon(PM_STONE_GOLEM))) { 3215. char kbuf[BUFSZ]; 3216. 3217. Strcpy(kbuf, (otmp->quan == 1L) ? an(onambuf) 3218. : onambuf); 3219. pline("Snatching %s is a fatal mistake.", kbuf); 3220. /* corpse probably has a rot timer but is now 3221. OBJ_FREE; end of game cleanup will panic if 3222. it isn't part of current level; plus it would 3223. be missing from bones, so put it on the floor */ 3224. place_object(otmp, u.ux, u.uy); /* but don't stack */ 3225. 3226. instapetrify(kbuf); 3227. /* life-saved; free the corpse again */ 3228. obj_extract_self(otmp); 3229. } 3230. (void) hold_another_object(otmp, "You drop %s!", 3231. doname(otmp), (const char *) 0); 3232. break; 3233. default: 3234. /* to floor beneath mon */ 3235. You("yank %s from %s %s!", the(onambuf), 3236. s_suffix(mon_nam(mtmp)), mon_hand); 3237. obj_no_longer_held(otmp); 3238. place_object(otmp, mtmp->mx, mtmp->my); 3239. stackobj(otmp); 3240. break; 3241. } 3242. } else { 3243. pline1(msg_slipsfree); 3244. } 3245. } else { /* mtmp isn't wielding a weapon; attack it */ 3246. boolean do_snap = TRUE; 3247. 3248. if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers 3249. && !sensemon(mtmp)) { 3250. stumble_onto_mimic(mtmp); 3251. do_snap = FALSE; 3252. } else { 3253. You("flick your bullwhip towards %s.", mon_nam(mtmp)); 3254. } 3255. if (proficient && force_attack(mtmp, FALSE)) 3256. return ECMD_TIME; 3257. if (do_snap) 3258. pline1(msg_snap); 3259. } 3260. /* regardless of mtmp's weapon or hero's proficiency */ 3261. wakeup(mtmp, TRUE); 3262. 3263. } else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { 3264. /* it must be air -- water checked above */ 3265. You("snap your whip through thin air."); 3266. 3267. } else { 3268. pline1(msg_snap); 3269. } 3270. return ECMD_TIME; 3271. } 3272. 3273. static const char 3274. not_enough_room[] = "There's not enough room here to use that.", 3275. where_to_hit[] = "Where do you want to hit?", 3276. cant_see_spot[] = "won't hit anything if you can't see that spot.", 3277. cant_reach[] = "can't reach that spot from here."; 3278. 3279. #define glyph_is_poleable(G) \ 3280. (glyph_is_monster(G) || glyph_is_invisible(G) || glyph_is_statue(G)) 3281. 3282. /* find pos of monster in range, if only one monster */ 3283. staticfn boolean 3284. find_poleable_mon(coord *pos) 3285. { 3286. struct monst *mtmp; 3287. coord mpos = { 0, 0 }; /* no candidate location yet */ 3288. boolean impaired; 3289. coordxy x, y, lo_x, hi_x, lo_y, hi_y, rt; 3290. int glyph; 3291. 3292. impaired = (Confusion || Stunned || Hallucination); 3293. rt = isqrt(gp.polearm_range_max); 3294. lo_x = max(u.ux - rt, 1), hi_x = min(u.ux + rt, COLNO - 1); 3295. lo_y = max(u.uy - rt, 0), hi_y = min(u.uy + rt, ROWNO - 1); 3296. for (x = lo_x; x <= hi_x; ++x) { 3297. for (y = lo_y; y <= hi_y; ++y) { 3298. if (!get_valid_polearm_position(x, y)) 3299. continue; 3300. glyph = glyph_at(x, y); 3301. if (!impaired 3302. && glyph_is_monster(glyph) 3303. && (mtmp = m_at(x, y)) != 0 3304. && (mtmp->mtame || (mtmp->mpeaceful && flags.confirm))) 3305. continue; 3306. if (glyph_is_poleable(glyph) 3307. && (!glyph_is_statue(glyph) || impaired)) { 3308. if (mpos.x) 3309. return FALSE; /* more than one candidate location */ 3310. mpos.x = x, mpos.y = y; 3311. } 3312. } 3313. } 3314. if (!mpos.x) 3315. return FALSE; /* no candidate location */ 3316. *pos = mpos; 3317. return TRUE; 3318. } 3319. 3320. staticfn boolean 3321. get_valid_polearm_position(coordxy x, coordxy y) 3322. { 3323. int glyph; 3324. 3325. glyph = glyph_at(x, y); 3326. 3327. return (isok(x, y) && distu(x, y) >= gp.polearm_range_min 3328. && distu(x, y) <= gp.polearm_range_max 3329. && (cansee(x, y) || (couldsee(x, y) 3330. && glyph_is_poleable(glyph)))); 3331. } 3332. 3333. staticfn void 3334. display_polearm_positions(boolean on_off) 3335. { 3336. coordxy x, y, dx, dy; 3337. 3338. if (on_off) { 3339. /* on */ 3340. tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos)); 3341. for (dx = -3; dx <= 3; dx++) 3342. for (dy = -3; dy <= 3; dy++) { 3343. x = dx + (int) u.ux; 3344. y = dy + (int) u.uy; 3345. if (get_valid_polearm_position(x, y)) { 3346. tmp_at(x, y); 3347. } 3348. } 3349. } else { 3350. /* off */ 3351. tmp_at(DISP_END, 0); 3352. } 3353. } 3354. 3355. /* 3356. * Calculate allowable range (pole's reach is always 2 steps): 3357. * unskilled and basic: orthogonal direction, 4..4; 3358. * skilled: as basic, plus knight's jump position, 4..5; 3359. * expert: as skilled, plus diagonal, 4..8. 3360. * ...9... 3361. * .85458. 3362. * .52125. 3363. * 9410149 3364. * .52125. 3365. * .85458. 3366. * ...9... 3367. * (Note: no roles in NetHack can become expert or better 3368. * for polearm skill; Yeoman in slash'em can become expert.) 3369. */ 3370. staticfn void 3371. calc_pole_range(int *min_range, int *max_range) 3372. { 3373. int typ = uwep_skill_type(); 3374. 3375. *min_range = 4; 3376. if (typ == P_NONE || P_SKILL(typ) <= P_BASIC) 3377. *max_range = 4; 3378. else if (P_SKILL(typ) == P_SKILLED) 3379. *max_range = 5; 3380. else 3381. *max_range = 8; /* (P_SKILL(typ) >= P_EXPERT) */ 3382. 3383. gp.polearm_range_min = *min_range; 3384. gp.polearm_range_max = *max_range; 3385. 3386. } 3387. 3388. /* return TRUE if hero is wielding a polearm and there's 3389. at least one monster they could hit with it */ 3390. boolean 3391. could_pole_mon(void) 3392. { 3393. int min_range, max_range; 3394. coord cc; 3395. struct monst *hitm = svc.context.polearm.hitmon; 3396. 3397. if (!uwep || !is_pole(uwep)) 3398. return FALSE; 3399. 3400. calc_pole_range(&min_range, &max_range); 3401. 3402. cc.x = u.ux; 3403. cc.y = u.uy; 3404. if (!find_poleable_mon(&cc)) { 3405. if (hitm && !DEADMONSTER(hitm) && sensemon(hitm) 3406. && mdistu(hitm) <= max_range && mdistu(hitm) >= min_range) 3407. return TRUE; 3408. } else { 3409. return TRUE; 3410. } 3411. return FALSE; 3412. } 3413. 3414. /* was Snickersnee used to attack at distance this turn already? */ 3415. staticfn boolean 3416. snickersnee_used_dist_attk(struct obj *obj) 3417. { 3418. if (obj && obj == uwep && u_wield_art(ART_SNICKERSNEE) 3419. && svc.context.snickersnee_turn == svm.moves) 3420. return TRUE; 3421. return FALSE; 3422. } 3423. 3424. /* Distance attacks by pole-weapons */ 3425. int 3426. use_pole(struct obj *obj, boolean autohit) 3427. { 3428. const char thump[] = "Thump! Your blow bounces harmlessly off the %s."; 3429. int res = ECMD_OK, max_range, min_range, glyph; 3430. coord cc; 3431. struct monst *mtmp; 3432. struct monst *hitm = svc.context.polearm.hitmon; 3433. boolean freehit = FALSE; 3434. 3435. /* Are you allowed to use the pole? */ 3436. if (u.uswallow) { 3437. pline(not_enough_room); 3438. return ECMD_OK; 3439. } 3440. if (obj != uwep) { 3441. if (wield_tool(obj, "swing")) { 3442. cmdq_add_ec(CQ_CANNED, doapply); 3443. cmdq_add_key(CQ_CANNED, obj->invlet); 3444. return ECMD_TIME; 3445. } 3446. return ECMD_OK; 3447. } 3448. /* assert(obj == uwep); */ 3449. 3450. calc_pole_range(&min_range, &max_range); 3451. 3452. /* Prompt for a location */ 3453. if (!autohit) 3454. pline(where_to_hit); 3455. cc.x = u.ux; 3456. cc.y = u.uy; 3457. if (!find_poleable_mon(&cc) && hitm 3458. && !DEADMONSTER(hitm) && sensemon(hitm) 3459. && mdistu(hitm) <= max_range && mdistu(hitm) >= min_range) { 3460. cc.x = hitm->mx; 3461. cc.y = hitm->my; 3462. } 3463. if (!autohit) { 3464. getpos_sethilite(display_polearm_positions, 3465. get_valid_polearm_position); 3466. if (getpos(&cc, TRUE, "the spot to hit") < 0) 3467. /* ESC; uses turn iff polearm became wielded */ 3468. return (res | ECMD_CANCEL); 3469. } 3470. 3471. glyph = glyph_at(cc.x, cc.y); 3472. if (distu(cc.x, cc.y) > max_range) { 3473. pline("Too far!"); 3474. return ECMD_FAIL; 3475. } else if (distu(cc.x, cc.y) < min_range) { 3476. if (autohit && u_at(cc.x, cc.y)) 3477. pline("Don't know what to hit."); 3478. else 3479. pline("Too close!"); 3480. return ECMD_FAIL; 3481. } else if (!cansee(cc.x, cc.y) && !glyph_is_poleable(glyph)) { 3482. You(cant_see_spot); 3483. return ECMD_FAIL; 3484. } else if (!couldsee(cc.x, cc.y)) { /* Eyes of the Overworld */ 3485. You(cant_reach); 3486. return ECMD_FAIL; 3487. } 3488. 3489. svc.context.polearm.hitmon = (struct monst *) 0; 3490. /* Attack the monster there */ 3491. gb.bhitpos = cc; 3492. if ((mtmp = m_at(gb.bhitpos.x, gb.bhitpos.y)) != (struct monst *) 0) { 3493. if (attack_checks(mtmp, uwep)) /* can attack proceed? */ 3494. /* no, abort the attack attempt; result depends on 3495. res: 1 => polearm became wielded, 0 => already wielded; 3496. svc.context.move: 1 => discovered hidden monster at target spot, 3497. 0 => answered 'n' to "Really attack?" prompt */ 3498. return res | (svc.context.move ? ECMD_TIME : ECMD_OK); 3499. if (overexertion()) 3500. return ECMD_TIME; /* burn nutrition; maybe pass out */ 3501. svc.context.polearm.hitmon = mtmp; 3502. 3503. if (snickersnee_used_dist_attk(obj)) { 3504. pline_The("blade doesn't reach there!"); 3505. return ECMD_FAIL; 3506. } 3507. 3508. check_caitiff(mtmp); 3509. gn.notonhead = (gb.bhitpos.x != mtmp->mx || gb.bhitpos.y != mtmp->my); 3510. 3511. /* Snickersnee allows one free hit from a distance per turn */ 3512. if (obj == uwep && u_wield_art(ART_SNICKERSNEE)) { 3513. freehit = (svm.moves != svc.context.snickersnee_turn); 3514. svc.context.snickersnee_turn = svm.moves; 3515. if (freehit && !Deaf) { 3516. Soundeffect(se_sword_blade_rings, 100); 3517. pline("Shkinng!"); /* /sha-kin!/ */ 3518. } 3519. } 3520. 3521. (void) thitmonst(mtmp, uwep); 3522. } else if (glyph_is_statue(glyph) /* might be hallucinatory */ 3523. && sobj_at(STATUE, gb.bhitpos.x, gb.bhitpos.y)) { 3524. struct trap *t = t_at(gb.bhitpos.x, gb.bhitpos.y); 3525. 3526. if (t && t->ttyp == STATUE_TRAP 3527. && activate_statue_trap(t, t->tx, t->ty, FALSE)) { 3528. ; /* feedback has been give by animate_statue() */ 3529. } else { 3530. /* Since statues look like monsters now, we say something 3531. different from "you miss" or "there's nobody there". 3532. Note: we only do this when a statue is displayed here, 3533. because the player is probably attempting to attack it; 3534. other statues obscured by anything are just ignored. */ 3535. pline(thump, "statue"); 3536. wake_nearto(gb.bhitpos.x, gb.bhitpos.y, 25); 3537. } 3538. } else { 3539. /* no monster here and no statue seen or remembered here */ 3540. (void) unmap_invisible(gb.bhitpos.x, gb.bhitpos.y); 3541. 3542. if (glyph_to_obj(glyph) == BOULDER 3543. && sobj_at(BOULDER, gb.bhitpos.x, gb.bhitpos.y)) { 3544. pline(thump, "boulder"); 3545. wake_nearto(gb.bhitpos.x, gb.bhitpos.y, 25); 3546. } else if (!accessible(gb.bhitpos.x, gb.bhitpos.y) 3547. || IS_FURNITURE(levl[gb.bhitpos.x][gb.bhitpos.y].typ)) { 3548. /* similar to 'F'orcefight with a melee weapon; we know that 3549. the spot can be seen or we wouldn't have gotten this far */ 3550. You("uselessly attack %s.", 3551. (levl[gb.bhitpos.x][gb.bhitpos.y].typ == STONE 3552. || levl[gb.bhitpos.x][gb.bhitpos.y].typ == SCORR) 3553. ? "stone" 3554. : glyph_is_cmap(glyph) 3555. ? the(defsyms[glyph_to_cmap(glyph)].explanation) 3556. : (const char *) "an unknown obstacle"); 3557. } else { 3558. You("miss; there is no one there to hit."); 3559. } 3560. } 3561. u_wipe_engr(2); /* same as for melee or throwing */ 3562. return freehit ? ECMD_OK : ECMD_TIME; 3563. } 3564. 3565. #undef glyph_is_poleable 3566. 3567. staticfn int 3568. use_cream_pie(struct obj *obj) 3569. { 3570. boolean wasblind = Blind; 3571. boolean wascreamed = u.ucreamed; 3572. boolean several = FALSE; 3573. 3574. if (obj->quan > 1L) { 3575. several = TRUE; 3576. obj = splitobj(obj, 1L); 3577. } 3578. if (Hallucination) 3579. You("give yourself a facial."); 3580. else 3581. You("immerse your %s in %s%s.", body_part(FACE), 3582. several ? "one of " : "", 3583. several ? makeplural(the(xname(obj))) : the(xname(obj))); 3584. if (can_blnd((struct monst *) 0, &gy.youmonst, AT_WEAP, obj)) { 3585. int blindinc = rnd(25); 3586. 3587. u.ucreamed += blindinc; 3588. make_blinded(BlindedTimeout + (long) blindinc, FALSE); 3589. if (!Blind || (Blind && wasblind)) 3590. pline("There's %ssticky goop all over your %s.", 3591. wascreamed ? "more " : "", body_part(FACE)); 3592. else /* Blind && !wasblind */ 3593. You_cant("see through all the sticky goop on your %s.", 3594. body_part(FACE)); 3595. } 3596. 3597. setnotworn(obj); 3598. /* useup() is appropriate, but we want costly_alteration()'s message */ 3599. costly_alteration(obj, COST_SPLAT); 3600. obj_extract_self(obj); 3601. delobj(obj); 3602. return ECMD_OK; 3603. } 3604. 3605. /* getobj callback for object to rub royal jelly on */ 3606. staticfn int 3607. jelly_ok(struct obj *obj) 3608. { 3609. if (obj && obj->otyp == EGG) 3610. return GETOBJ_SUGGEST; 3611. 3612. return GETOBJ_EXCLUDE; 3613. } 3614. 3615. staticfn int 3616. use_royal_jelly(struct obj **optr) 3617. { 3618. int oldcorpsenm; 3619. unsigned was_timed; 3620. struct obj *eobj, *obj = *optr; 3621. boolean splitit = (obj->quan > 1L); 3622. 3623. if (splitit) 3624. obj = splitobj(obj, 1L); 3625. /* remove from inventory so that it won't be offered as a choice 3626. to rub on itself */ 3627. freeinv(obj); 3628. 3629. /* right now you can rub one royal jelly on an entire stack of eggs */ 3630. eobj = getobj("rub the royal jelly on", jelly_ok, GETOBJ_PROMPT); 3631. if (!eobj) { 3632. if (splitit) { 3633. (void) unsplitobj(obj); 3634. update_inventory(); /* freeinv() updated perminv w/ obj omitted */ 3635. } else { 3636. /* this lump was already separate; pervent merge */ 3637. addinv_nomerge(obj); /* put unused lump back; updates perminv */ 3638. } 3639. return ECMD_CANCEL; 3640. } 3641. 3642. You("smear royal jelly all over %s.", yname(eobj)); 3643. if (eobj->otyp != EGG) { 3644. pline1(nothing_happens); 3645. goto useup_jelly; 3646. } 3647. 3648. oldcorpsenm = eobj->corpsenm; 3649. if (eobj->corpsenm == PM_KILLER_BEE) 3650. eobj->corpsenm = PM_QUEEN_BEE; 3651. 3652. if (obj->cursed) { 3653. if (eobj->timed || eobj->corpsenm != oldcorpsenm) 3654. pline("The %s %s feebly.", xname(eobj), otense(eobj, "quiver")); 3655. else 3656. pline("%s", nothing_seems_to_happen); 3657. kill_egg(eobj); 3658. goto useup_jelly; 3659. } 3660. 3661. was_timed = eobj->timed; 3662. if (eobj->corpsenm != NON_PM) { 3663. if (!eobj->timed) 3664. attach_egg_hatch_timeout(eobj, 0L); 3665. /* blessed royal jelly will make the hatched creature think 3666. you're the parent - but has no effect if you laid the egg */ 3667. if (obj->blessed && !eobj->spe) 3668. eobj->spe = 2; 3669. } 3670. 3671. if ((eobj->timed && !was_timed) || eobj->spe == 2 3672. || eobj->corpsenm != oldcorpsenm) 3673. pline("The %s %s briefly.", xname(eobj), otense(eobj, "quiver")); 3674. else 3675. pline("%s", nothing_seems_to_happen); 3676. 3677. useup_jelly: 3678. /* not useup() because we've already done freeinv() */ 3679. setnotworn(obj); 3680. obfree(obj, (struct obj *) 0); 3681. *optr = 0; 3682. return ECMD_TIME; 3683. } 3684. 3685. staticfn int 3686. grapple_range(void) 3687. { 3688. int typ = uwep_skill_type(); 3689. int max_range = 4; 3690. 3691. if (typ == P_NONE || P_SKILL(typ) <= P_BASIC) 3692. max_range = 4; 3693. else if (P_SKILL(typ) == P_SKILLED) 3694. max_range = 5; 3695. else 3696. max_range = 8; 3697. return max_range; 3698. } 3699. 3700. staticfn boolean 3701. can_grapple_location(coordxy x, coordxy y) 3702. { 3703. return (isok(x, y) && cansee(x, y) && distu(x, y) <= grapple_range()); 3704. } 3705. 3706. staticfn void 3707. display_grapple_positions(boolean on_off) 3708. { 3709. coordxy x, y, dx, dy; 3710. 3711. if (on_off) { 3712. /* on */ 3713. tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos)); 3714. for (dx = -3; dx <= 3; dx++) 3715. for (dy = -3; dy <= 3; dy++) { 3716. x = dx + (int) u.ux; 3717. y = dy + (int) u.uy; 3718. if (can_grapple_location(x, y) && !u_at(x, y)) { 3719. tmp_at(x, y); 3720. } 3721. } 3722. } else { 3723. /* off */ 3724. tmp_at(DISP_END, 0); 3725. } 3726. } 3727. 3728. staticfn int 3729. use_grapple(struct obj *obj) 3730. { 3731. int res = ECMD_OK, typ, tohit; 3732. boolean save_confirm; 3733. coord cc; 3734. struct monst *mtmp; 3735. struct obj *otmp; 3736. 3737. /* Are you allowed to use the hook? */ 3738. if (u.uswallow) { 3739. pline(not_enough_room); 3740. return ECMD_OK; 3741. } 3742. if (obj != uwep) { 3743. /* "cast": grappling hook evolved from slash'em's fishing pole */ 3744. if (wield_tool(obj, "cast")) { 3745. cmdq_add_ec(CQ_CANNED, doapply); 3746. cmdq_add_key(CQ_CANNED, obj->invlet); 3747. return ECMD_TIME; 3748. } 3749. return ECMD_OK; 3750. } 3751. /* assert(obj == uwep); */ 3752. 3753. /* Prompt for a location */ 3754. pline(where_to_hit); 3755. cc.x = u.ux; 3756. cc.y = u.uy; 3757. getpos_sethilite(display_grapple_positions, can_grapple_location); 3758. if (getpos(&cc, TRUE, "the spot to hit") < 0) 3759. /* ESC; uses turn iff grapnel became wielded */ 3760. return (res | ECMD_CANCEL); 3761. 3762. /* Calculate range; unlike use_pole(), there's no minimum for range */ 3763. typ = uwep_skill_type(); 3764. if (distu(cc.x, cc.y) > grapple_range()) { 3765. pline("Too far!"); 3766. return res; 3767. } else if (!cansee(cc.x, cc.y)) { 3768. You(cant_see_spot); 3769. return res; 3770. } else if (!couldsee(cc.x, cc.y)) { /* Eyes of the Overworld */ 3771. You(cant_reach); 3772. return res; 3773. } 3774. 3775. /* What do you want to hit? */ 3776. tohit = rn2(5); 3777. if (typ != P_NONE && P_SKILL(typ) >= P_SKILLED) { 3778. winid tmpwin = create_nhwindow(NHW_MENU); 3779. anything any; 3780. char buf[BUFSZ]; 3781. menu_item *selected; 3782. int clr = NO_COLOR; 3783. 3784. any = cg.zeroany; /* set all bits to zero */ 3785. any.a_int = 1; /* use index+1 (can't use 0) as identifier */ 3786. start_menu(tmpwin, MENU_BEHAVE_STANDARD); 3787. any.a_int++; 3788. Sprintf(buf, "an object on the %s", surface(cc.x, cc.y)); 3789. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 3790. clr, buf, MENU_ITEMFLAGS_NONE); 3791. any.a_int++; 3792. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, 3793. clr, "a monster", MENU_ITEMFLAGS_NONE); 3794. any.a_int++; 3795. Sprintf(buf, "the %s", surface(cc.x, cc.y)); 3796. add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr, 3797. buf, MENU_ITEMFLAGS_NONE); 3798. end_menu(tmpwin, "Aim for what?"); 3799. tohit = rn2(4); 3800. if (select_menu(tmpwin, PICK_ONE, &selected) > 0 3801. && rn2(P_SKILL(typ) > P_SKILLED ? 20 : 2)) 3802. tohit = selected[0].item.a_int - 1; 3803. free((genericptr_t) selected); 3804. destroy_nhwindow(tmpwin); 3805. } 3806. 3807. /* possibly scuff engraving at your feet; 3808. any engraving at the target location is unaffected */ 3809. if (tohit == 2 || !rn2(2)) 3810. u_wipe_engr(rnd(2)); 3811. 3812. /* What did you hit? */ 3813. switch (tohit) { 3814. case 0: /* Trap */ 3815. /* FIXME -- untrap needs to deal with non-adjacent traps */ 3816. break; 3817. case 1: /* Object */ 3818. if ((otmp = svl.level.objects[cc.x][cc.y]) != 0) { 3819. You("snag an object from the %s!", surface(cc.x, cc.y)); 3820. (void) pickup_object(otmp, 1L, FALSE); 3821. /* If pickup fails, leave it alone */ 3822. newsym(cc.x, cc.y); 3823. return ECMD_TIME; 3824. } 3825. break; 3826. case 2: /* Monster */ 3827. gb.bhitpos = cc; 3828. if ((mtmp = m_at(cc.x, cc.y)) == (struct monst *) 0) 3829. break; 3830. gn.notonhead = (gb.bhitpos.x != mtmp->mx || gb.bhitpos.y != mtmp->my); 3831. save_confirm = flags.confirm; 3832. if (verysmall(mtmp->data) && !rn2(4) 3833. && enexto(&cc, u.ux, u.uy, (struct permonst *) 0)) { 3834. flags.confirm = FALSE; 3835. (void) attack_checks(mtmp, uwep); 3836. flags.confirm = save_confirm; 3837. check_caitiff(mtmp); /* despite fact there's no damage */ 3838. You("pull in %s!", mon_nam(mtmp)); 3839. mtmp->mundetected = 0; 3840. rloc_to(mtmp, cc.x, cc.y); 3841. return ECMD_TIME; 3842. } else if ((!bigmonst(mtmp->data) && !strongmonst(mtmp->data)) 3843. || rn2(4)) { 3844. flags.confirm = FALSE; 3845. (void) attack_checks(mtmp, uwep); 3846. flags.confirm = save_confirm; 3847. check_caitiff(mtmp); 3848. (void) thitmonst(mtmp, uwep); 3849. return ECMD_TIME; 3850. } 3851. FALLTHROUGH; 3852. /*FALLTHRU*/ 3853. case 3: /* Surface */ 3854. if (IS_AIR(levl[cc.x][cc.y].typ) || is_pool(cc.x, cc.y)) 3855. pline_The("hook slices through the %s.", surface(cc.x, cc.y)); 3856. else { 3857. You("are yanked toward the %s!", surface(cc.x, cc.y)); 3858. hurtle(sgn(cc.x - u.ux), sgn(cc.y - u.uy), 1, FALSE); 3859. spoteffects(TRUE); 3860. } 3861. return ECMD_TIME; 3862. default: /* Yourself (oops!) */ 3863. if (P_SKILL(typ) <= P_BASIC) { 3864. You("hook yourself!"); 3865. losehp(Maybe_Half_Phys(rn1(10, 10)), "a grappling hook", 3866. KILLED_BY); 3867. return ECMD_TIME; 3868. } 3869. break; 3870. } 3871. pline1(nothing_happens); 3872. return ECMD_TIME; 3873. } 3874. 3875. staticfn void 3876. discard_broken_wand(void) 3877. { 3878. struct obj *obj; 3879. 3880. obj = gc.current_wand; /* [see dozap() and destroy_items()] */ 3881. gc.current_wand = 0; 3882. if (obj) 3883. delobj(obj); 3884. nomul(0); 3885. } 3886. 3887. staticfn void 3888. broken_wand_explode(struct obj *obj, int dmg, int expltype) 3889. { 3890. explode(u.ux, u.uy, -(obj->otyp), dmg, WAND_CLASS, expltype); 3891. makeknown(obj->otyp); /* explode describes the effect */ 3892. discard_broken_wand(); 3893. } 3894. 3895. /* if x,y has lava or water, dunk any boulders at that location into it */ 3896. void 3897. maybe_dunk_boulders(coordxy x, coordxy y) 3898. { 3899. struct obj *otmp; 3900. 3901. while (is_pool_or_lava(x, y) && (otmp = sobj_at(BOULDER, x, y)) != 0) { 3902. obj_extract_self(otmp); 3903. (void) boulder_hits_pool(otmp, x,y, FALSE); 3904. } 3905. } 3906. 3907. /* return 1 if the wand is broken, hence some time elapsed */ 3908. staticfn int 3909. do_break_wand(struct obj *obj) 3910. { 3911. #define BY_OBJECT ((struct monst *) 0) 3912. static const char nothing_else_happens[] = "But nothing else happens..."; 3913. int i; 3914. coordxy x, y; 3915. struct monst *mon; 3916. int dmg, damage; 3917. boolean affects_objects; 3918. boolean shop_damage = FALSE; 3919. boolean fillmsg = FALSE; 3920. char confirm[QBUFSZ], buf[BUFSZ]; 3921. boolean is_fragile = (objdescr_is(obj, "balsa") 3922. || objdescr_is(obj, "glass")); 3923. 3924. if (nohands(gy.youmonst.data)) { 3925. You_cant("break %s without hands!", yname(obj)); 3926. return ECMD_OK; 3927. } else if (!freehand()) { 3928. Your("%s are occupied!", makeplural(body_part(HAND))); 3929. return ECMD_OK; 3930. } else if (ACURR(A_STR) < (is_fragile ? 5 : 10)) { 3931. You("don't have the strength to break %s!", yname(obj)); 3932. return ECMD_OK; 3933. } 3934. if (!paranoid_query(ParanoidBreakwand, 3935. safe_qbuf(confirm, 3936. "Are you really sure you want to break ", 3937. "?", obj, yname, ysimple_name, "the wand"))) 3938. return ECMD_OK; 3939. pline("Raising %s high above your %s, you %s it in two!", yname(obj), 3940. body_part(HEAD), is_fragile ? "snap" : "break"); 3941. 3942. /* [ALI] Do this first so that wand is removed from bill. Otherwise, 3943. * the freeinv() below also hides it from setpaid() which causes problems. 3944. */ 3945. if (obj->unpaid) { 3946. check_unpaid(obj); /* Extra charge for use */ 3947. costly_alteration(obj, COST_DSTROY); 3948. } 3949. 3950. gc.current_wand = obj; /* destroy_items might reset this */ 3951. freeinv(obj); /* hide it from destroy_items instead... */ 3952. setnotworn(obj); /* so we need to do this ourselves */ 3953. 3954. if (!zappable(obj)) { 3955. pline(nothing_else_happens); 3956. discard_broken_wand(); 3957. return ECMD_TIME; 3958. } 3959. /* successful call to zappable() consumes a charge; put it back */ 3960. obj->spe++; 3961. /* might have "wrested" a final charge, taking it from 0 to -1; 3962. if so, we just brought it back up to 0, which wouldn't do much 3963. below so give it 1..3 charges now, usually making it stronger 3964. than an ordinary last charge (the wand is already gone from 3965. inventory, so perm_invent can't accidentally reveal this) */ 3966. if (!obj->spe) 3967. obj->spe = rnd(3); 3968. 3969. obj->ox = u.ux; 3970. obj->oy = u.uy; 3971. dmg = obj->spe * 4; 3972. affects_objects = FALSE; 3973. 3974. switch (obj->otyp) { 3975. case WAN_OPENING: 3976. if (u.ustuck) { 3977. release_hold(); 3978. if (obj->dknown) 3979. makeknown(WAN_OPENING); 3980. discard_broken_wand(); 3981. return ECMD_TIME; 3982. } 3983. FALLTHROUGH; 3984. /*FALLTHRU*/ 3985. case WAN_WISHING: 3986. case WAN_NOTHING: 3987. case WAN_LOCKING: 3988. case WAN_PROBING: 3989. case WAN_ENLIGHTENMENT: 3990. case WAN_SECRET_DOOR_DETECTION: 3991. case WAN_STASIS: 3992. pline(nothing_else_happens); 3993. discard_broken_wand(); 3994. return ECMD_TIME; 3995. case WAN_DEATH: 3996. case WAN_LIGHTNING: 3997. broken_wand_explode(obj, dmg * 4, EXPL_MAGICAL); 3998. return ECMD_TIME; 3999. case WAN_FIRE: 4000. broken_wand_explode(obj, dmg * 2, EXPL_FIERY); 4001. return ECMD_TIME; 4002. case WAN_COLD: 4003. broken_wand_explode(obj, dmg * 2, EXPL_FROSTY); 4004. return ECMD_TIME; 4005. case WAN_MAGIC_MISSILE: 4006. broken_wand_explode(obj, dmg, EXPL_MAGICAL); 4007. return ECMD_TIME; 4008. case WAN_STRIKING: 4009. /* we want this before the explosion instead of at the very end */ 4010. Soundeffect(se_wall_of_force, 65); 4011. pline("A wall of force smashes down around you!"); 4012. dmg = d(1 + obj->spe, 6); /* normally 2d12 */ 4013. FALLTHROUGH; 4014. /*FALLTHRU*/ 4015. case WAN_CANCELLATION: 4016. case WAN_POLYMORPH: 4017. case WAN_TELEPORTATION: 4018. case WAN_UNDEAD_TURNING: 4019. affects_objects = TRUE; 4020. break; 4021. default: 4022. break; 4023. } 4024. 4025. /* magical explosion and its visual effect occur before specific effects 4026. */ 4027. /* [TODO? This really ought to prevent the explosion from being 4028. fatal so that we never leave a bones file where none of the 4029. surrounding targets (or underlying objects) got affected yet.] */ 4030. explode(obj->ox, obj->oy, -(obj->otyp), rnd(dmg), WAND_CLASS, 4031. EXPL_MAGICAL); 4032. 4033. /* prepare for potential feedback from polymorph... */ 4034. zapsetup(); 4035. 4036. /* this makes it hit us last, so that we can see the action first */ 4037. for (i = 0; i <= N_DIRS; i++) { 4038. gb.bhitpos.x = x = obj->ox + xdir[i]; 4039. gb.bhitpos.y = y = obj->oy + ydir[i]; 4040. if (!isok(x, y)) 4041. continue; 4042. 4043. if (obj->otyp == WAN_DIGGING) { 4044. schar typ; 4045. enum digcheck_result dcres = dig_check(BY_OBJECT, x, y); 4046. 4047. if (dcres < DIGCHECK_FAILED || dcres == DIGCHECK_FAIL_BOULDER) { 4048. if (IS_WALL(levl[x][y].typ) || IS_DOOR(levl[x][y].typ)) { 4049. /* normally, pits and holes don't anger guards, but they 4050. * do if it's a wall or door that's being dug */ 4051. watch_dig((struct monst *) 0, x, y, TRUE); 4052. if (*in_rooms(x, y, SHOPBASE)) 4053. shop_damage = TRUE; 4054. } 4055. if (levl[x][y].typ == ICE) 4056. spot_stop_timers(x, y, MELT_ICE_AWAY); 4057. /* 4058. * Let liquid flow into the newly created pits. 4059. * Adjust corresponding code in music.c for 4060. * drum of earthquake if you alter this sequence. 4061. */ 4062. typ = fillholetyp(x, y, FALSE); 4063. if (typ != ROOM) { 4064. levl[x][y].typ = typ, levl[x][y].flags = 0; 4065. liquid_flow(x, y, typ, t_at(x, y), 4066. fillmsg 4067. ? (char *) 0 4068. : "Some holes are quickly filled with %s!"); 4069. fillmsg = TRUE; 4070. } else { 4071. digactualhole(x, y, BY_OBJECT, 4072. (rn2(obj->spe) < 3 4073. || (!Can_dig_down(&u.uz) 4074. && !levl[x][y].candig)) ? PIT : HOLE); 4075. } 4076. } 4077. fill_pit(x, y); 4078. maybe_dunk_boulders(x, y); 4079. recalc_block_point(x, y); 4080. continue; 4081. } else if (obj->otyp == WAN_CREATE_MONSTER) { 4082. /* u.ux,u.uy creates it near you--x,y might create it in rock */ 4083. (void) makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS); 4084. continue; 4085. } else if (x != u.ux || y != u.uy) { 4086. /* 4087. * Wand breakage is targeting a square adjacent to the hero, 4088. * which might contain a monster or a pile of objects or both. 4089. * Handle objects last; avoids having undead turning raise an 4090. * undead's corpse and then attack resulting undead monster. 4091. * obj->bypass in bhitm() prevents the polymorphing of items 4092. * dropped due to monster's polymorph and prevents undead 4093. * turning that kills an undead from raising resulting corpse. 4094. */ 4095. if ((mon = m_at(x, y)) != 0) { 4096. (void) bhitm(mon, obj); 4097. /* if (disp.botl) bot(); */ 4098. } 4099. if (affects_objects && svl.level.objects[x][y]) { 4100. (void) bhitpile(obj, bhito, x, y, 0); 4101. if (disp.botl) 4102. bot(); /* potion effects */ 4103. } 4104. } else { 4105. /* 4106. * Wand breakage is targeting the hero. Using xdir[]+ydir[] 4107. * deltas for location selection causes this case to happen 4108. * after all the surrounding squares have been handled. 4109. * Process objects first, in case damage is fatal and leaves 4110. * bones, or teleportation sends one or more of the objects to 4111. * same destination as hero (lookhere/autopickup); also avoids 4112. * the polymorphing of gear dropped due to hero's transformation. 4113. * (Unlike with monsters being hit by zaps, we can't rely on use 4114. * of obj->bypass in the zap code to accomplish that last case 4115. * since it's also used by retouch_equipment() for polyself.) 4116. */ 4117. if (affects_objects && svl.level.objects[x][y]) { 4118. (void) bhitpile(obj, bhito, x, y, 0); 4119. if (disp.botl) 4120. bot(); /* potion effects */ 4121. } 4122. damage = zapyourself(obj, FALSE); 4123. if (damage) { 4124. Sprintf(buf, "killed %sself by breaking a wand", uhim()); 4125. losehp(Maybe_Half_Phys(damage), buf, NO_KILLER_PREFIX); 4126. } 4127. if (disp.botl) 4128. bot(); /* blindness */ 4129. } 4130. } 4131. 4132. /* potentially give post zap/break feedback */ 4133. zapwrapup(); 4134. 4135. /* Note: if player fell thru, this call is a no-op. 4136. Damage is handled in digactualhole in that case */ 4137. if (shop_damage) 4138. pay_for_damage("dig into", FALSE); 4139. 4140. if (obj->otyp == WAN_LIGHT) 4141. litroom(TRUE, obj); /* only needs to be done once */ 4142. 4143. discard_broken_wand(); 4144. return ECMD_TIME; 4145. #undef BY_OBJECT 4146. } 4147. 4148. /* getobj callback for object to apply - this is more complex than most other 4149. * callbacks because there are a lot of appliables */ 4150. staticfn int 4151. apply_ok(struct obj *obj) 4152. { 4153. if (!obj) 4154. return GETOBJ_EXCLUDE; 4155. 4156. /* all tools, all wands (breaking), all spellbooks (flipping through - 4157. including blank/novel/Book of the Dead) */ 4158. if (obj->oclass == TOOL_CLASS || obj->oclass == WAND_CLASS 4159. || obj->oclass == SPBOOK_CLASS) 4160. return GETOBJ_SUGGEST; 4161. 4162. /* applying coins to flip them is a minor easter egg, so do not suggest 4163. coin application to the player */ 4164. if (obj->oclass == COIN_CLASS) 4165. return GETOBJ_DOWNPLAY; 4166. 4167. /* certain weapons */ 4168. if (obj->oclass == WEAPON_CLASS 4169. && (is_pick(obj) || is_axe(obj) || is_pole(obj) 4170. || obj->otyp == BULLWHIP)) 4171. return GETOBJ_SUGGEST; 4172. 4173. if (obj->oclass == POTION_CLASS) { 4174. /* permit applying unknown potions, but don't suggest them */ 4175. if (!obj->dknown || !objects[obj->otyp].oc_name_known) 4176. return GETOBJ_DOWNPLAY; 4177. 4178. /* only applicable potion is oil, and it will only be suggested as a 4179. choice when already discovered */ 4180. if (obj->otyp == POT_OIL) 4181. return GETOBJ_SUGGEST; 4182. } 4183. 4184. /* certain foods */ 4185. if (obj->otyp == CREAM_PIE || obj->otyp == EUCALYPTUS_LEAF 4186. || obj->otyp == LUMP_OF_ROYAL_JELLY) 4187. return GETOBJ_SUGGEST; 4188. 4189. if (obj->otyp == BANANA && Hallucination) 4190. return GETOBJ_DOWNPLAY; 4191. 4192. if (is_graystone(obj)) { 4193. /* The only case where we don't suggest a gray stone is if we KNOW it 4194. isn't a touchstone. */ 4195. if (!obj->dknown) 4196. return GETOBJ_SUGGEST; 4197. 4198. if (obj->otyp != TOUCHSTONE 4199. && (objects[TOUCHSTONE].oc_name_known 4200. || objects[obj->otyp].oc_name_known)) 4201. return GETOBJ_EXCLUDE_SELECTABLE; 4202. 4203. return GETOBJ_SUGGEST; 4204. } 4205. 4206. /* item can't be applied; if picked anyway, 4207. _EXCLUDE would yield "That is a silly thing to apply.", 4208. _EXCLUDE_SELECTABLE yields "Sorry, I don't know how to use that." */ 4209. return GETOBJ_EXCLUDE_SELECTABLE; 4210. } 4211. 4212. /* the #apply command, 'a' */ 4213. int 4214. doapply(void) 4215. { 4216. struct obj *obj; 4217. int res = ECMD_TIME; 4218. 4219. if (nohands(gy.youmonst.data)) { 4220. You("aren't able to use or apply tools in your current form."); 4221. return ECMD_OK; 4222. } 4223. if (check_capacity((char *) 0)) 4224. return ECMD_OK; 4225. 4226. obj = getobj("use or apply", apply_ok, GETOBJ_NOFLAGS); 4227. if (!obj) 4228. return ECMD_CANCEL; 4229. 4230. if (!retouch_object(&obj, FALSE)) 4231. return ECMD_TIME; /* evading your grasp costs a turn; just be 4232. grateful that you don't drop it as well */ 4233. 4234. if (obj->oclass == WAND_CLASS) 4235. return do_break_wand(obj); 4236. 4237. if (obj->oclass == SPBOOK_CLASS) 4238. return flip_through_book(obj); 4239. 4240. if (obj->oclass == COIN_CLASS) 4241. return flip_coin(obj); 4242. 4243. switch (obj->otyp) { 4244. case BLINDFOLD: 4245. case LENSES: 4246. if (obj == ublindf) { 4247. if (!cursed(obj)) 4248. Blindf_off(obj); 4249. } else if (!ublindf) { 4250. Blindf_on(obj); 4251. } else { 4252. You("are already %s.", 4253. (ublindf->otyp == TOWEL) ? "covered by a towel" 4254. : (ublindf->otyp == BLINDFOLD) ? "wearing a blindfold" 4255. : "wearing lenses"); 4256. } 4257. break; 4258. case CREAM_PIE: 4259. res = use_cream_pie(obj); 4260. obj = (struct obj *) 0; 4261. break; 4262. case LUMP_OF_ROYAL_JELLY: 4263. res = use_royal_jelly(&obj); 4264. break; 4265. case BULLWHIP: 4266. res = use_whip(obj); 4267. break; 4268. case GRAPPLING_HOOK: 4269. res = use_grapple(obj); 4270. break; 4271. case LARGE_BOX: 4272. case CHEST: 4273. case ICE_BOX: 4274. case SACK: 4275. case BAG_OF_HOLDING: 4276. case OILSKIN_SACK: 4277. res = use_container(&obj, TRUE, FALSE); 4278. break; 4279. case BAG_OF_TRICKS: 4280. (void) bagotricks(obj, FALSE, (int *) 0); 4281. break; 4282. case CAN_OF_GREASE: 4283. res = use_grease(obj); 4284. break; 4285. case LOCK_PICK: 4286. case CREDIT_CARD: 4287. case SKELETON_KEY: 4288. res = (pick_lock(obj, 0, 0, NULL) != 0) ? ECMD_TIME : ECMD_OK; 4289. break; 4290. case PICK_AXE: 4291. case DWARVISH_MATTOCK: 4292. res = use_pick_axe(obj); 4293. break; 4294. case TINNING_KIT: 4295. use_tinning_kit(obj); 4296. break; 4297. case LEASH: 4298. res = use_leash(obj); 4299. break; 4300. case SADDLE: 4301. res = use_saddle(obj); 4302. break; 4303. case MAGIC_WHISTLE: 4304. use_magic_whistle(obj); 4305. break; 4306. case TIN_WHISTLE: 4307. use_whistle(obj); 4308. break; 4309. case EUCALYPTUS_LEAF: 4310. /* MRKR: Every Australian knows that a gum leaf makes an excellent 4311. * whistle, especially if your pet is a tame kangaroo named Skippy. 4312. */ 4313. if (obj->blessed) { 4314. use_magic_whistle(obj); 4315. /* sometimes the blessing will be worn off */ 4316. if (!rn2(49)) { 4317. if (!Blind) { 4318. pline("%s %s.", Yobjnam2(obj, "glow"), hcolor("brown")); 4319. set_bknown(obj, 1); 4320. } 4321. unbless(obj); 4322. } 4323. } else { 4324. use_whistle(obj); 4325. } 4326. break; 4327. case STETHOSCOPE: 4328. res = use_stethoscope(obj); 4329. break; 4330. case MIRROR: 4331. res = use_mirror(obj); 4332. break; 4333. case BELL: 4334. case BELL_OF_OPENING: 4335. use_bell(&obj); 4336. break; 4337. case CANDELABRUM_OF_INVOCATION: 4338. use_candelabrum(obj); 4339. break; 4340. case WAX_CANDLE: 4341. case TALLOW_CANDLE: 4342. use_candle(&obj); 4343. break; 4344. case OIL_LAMP: 4345. case MAGIC_LAMP: 4346. case BRASS_LANTERN: 4347. use_lamp(obj); 4348. break; 4349. case POT_OIL: 4350. light_cocktail(&obj); 4351. break; 4352. case EXPENSIVE_CAMERA: 4353. res = use_camera(obj); 4354. break; 4355. case TOWEL: 4356. res = use_towel(obj); 4357. break; 4358. case CRYSTAL_BALL: 4359. use_crystal_ball(&obj); 4360. break; 4361. case MAGIC_MARKER: 4362. res = dowrite(obj); 4363. break; 4364. case TIN_OPENER: 4365. res = use_tin_opener(obj); 4366. break; 4367. case FIGURINE: 4368. res = use_figurine(&obj); 4369. break; 4370. case UNICORN_HORN: 4371. use_unicorn_horn(&obj); 4372. break; 4373. case WOODEN_FLUTE: 4374. case MAGIC_FLUTE: 4375. case TOOLED_HORN: 4376. case FROST_HORN: 4377. case FIRE_HORN: 4378. case WOODEN_HARP: 4379. case MAGIC_HARP: 4380. case BUGLE: 4381. case LEATHER_DRUM: 4382. case DRUM_OF_EARTHQUAKE: 4383. res = do_play_instrument(obj); 4384. break; 4385. case HORN_OF_PLENTY: /* not a musical instrument */ 4386. (void) hornoplenty(obj, FALSE, (struct obj *) 0); 4387. break; 4388. case LAND_MINE: 4389. case BEARTRAP: 4390. use_trap(obj); 4391. if (go.occupation == set_trap) 4392. obj = (struct obj *) 0; /* not gone yet but behave as if it was */ 4393. break; 4394. case FLINT: 4395. case LUCKSTONE: 4396. case LOADSTONE: 4397. case TOUCHSTONE: 4398. res = use_stone(obj); 4399. break; 4400. case BANANA: 4401. if (Hallucination) { 4402. pline("It rings! ... But no-one answers."); 4403. break; 4404. } 4405. FALLTHROUGH; 4406. /*FALLTHRU*/ 4407. default: 4408. /* Pole-weapons can strike at a distance */ 4409. if (is_pole(obj)) { 4410. res = use_pole(obj, FALSE); 4411. break; 4412. } else if (is_pick(obj) || is_axe(obj)) { 4413. res = use_pick_axe(obj); 4414. break; 4415. } 4416. pline("Sorry, I don't know how to use that."); 4417. return ECMD_FAIL; 4418. } 4419. /* This assumes that anything that potentially destroyed obj has kept 4420. * track of it and set obj to null before this point. */ 4421. if (obj && obj->oartifact) { 4422. res |= arti_speak(obj); /* sets ECMD_TIME bit if artifact speaks */ 4423. } 4424. return res; 4425. } 4426. 4427. /* Keep track of unfixable troubles for purposes of messages saying you feel 4428. * great. 4429. */ 4430. int 4431. unfixable_trouble_count(boolean is_horn) 4432. { 4433. int unfixable_trbl = 0; 4434. 4435. if (Stoned) 4436. unfixable_trbl++; 4437. if (Slimed) 4438. unfixable_trbl++; 4439. if (Strangled) 4440. unfixable_trbl++; 4441. if (ATEMP(A_DEX) < 0 && Wounded_legs) 4442. unfixable_trbl++; 4443. if (ATEMP(A_STR) < 0 && u.uhs >= WEAK) 4444. unfixable_trbl++; 4445. /* lycanthropy is undesirable, but it doesn't actually make you feel bad 4446. so don't count it as a trouble which can't be fixed */ 4447. 4448. /* 4449. * Unicorn horn can fix these when they're timed but not when 4450. * they aren't. Potion of restore ability doesn't touch them, 4451. * so they're always unfixable for the not-unihorn case. 4452. * [Most of these are timed only, so always curable via horn. 4453. * An exception is Stunned, which can be forced On by certain 4454. * polymorph forms (stalker, bats).] 4455. */ 4456. if (Sick && (!is_horn || (Sick & ~TIMEOUT) != 0L)) 4457. unfixable_trbl++; 4458. if (Stunned && (!is_horn || (HStun & ~TIMEOUT) != 0L)) 4459. unfixable_trbl++; 4460. if (Confusion && (!is_horn || (HConfusion & ~TIMEOUT) != 0L)) 4461. unfixable_trbl++; 4462. if (Hallucination && (!is_horn || (HHallucination & ~TIMEOUT) != 0L)) 4463. unfixable_trbl++; 4464. if (Vomiting && (!is_horn || (Vomiting & ~TIMEOUT) != 0L)) 4465. unfixable_trbl++; 4466. if (Deaf && (!is_horn || (HDeaf & ~TIMEOUT) != 0L)) 4467. unfixable_trbl++; 4468. 4469. return unfixable_trbl; 4470. } 4471. 4472. staticfn int 4473. flip_through_book(struct obj *obj) 4474. { 4475. if (Underwater) { 4476. You("don't want to get the pages even more soggy, do you?"); 4477. return ECMD_OK; 4478. } 4479. 4480. You("flip through the pages of %s.", thesimpleoname(obj)); 4481. 4482. if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { 4483. if (!Deaf) { 4484. if (!Hallucination) { 4485. Soundeffect(se_rustling_paper, 50); 4486. } 4487. You_hear("the pages make an unpleasant %s sound.", 4488. Hallucination ? "chuckling" 4489. : "rustling"); 4490. } else if (!Blind) { 4491. You_see("the pages glow faintly %s.", hcolor(NH_RED)); 4492. } else { 4493. You_feel("the pages tremble."); 4494. } 4495. } else if (Blind) { 4496. pline("The pages feel %s.", 4497. Hallucination ? "freshly picked" 4498. : "rough and dry"); 4499. } else if (obj->otyp == SPE_BLANK_PAPER) { 4500. pline("This spellbook %s.", 4501. Hallucination ? "doesn't have much of a plot" 4502. : "has nothing written in it"); 4503. makeknown(obj->otyp); 4504. } else if (Hallucination) { 4505. You("enjoy the animated initials."); 4506. } else if (obj->otyp == SPE_NOVEL) { 4507. pline("This looks like it might be interesting to read."); 4508. } else { 4509. static const char *const fadeness[] = { 4510. "fresh", 4511. "slightly faded", 4512. "very faded", 4513. "extremely faded", 4514. "barely visible" 4515. }; 4516. int findx = min(obj->spestudied, MAX_SPELL_STUDY); 4517. 4518. pline("The%s ink in this spellbook is %s.", 4519. objects[obj->otyp].oc_magic ? " magical" : "", 4520. fadeness[findx]); 4521. } 4522. 4523. return ECMD_TIME; 4524. } 4525. 4526. staticfn int 4527. flip_coin(struct obj *obj) 4528. { 4529. struct obj *otmp = obj; 4530. boolean lose_coin = FALSE; 4531. 4532. You("flip %s.", an(singular(obj, xname))); 4533. if (Underwater) { 4534. pline("It tumbles away."); 4535. lose_coin = TRUE; 4536. } else if (Glib || Fumbling 4537. || (ACURR(A_DEX) < 10 && !rn2(ACURR(A_DEX)))) { 4538. pline("It slips between your %s.", fingers_or_gloves(FALSE)); 4539. lose_coin = TRUE; 4540. } 4541. 4542. if (lose_coin) { 4543. if (otmp->quan > 1L) 4544. otmp = splitobj(otmp, 1L); 4545. dropx(otmp); 4546. return ECMD_TIME; 4547. } 4548. if (Hallucination) { 4549. pline(rn2(100) ? "Wow, a double header!" 4550. /* edge case */ 4551. : "The coin miraculously lands on its edge!"); 4552. } else { 4553. pline("It comes up %s.", rn2(2) ? "heads" : "tails"); 4554. } 4555. return ECMD_TIME; 4556. } 4557. 4558. /*apply.c*/