Source:NetHack 3.6.4/src/steal.c
Jump to navigation
Jump to search
Below is the full text to steal.c from the source code of NetHack 3.6.4. To link to a particular line, write [[Source:NetHack 3.6.4/src/steal.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 steal.c $NHDT-Date: 1570566382 2019/10/08 20:26:22 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.75 $ */ 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. STATIC_PTR int NDECL(stealarm); 9. 10. STATIC_DCL const char *FDECL(equipname, (struct obj *)); 11. 12. STATIC_OVL const char * 13. equipname(otmp) 14. register struct obj *otmp; 15. { 16. return ((otmp == uarmu) 17. ? "shirt" 18. : (otmp == uarmf) 19. ? "boots" 20. : (otmp == uarms) 21. ? "shield" 22. : (otmp == uarmg) 23. ? "gloves" 24. : (otmp == uarmc) 25. ? cloak_simple_name(otmp) 26. : (otmp == uarmh) 27. ? helm_simple_name(otmp) 28. : suit_simple_name(otmp)); 29. } 30. 31. /* proportional subset of gold; return value actually fits in an int */ 32. long 33. somegold(lmoney) 34. long lmoney; 35. { 36. #ifdef LINT /* long conv. ok */ 37. int igold = 0; 38. #else 39. int igold = (lmoney >= (long) LARGEST_INT) ? LARGEST_INT : (int) lmoney; 40. #endif 41. 42. if (igold < 50) 43. ; /* all gold */ 44. else if (igold < 100) 45. igold = rn1(igold - 25 + 1, 25); 46. else if (igold < 500) 47. igold = rn1(igold - 50 + 1, 50); 48. else if (igold < 1000) 49. igold = rn1(igold - 100 + 1, 100); 50. else if (igold < 5000) 51. igold = rn1(igold - 500 + 1, 500); 52. else if (igold < 10000) 53. igold = rn1(igold - 1000 + 1, 1000); 54. else 55. igold = rn1(igold - 5000 + 1, 5000); 56. 57. return (long) igold; 58. } 59. 60. /* 61. * Find the first (and hopefully only) gold object in a chain. 62. * Used when leprechaun (or you as leprechaun) looks for 63. * someone else's gold. Returns a pointer so the gold may 64. * be seized without further searching. 65. * May search containers too. 66. * Deals in gold only, as leprechauns don't care for lesser coins. 67. */ 68. struct obj * 69. findgold(chain) 70. register struct obj *chain; 71. { 72. while (chain && chain->otyp != GOLD_PIECE) 73. chain = chain->nobj; 74. return chain; 75. } 76. 77. /* 78. * Steal gold coins only. Leprechauns don't care for lesser coins. 79. */ 80. void 81. stealgold(mtmp) 82. register struct monst *mtmp; 83. { 84. register struct obj *fgold = g_at(u.ux, u.uy); 85. register struct obj *ygold; 86. register long tmp; 87. struct monst *who; 88. const char *whose, *what; 89. 90. /* skip lesser coins on the floor */ 91. while (fgold && fgold->otyp != GOLD_PIECE) 92. fgold = fgold->nexthere; 93. 94. /* Do you have real gold? */ 95. ygold = findgold(invent); 96. 97. if (fgold && (!ygold || fgold->quan > ygold->quan || !rn2(5))) { 98. obj_extract_self(fgold); 99. add_to_minv(mtmp, fgold); 100. newsym(u.ux, u.uy); 101. if (u.usteed) { 102. who = u.usteed; 103. whose = s_suffix(y_monnam(who)); 104. what = makeplural(mbodypart(who, FOOT)); 105. } else { 106. who = &youmonst; 107. whose = "your"; 108. what = makeplural(body_part(FOOT)); 109. } 110. /* [ avoid "between your rear regions" :-] */ 111. if (slithy(who->data)) 112. what = "coils"; 113. /* reduce "rear hooves/claws" to "hooves/claws" */ 114. if (!strncmp(what, "rear ", 5)) 115. what += 5; 116. pline("%s quickly snatches some gold from %s %s %s!", Monnam(mtmp), 117. (Levitation || Flying) ? "beneath" : "between", whose, what); 118. if (!ygold || !rn2(5)) { 119. if (!tele_restrict(mtmp)) 120. (void) rloc(mtmp, TRUE); 121. monflee(mtmp, 0, FALSE, FALSE); 122. } 123. } else if (ygold) { 124. const int gold_price = objects[GOLD_PIECE].oc_cost; 125. 126. tmp = (somegold(money_cnt(invent)) + gold_price - 1) / gold_price; 127. tmp = min(tmp, ygold->quan); 128. if (tmp < ygold->quan) 129. ygold = splitobj(ygold, tmp); 130. else 131. setnotworn(ygold); 132. freeinv(ygold); 133. add_to_minv(mtmp, ygold); 134. Your("purse feels lighter."); 135. if (!tele_restrict(mtmp)) 136. (void) rloc(mtmp, TRUE); 137. monflee(mtmp, 0, FALSE, FALSE); 138. context.botl = 1; 139. } 140. } 141. 142. /* steal armor after you finish taking it off */ 143. unsigned int stealoid; /* object to be stolen */ 144. unsigned int stealmid; /* monster doing the stealing */ 145. 146. STATIC_PTR int 147. stealarm(VOID_ARGS) 148. { 149. register struct monst *mtmp; 150. register struct obj *otmp; 151. 152. for (otmp = invent; otmp; otmp = otmp->nobj) { 153. if (otmp->o_id == stealoid) { 154. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 155. if (mtmp->m_id == stealmid) { 156. if (DEADMONSTER(mtmp)) 157. impossible("stealarm(): dead monster stealing"); 158. if (!dmgtype(mtmp->data, AD_SITM)) /* polymorphed */ 159. goto botm; 160. if (otmp->unpaid) 161. subfrombill(otmp, shop_keeper(*u.ushops)); 162. freeinv(otmp); 163. pline("%s steals %s!", Monnam(mtmp), doname(otmp)); 164. (void) mpickobj(mtmp, otmp); /* may free otmp */ 165. /* Implies seduction, "you gladly hand over ..." 166. so we don't set mavenge bit here. */ 167. monflee(mtmp, 0, FALSE, FALSE); 168. if (!tele_restrict(mtmp)) 169. (void) rloc(mtmp, TRUE); 170. break; 171. } 172. } 173. break; 174. } 175. } 176. botm: 177. stealoid = 0; 178. return 0; 179. } 180. 181. /* An object you're wearing has been taken off by a monster (theft or 182. seduction). Also used if a worn item gets transformed (stone to flesh). */ 183. void 184. remove_worn_item(obj, unchain_ball) 185. struct obj *obj; 186. boolean unchain_ball; /* whether to unpunish or just unwield */ 187. { 188. if (donning(obj)) 189. cancel_don(); 190. if (!obj->owornmask) 191. return; 192. 193. if (obj->owornmask & W_ARMOR) { 194. if (obj == uskin) { 195. impossible("Removing embedded scales?"); 196. skinback(TRUE); /* uarm = uskin; uskin = 0; */ 197. } 198. if (obj == uarm) 199. (void) Armor_off(); 200. else if (obj == uarmc) 201. (void) Cloak_off(); 202. else if (obj == uarmf) 203. (void) Boots_off(); 204. else if (obj == uarmg) 205. (void) Gloves_off(); 206. else if (obj == uarmh) 207. (void) Helmet_off(); 208. else if (obj == uarms) 209. (void) Shield_off(); 210. else if (obj == uarmu) 211. (void) Shirt_off(); 212. /* catchall -- should never happen */ 213. else 214. setworn((struct obj *) 0, obj->owornmask & W_ARMOR); 215. } else if (obj->owornmask & W_AMUL) { 216. Amulet_off(); 217. } else if (obj->owornmask & W_RING) { 218. Ring_gone(obj); 219. } else if (obj->owornmask & W_TOOL) { 220. Blindf_off(obj); 221. } else if (obj->owornmask & W_WEAPONS) { 222. if (obj == uwep) 223. uwepgone(); 224. if (obj == uswapwep) 225. uswapwepgone(); 226. if (obj == uquiver) 227. uqwepgone(); 228. } 229. 230. if (obj->owornmask & (W_BALL | W_CHAIN)) { 231. if (unchain_ball) 232. unpunish(); 233. } else if (obj->owornmask) { 234. /* catchall */ 235. setnotworn(obj); 236. } 237. } 238. 239. /* Returns 1 when something was stolen (or at least, when N should flee now) 240. * Returns -1 if the monster died in the attempt 241. * Avoid stealing the object stealoid 242. * Nymphs and monkeys won't steal coins 243. */ 244. int 245. steal(mtmp, objnambuf) 246. struct monst *mtmp; 247. char *objnambuf; 248. { 249. struct obj *otmp; 250. int tmp, could_petrify, armordelay, olddelay, icnt, 251. named = 0, retrycnt = 0; 252. boolean monkey_business, /* true iff an animal is doing the thievery */ 253. was_doffing, was_punished = Punished; 254. 255. if (objnambuf) 256. *objnambuf = '\0'; 257. /* the following is true if successful on first of two attacks. */ 258. if (!monnear(mtmp, u.ux, u.uy)) 259. return 0; 260. 261. /* food being eaten might already be used up but will not have 262. been removed from inventory yet; we don't want to steal that, 263. so this will cause it to be removed now */ 264. if (occupation) 265. (void) maybe_finished_meal(FALSE); 266. 267. icnt = inv_cnt(FALSE); /* don't include gold */ 268. if (!icnt || (icnt == 1 && uskin)) { 269. nothing_to_steal: 270. /* Not even a thousand men in armor can strip a naked man. */ 271. if (Blind) 272. pline("Somebody tries to rob you, but finds nothing to steal."); 273. else if (inv_cnt(TRUE) > inv_cnt(FALSE)) /* ('icnt' might be stale) */ 274. pline("%s tries to rob you, but isn't interested in gold.", 275. Monnam(mtmp)); 276. else 277. pline("%s tries to rob you, but there is nothing to steal!", 278. Monnam(mtmp)); 279. return 1; /* let her flee */ 280. } 281. 282. monkey_business = is_animal(mtmp->data); 283. if (monkey_business || uarmg) { 284. ; /* skip ring special cases */ 285. } else if (Adornment & LEFT_RING) { 286. otmp = uleft; 287. goto gotobj; 288. } else if (Adornment & RIGHT_RING) { 289. otmp = uright; 290. goto gotobj; 291. } 292. 293. retry: 294. tmp = 0; 295. for (otmp = invent; otmp; otmp = otmp->nobj) 296. if ((!uarm || otmp != uarmc) && otmp != uskin 297. && otmp->oclass != COIN_CLASS) 298. tmp += (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1; 299. if (!tmp) 300. goto nothing_to_steal; 301. tmp = rn2(tmp); 302. for (otmp = invent; otmp; otmp = otmp->nobj) 303. if ((!uarm || otmp != uarmc) && otmp != uskin 304. && otmp->oclass != COIN_CLASS) { 305. tmp -= (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1; 306. if (tmp < 0) 307. break; 308. } 309. if (!otmp) { 310. impossible("Steal fails!"); 311. return 0; 312. } 313. /* can't steal ring(s) while wearing gloves */ 314. if ((otmp == uleft || otmp == uright) && uarmg) 315. otmp = uarmg; 316. /* can't steal gloves while wielding - so steal the wielded item. */ 317. if (otmp == uarmg && uwep) 318. otmp = uwep; 319. /* can't steal armor while wearing cloak - so steal the cloak. */ 320. else if (otmp == uarm && uarmc) 321. otmp = uarmc; 322. /* can't steal shirt while wearing cloak or suit */ 323. else if (otmp == uarmu && uarmc) 324. otmp = uarmc; 325. else if (otmp == uarmu && uarm) 326. otmp = uarm; 327. 328. gotobj: 329. if (otmp->o_id == stealoid) 330. return 0; 331. 332. if (otmp->otyp == BOULDER && !throws_rocks(mtmp->data)) { 333. if (!retrycnt++) 334. goto retry; 335. goto cant_take; 336. } 337. /* animals can't overcome curse stickiness nor unlock chains */ 338. if (monkey_business) { 339. boolean ostuck; 340. 341. /* is the player prevented from voluntarily giving up this item? 342. (ignores loadstones; the !can_carry() check will catch those) */ 343. if (otmp == uball) 344. ostuck = TRUE; /* effectively worn; curse is implicit */ 345. else if (otmp == uquiver || (otmp == uswapwep && !u.twoweap)) 346. ostuck = FALSE; /* not really worn; curse doesn't matter */ 347. else 348. ostuck = ((otmp->cursed && otmp->owornmask) 349. /* nymphs can steal rings from under 350. cursed weapon but animals can't */ 351. || (otmp == uright && welded(uwep)) 352. || (otmp == uleft && welded(uwep) && bimanual(uwep))); 353. 354. if (ostuck || can_carry(mtmp, otmp) == 0) { 355. static const char *const how[] = { "steal", "snatch", "grab", 356. "take" }; 357. cant_take: 358. pline("%s tries to %s %s%s but gives up.", Monnam(mtmp), 359. how[rn2(SIZE(how))], 360. (otmp->owornmask & W_ARMOR) ? "your " : "", 361. (otmp->owornmask & W_ARMOR) ? equipname(otmp) 362. : yname(otmp)); 363. /* the fewer items you have, the less likely the thief 364. is going to stick around to try again (0) instead of 365. running away (1) */ 366. return !rn2(inv_cnt(FALSE) / 5 + 2); 367. } 368. } 369. 370. if (otmp->otyp == LEASH && otmp->leashmon) { 371. if (monkey_business && otmp->cursed) 372. goto cant_take; 373. o_unleash(otmp); 374. } 375. 376. was_doffing = doffing(otmp); 377. /* stop donning/doffing now so that afternmv won't be clobbered 378. below; stop_occupation doesn't handle donning/doffing */ 379. olddelay = stop_donning(otmp); 380. /* you're going to notice the theft... */ 381. stop_occupation(); 382. 383. if (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) { 384. switch (otmp->oclass) { 385. case TOOL_CLASS: 386. case AMULET_CLASS: 387. case RING_CLASS: 388. case FOOD_CLASS: /* meat ring */ 389. remove_worn_item(otmp, TRUE); 390. break; 391. case ARMOR_CLASS: 392. armordelay = objects[otmp->otyp].oc_delay; 393. if (olddelay > 0 && olddelay < armordelay) 394. armordelay = olddelay; 395. if (monkey_business) { 396. /* animals usually don't have enough patience 397. to take off items which require extra time */ 398. if (armordelay >= 1 && !olddelay && rn2(10)) 399. goto cant_take; 400. remove_worn_item(otmp, TRUE); 401. break; 402. } else { 403. int curssv = otmp->cursed; 404. int slowly; 405. boolean seen = canspotmon(mtmp); 406. 407. otmp->cursed = 0; 408. /* can't charm you without first waking you */ 409. if (Unaware) 410. unmul((char *) 0); 411. slowly = (armordelay >= 1 || multi < 0); 412. if (flags.female) 413. pline("%s charms you. You gladly %s your %s.", 414. !seen ? "She" : Monnam(mtmp), 415. curssv ? "let her take" 416. : !slowly ? "hand over" 417. : was_doffing ? "continue removing" 418. : "start removing", 419. equipname(otmp)); 420. else 421. pline("%s seduces you and %s off your %s.", 422. !seen ? "She" : Adjmonnam(mtmp, "beautiful"), 423. curssv 424. ? "helps you to take" 425. : !slowly ? "you take" 426. : was_doffing ? "you continue taking" 427. : "you start taking", 428. equipname(otmp)); 429. named++; 430. /* the following is to set multi for later on */ 431. nomul(-armordelay); 432. multi_reason = "taking off clothes"; 433. nomovemsg = 0; 434. remove_worn_item(otmp, TRUE); 435. otmp->cursed = curssv; 436. if (multi < 0) { 437. /* 438. multi = 0; 439. afternmv = 0; 440. */ 441. stealoid = otmp->o_id; 442. stealmid = mtmp->m_id; 443. afternmv = stealarm; 444. return 0; 445. } 446. } 447. break; 448. default: 449. impossible("Tried to steal a strange worn thing. [%d]", 450. otmp->oclass); 451. } 452. } else if (otmp->owornmask) /* weapon or ball&chain */ 453. remove_worn_item(otmp, TRUE); 454. 455. /* do this before removing it from inventory */ 456. if (objnambuf) 457. Strcpy(objnambuf, yname(otmp)); 458. /* usually set mavenge bit so knights won't suffer an alignment penalty 459. during retaliation; not applicable for removing attached iron ball */ 460. if (!Conflict && !(was_punished && !Punished)) 461. mtmp->mavenge = 1; 462. 463. if (otmp->unpaid) 464. subfrombill(otmp, shop_keeper(*u.ushops)); 465. freeinv(otmp); 466. /* if attached ball was taken, uball and uchain are now Null */ 467. pline("%s%s stole %s.", named ? "She" : Monnam(mtmp), 468. (was_punished && !Punished) ? " removed your chain and" : "", 469. doname(otmp)); 470. could_petrify = (otmp->otyp == CORPSE 471. && touch_petrifies(&mons[otmp->corpsenm])); 472. (void) mpickobj(mtmp, otmp); /* may free otmp */ 473. if (could_petrify && !(mtmp->misc_worn_check & W_ARMG)) { 474. minstapetrify(mtmp, TRUE); 475. return -1; 476. } 477. return (multi < 0) ? 0 : 1; 478. } 479. 480. /* Returns 1 if otmp is free'd, 0 otherwise. */ 481. int 482. mpickobj(mtmp, otmp) 483. register struct monst *mtmp; 484. register struct obj *otmp; 485. { 486. int freed_otmp; 487. boolean snuff_otmp = FALSE; 488. 489. if (!otmp) { 490. impossible("monster (%s) taking or picking up nothing?", 491. mtmp->data->mname); 492. return 1; 493. } else if (otmp == uball || otmp == uchain) { 494. impossible("monster (%s) taking or picking up attached %s (%s)?", 495. mtmp->data->mname, 496. (otmp == uchain) ? "chain" : "ball", simpleonames(otmp)); 497. return 0; 498. } 499. /* if monster is acquiring a thrown or kicked object, the throwing 500. or kicking code shouldn't continue to track and place it */ 501. if (otmp == thrownobj) 502. thrownobj = 0; 503. else if (otmp == kickedobj) 504. kickedobj = 0; 505. /* don't want hidden light source inside the monster; assumes that 506. engulfers won't have external inventories; whirly monsters cause 507. the light to be extinguished rather than letting it shine thru */ 508. if (obj_sheds_light(otmp) && attacktype(mtmp->data, AT_ENGL)) { 509. /* this is probably a burning object that you dropped or threw */ 510. if (u.uswallow && mtmp == u.ustuck && !Blind) 511. pline("%s out.", Tobjnam(otmp, "go")); 512. snuff_otmp = TRUE; 513. } 514. /* for hero owned object on shop floor, mtmp is taking possession 515. and if it's eventually dropped in a shop, shk will claim it */ 516. if (!mtmp->mtame) 517. otmp->no_charge = 0; 518. /* Must do carrying effects on object prior to add_to_minv() */ 519. carry_obj_effects(otmp); 520. /* add_to_minv() might free otmp [if merged with something else], 521. so we have to call it after doing the object checks */ 522. freed_otmp = add_to_minv(mtmp, otmp); 523. /* and we had to defer this until object is in mtmp's inventory */ 524. if (snuff_otmp) 525. snuff_light_source(mtmp->mx, mtmp->my); 526. return freed_otmp; 527. } 528. 529. /* called for AD_SAMU (the Wizard and quest nemeses) */ 530. void 531. stealamulet(mtmp) 532. struct monst *mtmp; 533. { 534. char buf[BUFSZ]; 535. struct obj *otmp = 0, *obj = 0; 536. int real = 0, fake = 0, n; 537. 538. /* target every quest artifact, not just current role's; 539. if hero has more than one, choose randomly so that player 540. can't use inventory ordering to influence the theft */ 541. for (n = 0, obj = invent; obj; obj = obj->nobj) 542. if (any_quest_artifact(obj)) 543. ++n, otmp = obj; 544. if (n > 1) { 545. n = rnd(n); 546. for (otmp = invent; otmp; otmp = otmp->nobj) 547. if (any_quest_artifact(otmp) && !--n) 548. break; 549. } 550. 551. if (!otmp) { 552. /* if we didn't find any quest arifact, find another valuable item */ 553. if (u.uhave.amulet) { 554. real = AMULET_OF_YENDOR; 555. fake = FAKE_AMULET_OF_YENDOR; 556. } else if (u.uhave.bell) { 557. real = BELL_OF_OPENING; 558. fake = BELL; 559. } else if (u.uhave.book) { 560. real = SPE_BOOK_OF_THE_DEAD; 561. } else if (u.uhave.menorah) { 562. real = CANDELABRUM_OF_INVOCATION; 563. } else 564. return; /* you have nothing of special interest */ 565. 566. /* If we get here, real and fake have been set up. */ 567. for (n = 0, obj = invent; obj; obj = obj->nobj) 568. if (obj->otyp == real || (obj->otyp == fake && !mtmp->iswiz)) 569. ++n, otmp = obj; 570. if (n > 1) { 571. n = rnd(n); 572. for (otmp = invent; otmp; otmp = otmp->nobj) 573. if ((otmp->otyp == real 574. || (otmp->otyp == fake && !mtmp->iswiz)) && !--n) 575. break; 576. } 577. } 578. 579. if (otmp) { /* we have something to snatch */ 580. /* take off outer gear if we're targetting [hypothetical] 581. quest artifact suit, shirt, gloves, or rings */ 582. if ((otmp == uarm || otmp == uarmu) && uarmc) 583. remove_worn_item(uarmc, FALSE); 584. if (otmp == uarmu && uarm) 585. remove_worn_item(uarm, FALSE); 586. if ((otmp == uarmg || ((otmp == uright || otmp == uleft) && uarmg)) 587. && uwep) { 588. /* gloves are about to be unworn; unwield weapon(s) first */ 589. if (u.twoweap) /* remove_worn_item(uswapwep) indirectly */ 590. remove_worn_item(uswapwep, FALSE); /* clears u.twoweap */ 591. remove_worn_item(uwep, FALSE); 592. } 593. if ((otmp == uright || otmp == uleft) && uarmg) 594. /* calls Gloves_off() to handle wielded cockatrice corpse */ 595. remove_worn_item(uarmg, FALSE); 596. 597. /* finally, steal the target item */ 598. if (otmp->owornmask) 599. remove_worn_item(otmp, TRUE); 600. if (otmp->unpaid) 601. subfrombill(otmp, shop_keeper(*u.ushops)); 602. freeinv(otmp); 603. Strcpy(buf, doname(otmp)); 604. (void) mpickobj(mtmp, otmp); /* could merge and free otmp but won't */ 605. pline("%s steals %s!", Monnam(mtmp), buf); 606. if (can_teleport(mtmp->data) && !tele_restrict(mtmp)) 607. (void) rloc(mtmp, TRUE); 608. } 609. } 610. 611. /* when a mimic gets poked with something, it might take that thing 612. (at present, only implemented for when the hero does the poking) */ 613. void 614. maybe_absorb_item(mon, obj, ochance, achance) 615. struct monst *mon; 616. struct obj *obj; 617. int ochance, achance; /* percent chance for ordinary item, artifact */ 618. { 619. if (obj == uball || obj == uchain || obj->oclass == ROCK_CLASS 620. || obj_resists(obj, 100 - ochance, 100 - achance) 621. || !touch_artifact(obj, mon)) 622. return; 623. 624. if (carried(obj)) { 625. if (obj->owornmask) 626. remove_worn_item(obj, TRUE); 627. if (obj->unpaid) 628. subfrombill(obj, shop_keeper(*u.ushops)); 629. if (cansee(mon->mx, mon->my)) { 630. const char *MonName = Monnam(mon); 631. 632. /* mon might be invisible; avoid "It pulls ... and absorbs it!" */ 633. if (!strcmp(MonName, "It")) 634. MonName = "Something"; 635. pline("%s pulls %s away from you and absorbs %s!", MonName, 636. yname(obj), (obj->quan > 1L) ? "them" : "it"); 637. } else { 638. const char *hand_s = body_part(HAND); 639. 640. if (bimanual(obj)) 641. hand_s = makeplural(hand_s); 642. pline("%s %s pulled from your %s!", upstart(yname(obj)), 643. otense(obj, "are"), hand_s); 644. } 645. freeinv(obj); 646. } else { 647. /* not carried; presumably thrown or kicked */ 648. if (canspotmon(mon)) 649. pline("%s absorbs %s!", Monnam(mon), yname(obj)); 650. } 651. /* add to mon's inventory */ 652. (void) mpickobj(mon, obj); 653. } 654. 655. /* drop one object taken from a (possibly dead) monster's inventory */ 656. void 657. mdrop_obj(mon, obj, verbosely) 658. struct monst *mon; 659. struct obj *obj; 660. boolean verbosely; 661. { 662. int omx = mon->mx, omy = mon->my; 663. boolean update_mon = FALSE; 664. 665. if (obj->owornmask) { 666. /* perform worn item handling if the monster is still alive */ 667. if (!DEADMONSTER(mon)) { 668. mon->misc_worn_check &= ~obj->owornmask; 669. update_mon = TRUE; 670. 671. /* don't charge for an owned saddle on dead steed (provided 672. that the hero is within the same shop at the time) */ 673. } else if (mon->mtame && (obj->owornmask & W_SADDLE) != 0L 674. && !obj->unpaid && costly_spot(omx, omy) 675. /* being at costly_spot guarantees lev->roomno is not 0 */ 676. && index(in_rooms(u.ux, u.uy, SHOPBASE), 677. levl[omx][omy].roomno)) { 678. obj->no_charge = 1; 679. } 680. /* this should be done even if the monster has died */ 681. if (obj->owornmask & W_WEP) 682. setmnotwielded(mon, obj); 683. obj->owornmask = 0L; 684. } 685. /* obj_no_longer_held(obj); -- done by place_object */ 686. if (verbosely && cansee(omx, omy)) 687. pline("%s drops %s.", Monnam(mon), distant_name(obj, doname)); 688. if (!flooreffects(obj, omx, omy, "fall")) { 689. place_object(obj, omx, omy); 690. stackobj(obj); 691. } 692. /* do this last, after placing obj on floor; removing steed's saddle 693. throws rider, possibly inflicting fatal damage and producing bones */ 694. if (update_mon) 695. update_mon_intrinsics(mon, obj, FALSE, TRUE); 696. } 697. 698. /* some monsters bypass the normal rules for moving between levels or 699. even leaving the game entirely; when that happens, prevent them from 700. taking the Amulet, invocation items, or quest artifact with them */ 701. void 702. mdrop_special_objs(mon) 703. struct monst *mon; 704. { 705. struct obj *obj, *otmp; 706. 707. for (obj = mon->minvent; obj; obj = otmp) { 708. otmp = obj->nobj; 709. /* the Amulet, invocation tools, and Rider corpses resist even when 710. artifacts and ordinary objects are given 0% resistance chance; 711. current role's quest artifact is rescued too--quest artifacts 712. for the other roles are not */ 713. if (obj_resists(obj, 0, 0) || is_quest_artifact(obj)) { 714. obj_extract_self(obj); 715. if (mon->mx) { 716. mdrop_obj(mon, obj, FALSE); 717. } else { /* migrating monster not on map */ 718. if (obj->owornmask) { 719. mon->misc_worn_check &= ~obj->owornmask; 720. if (obj->owornmask & W_WEP) 721. setmnotwielded(mon, obj); 722. obj->owornmask = 0L; 723. } 724. rloco(obj); 725. } 726. } 727. } 728. } 729. 730. /* release the objects the creature is carrying */ 731. void 732. relobj(mtmp, show, is_pet) 733. struct monst *mtmp; 734. int show; 735. boolean is_pet; /* If true, pet should keep wielded/worn items */ 736. { 737. struct obj *otmp; 738. int omx = mtmp->mx, omy = mtmp->my; 739. 740. /* vault guard's gold goes away rather than be dropped... */ 741. if (mtmp->isgd && (otmp = findgold(mtmp->minvent)) != 0) { 742. if (canspotmon(mtmp)) 743. pline("%s gold %s.", s_suffix(Monnam(mtmp)), 744. canseemon(mtmp) ? "vanishes" : "seems to vanish"); 745. obj_extract_self(otmp); 746. obfree(otmp, (struct obj *) 0); 747. } /* isgd && has gold */ 748. 749. while ((otmp = (is_pet ? droppables(mtmp) : mtmp->minvent)) != 0) { 750. obj_extract_self(otmp); 751. mdrop_obj(mtmp, otmp, is_pet && flags.verbose); 752. } 753. 754. if (show && cansee(omx, omy)) 755. newsym(omx, omy); 756. } 757. 758. /*steal.c*/