Source:NetHack 5.0.0/src/steal.c
Jump to navigation
Jump to search
Below is the full text to steal.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/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 5.0 steal.c $NHDT-Date: 1720895742 2024/07/13 18:35:42 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.132 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2012. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. 8. staticfn int unstolenarm(void); 9. staticfn int stealarm(void); 10. staticfn void worn_item_removal(struct monst *, struct obj *); 11. 12. /* proportional subset of gold; return value actually fits in an int */ 13. long 14. somegold(long lmoney) 15. { 16. int igold = (lmoney >= (long) LARGEST_INT) ? LARGEST_INT : (int) lmoney; 17. 18. if (igold < 50) 19. ; /* all gold */ 20. else if (igold < 100) 21. igold = rn1(igold - 25 + 1, 25); 22. else if (igold < 500) 23. igold = rn1(igold - 50 + 1, 50); 24. else if (igold < 1000) 25. igold = rn1(igold - 100 + 1, 100); 26. else if (igold < 5000) 27. igold = rn1(igold - 500 + 1, 500); 28. else if (igold < 10000) 29. igold = rn1(igold - 1000 + 1, 1000); 30. else 31. igold = rn1(igold - 5000 + 1, 5000); 32. 33. return (long) igold; 34. } 35. 36. /* 37. * Find the first (and hopefully only) gold object in a chain. 38. * Used when leprechaun (or you as leprechaun) looks for 39. * someone else's gold. Returns a pointer so the gold may 40. * be seized without further searching. 41. * May search containers too. 42. * Deals in gold only, as leprechauns don't care for lesser coins. 43. */ 44. struct obj * 45. findgold(struct obj *argchain) 46. { 47. struct obj *chain = argchain; /* allow arg to be nonnull */ 48. 49. while (chain && chain->otyp != GOLD_PIECE) 50. chain = chain->nobj; 51. return chain; 52. } 53. 54. /* 55. * Steal gold coins only. Leprechauns don't care for lesser coins. 56. */ 57. void 58. stealgold(struct monst *mtmp) 59. { 60. struct obj *fgold = g_at(u.ux, u.uy); 61. struct obj *ygold; 62. long tmp; 63. struct monst *who; 64. const char *whose, *what; 65. 66. /* skip lesser coins on the floor */ 67. while (fgold && fgold->otyp != GOLD_PIECE) 68. fgold = fgold->nexthere; 69. 70. /* Do you have real gold? */ 71. ygold = findgold(gi.invent); 72. 73. if (fgold && (!ygold || fgold->quan > ygold->quan || !rn2(5))) { 74. obj_extract_self(fgold); 75. add_to_minv(mtmp, fgold); 76. newsym(u.ux, u.uy); 77. if (u.usteed) { 78. who = u.usteed; 79. whose = s_suffix(y_monnam(who)); 80. what = makeplural(mbodypart(who, FOOT)); 81. } else { 82. who = &gy.youmonst; 83. whose = "your"; 84. what = makeplural(body_part(FOOT)); 85. } 86. /* [ avoid "between your rear regions" :-] */ 87. if (slithy(who->data)) 88. what = "coils"; 89. /* reduce "rear hooves/claws" to "hooves/claws" */ 90. if (!strncmp(what, "rear ", 5)) 91. what += 5; 92. pline("%s quickly snatches some gold from %s %s %s!", Monnam(mtmp), 93. (Levitation || Flying) ? "beneath" : "between", whose, what); 94. if (!ygold || !rn2(5)) { 95. if (!tele_restrict(mtmp)) 96. (void) rloc(mtmp, RLOC_MSG); 97. monflee(mtmp, 0, FALSE, FALSE); 98. } 99. } else if (ygold) { 100. const int gold_price = objects[GOLD_PIECE].oc_cost; 101. 102. tmp = (somegold(money_cnt(gi.invent)) + gold_price - 1) / gold_price; 103. tmp = min(tmp, ygold->quan); 104. if (tmp < ygold->quan) 105. ygold = splitobj(ygold, tmp); 106. else 107. setnotworn(ygold); 108. freeinv(ygold); 109. add_to_minv(mtmp, ygold); 110. Your("purse feels lighter."); 111. if (!tele_restrict(mtmp)) 112. (void) rloc(mtmp, RLOC_MSG); 113. monflee(mtmp, 0, FALSE, FALSE); 114. disp.botl = TRUE; 115. } 116. } 117. 118. /* monster who was stealing from hero has just died */ 119. void 120. thiefdead(void) 121. { 122. /* hero is busy taking off an item of armor which takes multiple turns */ 123. gs.stealmid = 0; 124. if (ga.afternmv == stealarm) { 125. ga.afternmv = unstolenarm; 126. gn.nomovemsg = (char *) 0; 127. } 128. } 129. 130. /* checks whether hero can be responsive to seduction attempts; similar to 131. Unaware but also includes paralysis */ 132. boolean 133. unresponsive(void) 134. { 135. if (gm.multi >= 0) 136. return FALSE; 137. 138. return (unconscious() || is_fainted() 139. || (gm.multi_reason 140. && (!strncmp(gm.multi_reason, "frozen", 6) 141. || !strncmp(gm.multi_reason, "paralyzed", 9)))); 142. } 143. 144. /* called via (*ga.afternmv)() when hero finishes taking off armor that 145. was slated to be stolen but the thief died in the interim */ 146. staticfn int 147. unstolenarm(void) 148. { 149. struct obj *obj; 150. 151. /* find the object before clearing stealoid; it has already become 152. not-worn and is still in hero's inventory */ 153. for (obj = gi.invent; obj; obj = obj->nobj) 154. if (obj->o_id == gs.stealoid) 155. break; 156. gs.stealoid = 0; 157. if (obj) { 158. You("finish taking off your %s.", armor_simple_name(obj)); 159. } 160. return 0; 161. } 162. 163. /* finish stealing an item of armor which takes multiple turns to take off */ 164. staticfn int 165. stealarm(void) 166. { 167. struct monst *mtmp; 168. struct obj *otmp, *nextobj; 169. 170. if (!gs.stealoid || !gs.stealmid) 171. goto botm; 172. 173. for (otmp = gi.invent; otmp; otmp = nextobj) { 174. nextobj = otmp->nobj; 175. if (otmp->o_id == gs.stealoid) { 176. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 177. if (mtmp->m_id == gs.stealmid) { 178. if (DEADMONSTER(mtmp)) { 179. impossible("stealarm(): dead monster stealing"); 180. goto botm; /* (could just use 'break' here) */ 181. } 182. /* maybe the thief polymorphed into something without a 183. steal attack, or perhaps while stealing hero's suit 184. the thief took away other items causing hero to fall 185. into water or lava and then teleport to safety */ 186. if (!dmgtype(mtmp->data, AD_SITM) 187. || distu(mtmp->mx, mtmp->my) > 2) 188. goto botm; /* (could just use 'break' here) */ 189. if (otmp->unpaid) 190. subfrombill(otmp, shop_keeper(*u.ushops)); 191. freeinv(otmp); 192. pline("%s steals %s!", Monnam(mtmp), doname(otmp)); 193. (void) mpickobj(mtmp, otmp); /* may free otmp */ 194. /* Implies seduction, "you gladly hand over ..." 195. so we don't set mavenge bit here. */ 196. monflee(mtmp, 0, FALSE, FALSE); 197. if (!tele_restrict(mtmp)) 198. (void) rloc(mtmp, RLOC_MSG); 199. break; 200. } 201. } 202. break; 203. } 204. } 205. botm: 206. gs.stealoid = gs.stealmid = 0; /* in case only one has been reset so far */ 207. return 0; 208. } 209. 210. /* An object you're wearing has been taken off by a monster (theft or 211. seduction). Also used if a worn item gets transformed (stone to flesh). */ 212. void 213. remove_worn_item( 214. struct obj *obj, 215. boolean unchain_ball) /* whether to unpunish or just unwield */ 216. { 217. unsigned oldinuse; 218. 219. if (donning(obj)) 220. cancel_don(); 221. if (!obj->owornmask) 222. return; 223. 224. /* 225. * Losing worn gear might drop hero into water or lava or onto a 226. * location-changing trap or take away the ability to breathe in water. 227. * Marking it 'in_use' prevents emergency_disrobe() from dropping it 228. * and lava_effects() from destroying it; other cases impacting object 229. * location (or destruction) might still have issues. 230. * 231. * Note: if a hangup save occurs when 'in_use' is set, the item will 232. * be destroyed via useup() during restore. Maybe remove_worn_item() 233. * and emergency_disrobe() should switch to using obj->bypass instead 234. * but that would need a lot more cooperation by callers. It's a 235. * tradeoff between protecting the player against unintentional hangup 236. * and defending the game against deliberate hangup when player sees a 237. * message about something undesirable followed by --More--. 238. */ 239. oldinuse = obj->in_use; 240. obj->in_use = 1; 241. 242. if (obj->owornmask & W_ARMOR) { 243. if (obj == uskin) { 244. impossible("Removing embedded scales?"); 245. skinback(TRUE); /* uarm = uskin; uskin = 0; */ 246. } 247. if (obj == uarm) 248. (void) Armor_off(); 249. else if (obj == uarmc) 250. (void) Cloak_off(); 251. else if (obj == uarmf) 252. (void) Boots_off(); 253. else if (obj == uarmg) 254. (void) Gloves_off(); 255. else if (obj == uarmh) 256. (void) Helmet_off(); 257. else if (obj == uarms) 258. (void) Shield_off(); 259. else if (obj == uarmu) 260. (void) Shirt_off(); 261. /* catchall -- should never happen */ 262. else 263. setworn((struct obj *) 0, obj->owornmask & W_ARMOR); 264. } else if (obj->owornmask & W_AMUL) { 265. Amulet_off(); 266. } else if (obj->owornmask & W_RING) { 267. Ring_gone(obj); 268. } else if (obj->owornmask & W_TOOL) { 269. Blindf_off(obj); 270. } else if (obj->owornmask & W_WEAPONS) { 271. if (obj == uwep) 272. uwepgone(); 273. if (obj == uswapwep) 274. uswapwepgone(); 275. if (obj == uquiver) 276. uqwepgone(); 277. } 278. 279. if (obj->owornmask & (W_BALL | W_CHAIN)) { 280. if (unchain_ball) 281. unpunish(); 282. } else if (obj->owornmask) { 283. /* catchall */ 284. setnotworn(obj); 285. } 286. 287. if (obj->where == OBJ_DELETED) 288. debugpline1("remove_worn_item() \"%s\" deleted!", simpleonames(obj)); 289. obj->in_use = oldinuse; 290. } 291. 292. /* during theft of a worn item: remove_worn_item(), prefaced by a message */ 293. staticfn void 294. worn_item_removal( 295. struct monst *mon, 296. struct obj *obj) 297. { 298. char objbuf[BUFSZ], article[20], *p; 299. const char *verb; 300. int strip_art; 301. 302. Strcpy(objbuf, doname(obj)); 303. /* massage the object description */ 304. strip_art = !strncmp(objbuf, "the ", 4) ? 4 305. : !strncmp(objbuf, "an ", 3) ? 3 306. : !strncmp(objbuf, "a ", 2) ? 2 307. : 0; 308. if (strip_art) { /* convert "a/an/the <object>" to "your object" */ 309. copynchars(article, objbuf, strip_art); 310. /* when removing attached iron ball, caller passes 'uchain'; 311. when formatted, it will be "an iron chain (attached to you)"; 312. change "an" to "the" rather than to "your" in that situation */ 313. (void) strsubst(objbuf, article, (obj == uchain) ? "the " : "your "); 314. } 315. /* these ought to be guarded against matching user-supplied name */ 316. (void) strsubst(objbuf, " (being worn)", ""); 317. (void) strsubst(objbuf, " (alternate weapon; not wielded)", ""); 318. /* convert "ring (on left hand)" to "ring (from left hand)" */ 319. if ((p = strstri(objbuf, " (on ")) 320. && (!strncmp(p + 5, "left ", 5) || !strncmp(p + 5, "right ", 6))) 321. (void) strsubst(p + 2, "on", "from"); 322. 323. /* slightly iffy for alternate weapon that isn't actively dual-wielded, 324. but it's better to alert the player to the change in equipment than 325. to suppress the message for that case */ 326. verb = ((obj->owornmask & W_WEAPONS) != 0L) ? "disarms" 327. : ((obj->owornmask & W_ACCESSORY) != 0L) ? "removes" 328. : "takes off"; 329. pline("%s %s %s.", Some_Monnam(mon), verb, objbuf); 330. iflags.last_msg = PLNMSG_MON_TAKES_OFF_ITEM; 331. /* removal might trigger more messages (due to loss of Lev|Fly; 332. descending happens before the theft in progress finishes) */ 333. remove_worn_item(obj, TRUE); 334. } 335. 336. /* Returns 1 when something was stolen (or at least, when N should flee now), 337. * returns -1 if the monster died in the attempt. 338. * Avoid stealing the object 'stealoid'. 339. * Nymphs and monkeys won't steal coins (so that their "steal item" attack 340. * doesn't become a superset of leprechaun's "steal gold" attack). 341. */ 342. int 343. steal(struct monst *mtmp, char *objnambuf) 344. { 345. struct obj *otmp; 346. char Monnambuf[BUFSZ]; 347. int tmp, could_petrify, armordelay, olddelay, icnt, 348. named = 0, retrycnt = 0; 349. boolean monkey_business = is_animal(mtmp->data), 350. seen = canspotmon(mtmp), 351. was_doffing, was_punished = Punished; 352. 353. if (objnambuf) 354. *objnambuf = '\0'; 355. /* the following is true if successful on first of two attacks. */ 356. if (!monnear(mtmp, u.ux, u.uy)) 357. return 0; 358. 359. /* stealing a worn item might drop hero into water or lava where 360. teleporting to safety could result in a previously visible thief 361. no longer being visible; it could also be a case of a blinded 362. hero being able to see via wearing the Eyes of the Overworld and 363. having those stolen; remember the name as it is now; if unseen, 364. nymphs will be "Someone" and monkeys will be "Something" */ 365. Strcpy(Monnambuf, Some_Monnam(mtmp)); 366. 367. /* food being eaten might already be used up but will not have 368. been removed from inventory yet; we don't want to steal that, 369. so this will cause it to be removed now */ 370. if (go.occupation) 371. (void) maybe_finished_meal(FALSE); 372. 373. icnt = inv_cnt(FALSE); /* don't include gold */ 374. if (!icnt || (icnt == 1 && uskin)) { 375. /* Not even a thousand men in armor can strip a naked man. */ 376. nothing_to_steal: 377. /* nymphs might target uchain if invent is empty; monkeys won't; 378. hero becomes unpunished but nymph ends up empty handed */ 379. if (Punished && !monkey_business && rn2(4)) { 380. /* uball is not carried (uchain never is) */ 381. assert(uball != NULL && uball->where == OBJ_FLOOR); 382. worn_item_removal(mtmp, uchain); 383. } else if (u.utrap && u.utraptype == TT_BURIEDBALL 384. && !monkey_business && !rn2(4)) { 385. boolean dummy; 386. 387. /* buried ball is not tracked via 'uball' and there is no chain 388. at all (hence no uchain to take off) */ 389. pline("%s takes off your unseen chain.", Monnambuf); 390. (void) openholdingtrap(&gy.youmonst, &dummy); 391. } else if (Blind) { 392. pline("Somebody tries to rob you, but finds nothing to steal."); 393. } else if (inv_cnt(TRUE) > inv_cnt(FALSE)) { 394. pline("%s tries to rob you, but isn't interested in gold.", 395. Monnambuf); 396. } else { 397. pline("%s tries to rob you, but there is nothing to steal!", 398. Monnambuf); 399. } 400. return 1; /* let her flee */ 401. } 402. 403. if (monkey_business || uarmg) { 404. ; /* skip ring special cases */ 405. } else if (Adornment & LEFT_RING) { 406. otmp = uleft; 407. goto gotobj; 408. } else if (Adornment & RIGHT_RING) { 409. otmp = uright; 410. goto gotobj; 411. } 412. 413. retry: 414. tmp = 0; 415. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 416. if ((!uarm || otmp != uarmc) && otmp != uskin 417. && otmp->oclass != COIN_CLASS) 418. tmp += (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1; 419. if (!tmp) 420. goto nothing_to_steal; 421. tmp = rn2(tmp); 422. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 423. if ((!uarm || otmp != uarmc) && otmp != uskin 424. && otmp->oclass != COIN_CLASS) { 425. tmp -= (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1; 426. if (tmp < 0) 427. break; 428. } 429. if (!otmp) { 430. impossible("Steal fails!"); 431. return 0; 432. } 433. /* can't steal ring(s) while wearing gloves */ 434. if ((otmp == uleft || otmp == uright) && uarmg) 435. otmp = uarmg; 436. /* can't steal gloves while wielding - so steal the wielded item. */ 437. if (otmp == uarmg && uwep) 438. otmp = uwep; 439. /* can't steal armor while wearing cloak - so steal the cloak. */ 440. else if (otmp == uarm && uarmc) 441. otmp = uarmc; 442. /* can't steal shirt while wearing cloak or suit */ 443. else if (otmp == uarmu && uarmc) 444. otmp = uarmc; 445. else if (otmp == uarmu && uarm) 446. otmp = uarm; 447. 448. gotobj: 449. if (otmp->o_id == gs.stealoid) 450. return 0; 451. 452. if (otmp->otyp == BOULDER && !throws_rocks(mtmp->data)) { 453. if (!retrycnt++) 454. goto retry; 455. goto cant_take; 456. } 457. /* animals can't overcome curse stickiness nor unlock chains */ 458. if (monkey_business) { 459. boolean ostuck; 460. 461. /* is the player prevented from voluntarily giving up this item? 462. (ignores loadstones; the !can_carry() check will catch those) */ 463. if (otmp == uball) 464. ostuck = TRUE; /* effectively worn; curse is implicit */ 465. else if (otmp == uquiver || (otmp == uswapwep && !u.twoweap)) 466. ostuck = FALSE; /* not really worn; curse doesn't matter */ 467. else 468. ostuck = ((otmp->cursed && otmp->owornmask) 469. /* nymphs can steal rings from under 470. cursed weapon but animals can't */ 471. || (otmp == RING_ON_PRIMARY && welded(uwep)) 472. || (otmp == RING_ON_SECONDARY && welded(uwep) 473. && bimanual(uwep))); 474. 475. if (ostuck || can_carry(mtmp, otmp) == 0) { 476. static const char *const how[] = { 477. "steal", "snatch", "grab", "take" 478. }; 479. cant_take: 480. pline("%s tries to %s %s%s but gives up.", Monnambuf, 481. ROLL_FROM(how), 482. (otmp->owornmask & W_ARMOR) ? "your " : "", 483. (otmp->owornmask & W_ARMOR) ? armor_simple_name(otmp) 484. : yname(otmp)); 485. /* the fewer items you have, the less likely the thief 486. is going to stick around to try again (0) instead of 487. running away (1) */ 488. return !rn2(inv_cnt(FALSE) / 5 + 2); 489. } 490. } 491. 492. if (otmp->otyp == LEASH && otmp->leashmon) { 493. if (monkey_business && otmp->cursed) 494. goto cant_take; 495. o_unleash(otmp); 496. } 497. 498. was_doffing = doffing(otmp); 499. /* stop donning/doffing now so that afternmv won't be clobbered 500. below; stop_occupation doesn't handle donning/doffing */ 501. olddelay = stop_donning(otmp); 502. /* you're going to notice the theft... */ 503. stop_occupation(); 504. 505. if (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) { 506. switch (otmp->oclass) { 507. case TOOL_CLASS: 508. case AMULET_CLASS: 509. case RING_CLASS: 510. case FOOD_CLASS: /* meat ring */ 511. worn_item_removal(mtmp, otmp); 512. break; 513. case ARMOR_CLASS: 514. armordelay = objects[otmp->otyp].oc_delay; 515. if (olddelay > 0 && olddelay < armordelay) 516. armordelay = olddelay; 517. if (monkey_business || unresponsive()) { 518. /* animals usually don't have enough patience to take off 519. items which require extra time; unconscious or paralyzed 520. hero can't be charmed into taking off his own armor */ 521. if (armordelay >= 1 && !olddelay && rn2(10)) 522. goto cant_take; 523. worn_item_removal(mtmp, otmp); 524. break; 525. } else { 526. int curssv = otmp->cursed; 527. int slowly; 528. 529. otmp->cursed = 0; 530. slowly = (armordelay >= 1 || gm.multi < 0); 531. if (flags.female) 532. urgent_pline("%s charms you. You gladly %s your %s.", 533. !seen ? "She" : Monnambuf, 534. curssv ? "let her take" 535. : !slowly ? "hand over" 536. : was_doffing ? "continue removing" 537. : "start removing", 538. armor_simple_name(otmp)); 539. else 540. urgent_pline("%s seduces you and %s off your %s.", 541. !seen ? "She" : Adjmonnam(mtmp, "beautiful"), 542. curssv ? "helps you to take" 543. : !slowly ? "you take" 544. : was_doffing ? "you continue taking" 545. : "you start taking", 546. armor_simple_name(otmp)); 547. named++; 548. /* the following is to set multi for later on */ 549. nomul(-armordelay); 550. gm.multi_reason = "taking off clothes"; 551. gn.nomovemsg = 0; 552. remove_worn_item(otmp, TRUE); 553. otmp->cursed = curssv; 554. if (gm.multi < 0) { 555. gs.stealoid = otmp->o_id; 556. gs.stealmid = mtmp->m_id; 557. ga.afternmv = stealarm; 558. return 0; 559. } 560. } 561. break; 562. default: 563. impossible("Tried to steal a strange worn thing. [%d]", 564. otmp->oclass); 565. } 566. /* hero's blindfold might have just been stolen; if so, replace 567. cached "Someone" or "Something" with Monnam */ 568. if (!seen && canspotmon(mtmp)) 569. Strcpy(Monnambuf, Monnam(mtmp)); 570. } else if (otmp->owornmask) { /* weapon or ball&chain */ 571. struct obj *item = otmp; 572. 573. if (otmp == uball) /* non-Null uball implies non-Null uchain */ 574. item = uchain; /* yields a more accurate 'takes off' message */ 575. worn_item_removal(mtmp, item); 576. /* if we switched from uball to uchain for the preface message, 577. then unpunish() took place and both those pointers are now Null, 578. with 'item' a stale pointer to freed chain; the ball is still 579. present though and 'otmp' is still valid; if uball was also 580. wielded or quivered, the corresponding weapon pointer hasn't 581. been cleared yet; do that, with no preface message this time */ 582. if ((otmp->owornmask & W_WEAPONS) != 0L) 583. remove_worn_item(otmp, FALSE); 584. } 585. 586. /* do this before removing it from inventory */ 587. if (objnambuf) 588. Strcpy(objnambuf, yname(otmp)); 589. /* usually set mavenge bit so knights won't suffer an alignment penalty 590. during retaliation; not applicable for removing attached iron ball */ 591. if (!Conflict && !(was_punished && !Punished)) 592. mtmp->mavenge = 1; 593. 594. if (otmp->unpaid) 595. subfrombill(otmp, shop_keeper(*u.ushops)); 596. freeinv(otmp); 597. 598. /* if we just gave a message about removing a worn item and there have 599. been no intervening messages, shorten '<mon> stole <item>' message */ 600. if (iflags.last_msg == PLNMSG_MON_TAKES_OFF_ITEM 601. && mtmp->data->mlet == S_NYMPH) 602. ++named; 603. urgent_pline("%s stole %s.", named ? "She" : Monnambuf, doname(otmp)); 604. encumber_msg(); 605. could_petrify = (otmp->otyp == CORPSE 606. && touch_petrifies(&mons[otmp->corpsenm])); 607. otmp->how_lost = LOST_STOLEN; 608. (void) mpickobj(mtmp, otmp); /* may free otmp */ 609. if (could_petrify && !(mtmp->misc_worn_check & W_ARMG)) { 610. minstapetrify(mtmp, TRUE); 611. return -1; 612. } 613. return (gm.multi < 0) ? 0 : 1; 614. } 615. 616. /* Returns 1 if otmp is free'd, 0 otherwise. */ 617. int 618. mpickobj(struct monst *mtmp, struct obj *otmp) 619. { 620. int freed_otmp; 621. boolean snuff_otmp = FALSE; 622. 623. if (!otmp) { 624. impossible("monster (%s) taking or picking up nothing?", 625. pmname(mtmp->data, Mgender(mtmp))); 626. return 1; 627. } else if (otmp == uball || otmp == uchain) { 628. impossible("monster (%s) taking or picking up attached %s (%s)?", 629. pmname(mtmp->data, Mgender(mtmp)), 630. (otmp == uchain) ? "chain" : "ball", simpleonames(otmp)); 631. return 0; 632. } 633. /* if monster is acquiring a thrown or kicked object, the throwing 634. or kicking code shouldn't continue to track and place it */ 635. if (otmp == gt.thrownobj) 636. gt.thrownobj = 0; 637. else if (otmp == gk.kickedobj) 638. gk.kickedobj = 0; 639. /* an unpaid item can be on the floor; if a monster picks it up, take 640. it off the shop bill */ 641. if (otmp->unpaid || (Has_contents(otmp) && count_unpaid(otmp->cobj))) { 642. subfrombill(otmp, find_objowner(otmp, otmp->ox, otmp->oy)); 643. } 644. /* don't want hidden light source inside the monster; assumes that 645. engulfers won't have external inventories; whirly monsters cause 646. the light to be extinguished rather than letting it shine through */ 647. if (obj_sheds_light(otmp) && attacktype(mtmp->data, AT_ENGL)) { 648. /* this is probably a burning object that you dropped or threw */ 649. if (engulfing_u(mtmp) && !Blind) 650. pline("%s out.", Tobjnam(otmp, "go")); 651. snuff_otmp = TRUE; 652. } 653. /* for hero owned object on shop floor, mtmp is taking possession 654. and if it's eventually dropped in a shop, shk will claim it */ 655. otmp->no_charge = 0; 656. /* some object handling is only done if mtmp isn't a pet */ 657. if (!mtmp->mtame) { 658. /* if monst is unseen, some info hero knows about this object becomes 659. lost; continual pickup and drop by pets makes this too annoying if 660. it is applied to them; when engulfed (where monster can't be seen 661. because vision is disabled), or when held (or poly'd and holding) 662. while blind, behave as if the monster can be 'seen' by touch */ 663. if (!canseemon(mtmp) && mtmp != u.ustuck) 664. unknow_object(otmp); 665. /* if otmp has flags set for how it left hero's inventory, change 666. those flags; if thrown, now stolen and autopickup might override 667. pickup_types and autopickup exceptions based on 'pickup_stolen' 668. rather than 'pickup_thrown'; if previously stolen, stays stolen; 669. if previously dropped, now forgotten and autopickup will operate 670. normally regardless of the setting for 'dropped_nopick' */ 671. if (otmp->how_lost == LOST_THROWN) 672. otmp->how_lost = LOST_STOLEN; 673. else if (otmp->how_lost == LOST_DROPPED) 674. otmp->how_lost = LOST_NONE; 675. } 676. /* Must do carrying effects on object prior to add_to_minv() */ 677. carry_obj_effects(otmp); 678. /* add_to_minv() might free otmp [if merged with something else], 679. so we have to call it after doing the object checks */ 680. freed_otmp = add_to_minv(mtmp, otmp); 681. /* and we had to defer this until object is in mtmp's inventory */ 682. if (snuff_otmp) 683. snuff_light_source(mtmp->mx, mtmp->my); 684. return freed_otmp; 685. } 686. 687. /* called for AD_SAMU (the Wizard and quest nemeses) */ 688. void 689. stealamulet(struct monst *mtmp) 690. { 691. char buf[BUFSZ]; 692. struct obj *otmp = 0, *obj = 0; 693. int real = 0, fake = 0, n; 694. 695. /* target every quest artifact, not just current role's; 696. if hero has more than one, choose randomly so that player 697. can't use inventory ordering to influence the theft */ 698. for (n = 0, obj = gi.invent; obj; obj = obj->nobj) 699. if (any_quest_artifact(obj)) 700. ++n, otmp = obj; 701. if (n > 1) { 702. n = rnd(n); 703. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 704. if (any_quest_artifact(otmp) && !--n) 705. break; 706. } 707. 708. if (!otmp) { 709. /* if we didn't find any quest artifact, find another valuable item */ 710. if (u.uhave.amulet) { 711. real = AMULET_OF_YENDOR; 712. fake = FAKE_AMULET_OF_YENDOR; 713. } else if (u.uhave.bell) { 714. real = BELL_OF_OPENING; 715. fake = BELL; 716. } else if (u.uhave.book) { 717. real = SPE_BOOK_OF_THE_DEAD; 718. } else if (u.uhave.menorah) { 719. real = CANDELABRUM_OF_INVOCATION; 720. } else 721. return; /* you have nothing of special interest */ 722. 723. /* If we get here, real and fake have been set up. */ 724. for (n = 0, obj = gi.invent; obj; obj = obj->nobj) 725. if (obj->otyp == real || (obj->otyp == fake && !mtmp->iswiz)) 726. ++n, otmp = obj; 727. if (n > 1) { 728. n = rnd(n); 729. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 730. if ((otmp->otyp == real 731. || (otmp->otyp == fake && !mtmp->iswiz)) && !--n) 732. break; 733. } 734. } 735. 736. if (otmp) { /* we have something to snatch */ 737. /* take off outer gear if we're targeting [hypothetical] 738. quest artifact suit, shirt, gloves, or rings */ 739. if ((otmp == uarm || otmp == uarmu) && uarmc) 740. worn_item_removal(mtmp, uarmc); 741. if (otmp == uarmu && uarm) 742. worn_item_removal(mtmp, uarm); 743. if ((otmp == uarmg || ((otmp == uright || otmp == uleft) && uarmg)) 744. && uwep) { 745. /* gloves are about to be unworn; unwield weapon(s) first */ 746. if (u.twoweap) /* remove_worn_item(uswapwep) indirectly */ 747. worn_item_removal(mtmp, uswapwep); /* clears u.twoweap */ 748. worn_item_removal(mtmp, uwep); 749. } 750. if ((otmp == uright || otmp == uleft) && uarmg) 751. /* calls Gloves_off() to handle wielded cockatrice corpse */ 752. worn_item_removal(mtmp, uarmg); 753. 754. /* finally, steal the target item */ 755. if (otmp->owornmask) 756. worn_item_removal(mtmp, otmp); 757. if (otmp->unpaid) 758. subfrombill(otmp, shop_keeper(*u.ushops)); 759. freeinv(otmp); 760. Strcpy(buf, doname(otmp)); 761. (void) mpickobj(mtmp, otmp); /* could merge and free otmp but won't */ 762. pline("%s steals %s!", Some_Monnam(mtmp), buf); 763. if (can_teleport(mtmp->data) && !tele_restrict(mtmp)) 764. (void) rloc(mtmp, RLOC_MSG); 765. encumber_msg(); 766. } 767. } 768. 769. /* when a mimic gets poked with something, it might take that thing 770. (at present, only implemented for when the hero does the poking) */ 771. void 772. maybe_absorb_item( 773. struct monst *mon, 774. struct obj *obj, 775. int ochance, int achance) /* percent chance for ordinary item, artifact */ 776. { 777. if (obj == uball || obj == uchain || obj->oclass == ROCK_CLASS 778. || obj_resists(obj, 100 - ochance, 100 - achance) 779. || !touch_artifact(obj, mon)) 780. return; 781. 782. if (carried(obj)) { 783. if (obj->owornmask) 784. remove_worn_item(obj, TRUE); 785. if (obj->unpaid) 786. subfrombill(obj, shop_keeper(*u.ushops)); 787. if (cansee(mon->mx, mon->my)) { 788. /* Some_Monnam() avoids "It pulls ... and absorbs it!" 789. if hero can see the location but not the monster */ 790. pline("%s pulls %s away from you and absorbs %s!", 791. Some_Monnam(mon), /* Monnam() or "Something" */ 792. yname(obj), (obj->quan > 1L) ? "them" : "it"); 793. } else { 794. const char *hand_s = body_part(HAND); 795. 796. if (bimanual(obj)) 797. hand_s = makeplural(hand_s); 798. pline("%s %s pulled from your %s!", upstart(yname(obj)), 799. otense(obj, "are"), hand_s); 800. } 801. freeinv(obj); 802. encumber_msg(); 803. } else { 804. /* not carried; presumably thrown or kicked */ 805. if (canspotmon(mon)) 806. pline("%s absorbs %s!", Monnam(mon), yname(obj)); 807. } 808. /* add to mon's inventory */ 809. (void) mpickobj(mon, obj); 810. } 811. 812. /* drop one object taken from a (possibly dead) monster's inventory */ 813. void 814. mdrop_obj( 815. struct monst *mon, 816. struct obj *obj, 817. boolean verbosely) 818. { 819. coordxy omx = mon->mx, omy = mon->my; 820. long unwornmask = obj->owornmask; 821. /* call distant_name() for its possible side-effects even if the result 822. might not be printed, and do it before extracting obj from minvent */ 823. char *obj_name = distant_name(obj, doname); 824. 825. extract_from_minvent(mon, obj, FALSE, TRUE); 826. /* don't charge for an owned saddle on dead steed (provided 827. that the hero is within the same shop at the time) */ 828. if (unwornmask && mon->mtame && (unwornmask & W_SADDLE) != 0L 829. && !obj->unpaid && costly_spot(omx, omy) 830. /* being at costly_spot guarantees lev->roomno is not 0 */ 831. && strchr(in_rooms(u.ux, u.uy, SHOPBASE), levl[omx][omy].roomno)) { 832. obj->no_charge = 1; 833. } 834. /* obj_no_longer_held(obj); -- done by place_object */ 835. if (verbosely && cansee(omx, omy)) 836. pline_mon(mon, "%s drops %s.", Monnam(mon), obj_name); 837. if (!flooreffects(obj, omx, omy, "fall")) { 838. place_object(obj, omx, omy); 839. stackobj(obj); 840. } 841. /* do this last, after placing obj on floor; removing steed's saddle 842. throws rider, possibly inflicting fatal damage and producing bones; this 843. is why we had to call extract_from_minvent() with do_intrinsics=FALSE */ 844. if (!DEADMONSTER(mon) && unwornmask) 845. update_mon_extrinsics(mon, obj, FALSE, TRUE); 846. } 847. 848. /* some monsters bypass the normal rules for moving between levels or 849. even leaving the game entirely; when that happens, prevent them from 850. taking the Amulet, invocation items, or quest artifact with them */ 851. void 852. mdrop_special_objs(struct monst *mon) 853. { 854. struct obj *obj, *otmp; 855. 856. for (obj = mon->minvent; obj; obj = otmp) { 857. otmp = obj->nobj; 858. /* the Amulet, invocation tools, and Rider corpses resist even when 859. artifacts and ordinary objects are given 0% resistance chance; 860. current role's quest artifact is rescued too--quest artifacts 861. for the other roles are not */ 862. if (obj_resists(obj, 0, 0) || is_quest_artifact(obj)) { 863. if (mon->mx) { 864. mdrop_obj(mon, obj, FALSE); 865. } else { /* migrating monster not on map */ 866. extract_from_minvent(mon, obj, TRUE, TRUE); 867. rloco(obj); 868. } 869. } 870. } 871. } 872. 873. /* release the objects the creature is carrying */ 874. void 875. relobj( 876. struct monst *mtmp, 877. int show, 878. boolean is_pet) /* If true, pet should keep wielded/worn items */ 879. { 880. struct obj *otmp; 881. int omx = mtmp->mx, omy = mtmp->my; 882. 883. /* vault guard's gold goes away rather than be dropped... */ 884. if (mtmp->isgd && (otmp = findgold(mtmp->minvent)) != 0) { 885. if (canspotmon(mtmp)) 886. pline("%s gold %s.", s_suffix(Monnam(mtmp)), 887. canseemon(mtmp) ? "vanishes" : "seems to vanish"); 888. obj_extract_self(otmp); 889. obfree(otmp, (struct obj *) 0); 890. } /* isgd && has gold */ 891. 892. while ((otmp = (is_pet ? droppables(mtmp) : mtmp->minvent)) != 0) { 893. mdrop_obj(mtmp, otmp, is_pet && flags.verbose); 894. } 895. 896. if (show && cansee(omx, omy)) 897. newsym(omx, omy); 898. } 899. 900. /*steal.c*/