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