Source:NetHack 3.6.4/src/artifact.c
Jump to navigation
Jump to search
Below is the full text to artifact.c from the source code of NetHack 3.6.4. To link to a particular line, write [[Source:NetHack 3.6.4/src/artifact.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 artifact.c $NHDT-Date: 1553363416 2019/03/23 17:50:16 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.129 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2013. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. #include "artifact.h" 8. #include "artilist.h" 9. 10. /* 11. * Note: both artilist[] and artiexist[] have a dummy element #0, 12. * so loops over them should normally start at #1. The primary 13. * exception is the save & restore code, which doesn't care about 14. * the contents, just the total size. 15. */ 16. 17. extern boolean notonhead; /* for long worms */ 18. 19. #define get_artifact(o) \ 20. (((o) && (o)->oartifact) ? &artilist[(int) (o)->oartifact] : 0) 21. 22. STATIC_DCL boolean FDECL(bane_applies, (const struct artifact *, 23. struct monst *)); 24. STATIC_DCL int FDECL(spec_applies, (const struct artifact *, struct monst *)); 25. STATIC_DCL int FDECL(arti_invoke, (struct obj *)); 26. STATIC_DCL boolean FDECL(Mb_hit, (struct monst * magr, struct monst *mdef, 27. struct obj *, int *, int, BOOLEAN_P, char *)); 28. STATIC_DCL unsigned long FDECL(abil_to_spfx, (long *)); 29. STATIC_DCL uchar FDECL(abil_to_adtyp, (long *)); 30. STATIC_DCL int FDECL(glow_strength, (int)); 31. STATIC_DCL boolean FDECL(untouchable, (struct obj *, BOOLEAN_P)); 32. STATIC_DCL int FDECL(count_surround_traps, (int, int)); 33. 34. /* The amount added to the victim's total hit points to insure that the 35. victim will be killed even after damage bonus/penalty adjustments. 36. Most such penalties are small, and 200 is plenty; the exception is 37. half physical damage. 3.3.1 and previous versions tried to use a very 38. large number to account for this case; now, we just compute the fatal 39. damage by adding it to 2 times the total hit points instead of 1 time. 40. Note: this will still break if they have more than about half the number 41. of hit points that will fit in a 15 bit integer. */ 42. #define FATAL_DAMAGE_MODIFIER 200 43. 44. /* coordinate effects from spec_dbon() with messages in artifact_hit() */ 45. STATIC_OVL int spec_dbon_applies = 0; 46. 47. /* flags including which artifacts have already been created */ 48. static boolean artiexist[1 + NROFARTIFACTS + 1]; 49. /* and a discovery list for them (no dummy first entry here) */ 50. STATIC_OVL xchar artidisco[NROFARTIFACTS]; 51. 52. STATIC_DCL void NDECL(hack_artifacts); 53. STATIC_DCL boolean FDECL(attacks, (int, struct obj *)); 54. 55. /* handle some special cases; must be called after u_init() */ 56. STATIC_OVL void 57. hack_artifacts() 58. { 59. struct artifact *art; 60. int alignmnt = aligns[flags.initalign].value; 61. 62. /* Fix up the alignments of "gift" artifacts */ 63. for (art = artilist + 1; art->otyp; art++) 64. if (art->role == Role_switch && art->alignment != A_NONE) 65. art->alignment = alignmnt; 66. 67. /* Excalibur can be used by any lawful character, not just knights */ 68. if (!Role_if(PM_KNIGHT)) 69. artilist[ART_EXCALIBUR].role = NON_PM; 70. 71. /* Fix up the quest artifact */ 72. if (urole.questarti) { 73. artilist[urole.questarti].alignment = alignmnt; 74. artilist[urole.questarti].role = Role_switch; 75. } 76. return; 77. } 78. 79. /* zero out the artifact existence list */ 80. void 81. init_artifacts() 82. { 83. (void) memset((genericptr_t) artiexist, 0, sizeof artiexist); 84. (void) memset((genericptr_t) artidisco, 0, sizeof artidisco); 85. hack_artifacts(); 86. } 87. 88. void 89. save_artifacts(fd) 90. int fd; 91. { 92. bwrite(fd, (genericptr_t) artiexist, sizeof artiexist); 93. bwrite(fd, (genericptr_t) artidisco, sizeof artidisco); 94. } 95. 96. void 97. restore_artifacts(fd) 98. int fd; 99. { 100. mread(fd, (genericptr_t) artiexist, sizeof artiexist); 101. mread(fd, (genericptr_t) artidisco, sizeof artidisco); 102. hack_artifacts(); /* redo non-saved special cases */ 103. } 104. 105. const char * 106. artiname(artinum) 107. int artinum; 108. { 109. if (artinum <= 0 || artinum > NROFARTIFACTS) 110. return ""; 111. return artilist[artinum].name; 112. } 113. 114. /* 115. Make an artifact. If a specific alignment is specified, then an object of 116. the appropriate alignment is created from scratch, or 0 is returned if 117. none is available. (If at least one aligned artifact has already been 118. given, then unaligned ones also become eligible for this.) 119. If no alignment is given, then 'otmp' is converted 120. into an artifact of matching type, or returned as-is if that's not 121. possible. 122. For the 2nd case, caller should use ``obj = mk_artifact(obj, A_NONE); 123. for the 1st, ``obj = mk_artifact((struct obj *)0, some_alignment);. 124. */ 125. struct obj * 126. mk_artifact(otmp, alignment) 127. struct obj *otmp; /* existing object; ignored if alignment specified */ 128. aligntyp alignment; /* target alignment, or A_NONE */ 129. { 130. const struct artifact *a; 131. int m, n, altn; 132. boolean by_align = (alignment != A_NONE); 133. short o_typ = (by_align || !otmp) ? 0 : otmp->otyp; 134. boolean unique = !by_align && otmp && objects[o_typ].oc_unique; 135. short eligible[NROFARTIFACTS]; 136. 137. n = altn = 0; /* no candidates found yet */ 138. eligible[0] = 0; /* lint suppression */ 139. /* gather eligible artifacts */ 140. for (m = 1, a = &artilist[m]; a->otyp; a++, m++) { 141. if (artiexist[m]) 142. continue; 143. if ((a->spfx & SPFX_NOGEN) || unique) 144. continue; 145. 146. if (!by_align) { 147. /* looking for a particular type of item; not producing a 148. divine gift so we don't care about role's first choice */ 149. if (a->otyp == o_typ) 150. eligible[n++] = m; 151. continue; /* move on to next possibility */ 152. } 153. 154. /* we're looking for an alignment-specific item 155. suitable for hero's role+race */ 156. if ((a->alignment == alignment || a->alignment == A_NONE) 157. /* avoid enemies' equipment */ 158. && (a->race == NON_PM || !race_hostile(&mons[a->race]))) { 159. /* when a role-specific first choice is available, use it */ 160. if (Role_if(a->role)) { 161. /* make this be the only possibility in the list */ 162. eligible[0] = m; 163. n = 1; 164. break; /* skip all other candidates */ 165. } 166. /* found something to consider for random selection */ 167. if (a->alignment != A_NONE || u.ugifts > 0) { 168. /* right alignment, or non-aligned with at least 1 169. previous gift bestowed, makes this one viable */ 170. eligible[n++] = m; 171. } else { 172. /* non-aligned with no previous gifts; 173. if no candidates have been found yet, record 174. this one as a[nother] fallback possibility in 175. case all aligned candidates have been used up 176. (via wishing, naming, bones, random generation) */ 177. if (!n) 178. eligible[altn++] = m; 179. /* [once a regular candidate is found, the list 180. is overwritten and `altn' becomes irrelevant] */ 181. } 182. } 183. } 184. 185. /* resort to fallback list if main list was empty */ 186. if (!n) 187. n = altn; 188. 189. if (n) { 190. /* found at least one candidate; pick one at random */ 191. m = eligible[rn2(n)]; /* [0..n-1] */ 192. a = &artilist[m]; 193. 194. /* make an appropriate object if necessary, then christen it */ 195. if (by_align) 196. otmp = mksobj((int) a->otyp, TRUE, FALSE); 197. 198. if (otmp) { 199. otmp = oname(otmp, a->name); 200. otmp->oartifact = m; 201. artiexist[m] = TRUE; 202. } 203. } else { 204. /* nothing appropriate could be found; return original object */ 205. if (by_align) 206. otmp = 0; /* (there was no original object) */ 207. } 208. return otmp; 209. } 210. 211. /* 212. * Returns the full name (with articles and correct capitalization) of an 213. * artifact named "name" if one exists, or NULL, it not. 214. * The given name must be rather close to the real name for it to match. 215. * The object type of the artifact is returned in otyp if the return value 216. * is non-NULL. 217. */ 218. const char * 219. artifact_name(name, otyp) 220. const char *name; 221. short *otyp; 222. { 223. register const struct artifact *a; 224. register const char *aname; 225. 226. if (!strncmpi(name, "the ", 4)) 227. name += 4; 228. 229. for (a = artilist + 1; a->otyp; a++) { 230. aname = a->name; 231. if (!strncmpi(aname, "the ", 4)) 232. aname += 4; 233. if (!strcmpi(name, aname)) { 234. *otyp = a->otyp; 235. return a->name; 236. } 237. } 238. 239. return (char *) 0; 240. } 241. 242. boolean 243. exist_artifact(otyp, name) 244. int otyp; 245. const char *name; 246. { 247. register const struct artifact *a; 248. boolean *arex; 249. 250. if (otyp && *name) 251. for (a = artilist + 1, arex = artiexist + 1; a->otyp; a++, arex++) 252. if ((int) a->otyp == otyp && !strcmp(a->name, name)) 253. return *arex; 254. return FALSE; 255. } 256. 257. void 258. artifact_exists(otmp, name, mod) 259. struct obj *otmp; 260. const char *name; 261. boolean mod; 262. { 263. register const struct artifact *a; 264. 265. if (otmp && *name) 266. for (a = artilist + 1; a->otyp; a++) 267. if (a->otyp == otmp->otyp && !strcmp(a->name, name)) { 268. register int m = (int) (a - artilist); 269. otmp->oartifact = (char) (mod ? m : 0); 270. otmp->age = 0; 271. if (otmp->otyp == RIN_INCREASE_DAMAGE) 272. otmp->spe = 0; 273. artiexist[m] = mod; 274. break; 275. } 276. return; 277. } 278. 279. int 280. nartifact_exist() 281. { 282. int a = 0; 283. int n = SIZE(artiexist); 284. 285. while (n > 1) 286. if (artiexist[--n]) 287. a++; 288. 289. return a; 290. } 291. 292. boolean 293. spec_ability(otmp, abil) 294. struct obj *otmp; 295. unsigned long abil; 296. { 297. const struct artifact *arti = get_artifact(otmp); 298. 299. return (boolean) (arti && (arti->spfx & abil) != 0L); 300. } 301. 302. /* used so that callers don't need to known about SPFX_ codes */ 303. boolean 304. confers_luck(obj) 305. struct obj *obj; 306. { 307. /* might as well check for this too */ 308. if (obj->otyp == LUCKSTONE) 309. return TRUE; 310. 311. return (boolean) (obj->oartifact && spec_ability(obj, SPFX_LUCK)); 312. } 313. 314. /* used to check whether a monster is getting reflection from an artifact */ 315. boolean 316. arti_reflects(obj) 317. struct obj *obj; 318. { 319. const struct artifact *arti = get_artifact(obj); 320. 321. if (arti) { 322. /* while being worn */ 323. if ((obj->owornmask & ~W_ART) && (arti->spfx & SPFX_REFLECT)) 324. return TRUE; 325. /* just being carried */ 326. if (arti->cspfx & SPFX_REFLECT) 327. return TRUE; 328. } 329. return FALSE; 330. } 331. 332. /* decide whether this obj is effective when attacking against shades; 333. does not consider the bonus for blessed objects versus undead */ 334. boolean 335. shade_glare(obj) 336. struct obj *obj; 337. { 338. const struct artifact *arti; 339. 340. /* any silver object is effective */ 341. if (objects[obj->otyp].oc_material == SILVER) 342. return TRUE; 343. /* non-silver artifacts with bonus against undead also are effective */ 344. arti = get_artifact(obj); 345. if (arti && (arti->spfx & SPFX_DFLAG2) && arti->mtype == M2_UNDEAD) 346. return TRUE; 347. /* [if there was anything with special bonus against noncorporeals, 348. it would be effective too] */ 349. /* otherwise, harmless to shades */ 350. return FALSE; 351. } 352. 353. /* returns 1 if name is restricted for otmp->otyp */ 354. boolean 355. restrict_name(otmp, name) 356. struct obj *otmp; 357. const char *name; 358. { 359. register const struct artifact *a; 360. const char *aname, *odesc, *other; 361. boolean sametype[NUM_OBJECTS]; 362. int i, lo, hi, otyp = otmp->otyp, ocls = objects[otyp].oc_class; 363. 364. if (!*name) 365. return FALSE; 366. if (!strncmpi(name, "the ", 4)) 367. name += 4; 368. 369. /* decide what types of objects are the same as otyp; 370. if it's been discovered, then only itself matches; 371. otherwise, include all other undiscovered objects 372. of the same class which have the same description 373. or share the same pool of shuffled descriptions */ 374. (void) memset((genericptr_t) sametype, 0, sizeof sametype); /* FALSE */ 375. sametype[otyp] = TRUE; 376. if (!objects[otyp].oc_name_known 377. && (odesc = OBJ_DESCR(objects[otyp])) != 0) { 378. obj_shuffle_range(otyp, &lo, &hi); 379. for (i = bases[ocls]; i < NUM_OBJECTS; i++) { 380. if (objects[i].oc_class != ocls) 381. break; 382. if (!objects[i].oc_name_known 383. && (other = OBJ_DESCR(objects[i])) != 0 384. && (!strcmp(odesc, other) || (i >= lo && i <= hi))) 385. sametype[i] = TRUE; 386. } 387. } 388. 389. /* Since almost every artifact is SPFX_RESTR, it doesn't cost 390. us much to do the string comparison before the spfx check. 391. Bug fix: don't name multiple elven daggers "Sting". 392. */ 393. for (a = artilist + 1; a->otyp; a++) { 394. if (!sametype[a->otyp]) 395. continue; 396. aname = a->name; 397. if (!strncmpi(aname, "the ", 4)) 398. aname += 4; 399. if (!strcmp(aname, name)) 400. return (boolean) ((a->spfx & (SPFX_NOGEN | SPFX_RESTR)) != 0 401. || otmp->quan > 1L); 402. } 403. 404. return FALSE; 405. } 406. 407. STATIC_OVL boolean 408. attacks(adtyp, otmp) 409. int adtyp; 410. struct obj *otmp; 411. { 412. register const struct artifact *weap; 413. 414. if ((weap = get_artifact(otmp)) != 0) 415. return (boolean) (weap->attk.adtyp == adtyp); 416. return FALSE; 417. } 418. 419. boolean 420. defends(adtyp, otmp) 421. int adtyp; 422. struct obj *otmp; 423. { 424. register const struct artifact *weap; 425. 426. if ((weap = get_artifact(otmp)) != 0) 427. return (boolean) (weap->defn.adtyp == adtyp); 428. return FALSE; 429. } 430. 431. /* used for monsters */ 432. boolean 433. defends_when_carried(adtyp, otmp) 434. int adtyp; 435. struct obj *otmp; 436. { 437. register const struct artifact *weap; 438. 439. if ((weap = get_artifact(otmp)) != 0) 440. return (boolean) (weap->cary.adtyp == adtyp); 441. return FALSE; 442. } 443. 444. /* determine whether an item confers Protection */ 445. boolean 446. protects(otmp, being_worn) 447. struct obj *otmp; 448. boolean being_worn; 449. { 450. const struct artifact *arti; 451. 452. if (being_worn && objects[otmp->otyp].oc_oprop == PROTECTION) 453. return TRUE; 454. arti = get_artifact(otmp); 455. if (!arti) 456. return FALSE; 457. return (boolean) ((arti->cspfx & SPFX_PROTECT) != 0 458. || (being_worn && (arti->spfx & SPFX_PROTECT) != 0)); 459. } 460. 461. /* 462. * a potential artifact has just been worn/wielded/picked-up or 463. * unworn/unwielded/dropped. Pickup/drop only set/reset the W_ART mask. 464. */ 465. void 466. set_artifact_intrinsic(otmp, on, wp_mask) 467. struct obj *otmp; 468. boolean on; 469. long wp_mask; 470. { 471. long *mask = 0; 472. register const struct artifact *art, *oart = get_artifact(otmp); 473. register struct obj *obj; 474. register uchar dtyp; 475. register long spfx; 476. 477. if (!oart) 478. return; 479. 480. /* effects from the defn field */ 481. dtyp = (wp_mask != W_ART) ? oart->defn.adtyp : oart->cary.adtyp; 482. 483. if (dtyp == AD_FIRE) 484. mask = &EFire_resistance; 485. else if (dtyp == AD_COLD) 486. mask = &ECold_resistance; 487. else if (dtyp == AD_ELEC) 488. mask = &EShock_resistance; 489. else if (dtyp == AD_MAGM) 490. mask = &EAntimagic; 491. else if (dtyp == AD_DISN) 492. mask = &EDisint_resistance; 493. else if (dtyp == AD_DRST) 494. mask = &EPoison_resistance; 495. else if (dtyp == AD_DRLI) 496. mask = &EDrain_resistance; 497. 498. if (mask && wp_mask == W_ART && !on) { 499. /* find out if some other artifact also confers this intrinsic; 500. if so, leave the mask alone */ 501. for (obj = invent; obj; obj = obj->nobj) { 502. if (obj != otmp && obj->oartifact) { 503. art = get_artifact(obj); 504. if (art && art->cary.adtyp == dtyp) { 505. mask = (long *) 0; 506. break; 507. } 508. } 509. } 510. } 511. if (mask) { 512. if (on) 513. *mask |= wp_mask; 514. else 515. *mask &= ~wp_mask; 516. } 517. 518. /* intrinsics from the spfx field; there could be more than one */ 519. spfx = (wp_mask != W_ART) ? oart->spfx : oart->cspfx; 520. if (spfx && wp_mask == W_ART && !on) { 521. /* don't change any spfx also conferred by other artifacts */ 522. for (obj = invent; obj; obj = obj->nobj) 523. if (obj != otmp && obj->oartifact) { 524. art = get_artifact(obj); 525. if (art) 526. spfx &= ~art->cspfx; 527. } 528. } 529. 530. if (spfx & SPFX_SEARCH) { 531. if (on) 532. ESearching |= wp_mask; 533. else 534. ESearching &= ~wp_mask; 535. } 536. if (spfx & SPFX_HALRES) { 537. /* make_hallucinated must (re)set the mask itself to get 538. * the display right */ 539. /* restoring needed because this is the only artifact intrinsic 540. * that can print a message--need to guard against being printed 541. * when restoring a game 542. */ 543. (void) make_hallucinated((long) !on, restoring ? FALSE : TRUE, 544. wp_mask); 545. } 546. if (spfx & SPFX_ESP) { 547. if (on) 548. ETelepat |= wp_mask; 549. else 550. ETelepat &= ~wp_mask; 551. see_monsters(); 552. } 553. if (spfx & SPFX_STLTH) { 554. if (on) 555. EStealth |= wp_mask; 556. else 557. EStealth &= ~wp_mask; 558. } 559. if (spfx & SPFX_REGEN) { 560. if (on) 561. ERegeneration |= wp_mask; 562. else 563. ERegeneration &= ~wp_mask; 564. } 565. if (spfx & SPFX_TCTRL) { 566. if (on) 567. ETeleport_control |= wp_mask; 568. else 569. ETeleport_control &= ~wp_mask; 570. } 571. if (spfx & SPFX_WARN) { 572. if (spec_m2(otmp)) { 573. if (on) { 574. EWarn_of_mon |= wp_mask; 575. context.warntype.obj |= spec_m2(otmp); 576. } else { 577. EWarn_of_mon &= ~wp_mask; 578. context.warntype.obj &= ~spec_m2(otmp); 579. } 580. see_monsters(); 581. } else { 582. if (on) 583. EWarning |= wp_mask; 584. else 585. EWarning &= ~wp_mask; 586. } 587. } 588. if (spfx & SPFX_EREGEN) { 589. if (on) 590. EEnergy_regeneration |= wp_mask; 591. else 592. EEnergy_regeneration &= ~wp_mask; 593. } 594. if (spfx & SPFX_HSPDAM) { 595. if (on) 596. EHalf_spell_damage |= wp_mask; 597. else 598. EHalf_spell_damage &= ~wp_mask; 599. } 600. if (spfx & SPFX_HPHDAM) { 601. if (on) 602. EHalf_physical_damage |= wp_mask; 603. else 604. EHalf_physical_damage &= ~wp_mask; 605. } 606. if (spfx & SPFX_XRAY) { 607. /* this assumes that no one else is using xray_range */ 608. if (on) 609. u.xray_range = 3; 610. else 611. u.xray_range = -1; 612. vision_full_recalc = 1; 613. } 614. if ((spfx & SPFX_REFLECT) && (wp_mask & W_WEP)) { 615. if (on) 616. EReflecting |= wp_mask; 617. else 618. EReflecting &= ~wp_mask; 619. } 620. if (spfx & SPFX_PROTECT) { 621. if (on) 622. EProtection |= wp_mask; 623. else 624. EProtection &= ~wp_mask; 625. } 626. 627. if (wp_mask == W_ART && !on && oart->inv_prop) { 628. /* might have to turn off invoked power too */ 629. if (oart->inv_prop <= LAST_PROP 630. && (u.uprops[oart->inv_prop].extrinsic & W_ARTI)) 631. (void) arti_invoke(otmp); 632. } 633. } 634. 635. /* touch_artifact()'s return value isn't sufficient to tell whether it 636. dished out damage, and tracking changes to u.uhp, u.mh, Lifesaved 637. when trying to avoid second wounding is too cumbersome */ 638. STATIC_VAR boolean touch_blasted; /* for retouch_object() */ 639. 640. /* 641. * creature (usually hero) tries to touch (pick up or wield) an artifact obj. 642. * Returns 0 if the object refuses to be touched. 643. * This routine does not change any object chains. 644. * Ignores such things as gauntlets, assuming the artifact is not 645. * fooled by such trappings. 646. */ 647. int 648. touch_artifact(obj, mon) 649. struct obj *obj; 650. struct monst *mon; 651. { 652. register const struct artifact *oart = get_artifact(obj); 653. boolean badclass, badalign, self_willed, yours; 654. 655. touch_blasted = FALSE; 656. if (!oart) 657. return 1; 658. 659. yours = (mon == &youmonst); 660. /* all quest artifacts are self-willed; if this ever changes, `badclass' 661. will have to be extended to explicitly include quest artifacts */ 662. self_willed = ((oart->spfx & SPFX_INTEL) != 0); 663. if (yours) { 664. badclass = self_willed 665. && ((oart->role != NON_PM && !Role_if(oart->role)) 666. || (oart->race != NON_PM && !Race_if(oart->race))); 667. badalign = ((oart->spfx & SPFX_RESTR) != 0 668. && oart->alignment != A_NONE 669. && (oart->alignment != u.ualign.type 670. || u.ualign.record < 0)); 671. } else if (!is_covetous(mon->data) && !is_mplayer(mon->data)) { 672. badclass = self_willed && oart->role != NON_PM 673. && oart != &artilist[ART_EXCALIBUR]; 674. badalign = (oart->spfx & SPFX_RESTR) && oart->alignment != A_NONE 675. && (oart->alignment != mon_aligntyp(mon)); 676. } else { /* an M3_WANTSxxx monster or a fake player */ 677. /* special monsters trying to take the Amulet, invocation tools or 678. quest item can touch anything except `spec_applies' artifacts */ 679. badclass = badalign = FALSE; 680. } 681. /* weapons which attack specific categories of monsters are 682. bad for them even if their alignments happen to match */ 683. if (!badalign) 684. badalign = bane_applies(oart, mon); 685. 686. if (((badclass || badalign) && self_willed) 687. || (badalign && (!yours || !rn2(4)))) { 688. int dmg, tmp; 689. char buf[BUFSZ]; 690. 691. if (!yours) 692. return 0; 693. You("are blasted by %s power!", s_suffix(the(xname(obj)))); 694. touch_blasted = TRUE; 695. dmg = d((Antimagic ? 2 : 4), (self_willed ? 10 : 4)); 696. /* add half (maybe quarter) of the usual silver damage bonus */ 697. if (objects[obj->otyp].oc_material == SILVER && Hate_silver) 698. tmp = rnd(10), dmg += Maybe_Half_Phys(tmp); 699. Sprintf(buf, "touching %s", oart->name); 700. losehp(dmg, buf, KILLED_BY); /* magic damage, not physical */ 701. exercise(A_WIS, FALSE); 702. } 703. 704. /* can pick it up unless you're totally non-synch'd with the artifact */ 705. if (badclass && badalign && self_willed) { 706. if (yours) { 707. if (!carried(obj)) 708. pline("%s your grasp!", Tobjnam(obj, "evade")); 709. else 710. pline("%s beyond your control!", Tobjnam(obj, "are")); 711. } 712. return 0; 713. } 714. 715. return 1; 716. } 717. 718. /* decide whether an artifact itself is vulnerable to a particular type 719. of erosion damage, independent of the properties of its bearer */ 720. boolean 721. arti_immune(obj, dtyp) 722. struct obj *obj; 723. int dtyp; 724. { 725. register const struct artifact *weap = get_artifact(obj); 726. 727. if (!weap) 728. return FALSE; 729. if (dtyp == AD_PHYS) 730. return FALSE; /* nothing is immune to phys dmg */ 731. return (boolean) (weap->attk.adtyp == dtyp 732. || weap->defn.adtyp == dtyp 733. || weap->cary.adtyp == dtyp); 734. } 735. 736. STATIC_OVL boolean 737. bane_applies(oart, mon) 738. const struct artifact *oart; 739. struct monst *mon; 740. { 741. struct artifact atmp; 742. 743. if (oart && (oart->spfx & SPFX_DBONUS) != 0) { 744. atmp = *oart; 745. atmp.spfx &= SPFX_DBONUS; /* clear other spfx fields */ 746. if (spec_applies(&atmp, mon)) 747. return TRUE; 748. } 749. return FALSE; 750. } 751. 752. /* decide whether an artifact's special attacks apply against mtmp */ 753. STATIC_OVL int 754. spec_applies(weap, mtmp) 755. register const struct artifact *weap; 756. struct monst *mtmp; 757. { 758. struct permonst *ptr; 759. boolean yours; 760. 761. if (!(weap->spfx & (SPFX_DBONUS | SPFX_ATTK))) 762. return (weap->attk.adtyp == AD_PHYS); 763. 764. yours = (mtmp == &youmonst); 765. ptr = mtmp->data; 766. 767. if (weap->spfx & SPFX_DMONS) { 768. return (ptr == &mons[(int) weap->mtype]); 769. } else if (weap->spfx & SPFX_DCLAS) { 770. return (weap->mtype == (unsigned long) ptr->mlet); 771. } else if (weap->spfx & SPFX_DFLAG1) { 772. return ((ptr->mflags1 & weap->mtype) != 0L); 773. } else if (weap->spfx & SPFX_DFLAG2) { 774. return ((ptr->mflags2 & weap->mtype) 775. || (yours 776. && ((!Upolyd && (urace.selfmask & weap->mtype)) 777. || ((weap->mtype & M2_WERE) && u.ulycn >= LOW_PM)))); 778. } else if (weap->spfx & SPFX_DALIGN) { 779. return yours ? (u.ualign.type != weap->alignment) 780. : (ptr->maligntyp == A_NONE 781. || sgn(ptr->maligntyp) != weap->alignment); 782. } else if (weap->spfx & SPFX_ATTK) { 783. struct obj *defending_weapon = (yours ? uwep : MON_WEP(mtmp)); 784. 785. if (defending_weapon && defending_weapon->oartifact 786. && defends((int) weap->attk.adtyp, defending_weapon)) 787. return FALSE; 788. switch (weap->attk.adtyp) { 789. case AD_FIRE: 790. return !(yours ? Fire_resistance : resists_fire(mtmp)); 791. case AD_COLD: 792. return !(yours ? Cold_resistance : resists_cold(mtmp)); 793. case AD_ELEC: 794. return !(yours ? Shock_resistance : resists_elec(mtmp)); 795. case AD_MAGM: 796. case AD_STUN: 797. return !(yours ? Antimagic : (rn2(100) < ptr->mr)); 798. case AD_DRST: 799. return !(yours ? Poison_resistance : resists_poison(mtmp)); 800. case AD_DRLI: 801. return !(yours ? Drain_resistance : resists_drli(mtmp)); 802. case AD_STON: 803. return !(yours ? Stone_resistance : resists_ston(mtmp)); 804. default: 805. impossible("Weird weapon special attack."); 806. } 807. } 808. return 0; 809. } 810. 811. /* return the M2 flags of monster that an artifact's special attacks apply 812. * against */ 813. long 814. spec_m2(otmp) 815. struct obj *otmp; 816. { 817. const struct artifact *artifact = get_artifact(otmp); 818. 819. if (artifact) 820. return artifact->mtype; 821. return 0L; 822. } 823. 824. /* special attack bonus */ 825. int 826. spec_abon(otmp, mon) 827. struct obj *otmp; 828. struct monst *mon; 829. { 830. const struct artifact *weap = get_artifact(otmp); 831. 832. /* no need for an extra check for `NO_ATTK' because this will 833. always return 0 for any artifact which has that attribute */ 834. 835. if (weap && weap->attk.damn && spec_applies(weap, mon)) 836. return rnd((int) weap->attk.damn); 837. return 0; 838. } 839. 840. /* special damage bonus */ 841. int 842. spec_dbon(otmp, mon, tmp) 843. struct obj *otmp; 844. struct monst *mon; 845. int tmp; 846. { 847. register const struct artifact *weap = get_artifact(otmp); 848. 849. if (!weap || (weap->attk.adtyp == AD_PHYS /* check for `NO_ATTK' */ 850. && weap->attk.damn == 0 && weap->attk.damd == 0)) 851. spec_dbon_applies = FALSE; 852. else if (otmp->oartifact == ART_GRIMTOOTH) 853. /* Grimtooth has SPFX settings to warn against elves but we want its 854. damage bonus to apply to all targets, so bypass spec_applies() */ 855. spec_dbon_applies = TRUE; 856. else 857. spec_dbon_applies = spec_applies(weap, mon); 858. 859. if (spec_dbon_applies) 860. return weap->attk.damd ? rnd((int) weap->attk.damd) : max(tmp, 1); 861. return 0; 862. } 863. 864. /* add identified artifact to discoveries list */ 865. void 866. discover_artifact(m) 867. xchar m; 868. { 869. int i; 870. 871. /* look for this artifact in the discoveries list; 872. if we hit an empty slot then it's not present, so add it */ 873. for (i = 0; i < NROFARTIFACTS; i++) 874. if (artidisco[i] == 0 || artidisco[i] == m) { 875. artidisco[i] = m; 876. return; 877. } 878. /* there is one slot per artifact, so we should never reach the 879. end without either finding the artifact or an empty slot... */ 880. impossible("couldn't discover artifact (%d)", (int) m); 881. } 882. 883. /* used to decide whether an artifact has been fully identified */ 884. boolean 885. undiscovered_artifact(m) 886. xchar m; 887. { 888. int i; 889. 890. /* look for this artifact in the discoveries list; 891. if we hit an empty slot then it's undiscovered */ 892. for (i = 0; i < NROFARTIFACTS; i++) 893. if (artidisco[i] == m) 894. return FALSE; 895. else if (artidisco[i] == 0) 896. break; 897. return TRUE; 898. } 899. 900. /* display a list of discovered artifacts; return their count */ 901. int 902. disp_artifact_discoveries(tmpwin) 903. winid tmpwin; /* supplied by dodiscover() */ 904. { 905. int i, m, otyp; 906. char buf[BUFSZ]; 907. 908. for (i = 0; i < NROFARTIFACTS; i++) { 909. if (artidisco[i] == 0) 910. break; /* empty slot implies end of list */ 911. if (tmpwin == WIN_ERR) 912. continue; /* for WIN_ERR, we just count */ 913. 914. if (i == 0) 915. putstr(tmpwin, iflags.menu_headings, "Artifacts"); 916. m = artidisco[i]; 917. otyp = artilist[m].otyp; 918. Sprintf(buf, " %s [%s %s]", artiname(m), 919. align_str(artilist[m].alignment), simple_typename(otyp)); 920. putstr(tmpwin, 0, buf); 921. } 922. return i; 923. } 924. 925. /* 926. * Magicbane's intrinsic magic is incompatible with normal 927. * enchantment magic. Thus, its effects have a negative 928. * dependence on spe. Against low mr victims, it typically 929. * does "double athame" damage, 2d4. Occasionally, it will 930. * cast unbalancing magic which effectively averages out to 931. * 4d4 damage (3d4 against high mr victims), for spe = 0. 932. * 933. * Prior to 3.4.1, the cancel (aka purge) effect always 934. * included the scare effect too; now it's one or the other. 935. * Likewise, the stun effect won't be combined with either 936. * of those two; it will be chosen separately or possibly 937. * used as a fallback when scare or cancel fails. 938. * 939. * [Historical note: a change to artifact_hit() for 3.4.0 940. * unintentionally made all of Magicbane's special effects 941. * be blocked if the defender successfully saved against a 942. * stun attack. As of 3.4.1, those effects can occur but 943. * will be slightly less likely than they were in 3.3.x.] 944. */ 945. 946. enum mb_effect_indices { 947. MB_INDEX_PROBE = 0, 948. MB_INDEX_STUN, 949. MB_INDEX_SCARE, 950. MB_INDEX_CANCEL, 951. 952. NUM_MB_INDICES 953. }; 954. 955. #define MB_MAX_DIEROLL 8 /* rolls above this aren't magical */ 956. static const char *const mb_verb[2][NUM_MB_INDICES] = { 957. { "probe", "stun", "scare", "cancel" }, 958. { "prod", "amaze", "tickle", "purge" }, 959. }; 960. 961. /* called when someone is being hit by Magicbane */ 962. STATIC_OVL boolean 963. Mb_hit(magr, mdef, mb, dmgptr, dieroll, vis, hittee) 964. struct monst *magr, *mdef; /* attacker and defender */ 965. struct obj *mb; /* Magicbane */ 966. int *dmgptr; /* extra damage target will suffer */ 967. int dieroll; /* d20 that has already scored a hit */ 968. boolean vis; /* whether the action can be seen */ 969. char *hittee; /* target's name: "you" or mon_nam(mdef) */ 970. { 971. struct permonst *old_uasmon; 972. const char *verb; 973. boolean youattack = (magr == &youmonst), youdefend = (mdef == &youmonst), 974. resisted = FALSE, do_stun, do_confuse, result; 975. int attack_indx, fakeidx, scare_dieroll = MB_MAX_DIEROLL / 2; 976. 977. result = FALSE; /* no message given yet */ 978. /* the most severe effects are less likely at higher enchantment */ 979. if (mb->spe >= 3) 980. scare_dieroll /= (1 << (mb->spe / 3)); 981. /* if target successfully resisted the artifact damage bonus, 982. reduce overall likelihood of the assorted special effects */ 983. if (!spec_dbon_applies) 984. dieroll += 1; 985. 986. /* might stun even when attempting a more severe effect, but 987. in that case it will only happen if the other effect fails; 988. extra damage will apply regardless; 3.4.1: sometimes might 989. just probe even when it hasn't been enchanted */ 990. do_stun = (max(mb->spe, 0) < rn2(spec_dbon_applies ? 11 : 7)); 991. 992. /* the special effects also boost physical damage; increments are 993. generally cumulative, but since the stun effect is based on a 994. different criterium its damage might not be included; the base 995. damage is either 1d4 (athame) or 2d4 (athame+spec_dbon) depending 996. on target's resistance check against AD_STUN (handled by caller) 997. [note that a successful save against AD_STUN doesn't actually 998. prevent the target from ending up stunned] */ 999. attack_indx = MB_INDEX_PROBE; 1000. *dmgptr += rnd(4); /* (2..3)d4 */ 1001. if (do_stun) { 1002. attack_indx = MB_INDEX_STUN; 1003. *dmgptr += rnd(4); /* (3..4)d4 */ 1004. } 1005. if (dieroll <= scare_dieroll) { 1006. attack_indx = MB_INDEX_SCARE; 1007. *dmgptr += rnd(4); /* (3..5)d4 */ 1008. } 1009. if (dieroll <= (scare_dieroll / 2)) { 1010. attack_indx = MB_INDEX_CANCEL; 1011. *dmgptr += rnd(4); /* (4..6)d4 */ 1012. } 1013. 1014. /* give the hit message prior to inflicting the effects */ 1015. verb = mb_verb[!!Hallucination][attack_indx]; 1016. if (youattack || youdefend || vis) { 1017. result = TRUE; 1018. pline_The("magic-absorbing blade %s %s!", 1019. vtense((const char *) 0, verb), hittee); 1020. /* assume probing has some sort of noticeable feedback 1021. even if it is being done by one monster to another */ 1022. if (attack_indx == MB_INDEX_PROBE && !canspotmon(mdef)) 1023. map_invisible(mdef->mx, mdef->my); 1024. } 1025. 1026. /* now perform special effects */ 1027. switch (attack_indx) { 1028. case MB_INDEX_CANCEL: 1029. old_uasmon = youmonst.data; 1030. /* No mdef->mcan check: even a cancelled monster can be polymorphed 1031. * into a golem, and the "cancel" effect acts as if some magical 1032. * energy remains in spellcasting defenders to be absorbed later. 1033. */ 1034. if (!cancel_monst(mdef, mb, youattack, FALSE, FALSE)) { 1035. resisted = TRUE; 1036. } else { 1037. do_stun = FALSE; 1038. if (youdefend) { 1039. if (youmonst.data != old_uasmon) 1040. *dmgptr = 0; /* rehumanized, so no more damage */ 1041. if (u.uenmax > 0) { 1042. u.uenmax--; 1043. if (u.uen > 0) 1044. u.uen--; 1045. context.botl = TRUE; 1046. You("lose magical energy!"); 1047. } 1048. } else { 1049. if (mdef->data == &mons[PM_CLAY_GOLEM]) 1050. mdef->mhp = 1; /* cancelled clay golems will die */ 1051. if (youattack && attacktype(mdef->data, AT_MAGC)) { 1052. u.uenmax++; 1053. u.uen++; 1054. context.botl = TRUE; 1055. You("absorb magical energy!"); 1056. } 1057. } 1058. } 1059. break; 1060. 1061. case MB_INDEX_SCARE: 1062. if (youdefend) { 1063. if (Antimagic) { 1064. resisted = TRUE; 1065. } else { 1066. nomul(-3); 1067. multi_reason = "being scared stiff"; 1068. nomovemsg = ""; 1069. if (magr && magr == u.ustuck && sticks(youmonst.data)) { 1070. u.ustuck = (struct monst *) 0; 1071. You("release %s!", mon_nam(magr)); 1072. } 1073. } 1074. } else { 1075. if (rn2(2) && resist(mdef, WEAPON_CLASS, 0, NOTELL)) 1076. resisted = TRUE; 1077. else 1078. monflee(mdef, 3, FALSE, (mdef->mhp > *dmgptr)); 1079. } 1080. if (!resisted) 1081. do_stun = FALSE; 1082. break; 1083. 1084. case MB_INDEX_STUN: 1085. do_stun = TRUE; /* (this is redundant...) */ 1086. break; 1087. 1088. case MB_INDEX_PROBE: 1089. if (youattack && (mb->spe == 0 || !rn2(3 * abs(mb->spe)))) { 1090. pline_The("%s is insightful.", verb); 1091. /* pre-damage status */ 1092. probe_monster(mdef); 1093. } 1094. break; 1095. } 1096. /* stun if that was selected and a worse effect didn't occur */ 1097. if (do_stun) { 1098. if (youdefend) 1099. make_stunned(((HStun & TIMEOUT) + 3L), FALSE); 1100. else 1101. mdef->mstun = 1; 1102. /* avoid extra stun message below if we used mb_verb["stun"] above */ 1103. if (attack_indx == MB_INDEX_STUN) 1104. do_stun = FALSE; 1105. } 1106. /* lastly, all this magic can be confusing... */ 1107. do_confuse = !rn2(12); 1108. if (do_confuse) { 1109. if (youdefend) 1110. make_confused((HConfusion & TIMEOUT) + 4L, FALSE); 1111. else 1112. mdef->mconf = 1; 1113. } 1114. 1115. /* now give message(s) describing side-effects; Use fakename 1116. so vtense() won't be fooled by assigned name ending in 's' */ 1117. fakeidx = youdefend ? 1 : 0; 1118. if (youattack || youdefend || vis) { 1119. (void) upstart(hittee); /* capitalize */ 1120. if (resisted) { 1121. pline("%s %s!", hittee, vtense(fakename[fakeidx], "resist")); 1122. shieldeff(youdefend ? u.ux : mdef->mx, 1123. youdefend ? u.uy : mdef->my); 1124. } 1125. if ((do_stun || do_confuse) && flags.verbose) { 1126. char buf[BUFSZ]; 1127. 1128. buf[0] = '\0'; 1129. if (do_stun) 1130. Strcat(buf, "stunned"); 1131. if (do_stun && do_confuse) 1132. Strcat(buf, " and "); 1133. if (do_confuse) 1134. Strcat(buf, "confused"); 1135. pline("%s %s %s%c", hittee, vtense(fakename[fakeidx], "are"), buf, 1136. (do_stun && do_confuse) ? '!' : '.'); 1137. } 1138. } 1139. 1140. return result; 1141. } 1142. 1143. /* Function used when someone attacks someone else with an artifact 1144. * weapon. Only adds the special (artifact) damage, and returns a 1 if it 1145. * did something special (in which case the caller won't print the normal 1146. * hit message). This should be called once upon every artifact attack; 1147. * dmgval() no longer takes artifact bonuses into account. Possible 1148. * extension: change the killer so that when an orc kills you with 1149. * Stormbringer it's "killed by Stormbringer" instead of "killed by an orc". 1150. */ 1151. boolean 1152. artifact_hit(magr, mdef, otmp, dmgptr, dieroll) 1153. struct monst *magr, *mdef; 1154. struct obj *otmp; 1155. int *dmgptr; 1156. int dieroll; /* needed for Magicbane and vorpal blades */ 1157. { 1158. boolean youattack = (magr == &youmonst); 1159. boolean youdefend = (mdef == &youmonst); 1160. boolean vis = (!youattack && magr && cansee(magr->mx, magr->my)) 1161. || (!youdefend && cansee(mdef->mx, mdef->my)) 1162. || (youattack && u.uswallow && mdef == u.ustuck && !Blind); 1163. boolean realizes_damage; 1164. const char *wepdesc; 1165. static const char you[] = "you"; 1166. char hittee[BUFSZ]; 1167. 1168. Strcpy(hittee, youdefend ? you : mon_nam(mdef)); 1169. 1170. /* The following takes care of most of the damage, but not all-- 1171. * the exception being for level draining, which is specially 1172. * handled. Messages are done in this function, however. 1173. */ 1174. *dmgptr += spec_dbon(otmp, mdef, *dmgptr); 1175. 1176. if (youattack && youdefend) { 1177. impossible("attacking yourself with weapon?"); 1178. return FALSE; 1179. } 1180. 1181. realizes_damage = (youdefend || vis 1182. /* feel the effect even if not seen */ 1183. || (youattack && mdef == u.ustuck)); 1184. 1185. /* the four basic attacks: fire, cold, shock and missiles */ 1186. if (attacks(AD_FIRE, otmp)) { 1187. if (realizes_damage) 1188. pline_The("fiery blade %s %s%c", 1189. !spec_dbon_applies 1190. ? "hits" 1191. : (mdef->data == &mons[PM_WATER_ELEMENTAL]) 1192. ? "vaporizes part of" 1193. : "burns", 1194. hittee, !spec_dbon_applies ? '.' : '!'); 1195. if (!rn2(4)) 1196. (void) destroy_mitem(mdef, POTION_CLASS, AD_FIRE); 1197. if (!rn2(4)) 1198. (void) destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); 1199. if (!rn2(7)) 1200. (void) destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); 1201. if (youdefend && Slimed) 1202. burn_away_slime(); 1203. return realizes_damage; 1204. } 1205. if (attacks(AD_COLD, otmp)) { 1206. if (realizes_damage) 1207. pline_The("ice-cold blade %s %s%c", 1208. !spec_dbon_applies ? "hits" : "freezes", hittee, 1209. !spec_dbon_applies ? '.' : '!'); 1210. if (!rn2(4)) 1211. (void) destroy_mitem(mdef, POTION_CLASS, AD_COLD); 1212. return realizes_damage; 1213. } 1214. if (attacks(AD_ELEC, otmp)) { 1215. if (realizes_damage) 1216. pline_The("massive hammer hits%s %s%c", 1217. !spec_dbon_applies ? "" : "! Lightning strikes", 1218. hittee, !spec_dbon_applies ? '.' : '!'); 1219. if (spec_dbon_applies) 1220. wake_nearto(mdef->mx, mdef->my, 4 * 4); 1221. if (!rn2(5)) 1222. (void) destroy_mitem(mdef, RING_CLASS, AD_ELEC); 1223. if (!rn2(5)) 1224. (void) destroy_mitem(mdef, WAND_CLASS, AD_ELEC); 1225. return realizes_damage; 1226. } 1227. if (attacks(AD_MAGM, otmp)) { 1228. if (realizes_damage) 1229. pline_The("imaginary widget hits%s %s%c", 1230. !spec_dbon_applies 1231. ? "" 1232. : "! A hail of magic missiles strikes", 1233. hittee, !spec_dbon_applies ? '.' : '!'); 1234. return realizes_damage; 1235. } 1236. 1237. if (attacks(AD_STUN, otmp) && dieroll <= MB_MAX_DIEROLL) { 1238. /* Magicbane's special attacks (possibly modifies hittee[]) */ 1239. return Mb_hit(magr, mdef, otmp, dmgptr, dieroll, vis, hittee); 1240. } 1241. 1242. if (!spec_dbon_applies) { 1243. /* since damage bonus didn't apply, nothing more to do; 1244. no further attacks have side-effects on inventory */ 1245. return FALSE; 1246. } 1247. 1248. /* We really want "on a natural 20" but Nethack does it in */ 1249. /* reverse from AD&D. */ 1250. if (spec_ability(otmp, SPFX_BEHEAD)) { 1251. if (otmp->oartifact == ART_TSURUGI_OF_MURAMASA && dieroll == 1) { 1252. wepdesc = "The razor-sharp blade"; 1253. /* not really beheading, but so close, why add another SPFX */ 1254. if (youattack && u.uswallow && mdef == u.ustuck) { 1255. You("slice %s wide open!", mon_nam(mdef)); 1256. *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; 1257. return TRUE; 1258. } 1259. if (!youdefend) { 1260. /* allow normal cutworm() call to add extra damage */ 1261. if (notonhead) 1262. return FALSE; 1263. 1264. if (bigmonst(mdef->data)) { 1265. if (youattack) 1266. You("slice deeply into %s!", mon_nam(mdef)); 1267. else if (vis) 1268. pline("%s cuts deeply into %s!", Monnam(magr), 1269. hittee); 1270. *dmgptr *= 2; 1271. return TRUE; 1272. } 1273. *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; 1274. pline("%s cuts %s in half!", wepdesc, mon_nam(mdef)); 1275. otmp->dknown = TRUE; 1276. return TRUE; 1277. } else { 1278. if (bigmonst(youmonst.data)) { 1279. pline("%s cuts deeply into you!", 1280. magr ? Monnam(magr) : wepdesc); 1281. *dmgptr *= 2; 1282. return TRUE; 1283. } 1284. 1285. /* Players with negative AC's take less damage instead 1286. * of just not getting hit. We must add a large enough 1287. * value to the damage so that this reduction in 1288. * damage does not prevent death. 1289. */ 1290. *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER; 1291. pline("%s cuts you in half!", wepdesc); 1292. otmp->dknown = TRUE; 1293. return TRUE; 1294. } 1295. } else if (otmp->oartifact == ART_VORPAL_BLADE 1296. && (dieroll == 1 || mdef->data == &mons[PM_JABBERWOCK])) { 1297. static const char *const behead_msg[2] = { "%s beheads %s!", 1298. "%s decapitates %s!" }; 1299. 1300. if (youattack && u.uswallow && mdef == u.ustuck) 1301. return FALSE; 1302. wepdesc = artilist[ART_VORPAL_BLADE].name; 1303. if (!youdefend) { 1304. if (!has_head(mdef->data) || notonhead || u.uswallow) { 1305. if (youattack) 1306. pline("Somehow, you miss %s wildly.", mon_nam(mdef)); 1307. else if (vis) 1308. pline("Somehow, %s misses wildly.", mon_nam(magr)); 1309. *dmgptr = 0; 1310. return (boolean) (youattack || vis); 1311. } 1312. if (noncorporeal(mdef->data) || amorphous(mdef->data)) { 1313. pline("%s slices through %s %s.", wepdesc, 1314. s_suffix(mon_nam(mdef)), mbodypart(mdef, NECK)); 1315. return TRUE; 1316. } 1317. *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; 1318. pline(behead_msg[rn2(SIZE(behead_msg))], wepdesc, 1319. mon_nam(mdef)); 1320. if (Hallucination && !flags.female) 1321. pline("Good job Henry, but that wasn't Anne."); 1322. otmp->dknown = TRUE; 1323. return TRUE; 1324. } else { 1325. if (!has_head(youmonst.data)) { 1326. pline("Somehow, %s misses you wildly.", 1327. magr ? mon_nam(magr) : wepdesc); 1328. *dmgptr = 0; 1329. return TRUE; 1330. } 1331. if (noncorporeal(youmonst.data) || amorphous(youmonst.data)) { 1332. pline("%s slices through your %s.", wepdesc, 1333. body_part(NECK)); 1334. return TRUE; 1335. } 1336. *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER; 1337. pline(behead_msg[rn2(SIZE(behead_msg))], wepdesc, "you"); 1338. otmp->dknown = TRUE; 1339. /* Should amulets fall off? */ 1340. return TRUE; 1341. } 1342. } 1343. } 1344. if (spec_ability(otmp, SPFX_DRLI)) { 1345. /* some non-living creatures (golems, vortices) are 1346. vulnerable to life drain effects */ 1347. const char *life = nonliving(mdef->data) ? "animating force" : "life"; 1348. 1349. if (!youdefend) { 1350. if (vis) { 1351. if (otmp->oartifact == ART_STORMBRINGER) 1352. pline_The("%s blade draws the %s from %s!", 1353. hcolor(NH_BLACK), life, mon_nam(mdef)); 1354. else 1355. pline("%s draws the %s from %s!", 1356. The(distant_name(otmp, xname)), life, 1357. mon_nam(mdef)); 1358. } 1359. if (mdef->m_lev == 0) { 1360. *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; 1361. } else { 1362. int drain = monhp_per_lvl(mdef); 1363. 1364. *dmgptr += drain; 1365. mdef->mhpmax -= drain; 1366. mdef->m_lev--; 1367. drain /= 2; 1368. if (drain) 1369. healup(drain, 0, FALSE, FALSE); 1370. } 1371. return vis; 1372. } else { /* youdefend */ 1373. int oldhpmax = u.uhpmax; 1374. 1375. if (Blind) 1376. You_feel("an %s drain your %s!", 1377. (otmp->oartifact == ART_STORMBRINGER) 1378. ? "unholy blade" 1379. : "object", 1380. life); 1381. else if (otmp->oartifact == ART_STORMBRINGER) 1382. pline_The("%s blade drains your %s!", hcolor(NH_BLACK), life); 1383. else 1384. pline("%s drains your %s!", The(distant_name(otmp, xname)), 1385. life); 1386. losexp("life drainage"); 1387. if (magr && magr->mhp < magr->mhpmax) { 1388. magr->mhp += (oldhpmax - u.uhpmax) / 2; 1389. if (magr->mhp > magr->mhpmax) 1390. magr->mhp = magr->mhpmax; 1391. } 1392. return TRUE; 1393. } 1394. } 1395. return FALSE; 1396. } 1397. 1398. static NEARDATA const char recharge_type[] = { ALLOW_COUNT, ALL_CLASSES, 0 }; 1399. static NEARDATA const char invoke_types[] = { ALL_CLASSES, 0 }; 1400. /* #invoke: an "ugly check" filters out most objects */ 1401. 1402. /* the #invoke command */ 1403. int 1404. doinvoke() 1405. { 1406. struct obj *obj; 1407. 1408. obj = getobj(invoke_types, "invoke"); 1409. if (!obj) 1410. return 0; 1411. if (!retouch_object(&obj, FALSE)) 1412. return 1; 1413. return arti_invoke(obj); 1414. } 1415. 1416. STATIC_OVL int 1417. arti_invoke(obj) 1418. struct obj *obj; 1419. { 1420. register const struct artifact *oart = get_artifact(obj); 1421. if (!obj) { 1422. impossible("arti_invoke without obj"); 1423. return 0; 1424. } 1425. if (!oart || !oart->inv_prop) { 1426. if (obj->otyp == CRYSTAL_BALL) 1427. use_crystal_ball(&obj); 1428. else 1429. pline1(nothing_happens); 1430. return 1; 1431. } 1432. 1433. if (oart->inv_prop > LAST_PROP) { 1434. /* It's a special power, not "just" a property */ 1435. if (obj->age > monstermoves) { 1436. /* the artifact is tired :-) */ 1437. You_feel("that %s %s ignoring you.", the(xname(obj)), 1438. otense(obj, "are")); 1439. /* and just got more so; patience is essential... */ 1440. obj->age += (long) d(3, 10); 1441. return 1; 1442. } 1443. obj->age = monstermoves + rnz(100); 1444. 1445. switch (oart->inv_prop) { 1446. case TAMING: { 1447. struct obj pseudo; 1448. 1449. pseudo = 1450. zeroobj; /* neither cursed nor blessed, zero oextra too */ 1451. pseudo.otyp = SCR_TAMING; 1452. (void) seffects(&pseudo); 1453. break; 1454. } 1455. case HEALING: { 1456. int healamt = (u.uhpmax + 1 - u.uhp) / 2; 1457. long creamed = (long) u.ucreamed; 1458. 1459. if (Upolyd) 1460. healamt = (u.mhmax + 1 - u.mh) / 2; 1461. if (healamt || Sick || Slimed || Blinded > creamed) 1462. You_feel("better."); 1463. else 1464. goto nothing_special; 1465. if (healamt > 0) { 1466. if (Upolyd) 1467. u.mh += healamt; 1468. else 1469. u.uhp += healamt; 1470. } 1471. if (Sick) 1472. make_sick(0L, (char *) 0, FALSE, SICK_ALL); 1473. if (Slimed) 1474. make_slimed(0L, (char *) 0); 1475. if (Blinded > creamed) 1476. make_blinded(creamed, FALSE); 1477. context.botl = TRUE; 1478. break; 1479. } 1480. case ENERGY_BOOST: { 1481. int epboost = (u.uenmax + 1 - u.uen) / 2; 1482. 1483. if (epboost > 120) 1484. epboost = 120; /* arbitrary */ 1485. else if (epboost < 12) 1486. epboost = u.uenmax - u.uen; 1487. if (epboost) { 1488. u.uen += epboost; 1489. context.botl = TRUE; 1490. You_feel("re-energized."); 1491. } else 1492. goto nothing_special; 1493. break; 1494. } 1495. case UNTRAP: { 1496. if (!untrap(TRUE)) { 1497. obj->age = 0; /* don't charge for changing their mind */ 1498. return 0; 1499. } 1500. break; 1501. } 1502. case CHARGE_OBJ: { 1503. struct obj *otmp = getobj(recharge_type, "charge"); 1504. boolean b_effect; 1505. 1506. if (!otmp) { 1507. obj->age = 0; 1508. return 0; 1509. } 1510. b_effect = (obj->blessed && (oart->role == Role_switch 1511. || oart->role == NON_PM)); 1512. recharge(otmp, b_effect ? 1 : obj->cursed ? -1 : 0); 1513. update_inventory(); 1514. break; 1515. } 1516. case LEV_TELE: 1517. level_tele(); 1518. break; 1519. case CREATE_PORTAL: { 1520. int i, num_ok_dungeons, last_ok_dungeon = 0; 1521. d_level newlev; 1522. extern int n_dgns; /* from dungeon.c */ 1523. winid tmpwin = create_nhwindow(NHW_MENU); 1524. anything any; 1525. 1526. any = zeroany; /* set all bits to zero */ 1527. start_menu(tmpwin); 1528. /* use index+1 (cant use 0) as identifier */ 1529. for (i = num_ok_dungeons = 0; i < n_dgns; i++) { 1530. if (!dungeons[i].dunlev_ureached) 1531. continue; 1532. any.a_int = i + 1; 1533. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, 1534. dungeons[i].dname, MENU_UNSELECTED); 1535. num_ok_dungeons++; 1536. last_ok_dungeon = i; 1537. } 1538. end_menu(tmpwin, "Open a portal to which dungeon?"); 1539. if (num_ok_dungeons > 1) { 1540. /* more than one entry; display menu for choices */ 1541. menu_item *selected; 1542. int n; 1543. 1544. n = select_menu(tmpwin, PICK_ONE, &selected); 1545. if (n <= 0) { 1546. destroy_nhwindow(tmpwin); 1547. goto nothing_special; 1548. } 1549. i = selected[0].item.a_int - 1; 1550. free((genericptr_t) selected); 1551. } else 1552. i = last_ok_dungeon; /* also first & only OK dungeon */ 1553. destroy_nhwindow(tmpwin); 1554. 1555. /* 1556. * i is now index into dungeon structure for the new dungeon. 1557. * Find the closest level in the given dungeon, open 1558. * a use-once portal to that dungeon and go there. 1559. * The closest level is either the entry or dunlev_ureached. 1560. */ 1561. newlev.dnum = i; 1562. if (dungeons[i].depth_start >= depth(&u.uz)) 1563. newlev.dlevel = dungeons[i].entry_lev; 1564. else 1565. newlev.dlevel = dungeons[i].dunlev_ureached; 1566. 1567. if (u.uhave.amulet || In_endgame(&u.uz) || In_endgame(&newlev) 1568. || newlev.dnum == u.uz.dnum || !next_to_u()) { 1569. You_feel("very disoriented for a moment."); 1570. } else { 1571. if (!Blind) 1572. You("are surrounded by a shimmering sphere!"); 1573. else 1574. You_feel("weightless for a moment."); 1575. goto_level(&newlev, FALSE, FALSE, FALSE); 1576. } 1577. break; 1578. } 1579. case ENLIGHTENING: 1580. enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS); 1581. break; 1582. case CREATE_AMMO: { 1583. struct obj *otmp = mksobj(ARROW, TRUE, FALSE); 1584. 1585. if (!otmp) 1586. goto nothing_special; 1587. otmp->blessed = obj->blessed; 1588. otmp->cursed = obj->cursed; 1589. otmp->bknown = obj->bknown; 1590. if (obj->blessed) { 1591. if (otmp->spe < 0) 1592. otmp->spe = 0; 1593. otmp->quan += rnd(10); 1594. } else if (obj->cursed) { 1595. if (otmp->spe > 0) 1596. otmp->spe = 0; 1597. } else 1598. otmp->quan += rnd(5); 1599. otmp->owt = weight(otmp); 1600. otmp = hold_another_object(otmp, "Suddenly %s out.", 1601. aobjnam(otmp, "fall"), (char *) 0); 1602. nhUse(otmp); 1603. break; 1604. } 1605. } 1606. } else { 1607. long eprop = (u.uprops[oart->inv_prop].extrinsic ^= W_ARTI), 1608. iprop = u.uprops[oart->inv_prop].intrinsic; 1609. boolean on = (eprop & W_ARTI) != 0; /* true if prop just set */ 1610. 1611. if (on && obj->age > monstermoves) { 1612. /* the artifact is tired :-) */ 1613. u.uprops[oart->inv_prop].extrinsic ^= W_ARTI; 1614. You_feel("that %s %s ignoring you.", the(xname(obj)), 1615. otense(obj, "are")); 1616. /* can't just keep repeatedly trying */ 1617. obj->age += (long) d(3, 10); 1618. return 1; 1619. } else if (!on) { 1620. /* when turning off property, determine downtime */ 1621. /* arbitrary for now until we can tune this -dlc */ 1622. obj->age = monstermoves + rnz(100); 1623. } 1624. 1625. if ((eprop & ~W_ARTI) || iprop) { 1626. nothing_special: 1627. /* you had the property from some other source too */ 1628. if (carried(obj)) 1629. You_feel("a surge of power, but nothing seems to happen."); 1630. return 1; 1631. } 1632. switch (oart->inv_prop) { 1633. case CONFLICT: 1634. if (on) 1635. You_feel("like a rabble-rouser."); 1636. else 1637. You_feel("the tension decrease around you."); 1638. break; 1639. case LEVITATION: 1640. if (on) { 1641. float_up(); 1642. spoteffects(FALSE); 1643. } else 1644. (void) float_down(I_SPECIAL | TIMEOUT, W_ARTI); 1645. break; 1646. case INVIS: 1647. if (BInvis || Blind) 1648. goto nothing_special; 1649. newsym(u.ux, u.uy); 1650. if (on) 1651. Your("body takes on a %s transparency...", 1652. Hallucination ? "normal" : "strange"); 1653. else 1654. Your("body seems to unfade..."); 1655. break; 1656. } 1657. } 1658. 1659. return 1; 1660. } 1661. 1662. /* will freeing this object from inventory cause levitation to end? */ 1663. boolean 1664. finesse_ahriman(obj) 1665. struct obj *obj; 1666. { 1667. const struct artifact *oart; 1668. struct prop save_Lev; 1669. boolean result; 1670. 1671. /* if we aren't levitating or this isn't an artifact which confers 1672. levitation via #invoke then freeinv() won't toggle levitation */ 1673. if (!Levitation || (oart = get_artifact(obj)) == 0 1674. || oart->inv_prop != LEVITATION || !(ELevitation & W_ARTI)) 1675. return FALSE; 1676. 1677. /* arti_invoke(off) -> float_down() clears I_SPECIAL|TIMEOUT & W_ARTI; 1678. probe ahead to see whether that actually results in floating down; 1679. (this assumes that there aren't two simultaneously invoked artifacts 1680. both conferring levitation--safe, since if there were two of them, 1681. invoking the 2nd would negate the 1st rather than stack with it) */ 1682. save_Lev = u.uprops[LEVITATION]; 1683. HLevitation &= ~(I_SPECIAL | TIMEOUT); 1684. ELevitation &= ~W_ARTI; 1685. result = (boolean) !Levitation; 1686. u.uprops[LEVITATION] = save_Lev; 1687. return result; 1688. } 1689. 1690. /* WAC return TRUE if artifact is always lit */ 1691. boolean 1692. artifact_light(obj) 1693. struct obj *obj; 1694. { 1695. return (boolean) (get_artifact(obj) && obj->oartifact == ART_SUNSWORD); 1696. } 1697. 1698. /* KMH -- Talking artifacts are finally implemented */ 1699. void 1700. arti_speak(obj) 1701. struct obj *obj; 1702. { 1703. register const struct artifact *oart = get_artifact(obj); 1704. const char *line; 1705. char buf[BUFSZ]; 1706. 1707. /* Is this a speaking artifact? */ 1708. if (!oart || !(oart->spfx & SPFX_SPEAK)) 1709. return; 1710. 1711. line = getrumor(bcsign(obj), buf, TRUE); 1712. if (!*line) 1713. line = "NetHack rumors file closed for renovation."; 1714. pline("%s:", Tobjnam(obj, "whisper")); 1715. verbalize1(line); 1716. return; 1717. } 1718. 1719. boolean 1720. artifact_has_invprop(otmp, inv_prop) 1721. struct obj *otmp; 1722. uchar inv_prop; 1723. { 1724. const struct artifact *arti = get_artifact(otmp); 1725. 1726. return (boolean) (arti && (arti->inv_prop == inv_prop)); 1727. } 1728. 1729. /* Return the price sold to the hero of a given artifact or unique item */ 1730. long 1731. arti_cost(otmp) 1732. struct obj *otmp; 1733. { 1734. if (!otmp->oartifact) 1735. return (long) objects[otmp->otyp].oc_cost; 1736. else if (artilist[(int) otmp->oartifact].cost) 1737. return artilist[(int) otmp->oartifact].cost; 1738. else 1739. return (100L * (long) objects[otmp->otyp].oc_cost); 1740. } 1741. 1742. STATIC_OVL uchar 1743. abil_to_adtyp(abil) 1744. long *abil; 1745. { 1746. struct abil2adtyp_tag { 1747. long *abil; 1748. uchar adtyp; 1749. } abil2adtyp[] = { 1750. { &EFire_resistance, AD_FIRE }, 1751. { &ECold_resistance, AD_COLD }, 1752. { &EShock_resistance, AD_ELEC }, 1753. { &EAntimagic, AD_MAGM }, 1754. { &EDisint_resistance, AD_DISN }, 1755. { &EPoison_resistance, AD_DRST }, 1756. { &EDrain_resistance, AD_DRLI }, 1757. }; 1758. int k; 1759. 1760. for (k = 0; k < SIZE(abil2adtyp); k++) { 1761. if (abil2adtyp[k].abil == abil) 1762. return abil2adtyp[k].adtyp; 1763. } 1764. return 0; 1765. } 1766. 1767. STATIC_OVL unsigned long 1768. abil_to_spfx(abil) 1769. long *abil; 1770. { 1771. static const struct abil2spfx_tag { 1772. long *abil; 1773. unsigned long spfx; 1774. } abil2spfx[] = { 1775. { &ESearching, SPFX_SEARCH }, 1776. { &EHalluc_resistance, SPFX_HALRES }, 1777. { &ETelepat, SPFX_ESP }, 1778. { &EStealth, SPFX_STLTH }, 1779. { &ERegeneration, SPFX_REGEN }, 1780. { &ETeleport_control, SPFX_TCTRL }, 1781. { &EWarn_of_mon, SPFX_WARN }, 1782. { &EWarning, SPFX_WARN }, 1783. { &EEnergy_regeneration, SPFX_EREGEN }, 1784. { &EHalf_spell_damage, SPFX_HSPDAM }, 1785. { &EHalf_physical_damage, SPFX_HPHDAM }, 1786. { &EReflecting, SPFX_REFLECT }, 1787. }; 1788. int k; 1789. 1790. for (k = 0; k < SIZE(abil2spfx); k++) { 1791. if (abil2spfx[k].abil == abil) 1792. return abil2spfx[k].spfx; 1793. } 1794. return 0L; 1795. } 1796. 1797. /* 1798. * Return the first item that is conveying a particular intrinsic. 1799. */ 1800. struct obj * 1801. what_gives(abil) 1802. long *abil; 1803. { 1804. struct obj *obj; 1805. uchar dtyp; 1806. unsigned long spfx; 1807. long wornbits; 1808. long wornmask = (W_ARM | W_ARMC | W_ARMH | W_ARMS 1809. | W_ARMG | W_ARMF | W_ARMU 1810. | W_AMUL | W_RINGL | W_RINGR | W_TOOL 1811. | W_ART | W_ARTI); 1812. 1813. if (u.twoweap) 1814. wornmask |= W_SWAPWEP; 1815. dtyp = abil_to_adtyp(abil); 1816. spfx = abil_to_spfx(abil); 1817. wornbits = (wornmask & *abil); 1818. 1819. for (obj = invent; obj; obj = obj->nobj) { 1820. if (obj->oartifact 1821. && (abil != &EWarn_of_mon || context.warntype.obj)) { 1822. const struct artifact *art = get_artifact(obj); 1823. 1824. if (art) { 1825. if (dtyp) { 1826. if (art->cary.adtyp == dtyp /* carried */ 1827. || (art->defn.adtyp == dtyp /* defends while worn */ 1828. && (obj->owornmask & ~(W_ART | W_ARTI)))) 1829. return obj; 1830. } 1831. if (spfx) { 1832. /* property conferred when carried */ 1833. if ((art->cspfx & spfx) == spfx) 1834. return obj; 1835. /* property conferred when wielded or worn */ 1836. if ((art->spfx & spfx) == spfx && obj->owornmask) 1837. return obj; 1838. } 1839. } 1840. } else { 1841. if (wornbits && wornbits == (wornmask & obj->owornmask)) 1842. return obj; 1843. } 1844. } 1845. return (struct obj *) 0; 1846. } 1847. 1848. const char * 1849. glow_color(arti_indx) 1850. int arti_indx; 1851. { 1852. int colornum = artilist[arti_indx].acolor; 1853. const char *colorstr = clr2colorname(colornum); 1854. 1855. return hcolor(colorstr); 1856. } 1857. 1858. /* glow verb; [0] holds the value used when blind */ 1859. static const char *glow_verbs[] = { 1860. "quiver", "flicker", "glimmer", "gleam" 1861. }; 1862. 1863. /* relative strength that Sting is glowing (0..3), to select verb */ 1864. STATIC_OVL int 1865. glow_strength(count) 1866. int count; 1867. { 1868. /* glow strength should also be proportional to proximity and 1869. probably difficulty, but we don't have that information and 1870. gathering it is more trouble than this would be worth */ 1871. return (count > 12) ? 3 : (count > 4) ? 2 : (count > 0); 1872. } 1873. 1874. const char * 1875. glow_verb(count, ingsfx) 1876. int count; /* 0 means blind rather than no applicable creatures */ 1877. boolean ingsfx; 1878. { 1879. static char resbuf[20]; 1880. 1881. Strcpy(resbuf, glow_verbs[glow_strength(count)]); 1882. /* ing_suffix() will double the last consonant for all the words 1883. we're using and none of them should have that, so bypass it */ 1884. if (ingsfx) 1885. Strcat(resbuf, "ing"); 1886. return resbuf; 1887. } 1888. 1889. /* use for warning "glow" for Sting, Orcrist, and Grimtooth */ 1890. void 1891. Sting_effects(orc_count) 1892. int orc_count; /* new count (warn_obj_cnt is old count); -1 is a flag value */ 1893. { 1894. if (uwep 1895. && (uwep->oartifact == ART_STING 1896. || uwep->oartifact == ART_ORCRIST 1897. || uwep->oartifact == ART_GRIMTOOTH)) { 1898. int oldstr = glow_strength(warn_obj_cnt), 1899. newstr = glow_strength(orc_count); 1900. 1901. if (orc_count == -1 && warn_obj_cnt > 0) { 1902. /* -1 means that blindness has just been toggled; give a 1903. 'continue' message that eventual 'stop' message will match */ 1904. pline("%s is %s.", bare_artifactname(uwep), 1905. glow_verb(Blind ? 0 : warn_obj_cnt, TRUE)); 1906. } else if (newstr > 0 && newstr != oldstr) { 1907. /* 'start' message */ 1908. if (!Blind) 1909. pline("%s %s %s%c", bare_artifactname(uwep), 1910. otense(uwep, glow_verb(orc_count, FALSE)), 1911. glow_color(uwep->oartifact), 1912. (newstr > oldstr) ? '!' : '.'); 1913. else if (oldstr == 0) /* quivers */ 1914. pline("%s %s slightly.", bare_artifactname(uwep), 1915. otense(uwep, glow_verb(0, FALSE))); 1916. } else if (orc_count == 0 && warn_obj_cnt > 0) { 1917. /* 'stop' message */ 1918. pline("%s stops %s.", bare_artifactname(uwep), 1919. glow_verb(Blind ? 0 : warn_obj_cnt, TRUE)); 1920. } 1921. } 1922. } 1923. 1924. /* called when hero is wielding/applying/invoking a carried item, or 1925. after undergoing a transformation (alignment change, lycanthropy, 1926. polymorph) which might affect item access */ 1927. int 1928. retouch_object(objp, loseit) 1929. struct obj **objp; /* might be destroyed or unintentionally dropped */ 1930. boolean loseit; /* whether to drop it if hero can longer touch it */ 1931. { 1932. struct obj *obj = *objp; 1933. 1934. if (touch_artifact(obj, &youmonst)) { 1935. char buf[BUFSZ]; 1936. int dmg = 0, tmp; 1937. boolean ag = (objects[obj->otyp].oc_material == SILVER && Hate_silver), 1938. bane = bane_applies(get_artifact(obj), &youmonst); 1939. 1940. /* nothing else to do if hero can successfully handle this object */ 1941. if (!ag && !bane) 1942. return 1; 1943. 1944. /* hero can't handle this object, but didn't get touch_artifact()'s 1945. "<obj> evades your grasp|control" message; give an alternate one */ 1946. You_cant("handle %s%s!", yname(obj), 1947. obj->owornmask ? " anymore" : ""); 1948. /* also inflict damage unless touch_artifact() already did so */ 1949. if (!touch_blasted) { 1950. /* damage is somewhat arbitrary; half the usual 1d20 physical 1951. for silver, 1d10 magical for <foo>bane, potentially both */ 1952. if (ag) 1953. tmp = rnd(10), dmg += Maybe_Half_Phys(tmp); 1954. if (bane) 1955. dmg += rnd(10); 1956. Sprintf(buf, "handling %s", killer_xname(obj)); 1957. losehp(dmg, buf, KILLED_BY); 1958. exercise(A_CON, FALSE); 1959. } 1960. } 1961. 1962. /* removing a worn item might result in loss of levitation, 1963. dropping the hero onto a polymorph trap or into water or 1964. lava and potentially dropping or destroying the item */ 1965. if (obj->owornmask) { 1966. struct obj *otmp; 1967. 1968. remove_worn_item(obj, FALSE); 1969. for (otmp = invent; otmp; otmp = otmp->nobj) 1970. if (otmp == obj) 1971. break; 1972. if (!otmp) 1973. *objp = obj = 0; 1974. } 1975. 1976. /* if we still have it and caller wants us to drop it, do so now */ 1977. if (loseit && obj) { 1978. if (Levitation) { 1979. freeinv(obj); 1980. hitfloor(obj, TRUE); 1981. } else { 1982. /* dropx gives a message iff item lands on an altar */ 1983. if (!IS_ALTAR(levl[u.ux][u.uy].typ)) 1984. pline("%s to the %s.", Tobjnam(obj, "fall"), 1985. surface(u.ux, u.uy)); 1986. dropx(obj); 1987. } 1988. *objp = obj = 0; /* no longer in inventory */ 1989. } 1990. return 0; 1991. } 1992. 1993. /* an item which is worn/wielded or an artifact which conveys 1994. something via being carried or which has an #invoke effect 1995. currently in operation undergoes a touch test; if it fails, 1996. it will be unworn/unwielded and revoked but not dropped */ 1997. STATIC_OVL boolean 1998. untouchable(obj, drop_untouchable) 1999. struct obj *obj; 2000. boolean drop_untouchable; 2001. { 2002. struct artifact *art; 2003. boolean beingworn, carryeffect, invoked; 2004. long wearmask = ~(W_QUIVER | (u.twoweap ? 0L : W_SWAPWEP) | W_BALL); 2005. 2006. beingworn = ((obj->owornmask & wearmask) != 0L 2007. /* some items in use don't have any wornmask setting */ 2008. || (obj->oclass == TOOL_CLASS 2009. && (obj->lamplit || (obj->otyp == LEASH && obj->leashmon) 2010. || (Is_container(obj) && Has_contents(obj))))); 2011. 2012. if ((art = get_artifact(obj)) != 0) { 2013. carryeffect = (art->cary.adtyp || art->cspfx); 2014. invoked = (art->inv_prop > 0 && art->inv_prop <= LAST_PROP 2015. && (u.uprops[art->inv_prop].extrinsic & W_ARTI) != 0L); 2016. } else { 2017. carryeffect = invoked = FALSE; 2018. } 2019. 2020. if (beingworn || carryeffect || invoked) { 2021. if (!retouch_object(&obj, drop_untouchable)) { 2022. /* "<artifact> is beyond your control" or "you can't handle 2023. <object>" has been given and it is now unworn/unwielded 2024. and possibly dropped (depending upon caller); if dropped, 2025. carried effect was turned off, else we leave that alone; 2026. we turn off invocation property here if still carried */ 2027. if (invoked && obj) 2028. arti_invoke(obj); /* reverse #invoke */ 2029. return TRUE; 2030. } 2031. } 2032. return FALSE; 2033. } 2034. 2035. /* check all items currently in use (mostly worn) for touchability */ 2036. void 2037. retouch_equipment(dropflag) 2038. int dropflag; /* 0==don't drop, 1==drop all, 2==drop weapon */ 2039. { 2040. static int nesting = 0; /* recursion control */ 2041. struct obj *obj; 2042. boolean dropit, had_gloves = (uarmg != 0); 2043. int had_rings = (!!uleft + !!uright); 2044. 2045. /* 2046. * We can potentially be called recursively if losing/unwearing 2047. * an item causes worn helm of opposite alignment to come off or 2048. * be destroyed. 2049. * 2050. * BUG: if the initial call was due to putting on a helm of 2051. * opposite alignment and it does come off to trigger recursion, 2052. * after the inner call executes, the outer call will finish 2053. * using the non-helm alignment rather than the helm alignment 2054. * which triggered this in the first place. 2055. */ 2056. if (!nesting++) 2057. clear_bypasses(); /* init upon initial entry */ 2058. 2059. dropit = (dropflag > 0); /* drop all or drop weapon */ 2060. /* check secondary weapon first, before possibly unwielding primary */ 2061. if (u.twoweap) { 2062. bypass_obj(uswapwep); /* so loop below won't process it again */ 2063. (void) untouchable(uswapwep, dropit); 2064. } 2065. /* check primary weapon next so that they're handled together */ 2066. if (uwep) { 2067. bypass_obj(uwep); /* so loop below won't process it again */ 2068. (void) untouchable(uwep, dropit); 2069. } 2070. 2071. /* in case someone is daft enough to add artifact or silver saddle */ 2072. if (u.usteed && (obj = which_armor(u.usteed, W_SADDLE)) != 0) { 2073. /* untouchable() calls retouch_object() which expects an object in 2074. hero's inventory, but remove_worn_item() will be harmless for 2075. saddle and we're suppressing drop, so this works as intended */ 2076. if (untouchable(obj, FALSE)) 2077. dismount_steed(DISMOUNT_THROWN); 2078. } 2079. /* 2080. * TODO? Force off gloves if either or both rings are going to 2081. * become unworn; force off cloak [suit] before suit [shirt]. 2082. * The torso handling is hypothetical; the case for gloves is 2083. * not, due to the possibility of unwearing silver rings. 2084. */ 2085. 2086. dropit = (dropflag == 1); /* all untouchable items */ 2087. /* loss of levitation (silver ring, or Heart of Ahriman invocation) 2088. might cause hero to lose inventory items (by dropping into lava, 2089. for instance), so inventory traversal needs to rescan the whole 2090. invent chain each time it moves on to another object; we use bypass 2091. handling to keep track of which items have already been processed */ 2092. while ((obj = nxt_unbypassed_obj(invent)) != 0) 2093. (void) untouchable(obj, dropit); 2094. 2095. if (had_rings != (!!uleft + !!uright) && uarmg && uarmg->cursed) 2096. uncurse(uarmg); /* temporary? hack for ring removal plausibility */ 2097. if (had_gloves && !uarmg) 2098. selftouch("After losing your gloves, you"); 2099. 2100. if (!--nesting) 2101. clear_bypasses(); /* reset upon final exit */ 2102. } 2103. 2104. static int mkot_trap_warn_count = 0; 2105. 2106. STATIC_OVL int 2107. count_surround_traps(x, y) 2108. int x, y; 2109. { 2110. struct rm *levp; 2111. struct obj *otmp; 2112. struct trap *ttmp; 2113. int dx, dy, glyph, ret = 0; 2114. 2115. for (dx = x - 1; dx < x + 2; ++dx) 2116. for (dy = y - 1; dy < y + 2; ++dy) { 2117. if (!isok(dx, dy)) 2118. continue; 2119. /* If a trap is shown here, don't count it; the hero 2120. * should be expecting it. But if there is a trap here 2121. * that's not shown, either undiscovered or covered by 2122. * something, do count it. 2123. */ 2124. glyph = glyph_at(dx, dy); 2125. if (glyph_is_trap(glyph)) 2126. continue; 2127. if ((ttmp = t_at(dx, dy)) != 0) { 2128. ++ret; 2129. continue; 2130. } 2131. levp = &levl[dx][dy]; 2132. if (IS_DOOR(levp->typ) && (levp->doormask & D_TRAPPED) != 0) { 2133. ++ret; 2134. continue; 2135. } 2136. for (otmp = level.objects[dx][dy]; otmp; otmp = otmp->nexthere) 2137. if (Is_container(otmp) && otmp->otrapped) { 2138. ++ret; /* we're counting locations, so just */ 2139. break; /* count the first one in a pile */ 2140. } 2141. } 2142. /* 2143. * [Shouldn't we also check inventory for a trapped container? 2144. * Even if its trap has already been found, there's no 'tknown' 2145. * flag to help hero remember that so we have nothing comparable 2146. * to a shown glyph to justify skipping it.] 2147. */ 2148. return ret; 2149. } 2150. 2151. /* sense adjacent traps if wielding MKoT without wearing gloves */ 2152. void 2153. mkot_trap_warn() 2154. { 2155. static const char *const heat[7] = { 2156. "cool", "slightly warm", "warm", "very warm", 2157. "hot", "very hot", "like fire" 2158. }; 2159. 2160. if (!uarmg && uwep && uwep->oartifact == ART_MASTER_KEY_OF_THIEVERY) { 2161. int idx, ntraps = count_surround_traps(u.ux, u.uy); 2162. 2163. if (ntraps != mkot_trap_warn_count) { 2164. idx = min(ntraps, SIZE(heat) - 1); 2165. pline_The("Key feels %s%c", heat[idx], (ntraps > 3) ? '!' : '.'); 2166. } 2167. mkot_trap_warn_count = ntraps; 2168. } else 2169. mkot_trap_warn_count = 0; 2170. } 2171. 2172. /* Master Key is magic key if its bless/curse state meets our criteria: 2173. not cursed for rogues or blessed for non-rogues */ 2174. boolean 2175. is_magic_key(mon, obj) 2176. struct monst *mon; /* if null, non-rogue is assumed */ 2177. struct obj *obj; 2178. { 2179. if (((obj && obj->oartifact == ART_MASTER_KEY_OF_THIEVERY) 2180. && ((mon == &youmonst) ? Role_if(PM_ROGUE) 2181. : (mon && mon->data == &mons[PM_ROGUE]))) 2182. ? !obj->cursed : obj->blessed) 2183. return TRUE; 2184. return FALSE; 2185. } 2186. 2187. /* figure out whether 'mon' (usually youmonst) is carrying the magic key */ 2188. struct obj * 2189. has_magic_key(mon) 2190. struct monst *mon; /* if null, hero assumed */ 2191. { 2192. struct obj *o; 2193. short key = artilist[ART_MASTER_KEY_OF_THIEVERY].otyp; 2194. 2195. if (!mon) 2196. mon = &youmonst; 2197. for (o = ((mon == &youmonst) ? invent : mon->minvent); o; 2198. o = nxtobj(o, key, FALSE)) { 2199. if (is_magic_key(mon, o)) 2200. return o; 2201. } 2202. return (struct obj *) 0; 2203. } 2204. 2205. /*artifact.c*/