Source:NetHack 5.0.0/src/eat.c
Jump to navigation
Jump to search
Below is the full text to eat.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/eat.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 eat.c $NHDT-Date: 1740534854 2025/02/25 17:54:14 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.344 $ */ 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 eatmdone(void); 9. staticfn int eatfood(void); 10. staticfn struct obj *costly_tin(int); 11. staticfn int opentin(void); 12. staticfn int unfaint(void); 13. 14. staticfn const char *food_xname(struct obj *, boolean); 15. staticfn void choke(struct obj *); 16. staticfn void recalc_wt(void); 17. staticfn int adj_victual_nutrition(void); 18. staticfn struct obj *touchfood(struct obj *); 19. staticfn void do_reset_eat(void); 20. staticfn void done_eating(boolean); 21. staticfn void cprefx(int); 22. staticfn boolean temp_givit(int, struct permonst *); 23. staticfn void givit(int, struct permonst *); 24. staticfn void eye_of_newt_buzz(void); 25. staticfn void cpostfx(int); 26. staticfn void use_up_tin(struct obj *) NONNULLARG1; 27. staticfn void consume_tin(const char *); 28. staticfn void start_tin(struct obj *); 29. staticfn int eatcorpse(struct obj *); 30. staticfn void start_eating(struct obj *, boolean); 31. staticfn void garlic_breath(struct monst *); 32. staticfn boolean fprefx(struct obj *); 33. staticfn void fpostfx(struct obj *); 34. staticfn int bite(void); 35. staticfn int edibility_prompts(struct obj *); 36. staticfn int doeat_nonfood(struct obj *); 37. staticfn int tinopen_ok(struct obj *); 38. staticfn int rottenfood(struct obj *); 39. staticfn void eatspecial(void); 40. staticfn int bounded_increase(int, int, int); 41. staticfn void accessory_has_effect(struct obj *); 42. staticfn void eataccessory(struct obj *); 43. staticfn const char *foodword(struct obj *); 44. staticfn int tin_variety(struct obj *, boolean); 45. staticfn boolean maybe_cannibal(int, boolean); 46. staticfn int eat_ok(struct obj *); 47. staticfn int offer_ok(struct obj *); 48. staticfn int tin_ok(struct obj *); 49. 50. /* also used to see if you're allowed to eat cats and dogs */ 51. #define CANNIBAL_ALLOWED() (Role_if(PM_CAVE_DWELLER) || Race_if(PM_ORC)) 52. 53. /* Rider corpses are treated as non-rotting so that attempting to eat one 54. will be sure to reach the stage of eating where that meal is fatal; 55. acid blob corpses eventually rot away to nothing but before that happens 56. they can be sacrificed regardless of age which implies that they never 57. become rotten */ 58. #define nonrotting_corpse(mnum) \ 59. ((mnum) == PM_LIZARD || (mnum) == PM_LICHEN \ 60. || is_rider(&mons[mnum]) \ 61. || (mnum) == PM_ACID_BLOB) 62. 63. /* non-rotting non-corpses; unlike lizard corpses, these items will behave 64. as if rotten if they are cursed (fortune cookies handled elsewhere) */ 65. #define nonrotting_food(otyp) \ 66. ((otyp) == LEMBAS_WAFER || (otyp) == CRAM_RATION) 67. 68. /* see hunger states in hack.h - texts used on bottom line 69. Also used in botl.c and insight.c */ 70. const char *const hu_stat[] = { 71. "Satiated", " ", "Hungry ", "Weak ", 72. "Fainting", "Fainted ", "Starved " 73. }; 74. 75. static const struct victual_info zero_victual = { 0 }; 76. 77. /* used by getobj() callback routines eat_ok()/offer_ok()/tin_ok() to 78. indicate whether player was given an opportunity to eat or offer or 79. tin an item on the floor and declined, in order to insert "else" 80. into the "you don't have anything [else] to {eat | offer | tin}" 81. feedback if hero lacks any suitable items in inventory 82. [reinitialized every time it's used so does not need to be placed 83. in struct instance_globals g for potential bulk reinitialization] */ 84. static int getobj_else = 0; 85. 86. /* 87. * Decide whether a particular object can be eaten by the possibly 88. * polymorphed character. Not used for monster checks. 89. */ 90. boolean 91. is_edible(struct obj *obj) 92. { 93. /* protect invocation tools but not Rider corpses (handled elsewhere)*/ 94. /* if (obj->oclass != FOOD_CLASS && obj_resists(obj, 0, 0)) */ 95. if (objects[obj->otyp].oc_unique) 96. return FALSE; 97. /* above also prevents the Amulet from being eaten, so we must never 98. allow fake amulets to be eaten either [which is already the case] */ 99. 100. if (gy.youmonst.data == &mons[PM_FIRE_ELEMENTAL] 101. && is_flammable(obj)) 102. return TRUE; 103. 104. if (metallivorous(gy.youmonst.data) && is_metallic(obj) 105. && (gy.youmonst.data != &mons[PM_RUST_MONSTER] || is_rustprone(obj))) 106. return TRUE; 107. 108. /* Ghouls only eat non-veggy corpses or eggs (see dogfood()) */ 109. if (u.umonnum == PM_GHOUL) 110. return (boolean)((obj->otyp == CORPSE 111. && !vegan(&mons[obj->corpsenm])) 112. || (obj->otyp == EGG)); 113. 114. if (u.umonnum == PM_GELATINOUS_CUBE && is_organic(obj) 115. /* [g-cubes can eat containers and retain all contents 116. as engulfed items, but poly'd player can't do that] */ 117. && !Has_contents(obj)) 118. return TRUE; 119. 120. return (boolean) (obj->oclass == FOOD_CLASS); 121. } 122. 123. /* used for hero init, life saving (if choking), and prayer results of fix 124. starving, fix weak from hunger, or golden glow boon (if u.uhunger < 900) */ 125. void 126. init_uhunger(void) 127. { 128. disp.botl = (u.uhs != NOT_HUNGRY || ATEMP(A_STR) < 0); 129. u.uhunger = 900; 130. u.uhs = NOT_HUNGRY; 131. if (ATEMP(A_STR) < 0) { 132. ATEMP(A_STR) = 0; 133. encumber_msg(); 134. } 135. } 136. 137. /* tin types [SPINACH_TIN = -1, overrides corpsenm, nut==600] */ 138. static const struct { 139. const char *txt; /* description */ 140. int nut; /* nutrition */ 141. Bitfield(fodder, 1); /* stocked by health food shops */ 142. Bitfield(greasy, 1); /* causes slippery fingers */ 143. } tintxts[] = { { "rotten", -50, 0, 0 }, /* ROTTEN_TIN = 0 */ 144. { "homemade", 50, 1, 0 }, /* HOMEMADE_TIN = 1 */ 145. { "soup made from", 20, 1, 0 }, 146. { "french fried", 40, 0, 1 }, 147. { "pickled", 40, 1, 0 }, 148. { "boiled", 50, 1, 0 }, 149. { "smoked", 50, 1, 0 }, 150. { "dried", 55, 1, 0 }, 151. { "deep fried", 60, 0, 1 }, 152. { "szechuan", 70, 1, 0 }, 153. { "broiled", 80, 0, 0 }, 154. { "stir fried", 80, 0, 1 }, 155. { "sauteed", 95, 0, 0 }, 156. { "candied", 100, 1, 0 }, 157. { "pureed", 500, 1, 0 }, 158. { "", 0, 0, 0 } }; 159. #define TTSZ SIZE(tintxts) 160. 161. /* called after mimicking is over */ 162. staticfn int 163. eatmdone(void) 164. { 165. /* release `eatmbuf' */ 166. if (ge.eatmbuf) { 167. if (gn.nomovemsg == ge.eatmbuf) 168. gn.nomovemsg = 0; 169. free((genericptr_t) ge.eatmbuf), ge.eatmbuf = 0; 170. } 171. /* update display */ 172. if (U_AP_TYPE) { 173. gy.youmonst.m_ap_type = M_AP_NOTHING; 174. newsym(u.ux, u.uy); 175. } 176. return 0; 177. } 178. 179. /* called when hallucination is toggled */ 180. void 181. eatmupdate(void) 182. { 183. const char *altmsg = 0; 184. int altapp = 0; /* lint suppression */ 185. 186. if (!ge.eatmbuf || gn.nomovemsg != ge.eatmbuf) 187. return; 188. 189. if (is_obj_mappear(&gy.youmonst,ORANGE) && !Hallucination) { 190. /* revert from hallucinatory to "normal" mimicking */ 191. altmsg = "You now prefer mimicking yourself."; 192. altapp = GOLD_PIECE; 193. } else if (is_obj_mappear(&gy.youmonst,GOLD_PIECE) && Hallucination) { 194. /* won't happen; anything which might make immobilized 195. hero begin hallucinating (black light attack, theft 196. of Grayswandir) will terminate the mimicry first */ 197. altmsg = "Your rind escaped intact."; 198. altapp = ORANGE; 199. } 200. 201. if (altmsg) { 202. /* replace end-of-mimicking message */ 203. unsigned amlen = Strlen(altmsg); 204. if (amlen > Strlen(ge.eatmbuf)) { 205. free((genericptr_t) ge.eatmbuf); 206. ge.eatmbuf = (char *) alloc(amlen + 1); 207. } 208. gn.nomovemsg = strcpy(ge.eatmbuf, altmsg); 209. /* update current image */ 210. gy.youmonst.mappearance = altapp; 211. newsym(u.ux, u.uy); 212. } 213. } 214. 215. /* ``[the(] singular(food, xname) [)] */ 216. staticfn const char * 217. food_xname(struct obj *food, boolean the_pfx) 218. { 219. const char *result; 220. 221. if (food->otyp == CORPSE) { 222. result = corpse_xname(food, (const char *) 0, 223. CXN_SINGULAR | (the_pfx ? CXN_PFX_THE : 0)); 224. /* not strictly needed since pname values are capitalized 225. and the() is a no-op for them */ 226. if (type_is_pname(&mons[food->corpsenm])) 227. the_pfx = FALSE; 228. } else { 229. /* the ordinary case */ 230. result = singular(food, xname); 231. } 232. if (the_pfx) 233. result = the(result); 234. return result; 235. } 236. 237. /* Created by GAN 01/28/87 238. * Amended by AKP 09/22/87: if not hard, don't choke, just vomit. 239. * Amended by 3. 06/12/89: if not hard, sometimes choke anyway, to keep risk. 240. * 11/10/89: if hard, rarely vomit anyway, for slim chance. 241. * 242. * To a full belly all food is bad. (It.) 243. */ 244. staticfn void 245. choke(struct obj *food) 246. { 247. /* only happens if you were satiated */ 248. if (u.uhs != SATIATED) { 249. if (!food || food->otyp != AMULET_OF_STRANGULATION) 250. return; 251. } else if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL) { 252. adjalign(-1); /* gluttony is unchivalrous */ 253. You_feel("like a glutton!"); 254. } 255. 256. exercise(A_CON, FALSE); 257. 258. if (Breathless || Hunger || (!Strangled && !rn2(20))) { 259. /* choking by eating AoS doesn't involve stuffing yourself */ 260. if (food && food->otyp == AMULET_OF_STRANGULATION) { 261. You("choke, but recover your composure."); 262. return; 263. } 264. You("stuff yourself and then vomit voluminously."); 265. morehungry(Hunger ? (u.uhunger - 60) : 1000); /* just got very sick! */ 266. vomit(); 267. } else { 268. svk.killer.format = KILLED_BY_AN; 269. /* 270. * Note all "killer"s below read "Choked on %s" on the 271. * high score list & tombstone. So plan accordingly. 272. */ 273. if (food) { 274. You("choke over your %s.", foodword(food)); 275. if (food->oclass == COIN_CLASS) { 276. Strcpy(svk.killer.name, "very rich meal"); 277. } else { 278. svk.killer.format = KILLED_BY; 279. Strcpy(svk.killer.name, killer_xname(food)); 280. } 281. } else { 282. You("choke over it."); 283. Strcpy(svk.killer.name, "quick snack"); 284. } 285. You("die..."); 286. done(CHOKING); 287. } 288. } 289. 290. /* modify victual.piece->owt depending on time spent consuming it */ 291. staticfn void 292. recalc_wt(void) 293. { 294. struct obj *piece = svc.context.victual.piece; 295. 296. if (!piece) { 297. impossible("recalc_wt without piece"); 298. return; 299. } 300. debugpline1("Old weight = %d", piece->owt); 301. debugpline2("Used time = %d, Req'd time = %d", 302. svc.context.victual.usedtime, svc.context.victual.reqtime); 303. piece->owt = weight(piece); 304. debugpline1("New weight = %d", piece->owt); 305. } 306. 307. /* called when eating interrupted by an event */ 308. void 309. reset_eat(void) 310. { 311. /* we only set a flag here - the actual reset process is done after 312. * the round is spent eating. 313. */ 314. if (svc.context.victual.eating && !svc.context.victual.doreset) { 315. debugpline0("reset_eat..."); 316. svc.context.victual.doreset = 1; 317. } 318. return; 319. } 320. 321. /* base nutrition of a food-class object; this used to include a variation 322. of the code that is now in adj_victual_nutrition() and was moved due to 323. its affect on weight() */ 324. unsigned 325. obj_nutrition(struct obj *otmp) 326. { 327. unsigned nut = (otmp->otyp == CORPSE) ? mons[otmp->corpsenm].cnutrit 328. : otmp->globby ? otmp->owt 329. : (unsigned) objects[otmp->otyp].oc_nutrition; 330. 331. return nut; 332. } 333. 334. /* nutrition increment for next byte; this used to be factored into 335. victual.piece->oeaten but that produced weight change if hero 336. polymorphed to or from one of the races which has nutrition adjusted */ 337. staticfn int 338. adj_victual_nutrition(void) 339. { 340. int otyp = svc.context.victual.piece->otyp; 341. /* note: adj_victual_nutrition() is only called when 'nmod' is negative */ 342. int nut = -svc.context.victual.nmod; /* convert 'nmod' to positive */ 343. 344. assert(nut > 0); 345. if (otyp == LEMBAS_WAFER) { 346. if (maybe_polyd(is_elf(gy.youmonst.data), Race_if(PM_ELF))) 347. nut += (nut + 2) / 4; /* 800 -> 1000 */ 348. else if (maybe_polyd(is_orc(gy.youmonst.data), Race_if(PM_ORC))) 349. nut -= (nut + 2) / 4; /* 800 -> 600 */ 350. } else if (otyp == CRAM_RATION) { 351. if (maybe_polyd(is_dwarf(gy.youmonst.data), Race_if(PM_DWARF))) 352. nut += (nut + 3) / 6; /* 600 -> 700 */ 353. } 354. nut = max(nut, 1); 355. return nut; 356. } 357. 358. /* might destroy otmp if hero drops it */ 359. staticfn struct obj * 360. touchfood(struct obj *otmp) 361. { 362. if (otmp->quan > 1L) { 363. if (!carried(otmp)) 364. (void) splitobj(otmp, otmp->quan - 1L); 365. else 366. otmp = splitobj(otmp, 1L); 367. debugpline0("split food,"); 368. } 369. 370. if (!otmp->oeaten) { 371. costly_alteration(otmp, COST_BITE); 372. otmp->oeaten = obj_nutrition(otmp); 373. } 374. 375. if (carried(otmp)) { 376. freeinv(otmp); 377. if (inv_cnt(FALSE) >= invlet_basic) { 378. sellobj_state(SELL_DONTSELL); 379. dropy(otmp); 380. sellobj_state(SELL_NORMAL); 381. if (otmp->where == OBJ_DELETED) 382. otmp = (struct obj *) NULL; 383. } else { 384. otmp = addinv_nomerge(otmp); 385. } 386. } 387. return otmp; 388. } 389. 390. /* When food decays, in the middle of your meal, we don't want to dereference 391. * any dangling pointers, so set it to null (which should still trigger 392. * do_reset_eat() at the beginning of eatfood()) and check for null pointers 393. * in do_reset_eat(). 394. */ 395. void 396. food_disappears(struct obj *obj) 397. { 398. if (obj == svc.context.victual.piece) 399. svc.context.victual = zero_victual; /* victual.piece = 0, .o_id = 0 */ 400. 401. if (obj->timed) 402. obj_stop_timers(obj); 403. } 404. 405. /* renaming an object used to result in it having a different address, 406. so the sequence start eating/opening, get interrupted, name the food, 407. resume eating/opening would restart from scratch */ 408. void 409. food_substitution(struct obj *old_obj, struct obj *new_obj) 410. { 411. if (old_obj == svc.context.victual.piece) { 412. svc.context.victual.piece = new_obj; 413. svc.context.victual.o_id = new_obj->o_id; 414. } 415. if (old_obj == svc.context.tin.tin) { 416. svc.context.tin.tin = new_obj; 417. svc.context.tin.o_id = new_obj->o_id; 418. } 419. } 420. 421. staticfn void 422. do_reset_eat(void) 423. { 424. debugpline0("do_reset_eat..."); 425. if (svc.context.victual.piece) { 426. struct obj *otmp; 427. 428. svc.context.victual.o_id = 0; 429. otmp = touchfood(svc.context.victual.piece); 430. svc.context.victual.piece = otmp; 431. if (otmp) { 432. svc.context.victual.o_id = otmp->o_id; 433. recalc_wt(); 434. } 435. } 436. svc.context.victual.fullwarn 437. = svc.context.victual.eating 438. = svc.context.victual.doreset 439. = 0; 440. /* Do not set canchoke to FALSE; if we continue eating the same object 441. * we need to know if canchoke was set when they started eating it the 442. * previous time. And if we don't continue eating the same object 443. * canchoke always gets recalculated anyway. 444. */ 445. stop_occupation(); 446. newuhs(FALSE); 447. } 448. 449. /* if 'prop' is only set because of a timed value (so not an intrinsic 450. attribute or because of polymorph shape or worn or carried gear), return 451. its timeout, otherwise return 0; used by enlightenment */ 452. long 453. temp_resist(int prop) 454. { 455. struct prop *p = &u.uprops[prop]; 456. long timeout = p->intrinsic & TIMEOUT; 457. 458. if (timeout 459. /* and if not also protected by polymorph form */ 460. && (p->intrinsic & ~TIMEOUT) == 0L 461. /* and not by worn gear (dragon armor) */ 462. && !p->extrinsic 463. /* and property is not blocked; we don't expect this, but if it 464. is then the timeout doesn't matter so we won't extend that */ 465. && !p->blocked) { 466. return timeout; 467. } 468. return 0L; 469. } 470. 471. /* if temporary acid or stoning resistance is timing out while eating 472. something which that resistance is protecting against, caller will 473. extend resistance's duration so that it times out after meal finishes */ 474. boolean 475. eating_dangerous_corpse(int res) 476. { 477. struct obj *food; 478. int mnum; 479. 480. if (go.occupation == eatfood 481. && (food = svc.context.victual.piece) != 0 482. && food->otyp == CORPSE 483. && (mnum = food->corpsenm) >= LOW_PM 484. && (carried(food) || obj_here(food, u.ux, u.uy))) { 485. 486. if (res == ACID_RES && acidic(&mons[mnum])) 487. return TRUE; 488. /* flesh_petrifies() includes Medusa as well as touch_petrifies() */ 489. if (res == STONE_RES && flesh_petrifies(&mons[mnum])) 490. return TRUE; 491. } 492. return FALSE; 493. } 494. 495. #if 0 /* no longer used */ 496. staticfn void maybe_extend_timed_resist(int); 497. 498. /* if temp resist against 'prop' is about to timeout, extend it slightly */ 499. staticfn void 500. maybe_extend_timed_resist(int prop) 501. { 502. long timeout = temp_resist(prop); 503. 504. /* if hero is being protected from nasty effects of current meal by 505. temporary resistance (timed acid resist or timed stoning resist), 506. prevent expiration from occurring while the meal is in progress 507. so that player doesn't get feedback about becoming more vulnerable 508. and then have the hero stay unharmed; has a minor side-effect of 509. also extending the protection against other attacks of the sort 510. being resisted */ 511. if (timeout == 1L) { 512. set_itimeout(&u.uprops[prop].intrinsic, 2L); 513. } 514. } 515. #endif 516. 517. /* called each move during eating process */ 518. staticfn int 519. eatfood(void) 520. { 521. struct obj *food = svc.context.victual.piece; 522. 523. if (food && !carried(food) && !obj_here(food, u.ux, u.uy)) 524. food = 0; 525. if (!food) { 526. /* maybe it was stolen? */ 527. do_reset_eat(); 528. return 0; 529. } 530. if (!svc.context.victual.eating) 531. return 0; 532. 533. if (++svc.context.victual.usedtime <= svc.context.victual.reqtime) { 534. if (bite()) 535. return 0; 536. return 1; /* still busy */ 537. } else { /* done */ 538. done_eating(TRUE); 539. return 0; 540. } 541. } 542. 543. staticfn void 544. done_eating(boolean message) 545. { 546. struct obj *piece = svc.context.victual.piece; 547. 548. piece->in_use = TRUE; 549. go.occupation = 0; /* do this early, so newuhs() knows we're done */ 550. newuhs(FALSE); 551. if (gn.nomovemsg) { 552. if (message) 553. pline1(gn.nomovemsg); 554. gn.nomovemsg = 0; 555. } else if (message) { 556. You("finish %s %s.", 557. (gy.youmonst.data == &mons[PM_FIRE_ELEMENTAL]) ? "consuming" 558. : "eating", 559. food_xname(piece, TRUE)); 560. } 561. 562. if (piece->otyp == CORPSE || piece->globby) 563. cpostfx(piece->corpsenm); 564. else 565. fpostfx(piece); 566. 567. if (carried(piece)) 568. useup(piece); 569. else 570. useupf(piece, 1L); 571. 572. svc.context.victual = zero_victual; /* victual.piece = 0, .o_id = 0 */ 573. } 574. 575. void 576. eating_conducts(struct permonst *pd) 577. { 578. int ll_conduct = 0; 579. 580. if (!u.uconduct.food++) { 581. livelog_printf(LL_CONDUCT, "ate for the first time - %s", 582. pd->pmnames[NEUTRAL]); 583. ll_conduct++; 584. } 585. if (!vegan(pd)) { 586. if (!u.uconduct.unvegan++ && !ll_conduct) { 587. livelog_printf(LL_CONDUCT, 588. "consumed animal products (%s) for the first time", 589. pd->pmnames[NEUTRAL]); 590. ll_conduct++; 591. } 592. } 593. if (!vegetarian(pd)) { 594. if (!u.uconduct.unvegetarian && !ll_conduct) 595. livelog_printf(LL_CONDUCT, "tasted meat (%s) for the first time", 596. pd->pmnames[NEUTRAL]); 597. violated_vegetarian(); 598. } 599. } 600. 601. /* handle side-effects of mind flayer's tentacle attack */ 602. int 603. eat_brains( 604. struct monst *magr, 605. struct monst *mdef, 606. boolean visflag, 607. int *dmg_p) /* for dishing out extra damage in lieu of Int loss */ 608. { 609. struct permonst *pd = mdef->data; 610. boolean give_nutrit = FALSE; 611. int result = M_ATTK_HIT, xtra_dmg = rnd(10); 612. 613. /* previous tentacle attack might have triggered fatal passive 614. counterattack [callers ought to be updated to avoid this situation] */ 615. if (magr != &gy.youmonst && DEADMONSTER(magr)) { 616. return M_ATTK_AGR_DIED; 617. } 618. 619. if (noncorporeal(pd)) { 620. if (visflag) 621. pline("%s brain is unharmed.", 622. (mdef == &gy.youmonst) ? "Your" : s_suffix(Monnam(mdef))); 623. return M_ATTK_MISS; /* side-effects can't occur */ 624. } else if (magr == &gy.youmonst) { 625. You("eat %s brain!", s_suffix(mon_nam(mdef))); 626. } else if (mdef == &gy.youmonst) { 627. Your("brain is eaten!"); 628. } else { /* monster against monster */ 629. if (visflag && canspotmon(mdef)) 630. pline("%s brain is eaten!", s_suffix(Monnam(mdef))); 631. } 632. 633. if (flesh_petrifies(pd)) { 634. /* mind flayer has attempted to eat the brains of a petrification 635. inducing critter (most likely Medusa; attacking a cockatrice via 636. tentacle-touch should have been caught before reaching this far) */ 637. if (magr == &gy.youmonst) { 638. if (!Stone_resistance && !Stoned) 639. make_stoned(5L, (char *) 0, KILLED_BY_AN, 640. pmname(pd, Mgender(mdef))); 641. } else { 642. /* no need to check for poly_when_stoned or Stone_resistance; 643. mind flayers don't have those capabilities */ 644. if (visflag && canseemon(magr)) 645. pline("%s turns to stone!", Monnam(magr)); 646. monstone(magr); 647. if (!DEADMONSTER(magr)) { 648. /* life-saved; don't continue eating the brains */ 649. return M_ATTK_MISS; 650. } else { 651. if (magr->mtame && !visflag) 652. /* parallels mhitm.c's brief_feeling */ 653. You("have a sad thought for a moment, then it passes."); 654. return M_ATTK_AGR_DIED; 655. } 656. } 657. } 658. 659. if (magr == &gy.youmonst) { 660. /* 661. * player mind flayer is eating something's brain 662. */ 663. eating_conducts(pd); 664. if (mindless(pd)) { /* (cannibalism not possible here) */ 665. pline("%s doesn't notice.", Monnam(mdef)); 666. /* all done; no extra harm inflicted upon target */ 667. return M_ATTK_MISS; 668. } else if (is_rider(pd)) { 669. pline("Ingesting that is fatal."); 670. Sprintf(svk.killer.name, "unwisely ate the brain of %s", 671. pmname(pd, Mgender(mdef))); 672. svk.killer.format = NO_KILLER_PREFIX; 673. done(DIED); 674. /* life-saving needed to reach here */ 675. exercise(A_WIS, FALSE); 676. *dmg_p += xtra_dmg; /* Rider takes extra damage */ 677. } else { 678. morehungry(-rnd(30)); /* cannot choke */ 679. if (ABASE(A_INT) < AMAX(A_INT)) { 680. /* recover lost Int; won't increase current max */ 681. ABASE(A_INT) += rnd(4); 682. if (ABASE(A_INT) > AMAX(A_INT)) 683. ABASE(A_INT) = AMAX(A_INT); 684. disp.botl = TRUE; 685. } 686. exercise(A_WIS, TRUE); 687. *dmg_p += xtra_dmg; 688. } 689. /* targeting another mind flayer or your own underlying species 690. is cannibalism */ 691. (void) maybe_cannibal(monsndx(pd), TRUE); 692. 693. } else if (mdef == &gy.youmonst) { 694. /* 695. * monster mind flayer is eating hero's brain 696. */ 697. /* no such thing as mindless players */ 698. if (ABASE(A_INT) <= ATTRMIN(A_INT)) { 699. static NEARDATA const char brainlessness[] = "brainlessness"; 700. 701. if (Lifesaved) { 702. Strcpy(svk.killer.name, brainlessness); 703. svk.killer.format = KILLED_BY; 704. done(DIED); 705. /* amulet of life saving has now been used up */ 706. pline("Unfortunately your brain is still gone."); 707. /* sanity check against adding other forms of life-saving */ 708. u.uprops[LIFESAVED].extrinsic = 709. u.uprops[LIFESAVED].intrinsic = 0L; 710. } else { 711. Your("last thought fades away."); 712. } 713. Strcpy(svk.killer.name, brainlessness); 714. svk.killer.format = KILLED_BY; 715. done(DIED); 716. /* can only get here when in wizard or explore mode and user has 717. explicitly chosen not to die; arbitrarily boost intelligence */ 718. ABASE(A_INT) = ATTRMIN(A_INT) + 2; 719. You_feel("like a scarecrow."); 720. } 721. give_nutrit = TRUE; /* in case a conflicted pet is doing this */ 722. exercise(A_WIS, FALSE); 723. /* caller handles Int and memory loss */ 724. 725. } else { /* mhitm */ 726. /* 727. * monster mind flayer is eating another monster's brain 728. */ 729. if (mindless(pd)) { 730. if (visflag && canspotmon(mdef)) 731. pline("%s doesn't notice.", Monnam(mdef)); 732. return M_ATTK_MISS; 733. } else if (is_rider(pd)) { 734. mondied(magr); 735. if (DEADMONSTER(magr)) 736. result = M_ATTK_AGR_DIED; 737. /* Rider takes extra damage regardless of whether attacker dies */ 738. *dmg_p += xtra_dmg; 739. } else { 740. *dmg_p += xtra_dmg; 741. give_nutrit = TRUE; 742. if (*dmg_p >= mdef->mhp && visflag && canspotmon(mdef)) 743. pline("%s last thought fades away...", 744. s_suffix(Monnam(mdef))); 745. } 746. } 747. 748. if (give_nutrit && magr->mtame && !magr->isminion) { 749. EDOG(magr)->hungrytime += rnd(60); 750. magr->mconf = 0; 751. } 752. 753. return result; 754. } 755. 756. /* eating a corpse or egg of one's own species is usually naughty */ 757. staticfn boolean 758. maybe_cannibal(int pm, boolean allowmsg) 759. { 760. static NEARDATA long ate_brains = 0L; 761. struct permonst *fptr = &mons[pm]; /* food type */ 762. 763. /* when poly'd into a mind flayer, multiple tentacle hits in one 764. turn cause multiple digestion checks to occur; avoid giving 765. multiple luck penalties for the same attack */ 766. if (svm.moves == ate_brains) 767. return FALSE; 768. ate_brains = svm.moves; /* ate_anything, not just brains... */ 769. 770. if (!CANNIBAL_ALLOWED() 771. /* non-cannibalistic heroes shouldn't eat own species ever 772. and also shouldn't eat current species when polymorphed 773. (even if having the form of something which doesn't care 774. about cannibalism--hero's innate traits aren't altered) */ 775. && (your_race(fptr) 776. || (Upolyd && same_race(gy.youmonst.data, fptr)) 777. || (ismnum(u.ulycn) && were_beastie(pm) == u.ulycn))) { 778. if (allowmsg) { 779. if (Upolyd && your_race(fptr)) 780. You("have a bad feeling deep inside."); 781. You("cannibal! You will regret this!"); 782. } 783. HAggravate_monster |= FROMOUTSIDE; 784. change_luck(-rn1(4, 2)); /* -5..-2 */ 785. return TRUE; 786. } 787. return FALSE; 788. } 789. 790. staticfn void 791. cprefx(int pm) 792. { 793. (void) maybe_cannibal(pm, TRUE); 794. if (flesh_petrifies(&mons[pm])) { 795. if (!Stone_resistance 796. && !(poly_when_stoned(gy.youmonst.data) 797. && polymon(PM_STONE_GOLEM))) { 798. /* if food was a tin, use it up early to keep it out of bones */ 799. if (svc.context.tin.tin) 800. use_up_tin(svc.context.tin.tin); 801. 802. Sprintf(svk.killer.name, "tasting %s meat", 803. mons[pm].pmnames[NEUTRAL]); 804. svk.killer.format = KILLED_BY; 805. You("turn to stone."); 806. done(STONING); 807. if (svc.context.victual.piece) 808. svc.context.victual.eating = 0; 809. return; /* lifesaved */ 810. } 811. } 812. 813. switch (pm) { 814. case PM_LITTLE_DOG: 815. case PM_DOG: 816. case PM_LARGE_DOG: 817. case PM_KITTEN: 818. case PM_HOUSECAT: 819. case PM_LARGE_CAT: 820. /* cannibals are allowed to eat domestic animals without penalty */ 821. if (!CANNIBAL_ALLOWED()) { 822. You_feel("that eating the %s was a bad idea.", 823. mons[pm].pmnames[NEUTRAL]); 824. HAggravate_monster |= FROMOUTSIDE; 825. } 826. break; 827. case PM_LIZARD: 828. if (Stoned) 829. fix_petrification(); 830. break; 831. case PM_DEATH: 832. case PM_PESTILENCE: 833. case PM_FAMINE: { 834. pline("Eating that is instantly fatal."); 835. Sprintf(svk.killer.name, "unwisely ate the body of %s", 836. mons[pm].pmnames[NEUTRAL]); 837. svk.killer.format = NO_KILLER_PREFIX; 838. done(DIED); 839. /* life-saving needed to reach here */ 840. exercise(A_WIS, FALSE); 841. /* revive an actual corpse; can't do that if it was a tin; 842. 5.0: this used to assume that such tins were impossible but 843. they can be wished for in wizard mode; they can't make it 844. to normal play though because bones creation empties them */ 845. if (svc.context.victual.piece /* Null for tins */ 846. && svc.context.victual.piece->otyp == CORPSE /* paranoia */ 847. && revive_corpse(svc.context.victual.piece)) 848. svc.context.victual = zero_victual; /* victual.piece=0, .o_id=0 */ 849. return; 850. } 851. case PM_GREEN_SLIME: 852. if (!Slimed && !Unchanging && !slimeproof(gy.youmonst.data)) { 853. You("don't feel very well."); 854. make_slimed(10L, (char *) 0); 855. delayed_killer(SLIMED, KILLED_BY_AN, ""); 856. } 857. FALLTHROUGH; 858. /* Fall through */ 859. default: 860. if (acidic(&mons[pm]) && Stoned) 861. fix_petrification(); 862. break; 863. } 864. } 865. 866. void 867. fix_petrification(void) 868. { 869. char buf[BUFSZ]; 870. 871. if (Hallucination) 872. Sprintf(buf, "What a pity--you just ruined a future piece of %sart!", 873. ACURR(A_CHA) > 15 ? "fine " : ""); 874. else 875. Strcpy(buf, "You feel limber!"); 876. make_stoned(0L, buf, 0, (char *) 0); 877. } 878. 879. /* 880. * If you add an intrinsic that can be gotten by eating a monster, add it 881. * to intrinsic_possible() and givit(). (It must already be in prop.h to 882. * be an intrinsic property.) 883. * It would be very easy to make the intrinsics not try to give you one 884. * that you already had by checking to see if you have it in 885. * intrinsic_possible() instead of givit(), but we're not that nice. 886. */ 887. 888. /* intrinsic_possible() returns TRUE iff a monster can give an intrinsic. */ 889. int 890. intrinsic_possible(int type, struct permonst *ptr) 891. { 892. int res = 0; 893. 894. #ifdef DEBUG 895. #define ifdebugresist(Msg) \ 896. do { \ 897. if (res) \ 898. debugpline0(Msg); \ 899. } while (0) 900. #else 901. #define ifdebugresist(Msg) /*empty*/ 902. #endif 903. switch (type) { 904. case FIRE_RES: 905. res = (ptr->mconveys & MR_FIRE) != 0; 906. ifdebugresist("can get fire resistance"); 907. break; 908. case SLEEP_RES: 909. res = (ptr->mconveys & MR_SLEEP) != 0; 910. ifdebugresist("can get sleep resistance"); 911. break; 912. case COLD_RES: 913. res = (ptr->mconveys & MR_COLD) != 0; 914. ifdebugresist("can get cold resistance"); 915. break; 916. case DISINT_RES: 917. res = (ptr->mconveys & MR_DISINT) != 0; 918. ifdebugresist("can get disintegration resistance"); 919. break; 920. case SHOCK_RES: /* shock (electricity) resistance */ 921. res = (ptr->mconveys & MR_ELEC) != 0; 922. ifdebugresist("can get shock resistance"); 923. break; 924. case POISON_RES: 925. res = (ptr->mconveys & MR_POISON) != 0; 926. ifdebugresist("can get poison resistance"); 927. break; 928. case ACID_RES: 929. res = (ptr->mconveys & MR_ACID) != 0; 930. ifdebugresist("can get acid resistance temporarily"); 931. break; 932. case STONE_RES: 933. res = (ptr->mconveys & MR_STONE) != 0; 934. ifdebugresist("can get stoning resistance temporarily"); 935. break; 936. case TELEPORT: 937. res = can_teleport(ptr); 938. ifdebugresist("can get teleport"); 939. break; 940. case TELEPORT_CONTROL: 941. res = control_teleport(ptr); 942. ifdebugresist("can get teleport control"); 943. break; 944. case TELEPAT: 945. res = telepathic(ptr); 946. ifdebugresist("can get telepathy"); 947. break; 948. default: 949. /* res stays 0 */ 950. break; 951. } 952. #undef ifdebugresist 953. return res; 954. } 955. 956. /* The "do we or do we not give the intrinsic" logic from givit(), extracted 957. * into its own function. Depends on the monster's level and the type of 958. * intrinsic it is trying to give you. 959. */ 960. boolean 961. should_givit(int type, struct permonst *ptr) 962. { 963. int chance; 964. 965. /* some intrinsics are easier to get than others */ 966. switch (type) { 967. case POISON_RES: 968. if ((ptr == &mons[PM_KILLER_BEE] || ptr == &mons[PM_SCORPION]) 969. && !rn2(4)) 970. chance = 1; 971. else 972. chance = 15; 973. break; 974. case TELEPORT: 975. chance = 10; 976. break; 977. case TELEPORT_CONTROL: 978. chance = 12; 979. break; 980. case TELEPAT: 981. chance = 1; 982. break; 983. default: 984. chance = 15; 985. break; 986. } 987. 988. return (ptr->mlevel > rn2(chance)); 989. } 990. 991. staticfn boolean 992. temp_givit(int type, struct permonst *ptr) 993. { 994. int chance = (type == STONE_RES) ? 6 : (type == ACID_RES) ? 3 : 0; 995. 996. return chance ? (ptr->mlevel > rn2(chance)) : FALSE; 997. } 998. 999. /* givit() tries to give you an intrinsic based on the monster's level 1000. * and what type of intrinsic it is trying to give you. 1001. */ 1002. staticfn void 1003. givit(int type, struct permonst *ptr) 1004. { 1005. debugpline1("Attempting to give intrinsic %d", type); 1006. 1007. if (!should_givit(type, ptr) && !temp_givit(type, ptr)) 1008. return; 1009. 1010. switch (type) { 1011. case FIRE_RES: 1012. debugpline0("Trying to give fire resistance"); 1013. if (!(HFire_resistance & FROMOUTSIDE)) { 1014. You(Hallucination ? "be chillin'." : "feel a momentary chill."); 1015. HFire_resistance |= FROMOUTSIDE; 1016. } 1017. break; 1018. case SLEEP_RES: 1019. debugpline0("Trying to give sleep resistance"); 1020. if (!(HSleep_resistance & FROMOUTSIDE)) { 1021. You_feel("wide awake."); 1022. HSleep_resistance |= FROMOUTSIDE; 1023. } 1024. break; 1025. case COLD_RES: 1026. debugpline0("Trying to give cold resistance"); 1027. if (!(HCold_resistance & FROMOUTSIDE)) { 1028. You_feel("full of hot air."); 1029. HCold_resistance |= FROMOUTSIDE; 1030. } 1031. break; 1032. case DISINT_RES: 1033. debugpline0("Trying to give disintegration resistance"); 1034. if (!(HDisint_resistance & FROMOUTSIDE)) { 1035. You_feel(Hallucination ? "totally together, man." : "very firm."); 1036. HDisint_resistance |= FROMOUTSIDE; 1037. } 1038. break; 1039. case SHOCK_RES: /* shock (electricity) resistance */ 1040. debugpline0("Trying to give shock resistance"); 1041. if (!(HShock_resistance & FROMOUTSIDE)) { 1042. if (Hallucination) 1043. You_feel("grounded in reality."); 1044. else 1045. Your("health currently feels amplified!"); 1046. HShock_resistance |= FROMOUTSIDE; 1047. } 1048. break; 1049. case POISON_RES: 1050. debugpline0("Trying to give poison resistance"); 1051. if (!(HPoison_resistance & FROMOUTSIDE)) { 1052. You_feel(Poison_resistance ? "especially healthy." : "healthy."); 1053. HPoison_resistance |= FROMOUTSIDE; 1054. } 1055. break; 1056. case TELEPORT: 1057. debugpline0("Trying to give teleport"); 1058. if (!(HTeleportation & FROMOUTSIDE)) { 1059. You_feel(Hallucination ? "diffuse." : "very jumpy."); 1060. HTeleportation |= FROMOUTSIDE; 1061. } 1062. break; 1063. case TELEPORT_CONTROL: 1064. debugpline0("Trying to give teleport control"); 1065. if (!(HTeleport_control & FROMOUTSIDE)) { 1066. You_feel(Hallucination ? "centered in your personal space." 1067. : "in control of yourself."); 1068. HTeleport_control |= FROMOUTSIDE; 1069. } 1070. break; 1071. case TELEPAT: 1072. debugpline0("Trying to give telepathy"); 1073. if (!(HTelepat & FROMOUTSIDE)) { 1074. You_feel(Hallucination ? "in touch with the cosmos." 1075. : "a strange mental acuity."); 1076. HTelepat |= FROMOUTSIDE; 1077. /* If blind, make sure monsters show up. */ 1078. if (Blind) 1079. see_monsters(); 1080. } 1081. break; 1082. case ACID_RES: 1083. debugpline0("Giving timed acid resistance"); 1084. if (!Acid_resistance) 1085. You_feel("%s.", Hallucination ? "secure from flashbacks" 1086. : "less concerned about being harmed by acid"); 1087. incr_itimeout(&HAcid_resistance, d(3, 6)); 1088. break; 1089. case STONE_RES: 1090. debugpline0("Giving timed stoning resistance"); 1091. if (!Stone_resistance) 1092. You_feel("%s.", Hallucination ? "unusually limber" 1093. : "less concerned about becoming petrified"); 1094. incr_itimeout(&HStone_resistance, d(3, 6)); 1095. break; 1096. default: 1097. debugpline0("Tried to give an impossible intrinsic"); 1098. break; 1099. } 1100. } 1101. 1102. staticfn void 1103. eye_of_newt_buzz(void) 1104. { 1105. /* MRKR: "eye of newt" may give small magical energy boost */ 1106. if (rn2(3) || 3 * u.uen <= 2 * u.uenmax) { 1107. int old_uen = u.uen; 1108. 1109. u.uen += rnd(3); 1110. if (u.uen > u.uenmax) { 1111. if (!rn2(3)) { 1112. u.uenmax++; 1113. if (u.uenmax > u.uenpeak) 1114. u.uenpeak = u.uenmax; 1115. } 1116. u.uen = u.uenmax; 1117. } 1118. if (old_uen != u.uen) { 1119. You_feel("a mild buzz."); 1120. disp.botl = TRUE; 1121. } 1122. } 1123. } 1124. 1125. DISABLE_WARNING_FORMAT_NONLITERAL 1126. 1127. /* called after completely consuming a corpse */ 1128. staticfn void 1129. cpostfx(int pm) 1130. { 1131. int tmp = 0; 1132. int catch_lycanthropy = NON_PM; 1133. boolean check_intrinsics = FALSE; 1134. 1135. /* in case `afternmv' didn't get called for previously mimicking 1136. gold, clean up now to avoid `eatmbuf' memory leak */ 1137. if (ge.eatmbuf) 1138. (void) eatmdone(); 1139. 1140. switch (pm) { 1141. case PM_WRAITH: 1142. pluslvl(FALSE); 1143. break; 1144. case PM_HUMAN_WERERAT: 1145. catch_lycanthropy = PM_WERERAT; 1146. break; 1147. case PM_HUMAN_WEREJACKAL: 1148. catch_lycanthropy = PM_WEREJACKAL; 1149. break; 1150. case PM_HUMAN_WEREWOLF: 1151. catch_lycanthropy = PM_WEREWOLF; 1152. break; 1153. case PM_NURSE: 1154. if (Upolyd) 1155. u.mh = u.mhmax; 1156. else 1157. u.uhp = u.uhpmax; 1158. make_blinded(0L, !u.ucreamed); 1159. disp.botl = TRUE; 1160. check_intrinsics = TRUE; /* might also convey poison resistance */ 1161. break; 1162. case PM_STALKER: 1163. if (!Invis) { 1164. set_itimeout(&HInvis, (long) rn1(100, 50)); 1165. if (!Blind && !BInvis) 1166. self_invis_message(); 1167. } else { 1168. if (!(HInvis & INTRINSIC)) 1169. You_feel("hidden!"); 1170. HInvis |= FROMOUTSIDE; 1171. HSee_invisible |= FROMOUTSIDE; 1172. } 1173. newsym(u.ux, u.uy); 1174. FALLTHROUGH; 1175. /*FALLTHRU*/ 1176. case PM_YELLOW_LIGHT: 1177. case PM_GIANT_BAT: 1178. make_stunned((HStun & TIMEOUT) + 30L, FALSE); 1179. FALLTHROUGH; 1180. /*FALLTHRU*/ 1181. case PM_BAT: 1182. make_stunned((HStun & TIMEOUT) + 30L, FALSE); 1183. break; 1184. case PM_GIANT_MIMIC: 1185. tmp += 10; 1186. FALLTHROUGH; 1187. /*FALLTHRU*/ 1188. case PM_LARGE_MIMIC: 1189. tmp += 20; 1190. FALLTHROUGH; 1191. /*FALLTHRU*/ 1192. case PM_SMALL_MIMIC: 1193. tmp += 20; 1194. if (gy.youmonst.data->mlet != S_MIMIC && !Unchanging) { 1195. char buf[BUFSZ]; 1196. const char *tempshape = !Hallucination ? "a pile of gold" 1197. : "an orange"; 1198. 1199. if (!u.uconduct.polyselfs++) /* you're changing form */ 1200. livelog_printf(LL_CONDUCT, 1201. "changed form for the first time by mimicking %s", 1202. tempshape); 1203. You_cant("resist the temptation to mimic %s.", tempshape); 1204. /* A pile of gold can't ride. */ 1205. if (u.usteed) 1206. dismount_steed(DISMOUNT_FELL); 1207. nomul(-tmp); 1208. gm.multi_reason = "pretending to be a pile of gold"; 1209. Sprintf(buf, 1210. Hallucination 1211. ? "You suddenly dread being peeled and mimic %s again!" 1212. : "You now prefer mimicking %s again.", 1213. an(Upolyd ? pmname(gy.youmonst.data, Ugender) 1214. : gu.urace.noun)); 1215. ge.eatmbuf = dupstr(buf); 1216. gn.nomovemsg = ge.eatmbuf; 1217. ga.afternmv = eatmdone; 1218. /* ??? what if this was set before? */ 1219. gy.youmonst.m_ap_type = M_AP_OBJECT; 1220. gy.youmonst.mappearance = Hallucination ? ORANGE : GOLD_PIECE; 1221. newsym(u.ux, u.uy); 1222. curs_on_u(); 1223. /* make gold symbol show up now */ 1224. display_nhwindow(WIN_MAP, TRUE); 1225. } 1226. break; 1227. case PM_QUANTUM_MECHANIC: 1228. Your("velocity suddenly seems very uncertain!"); 1229. if (HFast & INTRINSIC) { 1230. HFast &= ~INTRINSIC; 1231. You("seem slower."); 1232. } else { 1233. HFast |= FROMOUTSIDE; 1234. You("seem faster."); 1235. } 1236. break; 1237. case PM_LIZARD: 1238. if ((HStun & TIMEOUT) > 2) 1239. make_stunned(2L, FALSE); 1240. if ((HConfusion & TIMEOUT) > 2) 1241. make_confused(2L, FALSE); 1242. check_intrinsics = TRUE; /* might convey temporary stoning resist */ 1243. break; 1244. case PM_CHAMELEON: 1245. case PM_DOPPELGANGER: 1246. case PM_SANDESTIN: /* moot--they don't leave corpses */ 1247. case PM_GENETIC_ENGINEER: 1248. if (Unchanging) { 1249. You_feel("momentarily different."); /* same as poly trap */ 1250. } else { 1251. /* polyself() is potentially fatal; if food is a tin, use it up 1252. early to keep it out of bones */ 1253. if (svc.context.tin.tin) { 1254. use_up_tin(svc.context.tin.tin); 1255. /* most tin effects end up being skipped */ 1256. lesshungry(200 + (metallivorous(gy.youmonst.data) ? 5 : 0)); 1257. } 1258. 1259. You("%s.", (pm == PM_GENETIC_ENGINEER) 1260. ? "undergo a freakish metamorphosis" 1261. : "feel a change coming over you"); 1262. polyself(POLY_NOFLAGS); 1263. } 1264. break; 1265. case PM_DISPLACER_BEAST: 1266. if (!Displaced) /* give a message (before setting the timeout) */ 1267. toggle_displacement((struct obj *) 0, 0L, TRUE); 1268. incr_itimeout(&HDisplaced, d(6, 6)); 1269. break; 1270. case PM_DISENCHANTER: 1271. /* picks an intrinsic at random and removes it; there's 1272. no feedback if hero already lacks the chosen ability */ 1273. debugpline0("using attrcurse to strip an intrinsic"); 1274. (void) attrcurse(); 1275. break; 1276. case PM_DEATH: 1277. case PM_PESTILENCE: 1278. case PM_FAMINE: 1279. /* life-saved; don't attempt to confer any intrinsics */ 1280. break; 1281. case PM_MIND_FLAYER: 1282. case PM_MASTER_MIND_FLAYER: 1283. if (ABASE(A_INT) < ATTRMAX(A_INT)) { 1284. if (!rn2(2)) { 1285. pline("Yum! That was real brain food!"); 1286. (void) adjattrib(A_INT, 1, FALSE); 1287. break; /* don't give them telepathy, too */ 1288. } 1289. } else { 1290. pline("For some reason, that tasted bland."); 1291. } 1292. FALLTHROUGH; 1293. /*FALLTHRU*/ 1294. default: 1295. check_intrinsics = TRUE; 1296. break; 1297. } 1298. 1299. /* possibly convey an intrinsic */ 1300. if (check_intrinsics) { 1301. struct permonst *ptr = &mons[pm]; 1302. 1303. if (dmgtype(ptr, AD_STUN) || dmgtype(ptr, AD_HALU) 1304. || pm == PM_VIOLET_FUNGUS) { 1305. pline("Oh wow! Great stuff!"); 1306. (void) make_hallucinated((HHallucination & TIMEOUT) + 200L, FALSE, 1307. 0L); 1308. } 1309. 1310. /* Eating magical monsters can give you some magical energy. */ 1311. if (attacktype(ptr, AT_MAGC) || pm == PM_NEWT) 1312. eye_of_newt_buzz(); 1313. 1314. tmp = corpse_intrinsic(ptr); 1315. 1316. /* if something was chosen, give it now (givit() might fail) */ 1317. if (tmp == -1) 1318. gainstr((struct obj *) 0, 0, TRUE); 1319. else if (tmp > 0) 1320. givit(tmp, ptr); 1321. } /* check_intrinsics */ 1322. 1323. if (ismnum(catch_lycanthropy)) { 1324. set_ulycn(catch_lycanthropy); 1325. retouch_equipment(2); 1326. } 1327. return; 1328. } 1329. 1330. RESTORE_WARNING_FORMAT_NONLITERAL 1331. 1332. /* Choose (one of) the intrinsics granted by a corpse, and return it. 1333. * If this corpse gives no intrinsics, return 0. 1334. * For the special not-real-prop cases of strength gain from giants 1335. * return fake prop value of -1. 1336. * Non-deterministic; should only be called once per corpse. 1337. */ 1338. int 1339. corpse_intrinsic(struct permonst *ptr) 1340. { 1341. /* Check the monster for all of the intrinsics. If this 1342. * monster can give more than one, pick one to try to give 1343. * from among all it can give. 1344. */ 1345. boolean conveys_STR = is_giant(ptr); 1346. int i; 1347. int count = 0; /* number of possible intrinsics */ 1348. int prop = 0; /* which one we will try to give */ 1349. 1350. if (conveys_STR) { 1351. count = 1; 1352. prop = -1; /* use -1 as fake prop index for STR */ 1353. debugpline1("\"Intrinsic\" strength, %d", prop); 1354. } 1355. for (i = 1; i <= LAST_PROP; i++) { 1356. if (!intrinsic_possible(i, ptr)) 1357. continue; 1358. ++count; 1359. /* a 1 in count chance of replacing the old choice 1360. with this one, and a count-1 in count chance 1361. of keeping the old choice (note that 1 in 1 and 1362. 0 in 1 are what we want for the first candidate) */ 1363. if (!rn2(count)) { 1364. debugpline2("Intrinsic %d replacing %d", i, prop); 1365. prop = i; 1366. } 1367. } 1368. /* if strength is the only candidate, give it 50% chance */ 1369. if (conveys_STR && count == 1 && !rn2(2)) 1370. prop = 0; 1371. 1372. return prop; 1373. } 1374. 1375. void 1376. violated_vegetarian(void) 1377. { 1378. u.uconduct.unvegetarian++; 1379. if (Role_if(PM_MONK)) { 1380. You_feel("guilty."); 1381. adjalign(-1); 1382. } 1383. return; 1384. } 1385. 1386. /* common code to check and possibly charge for 1 svc.context.tin.tin, 1387. * will split() svc.context.tin.tin if necessary */ 1388. staticfn struct obj * 1389. costly_tin(int alter_type) /* COST_xxx */ 1390. { 1391. struct obj *tin = svc.context.tin.tin; 1392. 1393. if (carried(tin) ? tin->unpaid 1394. : (costly_spot(tin->ox, tin->oy) && !tin->no_charge)) { 1395. if (tin->quan > 1L) { 1396. tin = svc.context.tin.tin = splitobj(tin, 1L); 1397. svc.context.tin.o_id = tin->o_id; 1398. } 1399. costly_alteration(tin, alter_type); 1400. } 1401. return tin; 1402. } 1403. 1404. int 1405. tin_variety_txt(char *s, int *tinvariety) 1406. { 1407. int k, l; 1408. 1409. if (s && tinvariety) { 1410. *tinvariety = -1; 1411. for (k = 0; k < TTSZ - 1; ++k) { 1412. l = (int) strlen(tintxts[k].txt); 1413. if (!strncmpi(s, tintxts[k].txt, l) && ((int) strlen(s) > l) 1414. && s[l] == ' ') { 1415. *tinvariety = k; 1416. return (l + 1); 1417. } 1418. } 1419. } 1420. return 0; 1421. } 1422. 1423. /* 1424. * This assumes that buf already contains the word "tin", 1425. * as is the case with caller xname(). 1426. */ 1427. void 1428. tin_details(struct obj *obj, int mnum, char *buf) 1429. { 1430. char buf2[BUFSZ]; 1431. 1432. if (!obj || !buf) 1433. return; 1434. 1435. int r = tin_variety(obj, TRUE); 1436. 1437. if (r == SPINACH_TIN) 1438. Strcat(buf, " of spinach"); 1439. else if (mnum == NON_PM) 1440. Strcpy(buf, "empty tin"); 1441. else { 1442. if ((obj->cknown || iflags.override_ID) && obj->spe < 0) { 1443. if (r == ROTTEN_TIN || r == HOMEMADE_TIN) { 1444. /* put these before the word tin */ 1445. Sprintf(buf2, "%s %s of ", tintxts[r].txt, buf); 1446. Strcpy(buf, buf2); 1447. } else { 1448. Sprintf(eos(buf), " of %s ", tintxts[r].txt); 1449. } 1450. } else { 1451. Strcpy(eos(buf), " of "); 1452. } 1453. if (vegetarian(&mons[mnum])) 1454. Sprintf(eos(buf), "%s", mons[mnum].pmnames[NEUTRAL]); 1455. else 1456. Sprintf(eos(buf), "%s meat", mons[mnum].pmnames[NEUTRAL]); 1457. } 1458. } 1459. 1460. void 1461. set_tin_variety(struct obj *obj, int forcetype) 1462. { 1463. int r, mnum = obj->corpsenm; 1464. 1465. if (forcetype == SPINACH_TIN 1466. || (forcetype == HEALTHY_TIN 1467. && (mnum == NON_PM /* empty or already spinach */ 1468. || !vegetarian(&mons[mnum])))) { /* replace meat */ 1469. obj->corpsenm = NON_PM; /* not based on any monster */ 1470. obj->spe = 1; /* spinach */ 1471. return; 1472. } else if (forcetype == HEALTHY_TIN) { 1473. r = tin_variety(obj, FALSE); 1474. if (r < 0 || r >= TTSZ) 1475. r = ROTTEN_TIN; /* shouldn't happen */ 1476. while ((r == ROTTEN_TIN && !obj->cursed) || !tintxts[r].fodder) 1477. r = rn2(TTSZ - 1); 1478. } else if (forcetype >= 0 && forcetype < TTSZ - 1) { 1479. r = forcetype; 1480. } else { /* RANDOM_TIN */ 1481. r = rn2(TTSZ - 1); /* take your pick */ 1482. if (r == ROTTEN_TIN && (ismnum(mnum) && nonrotting_corpse(mnum))) 1483. r = HOMEMADE_TIN; /* lizards don't rot */ 1484. } 1485. obj->spe = -(r + 1); /* offset by 1 to allow index 0 */ 1486. } 1487. 1488. staticfn int 1489. tin_variety( 1490. struct obj *obj, 1491. boolean displ) /* we're just displaying so leave things alone */ 1492. { 1493. int r, mnum = obj->corpsenm; 1494. 1495. if (obj->spe == 1) { 1496. r = SPINACH_TIN; 1497. } else if (obj->cursed) { 1498. r = ROTTEN_TIN; /* always rotten if cursed */ 1499. } else if (obj->spe < 0) { 1500. r = -(obj->spe); 1501. --r; /* get rid of the offset */ 1502. } else { 1503. r = rn2(TTSZ - 1); 1504. } 1505. 1506. if (!displ && r == HOMEMADE_TIN && !obj->blessed && !rn2(7)) 1507. r = ROTTEN_TIN; /* some homemade tins go bad */ 1508. 1509. if (r == ROTTEN_TIN && (ismnum(mnum) && nonrotting_corpse(mnum))) 1510. r = HOMEMADE_TIN; /* lizards don't rot */ 1511. return r; 1512. } 1513. 1514. /* finish consume_tin(); also potentially used by cprefx() and cpostfx() */ 1515. staticfn void 1516. use_up_tin(struct obj *tin) 1517. { 1518. if (carried(tin)) 1519. useup(tin); 1520. else 1521. useupf(tin, 1L); 1522. /* reset tin context */ 1523. svc.context.tin.tin = (struct obj *) NULL; 1524. svc.context.tin.o_id = 0; 1525. } 1526. 1527. staticfn void 1528. consume_tin(const char *mesg) 1529. { 1530. const char *what; 1531. int which, mnum, r, nutamt; 1532. /* if you've eaten tin itself, chance to not eat contents gets bypassed */ 1533. boolean always_eat = metallivorous(gy.youmonst.data); 1534. struct obj *tin = svc.context.tin.tin; 1535. 1536. r = tin_variety(tin, FALSE); 1537. if (tin->otrapped || (tin->cursed && r != HOMEMADE_TIN && !rn2(8))) { 1538. b_trapped("tin", NO_PART); 1539. tin = costly_tin(COST_DSTROY); 1540. use_up_tin(tin); 1541. return; 1542. } 1543. 1544. pline1(mesg); /* "You succeed in opening the tin." */ 1545. 1546. if (r != SPINACH_TIN) { 1547. mnum = tin->corpsenm; 1548. if (mnum == NON_PM) { 1549. if (Hallucination) 1550. pline("It's full of %s.", 1551. rn2(2) ? "air elemental souffle" 1552. : "dehydrated water"); 1553. else 1554. pline("It turns out to be empty."); 1555. observe_object(tin); 1556. tin->known = 1; 1557. tin = costly_tin(COST_OPEN); 1558. use_up_tin(tin); 1559. if (always_eat) 1560. lesshungry(5); /* metallivorous hero ate the tin itself */ 1561. return; 1562. } 1563. 1564. which = 0; /* 0=>plural, 1=>as-is, 2=>"the" prefix */ 1565. if ((mnum == PM_COCKATRICE || mnum == PM_CHICKATRICE) 1566. && (Stone_resistance || Hallucination)) { 1567. what = "chicken"; 1568. which = 1; /* suppress pluralization */ 1569. } else if (Hallucination) { 1570. what = rndmonnam(NULL); 1571. } else { 1572. what = mons[mnum].pmnames[NEUTRAL]; 1573. if (the_unique_pm(&mons[mnum])) 1574. which = 2; 1575. else if (type_is_pname(&mons[mnum])) 1576. which = 1; 1577. } 1578. if (which == 0) 1579. what = makeplural(what); 1580. else if (which == 2) 1581. what = the(what); 1582. 1583. if (!always_eat) { 1584. pline("It smells like %s.", what); 1585. if (y_n("Eat it?") == 'n') { 1586. if (flags.verbose) 1587. You("discard the open tin."); 1588. if (!Hallucination) { 1589. observe_object(tin); 1590. tin->known = 1; 1591. } 1592. tin = costly_tin(COST_OPEN); 1593. use_up_tin(tin); 1594. return; 1595. } 1596. } 1597. 1598. /* in case stop_occupation() was called on previous meal */ 1599. svc.context.victual = zero_victual; /* victual.piece = 0, .o_id = 0 */ 1600. 1601. You("consume %s %s.", tintxts[r].txt, mons[mnum].pmnames[NEUTRAL]); 1602. 1603. eating_conducts(&mons[mnum]); 1604. 1605. observe_object(tin); 1606. tin->known = 1; 1607. /* charge for one at pre-eating cost */ 1608. tin = svc.context.tin.tin = costly_tin(COST_OPEN); 1609. 1610. /* cprefx() or cpostfx() might use up tin to keep it out of bones */ 1611. cprefx(mnum); 1612. if (svc.context.tin.tin) 1613. cpostfx(mnum); 1614. if (!svc.context.tin.tin) 1615. return; 1616. 1617. if (tintxts[r].nut < 0) { /* rotten */ 1618. make_vomiting((long) rn1(15, 10), FALSE); 1619. } else { 1620. nutamt = tintxts[r].nut; 1621. /* nutrition from a homemade tin (made from a single corpse) 1622. shouldn't be more than nutrition from the corresponding 1623. corpse; other tinning modes might use more than one corpse 1624. or add extra ingredients so aren't similarly restricted */ 1625. if (r == HOMEMADE_TIN && nutamt > mons[mnum].cnutrit) 1626. nutamt = mons[mnum].cnutrit; 1627. if (always_eat) 1628. nutamt += 5; /* metallivorous hero ate the tin itself */ 1629. /* use up tin now; lesshungry() could be fatal and produce bones */ 1630. use_up_tin(tin), tin = NULL; 1631. lesshungry(nutamt); 1632. } 1633. 1634. if (tintxts[r].greasy) { 1635. /* normal hero is !Glib, because you can't open tins when Glib, 1636. but one poly'd into metallivorous form might already be Glib; 1637. it's debatable whether a rock mole should have its paws made 1638. slippery when eating a greasy tin, but we'll go with that... */ 1639. int alreadyglib = (int) (Glib & TIMEOUT); 1640. 1641. make_glib(alreadyglib + rn1(11, 5)); /* 5..15 */ 1642. pline("Eating %s food made your %s %s slippery.", 1643. tintxts[r].txt, fingers_or_gloves(TRUE), 1644. alreadyglib ? "even more" : "very"); 1645. } 1646. 1647. } else { /* spinach... */ 1648. if (tin->cursed) { 1649. pline("It contains some decaying%s%s substance.", 1650. Blind ? "" : " ", Blind ? "" : hcolor(NH_GREEN)); 1651. } else { 1652. pline("It contains spinach."); 1653. observe_object(tin); 1654. tin->known = 1; 1655. } 1656. 1657. if (!always_eat && y_n("Eat it?") == 'n') { 1658. if (flags.verbose) 1659. You("discard the open tin."); 1660. tin = costly_tin(COST_OPEN); 1661. use_up_tin(tin); 1662. return; 1663. } 1664. 1665. /* 1666. * Same order as with non-spinach above: 1667. * conduct update, side-effects, shop handling, and nutrition. 1668. */ 1669. /* don't need vegetarian checks for spinach */ 1670. if (!u.uconduct.food++) 1671. livelog_printf(LL_CONDUCT, "ate for the first time (spinach)"); 1672. if (!tin->cursed) 1673. pline("This makes you feel like %s!", 1674. /* "Swee'pea" is a character from the Popeye cartoons */ 1675. Hallucination ? "Swee'pea" 1676. /* "feel like Popeye" unless sustain ability suppresses 1677. any attribute change; this slightly oversimplifies 1678. things: we want "Popeye" if no strength increase 1679. occurs due to already being at maximum, but we won't 1680. get it if at-maximum and fixed-abil both apply */ 1681. : !Fixed_abil ? "Popeye" 1682. /* no gain, feel like another character from Popeye */ 1683. : (flags.female ? "Olive Oyl" : "Bluto")); 1684. gainstr(tin, 0, FALSE); 1685. 1686. tin = svc.context.tin.tin = costly_tin(COST_OPEN); 1687. nutamt = (tin->blessed ? 600 /* blessed */ 1688. : !tin->cursed ? (400 + rnd(200)) /* uncursed */ 1689. : (200 + rnd(400))); /* cursed */ 1690. if (always_eat) 1691. nutamt += 5; /* metallivorous hero also eats the tin itself */ 1692. /* use up tin first; lesshungry() could be fatal and produce bones */ 1693. use_up_tin(tin), tin = NULL; 1694. lesshungry(nutamt); 1695. } 1696. if (tin) 1697. use_up_tin(tin); 1698. return; 1699. } 1700. 1701. /* called during each move whilst opening a tin */ 1702. staticfn int 1703. opentin(void) 1704. { 1705. /* perhaps it was stolen (although that should cause interruption) */ 1706. if (!carried(svc.context.tin.tin) 1707. && (!obj_here(svc.context.tin.tin, u.ux, u.uy) 1708. || !can_reach_floor(TRUE))) 1709. return 0; /* %% probably we should use tinoid */ 1710. if (svc.context.tin.usedtime++ >= 50) { 1711. You("give up your attempt to open the tin."); 1712. return 0; 1713. } 1714. if (svc.context.tin.usedtime < svc.context.tin.reqtime) 1715. return 1; /* still busy */ 1716. 1717. consume_tin("You succeed in opening the tin."); 1718. return 0; 1719. } 1720. 1721. /* called when starting to open a tin */ 1722. staticfn void 1723. start_tin(struct obj *otmp) 1724. { 1725. const char *mesg = 0; 1726. int tmp; 1727. 1728. if (metallivorous(gy.youmonst.data)) { 1729. mesg = "You bite right into the metal tin..."; 1730. tmp = 0; 1731. } else if (cantwield(gy.youmonst.data)) { /* nohands || verysmall */ 1732. You("cannot handle the tin properly to open it."); 1733. return; 1734. } else if (otmp->blessed) { 1735. /* 50/50 chance for immediate access vs 1 turn delay (unless 1736. wielding blessed tin opener which always yields immediate 1737. access); 1 turn delay case is non-deterministic: getting 1738. interrupted and retrying might yield another 1 turn delay 1739. or might open immediately on 2nd (or 3rd, 4th, ...) try */ 1740. tmp = (uwep && uwep->blessed && uwep->otyp == TIN_OPENER) ? 0 1741. : rn2(2); 1742. if (!tmp) 1743. mesg = "The tin opens like magic!"; 1744. else 1745. pline_The("tin seems easy to open."); 1746. } else if (uwep) { 1747. switch (uwep->otyp) { 1748. case TIN_OPENER: 1749. mesg = "You easily open the tin."; /* iff tmp==0 */ 1750. tmp = rn2(uwep->cursed ? 3 : !uwep->blessed ? 2 : 1); 1751. break; 1752. case DAGGER: 1753. case SILVER_DAGGER: 1754. case ELVEN_DAGGER: 1755. case ORCISH_DAGGER: 1756. case ATHAME: 1757. case KNIFE: 1758. case STILETTO: 1759. case CRYSKNIFE: 1760. tmp = 3; 1761. break; 1762. case PICK_AXE: 1763. case AXE: 1764. tmp = 6; 1765. break; 1766. default: 1767. goto no_opener; 1768. } 1769. pline("Using %s you try to open the tin.", yobjnam(uwep, (char *) 0)); 1770. } else { 1771. no_opener: 1772. pline("It is not so easy to open this tin."); 1773. if (Glib) { 1774. pline_The("tin slips from your %s.", fingers_or_gloves(FALSE)); 1775. if (otmp->quan > 1L) { 1776. otmp = splitobj(otmp, 1L); 1777. } 1778. if (carried(otmp)) 1779. dropx(otmp); 1780. else 1781. stackobj(otmp); 1782. return; 1783. } 1784. tmp = rn1(1 + 500 / ((int) (ACURR(A_DEX) + ACURRSTR)), 10); 1785. } 1786. 1787. svc.context.tin.tin = otmp; 1788. svc.context.tin.o_id = otmp->o_id; 1789. if (!tmp) { 1790. consume_tin(mesg); /* begin immediately */ 1791. } else { 1792. svc.context.tin.reqtime = tmp; 1793. svc.context.tin.usedtime = 0; 1794. set_occupation(opentin, "opening the tin", 0); 1795. } 1796. return; 1797. } 1798. 1799. /* called when waking up after fainting */ 1800. int 1801. Hear_again(void) 1802. { 1803. /* Chance of deafness going away while fainted/sleeping/etc. */ 1804. if (!rn2(2)) { 1805. make_deaf(0L, FALSE); 1806. disp.botl = TRUE; 1807. } 1808. return 0; 1809. } 1810. 1811. /* called on the "first bite" of rotten food */ 1812. staticfn int 1813. rottenfood(struct obj *obj) 1814. { 1815. pline("Blecch! %s %s!", 1816. is_rottable(obj) ? "Rotten" : "Awful", foodword(obj)); 1817. if (!rn2(4)) { 1818. if (Hallucination) 1819. You_feel("rather trippy."); 1820. else 1821. You_feel("rather %s.", body_part(LIGHT_HEADED)); 1822. make_confused(HConfusion + d(2, 4), FALSE); 1823. } else if (!rn2(4) && !Blind) { 1824. pline("Everything suddenly goes dark."); 1825. /* hero is not Blind, but Blinded timer might be nonzero if 1826. blindness is being overridden by the Eyes of the Overworld */ 1827. make_blinded(BlindedTimeout + (long) d(2, 10), FALSE); 1828. if (!Blind) 1829. Your1(vision_clears); 1830. } else if (!rn2(3)) { 1831. const char *what, *where; 1832. int duration = rnd(10); 1833. 1834. if (!Blind) 1835. what = "goes", where = "dark"; 1836. else if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) 1837. what = "you lose control of", where = "yourself"; 1838. else 1839. what = "you slap against the", 1840. where = (u.usteed) ? "saddle" : surface(u.ux, u.uy); 1841. pline_The("world spins and %s %s.", what, where); 1842. incr_itimeout(&HDeaf, duration); 1843. disp.botl = TRUE; 1844. nomul(-duration); 1845. gm.multi_reason = "unconscious from rotten food"; 1846. gn.nomovemsg = "You are conscious again."; 1847. ga.afternmv = Hear_again; 1848. return 1; 1849. } 1850. return 0; 1851. } 1852. 1853. /* called when a corpse is selected as food */ 1854. staticfn int 1855. eatcorpse(struct obj *otmp) 1856. { 1857. int retcode = 0, tp = 0, mnum = otmp->corpsenm; 1858. long rotted = 0L; 1859. int ll_conduct = 0; 1860. boolean stoneable, 1861. slimeable = (mnum == PM_GREEN_SLIME && !Slimed && !Unchanging 1862. && !slimeproof(gy.youmonst.data)), 1863. glob = otmp->globby ? TRUE : FALSE; 1864. 1865. assert(ismnum(mnum)); 1866. stoneable = (flesh_petrifies(&mons[mnum]) && !Stone_resistance 1867. && !poly_when_stoned(gy.youmonst.data)); 1868. 1869. /* KMH, conduct */ 1870. if (!vegan(&mons[mnum])) 1871. if (!u.uconduct.unvegan++) { 1872. livelog_printf(LL_CONDUCT, 1873. "consumed animal products for the first time, by eating %s", 1874. an(food_xname(otmp, FALSE))); 1875. ll_conduct++; 1876. } 1877. if (!vegetarian(&mons[mnum])) { 1878. if (!u.uconduct.unvegetarian && !ll_conduct) 1879. livelog_printf(LL_CONDUCT, 1880. "tasted meat for the first time, by eating %s", 1881. an(food_xname(otmp, FALSE))); 1882. violated_vegetarian(); 1883. } 1884. if (!nonrotting_corpse(mnum)) { 1885. long age = peek_at_iced_corpse_age(otmp); 1886. 1887. rotted = (svm.moves - age) / (10L + rn2(20)); 1888. if (otmp->cursed) 1889. rotted += 2L; 1890. else if (otmp->blessed) 1891. rotted -= 2L; 1892. } 1893. 1894. /* 5.0: globs don't become tainted, they shrink away */ 1895. if (!glob && !stoneable && !slimeable && rotted > 5L) { 1896. boolean cannibal = maybe_cannibal(mnum, FALSE); 1897. 1898. /* tp++; -- early return makes this unnecessary */ 1899. pline("Ulch - that %s was tainted%s!", 1900. (mons[mnum].mlet == S_FUNGUS) ? "fungoid vegetation" 1901. : vegetarian(&mons[mnum]) ? "protoplasm" 1902. : "meat", 1903. cannibal ? ", you cannibal" : ""); 1904. if (Sick_resistance) { 1905. pline("It doesn't seem at all sickening, though..."); 1906. } else { 1907. long sick_time; 1908. 1909. sick_time = (long) rn1(10, 10); 1910. /* make sure new ill doesn't result in improvement */ 1911. if (Sick && (sick_time > Sick)) 1912. sick_time = (Sick > 1L) ? Sick - 1L : 1L; 1913. make_sick(sick_time, corpse_xname(otmp, "rotted", CXN_NORMAL), 1914. TRUE, SICK_VOMITABLE); 1915. 1916. pline("(It must have died too long ago to be safe to eat.)"); 1917. } 1918. if (carried(otmp)) 1919. useup(otmp); 1920. else 1921. useupf(otmp, 1L); 1922. return 2; 1923. } else if (acidic(&mons[mnum]) && !Acid_resistance) { 1924. tp++; 1925. You("have a very bad case of stomach acid."); /* not body_part() */ 1926. losehp(rnd(15), !glob ? "acidic corpse" : "acidic glob", 1927. KILLED_BY_AN); /* acid damage */ 1928. } else if (poisonous(&mons[mnum]) && rn2(5)) { 1929. tp++; 1930. pline("Ecch - that must have been poisonous!"); 1931. if (!Poison_resistance) { 1932. poison_strdmg(rnd(4), rnd(15), 1933. !glob ? "poisonous corpse" : "poisonous glob", 1934. KILLED_BY_AN); 1935. } else 1936. You("seem unaffected by the poison."); 1937. 1938. /* now any corpse left too long will make you mildly ill */ 1939. } else if ((rotted > 5L || (rotted > 3L && rn2(5))) && !Sick_resistance) { 1940. tp++; 1941. You_feel("%ssick.", (Sick) ? "very " : ""); 1942. losehp(rnd(8), !glob ? "cadaver" : "rotted glob", KILLED_BY_AN); 1943. } 1944. 1945. /* delay is weight dependent */ 1946. svc.context.victual.reqtime 1947. = 3 + ((!glob ? mons[mnum].cwt : otmp->owt) >> 6); 1948. 1949. if (!tp && !nonrotting_corpse(mnum) && (otmp->orotten || !rn2(7))) { 1950. if (rottenfood(otmp)) { 1951. otmp->orotten = TRUE; 1952. otmp = touchfood(otmp); 1953. if (!otmp) 1954. return 1; 1955. retcode = 1; 1956. } 1957. 1958. if (!mons[otmp->corpsenm].cnutrit) { 1959. /* no nutrition: rots away, no message if you passed out */ 1960. if (!retcode) 1961. pline_The("corpse rots away completely."); 1962. if (carried(otmp)) 1963. useup(otmp); 1964. else 1965. useupf(otmp, 1L); 1966. retcode = 2; 1967. } 1968. 1969. if (!retcode) 1970. consume_oeaten(otmp, 2); /* oeaten >>= 2 */ 1971. } else if ((mnum == PM_COCKATRICE || mnum == PM_CHICKATRICE) 1972. && (Stone_resistance || Hallucination)) { 1973. pline("This tastes just like chicken!"); 1974. } else if (mnum == PM_FLOATING_EYE && u.umonnum == PM_RAVEN) { 1975. You("peck the eyeball with delight."); 1976. } else if (tp) { 1977. ; /* we've already delivered a message; don't add "it tastes okay" */ 1978. } else { 1979. /* yummy is always False for omnivores, palatable always True */ 1980. boolean yummy = (vegan(&mons[mnum]) 1981. ? (!carnivorous(gy.youmonst.data) 1982. && herbivorous(gy.youmonst.data)) 1983. : (carnivorous(gy.youmonst.data) 1984. && !herbivorous(gy.youmonst.data))), 1985. palatable = ((vegetarian(&mons[mnum]) 1986. ? herbivorous(gy.youmonst.data) 1987. : carnivorous(gy.youmonst.data)) 1988. && rn2(10) 1989. && (rotted < 1 || !rn2((int) rotted + 1))); 1990. const char *pmxnam = food_xname(otmp, FALSE); 1991. static const char *const palatable_msgs[] = { 1992. /* first char: T = tastes ... , I = is ... */ 1993. /* veggies are always just "okay" */ 1994. "Tokay", "Istringy", "Igamey", "Ifatty", "Itough" 1995. }; 1996. int idx = vegetarian(&mons[mnum]) ? 0 : rn2(SIZE(palatable_msgs)); 1997. const char *palat_msg = palatable_msgs[idx]; 1998. boolean use_is = (Hallucination || (palatable && *palat_msg == 'I')); 1999. 2000. if (!strncmpi(pmxnam, "the ", 4)) 2001. pmxnam += 4; 2002. pline("%s%s %s %s%c", 2003. type_is_pname(&mons[mnum]) 2004. ? "" : the_unique_pm(&mons[mnum]) ? "The " : "This ", 2005. pmxnam, 2006. use_is ? "is" : "tastes", 2007. /* tiger reference is to TV ads for "Frosted Flakes", 2008. breakfast cereal targeted at kids by "Tony the tiger" */ 2009. Hallucination 2010. ? (yummy ? ((u.umonnum == PM_TIGER) ? "gr-r-reat" : "gnarly") 2011. : palatable ? "copacetic" : "grody") 2012. : (yummy ? "delicious" : palatable ? 2013. &palat_msg[1] : "terrible"), 2014. (yummy || !palatable) ? '!' : '.'); 2015. } 2016. 2017. return retcode; 2018. } 2019. 2020. /* called as you start to eat */ 2021. staticfn void 2022. start_eating(struct obj *otmp, boolean already_partly_eaten) 2023. { 2024. const char *old_nomovemsg, *save_nomovemsg; 2025. static char msgbuf[BUFSZ]; 2026. 2027. debugpline2("start_eating: %s (victual = %s)", 2028. /* note: fmt_ptr() returns a static buffer but supports 2029. several such so we don't need to copy the first result 2030. before calling it a second time */ 2031. fmt_ptr((genericptr_t) otmp), 2032. fmt_ptr((genericptr_t) svc.context.victual.piece)); 2033. debugpline1("reqtime = %d", svc.context.victual.reqtime); 2034. debugpline1("(original reqtime = %d)", objects[otmp->otyp].oc_delay); 2035. debugpline1("nmod = %d", svc.context.victual.nmod); 2036. debugpline1("oeaten = %d", otmp->oeaten); 2037. svc.context.victual.fullwarn = svc.context.victual.doreset = 0; 2038. svc.context.victual.eating = 1; 2039. 2040. if (otmp->otyp == CORPSE || otmp->globby) { 2041. cprefx(svc.context.victual.piece->corpsenm); 2042. if (!svc.context.victual.piece || !svc.context.victual.eating) { 2043. /* rider revived, or hero died and was lifesaved */ 2044. return; 2045. } 2046. } 2047. 2048. old_nomovemsg = gn.nomovemsg; 2049. if (bite()) { 2050. /* survived choking, finish off food that's nearly done; 2051. need this to handle cockatrice eggs, fortune cookies, etc */ 2052. if (++svc.context.victual.usedtime >= svc.context.victual.reqtime) { 2053. /* don't want done_eating() to issue gn.nomovemsg if it 2054. is due to vomit() called by bite() */ 2055. save_nomovemsg = gn.nomovemsg; 2056. if (!old_nomovemsg) 2057. gn.nomovemsg = 0; 2058. done_eating(FALSE); 2059. if (!old_nomovemsg) 2060. gn.nomovemsg = save_nomovemsg; 2061. } 2062. return; 2063. } 2064. 2065. if (++svc.context.victual.usedtime >= svc.context.victual.reqtime) { 2066. /* print "finish eating" message if they just resumed -dlc */ 2067. done_eating((svc.context.victual.reqtime > 1 2068. || already_partly_eaten) ? TRUE : FALSE); 2069. return; 2070. } 2071. 2072. Sprintf(msgbuf, "eating %s", food_xname(otmp, TRUE)); 2073. set_occupation(eatfood, msgbuf, 0); 2074. } 2075. 2076. /* used by shrink_glob() timer routine */ 2077. boolean 2078. eating_glob(struct obj *glob) 2079. { 2080. return (go.occupation == eatfood && glob == svc.context.victual.piece); 2081. } 2082. 2083. /* scare nearby monster when hero eats garlic */ 2084. staticfn void 2085. garlic_breath(struct monst *mtmp) 2086. { 2087. if (olfaction(mtmp->data) && distu(mtmp->mx, mtmp->my) < 7) 2088. monflee(mtmp, 0, FALSE, FALSE); 2089. } 2090. 2091. /* 2092. * Called on "first bite" of (non-corpse) food, after touchfood() has 2093. * marked it 'partly eaten'. Used for non-rotten non-tin non-corpse food. 2094. * Messages should use present tense since multi-turn food won't be 2095. * finishing at the time they're issued. 2096. * Returns FALSE if eating should not succeed for whatever reason. 2097. */ 2098. staticfn boolean 2099. fprefx(struct obj *otmp) 2100. { 2101. switch (otmp->otyp) { 2102. case EGG: 2103. if (otmp->corpsenm == PM_PYROLISK) { 2104. if (carried(otmp)) 2105. useup(otmp); 2106. else 2107. useupf(otmp, 1L); 2108. explode(u.ux, u.uy, -11, d(3, 6), 0, EXPL_FIERY); 2109. return FALSE; 2110. } else if (stale_egg(otmp)) { 2111. pline("Ugh. Rotten egg."); /* perhaps others like it */ 2112. /* increasing existing nausea means that it will take longer 2113. before eventual vomit, but also means that constitution 2114. will be abused more times before illness completes */ 2115. make_vomiting((Vomiting & TIMEOUT) + (long) d(10, 4), TRUE); 2116. } else 2117. goto give_feedback; 2118. break; 2119. case FOOD_RATION: /* nutrition 800 */ 2120. /* 200+800 remains below 1000+1, the satiation threshold */ 2121. if (u.uhunger <= 200) 2122. pline("%s!", Hallucination ? "Oh wow, like, superior, man" 2123. : "This food really hits the spot"); 2124. 2125. /* 700-1+800 remains below 1500, the choking threshold which 2126. triggers "you're having a hard time getting it down" feedback */ 2127. else if (u.uhunger < 700) 2128. pline("This satiates your %s!", body_part(STOMACH)); 2129. /* [satiation message may be inaccurate if eating gets interrupted] */ 2130. break; 2131. case TRIPE_RATION: 2132. if (carnivorous(gy.youmonst.data) && !humanoid(gy.youmonst.data)) { 2133. pline("This tripe ration is surprisingly good!"); 2134. } else if (maybe_polyd(is_orc(gy.youmonst.data), Race_if(PM_ORC))) { 2135. pline(Hallucination ? "Tastes great! Less filling!" 2136. : "Mmm, tripe... not bad!"); 2137. } else { 2138. pline("Yak - dog food!"); 2139. more_experienced(1, 0); 2140. newexplevel(); 2141. /* not cannibalism, but we use similar criteria 2142. for deciding whether to be sickened by this meal */ 2143. if (rn2(2) && !CANNIBAL_ALLOWED()) 2144. make_vomiting((long) rn1(svc.context.victual.reqtime, 14), 2145. FALSE); 2146. } 2147. break; 2148. case LEMBAS_WAFER: 2149. if (maybe_polyd(is_orc(gy.youmonst.data), Race_if(PM_ORC))) { 2150. pline("%s", "!#?&* elf kibble!"); 2151. break; 2152. } else if (maybe_polyd(is_elf(gy.youmonst.data), Race_if(PM_ELF))) { 2153. pline("A little goes a long way."); 2154. break; 2155. } 2156. goto give_feedback; 2157. case MEATBALL: 2158. case MEAT_STICK: 2159. case ENORMOUS_MEATBALL: 2160. case MEAT_RING: 2161. goto give_feedback; 2162. case CLOVE_OF_GARLIC: 2163. if (is_undead(gy.youmonst.data)) { 2164. make_vomiting((long) rn1(svc.context.victual.reqtime, 5), FALSE); 2165. break; 2166. } 2167. iter_mons(garlic_breath); 2168. FALLTHROUGH; 2169. /*FALLTHRU*/ 2170. default: 2171. if (otmp->otyp == SLIME_MOLD && !otmp->cursed 2172. && otmp->spe == svc.context.current_fruit) { 2173. pline("My, this is a %s %s!", 2174. Hallucination ? "primo" : "yummy", 2175. singular(otmp, xname)); 2176. } else if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) { 2177. ; /* skip core joke; feedback deferred til fpostfx() */ 2178. 2179. #if defined(MACOS9) || defined(MACOS) 2180. /* KMH -- Why should Unix have all the fun? 2181. We check MACOS before UNIX to get the Apple-specific apple 2182. message; the '#if UNIX' code will still kick in for pear. */ 2183. } else if (otmp->otyp == APPLE) { 2184. pline("Delicious! Must be a Macintosh!"); 2185. #endif 2186. 2187. #ifdef UNIX 2188. } else if (otmp->otyp == APPLE || otmp->otyp == PEAR) { 2189. if (!Hallucination) { 2190. pline("Core dumped."); 2191. } else { 2192. /* based on an old Usenet joke, a fake a.out manual page */ 2193. int x = rnd(100); 2194. 2195. pline("%s -- core dumped.", 2196. (x <= 75) 2197. ? "Segmentation fault" 2198. : (x <= 99) 2199. ? "Bus error" 2200. : "Yo' mama"); 2201. } 2202. #endif 2203. } else { 2204. give_feedback: 2205. pline("This %s is %s", singular(otmp, xname), 2206. otmp->cursed 2207. ? (Hallucination ? "grody!" : "terrible!") 2208. : (otmp->otyp == CRAM_RATION 2209. || otmp->otyp == K_RATION 2210. || otmp->otyp == C_RATION) 2211. ? "bland." 2212. : Hallucination ? "gnarly!" : "delicious!"); 2213. } 2214. break; /* default */ 2215. } /* switch */ 2216. return TRUE; 2217. } 2218. 2219. /* increment a combat intrinsic with limits on its growth */ 2220. staticfn int 2221. bounded_increase(int old, int inc, int typ) 2222. { 2223. int absold, absinc, sgnold, sgninc; 2224. 2225. /* don't include any amount coming from worn rings (caller handles 2226. 'protection' differently) */ 2227. if (uright && uright->otyp == typ && typ != RIN_PROTECTION) 2228. old -= uright->spe; 2229. if (uleft && uleft->otyp == typ && typ != RIN_PROTECTION) 2230. old -= uleft->spe; 2231. absold = abs(old), absinc = abs(inc); 2232. sgnold = sgn(old), sgninc = sgn(inc); 2233. 2234. if (absinc == 0 || sgnold != sgninc || absold + absinc < 10) { 2235. ; /* use inc as-is */ 2236. } else if (absold + absinc < 20) { 2237. absinc = rnd(absinc); /* 1..n */ 2238. if (absold + absinc < 10) 2239. absinc = 10 - absold; 2240. inc = sgninc * absinc; 2241. } else if (absold + absinc < 40) { 2242. absinc = rn2(absinc) ? 1 : 0; 2243. if (absold + absinc < 20) 2244. absinc = rnd(20 - absold); 2245. inc = sgninc * absinc; 2246. } else { 2247. inc = 0; /* no further increase allowed via this method */ 2248. } 2249. /* put amount from worn rings back */ 2250. if (uright && uright->otyp == typ && typ != RIN_PROTECTION) 2251. old += uright->spe; 2252. if (uleft && uleft->otyp == typ && typ != RIN_PROTECTION) 2253. old += uleft->spe; 2254. return old + inc; 2255. } 2256. 2257. staticfn void 2258. accessory_has_effect(struct obj *otmp) 2259. { 2260. pline("Magic spreads through your body as you digest the %s.", 2261. (otmp->oclass == RING_CLASS) ? "ring" : "amulet"); 2262. } 2263. 2264. staticfn void 2265. eataccessory(struct obj *otmp) 2266. { 2267. int typ = otmp->otyp; 2268. long oldprop; 2269. 2270. /* Note: rings are not so common that this is unbalancing. */ 2271. /* (How often do you even _find_ 3 rings of polymorph in a game?) */ 2272. oldprop = u.uprops[objects[typ].oc_oprop].intrinsic; 2273. if (otmp == uleft || otmp == uright) { 2274. Ring_gone(otmp); 2275. if (u.uhp <= 0) 2276. return; /* died from sink fall */ 2277. } 2278. observe_object(otmp); 2279. otmp->known = 1; /* by taste */ 2280. if (!rn2(otmp->oclass == RING_CLASS ? 3 : 5)) { 2281. switch (otmp->otyp) { 2282. default: 2283. if (!objects[typ].oc_oprop) 2284. break; /* should never happen */ 2285. 2286. if (!(u.uprops[objects[typ].oc_oprop].intrinsic & FROMOUTSIDE)) 2287. accessory_has_effect(otmp); 2288. 2289. u.uprops[objects[typ].oc_oprop].intrinsic |= FROMOUTSIDE; 2290. 2291. switch (typ) { 2292. case RIN_SEE_INVISIBLE: 2293. set_mimic_blocking(); 2294. see_monsters(); 2295. if (Invis && !oldprop && !ESee_invisible 2296. && !perceives(gy.youmonst.data) && !Blind) { 2297. newsym(u.ux, u.uy); 2298. pline("Suddenly you can see yourself."); 2299. makeknown(typ); 2300. } 2301. break; 2302. case RIN_INVISIBILITY: 2303. if (!oldprop && !EInvis && !BInvis && !See_invisible 2304. && !Blind) { 2305. newsym(u.ux, u.uy); 2306. Your("body takes on a %s transparency...", 2307. Hallucination ? "normal" : "strange"); 2308. makeknown(typ); 2309. } 2310. break; 2311. case RIN_PROTECTION_FROM_SHAPE_CHAN: 2312. rescham(); 2313. break; 2314. case RIN_LEVITATION: 2315. /* undo the `.intrinsic |= FROMOUTSIDE' done above */ 2316. u.uprops[LEVITATION].intrinsic = oldprop; 2317. if (!Levitation) { 2318. float_up(); 2319. incr_itimeout(&HLevitation, d(10, 20)); 2320. makeknown(typ); 2321. } 2322. break; 2323. } /* inner switch */ 2324. break; /* default case of outer switch */ 2325. 2326. case RIN_ADORNMENT: 2327. accessory_has_effect(otmp); 2328. if (adjattrib(A_CHA, otmp->spe, -1)) 2329. makeknown(typ); 2330. break; 2331. case RIN_GAIN_STRENGTH: 2332. accessory_has_effect(otmp); 2333. if (adjattrib(A_STR, otmp->spe, -1)) 2334. makeknown(typ); 2335. break; 2336. case RIN_GAIN_CONSTITUTION: 2337. accessory_has_effect(otmp); 2338. if (adjattrib(A_CON, otmp->spe, -1)) 2339. makeknown(typ); 2340. break; 2341. case RIN_INCREASE_ACCURACY: 2342. accessory_has_effect(otmp); 2343. u.uhitinc = (schar) bounded_increase((int) u.uhitinc, otmp->spe, 2344. RIN_INCREASE_ACCURACY); 2345. break; 2346. case RIN_INCREASE_DAMAGE: 2347. accessory_has_effect(otmp); 2348. u.udaminc = (schar) bounded_increase((int) u.udaminc, otmp->spe, 2349. RIN_INCREASE_DAMAGE); 2350. break; 2351. case RIN_PROTECTION: 2352. case AMULET_OF_GUARDING: 2353. accessory_has_effect(otmp); 2354. HProtection |= FROMOUTSIDE; 2355. u.ublessed = bounded_increase(u.ublessed, 2356. (typ == RIN_PROTECTION) ? otmp->spe 2357. : 2, /* fixed amount for amulet */ 2358. typ); 2359. disp.botl = TRUE; 2360. break; 2361. case RIN_FREE_ACTION: 2362. /* Give sleep resistance instead */ 2363. if (!(HSleep_resistance & FROMOUTSIDE)) 2364. accessory_has_effect(otmp); 2365. if (!Sleep_resistance) 2366. You_feel("wide awake."); 2367. HSleep_resistance |= FROMOUTSIDE; 2368. break; 2369. case AMULET_OF_CHANGE: 2370. accessory_has_effect(otmp); 2371. makeknown(typ); 2372. change_sex(); 2373. You("are suddenly very %s!", 2374. flags.female ? "feminine" : "masculine"); 2375. disp.botl = TRUE; 2376. break; 2377. case AMULET_OF_UNCHANGING: 2378. /* un-change: it's a pun */ 2379. if (!Unchanging && Upolyd) { 2380. accessory_has_effect(otmp); 2381. makeknown(typ); 2382. rehumanize(); 2383. } 2384. break; 2385. case AMULET_OF_STRANGULATION: /* bad idea! */ 2386. /* no message--this gives no permanent effect */ 2387. choke(otmp); 2388. break; 2389. case AMULET_OF_RESTFUL_SLEEP: { /* another bad idea! */ 2390. long newnap = (long) rnd(100), oldnap = (HSleepy & TIMEOUT); 2391. 2392. if (!(HSleepy & FROMOUTSIDE)) 2393. accessory_has_effect(otmp); 2394. HSleepy |= FROMOUTSIDE; 2395. /* might also be wearing one; use shorter of two timeouts */ 2396. if (newnap < oldnap || oldnap == 0L) 2397. HSleepy = (HSleepy & ~TIMEOUT) | newnap; 2398. break; 2399. } 2400. case RIN_SUSTAIN_ABILITY: 2401. case AMULET_OF_LIFE_SAVING: 2402. case AMULET_OF_FLYING: 2403. case AMULET_OF_REFLECTION: /* nice try */ 2404. /* can't eat Amulet of Yendor or fakes, 2405. * and no oc_prop even if you could -3. 2406. */ 2407. break; 2408. } 2409. } 2410. } 2411. 2412. /* called after eating non-food */ 2413. staticfn void 2414. eatspecial(void) 2415. { 2416. struct obj *otmp = svc.context.victual.piece; 2417. 2418. /* lesshungry wants an occupation to handle choke messages correctly */ 2419. set_occupation(eatfood, "eating non-food", 0); 2420. lesshungry(svc.context.victual.nmod); 2421. go.occupation = 0; 2422. svc.context.victual = zero_victual; /* victual.piece = 0, .o_id = 0 */ 2423. 2424. if (otmp->oclass == COIN_CLASS) { 2425. if (carried(otmp)) 2426. useupall(otmp); 2427. else 2428. useupf(otmp, otmp->quan); 2429. vault_gd_watching(GD_EATGOLD); 2430. return; 2431. } 2432. if (objects[otmp->otyp].oc_material == PAPER) { 2433. #ifdef MAIL_STRUCTURES 2434. if (otmp->otyp == SCR_MAIL) 2435. /* no nutrition */ 2436. pline("This junk mail is less than satisfying."); 2437. else 2438. #endif 2439. if (otmp->otyp == SCR_SCARE_MONSTER) 2440. /* to eat scroll, hero is currently polymorphed into a monster */ 2441. pline("Yuck%c", otmp->blessed ? '!' : '.'); 2442. else if (otmp->oclass == SCROLL_CLASS 2443. /* check description after checking for specific scrolls */ 2444. && objdescr_is(otmp, "YUM YUM")) 2445. pline("Yum%c", otmp->blessed ? '!' : '.'); 2446. else 2447. pline("Needs salt..."); 2448. } 2449. if (otmp->oclass == POTION_CLASS) { 2450. otmp->quan++; /* dopotion() does a useup() */ 2451. (void) dopotion(otmp); 2452. } else if (otmp->oclass == RING_CLASS || otmp->oclass == AMULET_CLASS) { 2453. eataccessory(otmp); 2454. } else if (otmp->otyp == LEASH && otmp->leashmon) { 2455. o_unleash(otmp); 2456. } 2457. 2458. /* KMH -- idea by "Tommy the Terrorist" */ 2459. if (otmp->otyp == TRIDENT && !otmp->cursed) { 2460. /* sugarless chewing gum which used to be heavily advertised on TV */ 2461. pline(Hallucination ? "Four out of five dentists agree." 2462. : "That was pure chewing satisfaction!"); 2463. exercise(A_WIS, TRUE); 2464. } 2465. if (otmp->otyp == FLINT && !otmp->cursed) { 2466. /* chewable vitamin for kids based on "The Flintstones" TV cartoon */ 2467. pline("Yabba-dabba delicious!"); 2468. exercise(A_CON, TRUE); 2469. } 2470. 2471. if (otmp == uwep && otmp->quan == 1L) 2472. uwepgone(); 2473. if (otmp == uquiver && otmp->quan == 1L) 2474. uqwepgone(); 2475. if (otmp == uswapwep && otmp->quan == 1L) 2476. uswapwepgone(); 2477. 2478. if (otmp == uball) 2479. unpunish(); 2480. if (otmp == uchain) 2481. unpunish(); /* but no useup() */ 2482. else if (carried(otmp)) 2483. useup(otmp); 2484. else 2485. useupf(otmp, 1L); 2486. } 2487. 2488. /* NOTE: the order of these words exactly corresponds to the 2489. order of oc_material values #define'd in objclass.h. */ 2490. static const char *const foodwords[] = { 2491. "meal", "liquid", "wax", "food", "meat", "paper", 2492. "cloth", "leather", "wood", "bone", "scale", "metal", 2493. "metal", "metal", "silver", "gold", "platinum", "mithril", 2494. "plastic", "glass", "rich food", "stone" 2495. }; 2496. 2497. staticfn const char * 2498. foodword(struct obj *otmp) 2499. { 2500. if (otmp->oclass == FOOD_CLASS) 2501. return "food"; 2502. if (otmp->oclass == GEM_CLASS && objects[otmp->otyp].oc_material == GLASS 2503. && otmp->dknown) 2504. makeknown(otmp->otyp); 2505. return foodwords[objects[otmp->otyp].oc_material]; 2506. } 2507. 2508. /* called after consuming (non-corpse) food */ 2509. staticfn void 2510. fpostfx(struct obj *otmp) 2511. { 2512. switch (otmp->otyp) { 2513. case SPRIG_OF_WOLFSBANE: 2514. if (ismnum(u.ulycn) || is_were(gy.youmonst.data)) 2515. you_unwere(TRUE); 2516. break; 2517. case CARROT: 2518. if (!u.uswallow 2519. || !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)) 2520. make_blinded((long) u.ucreamed, TRUE); 2521. break; 2522. case FORTUNE_COOKIE: 2523. outrumor(bcsign(otmp), BY_COOKIE); 2524. if (!Blind) 2525. if (!u.uconduct.literate++) 2526. livelog_printf(LL_CONDUCT, 2527. "became literate by reading the fortune inside a cookie"); 2528. break; 2529. case LUMP_OF_ROYAL_JELLY: 2530. if (gy.youmonst.data == &mons[PM_KILLER_BEE] && !Unchanging 2531. && polymon(PM_QUEEN_BEE)) 2532. break; 2533. 2534. /* This stuff seems to be VERY healthy! */ 2535. gainstr(otmp, 1, TRUE); 2536. if (Upolyd) { 2537. u.mh += otmp->cursed ? -rnd(20) : rnd(20), disp.botl = TRUE; 2538. if (u.mh > u.mhmax) { 2539. if (!rn2(17)) 2540. setuhpmax(u.mhmax + 1, FALSE); 2541. u.mh = u.mhmax; 2542. } else if (u.mh <= 0) { 2543. rehumanize(); 2544. } 2545. } else { 2546. u.uhp += otmp->cursed ? -rnd(20) : rnd(20), disp.botl = TRUE; 2547. if (u.uhp > u.uhpmax) { 2548. if (!rn2(17)) 2549. setuhpmax(u.uhpmax + 1, FALSE); 2550. u.uhp = u.uhpmax; 2551. } else if (u.uhp <= 0) { 2552. svk.killer.format = KILLED_BY_AN; 2553. Strcpy(svk.killer.name, "rotten lump of royal jelly"); 2554. done(POISONING); 2555. } 2556. } 2557. if (!otmp->cursed) 2558. heal_legs(0); 2559. break; 2560. case EGG: 2561. if (ismnum(otmp->corpsenm) 2562. && flesh_petrifies(&mons[otmp->corpsenm])) { 2563. if (!Stone_resistance 2564. && !(poly_when_stoned(gy.youmonst.data) 2565. && polymon(PM_STONE_GOLEM))) { 2566. if (!Stoned) { 2567. Sprintf(svk.killer.name, "%s egg", 2568. mons[otmp->corpsenm].pmnames[NEUTRAL]); 2569. make_stoned(5L, (char *) 0, KILLED_BY_AN, 2570. svk.killer.name); 2571. } 2572. } 2573. /* note: no "tastes like chicken" message for eggs */ 2574. } 2575. break; 2576. case EUCALYPTUS_LEAF: 2577. if (Sick && !otmp->cursed) 2578. make_sick(0L, (char *) 0, TRUE, SICK_ALL); 2579. if (Vomiting && !otmp->cursed) 2580. make_vomiting(0L, TRUE); 2581. break; 2582. case APPLE: 2583. if (otmp->cursed && !Sleep_resistance) { 2584. /* Snow White; 'poisoned' applies to [a subset of] weapons, 2585. not food, so we substitute cursed; fortunately our hero 2586. won't have to wait for a prince to be rescued/revived */ 2587. if (Race_if(PM_DWARF) && Hallucination) { 2588. verbalize("Heigh-ho, ho-hum, I think I'll skip work today."); 2589. } else if (Deaf || !flags.acoustics) { 2590. You("fall asleep."); 2591. } else { 2592. Soundeffect(se_sinister_laughter, 100); 2593. You_hear("sinister laughter as you fall asleep..."); 2594. } 2595. fall_asleep(-rn1(11, 20), TRUE); 2596. } 2597. break; 2598. } 2599. return; 2600. } 2601. 2602. #if 0 2603. /* intended for eating a spellbook while polymorphed, but not used; 2604. "leather" applied to appearance, not composition, and has been 2605. changed to "leathery" to reflect that */ 2606. staticfn boolean leather_cover(struct obj *); 2607. 2608. staticfn boolean 2609. leather_cover(struct obj *otmp) 2610. { 2611. const char *odesc = OBJ_DESCR(objects[otmp->otyp]); 2612. 2613. if (odesc && (otmp->oclass == SPBOOK_CLASS)) { 2614. if (!strcmp(odesc, "leather")) 2615. return TRUE; 2616. } 2617. return FALSE; 2618. } 2619. #endif 2620. 2621. /* 2622. * return 0 if the food was not dangerous. 2623. * return 1 if the food was dangerous and you chose to stop. 2624. * return 2 if the food was dangerous and you chose to eat it anyway. 2625. */ 2626. staticfn int 2627. edibility_prompts(struct obj *otmp) 2628. { 2629. /* Blessed food detection grants hero a one-use 2630. * ability to detect food that is unfit for consumption 2631. * or dangerous and avoid it. 2632. */ 2633. char buf[BUFSZ], foodsmell[BUFSZ], 2634. it_or_they[QBUFSZ]; 2635. /* 5.0: decaying globs don't become tainted anymore; in 3.6, they did */ 2636. boolean cadaver = (otmp->otyp == CORPSE), stoneorslime = FALSE; 2637. int material = objects[otmp->otyp].oc_material, mnum = otmp->corpsenm; 2638. long rotted = 0L; 2639. 2640. Strcpy(foodsmell, Tobjnam(otmp, "smell")); 2641. Strcpy(it_or_they, (otmp->quan == 1L) ? "it" : "they"); 2642. 2643. if (cadaver || otmp->otyp == EGG || otmp->otyp == TIN 2644. || otmp->otyp == GLOB_OF_GREEN_SLIME) { 2645. /* These checks must match those in eatcorpse() */ 2646. stoneorslime = (ismnum(mnum) 2647. && flesh_petrifies(&mons[mnum]) 2648. && !Stone_resistance 2649. && !poly_when_stoned(gy.youmonst.data)); 2650. 2651. if (mnum == PM_GREEN_SLIME || otmp->otyp == GLOB_OF_GREEN_SLIME) 2652. stoneorslime = (!Unchanging && !slimeproof(gy.youmonst.data)); 2653. 2654. if (cadaver && !nonrotting_corpse(mnum)) { 2655. long age = peek_at_iced_corpse_age(otmp); 2656. 2657. /* worst case rather than random 2658. in this calculation to force prompt */ 2659. rotted = (svm.moves - age) / (10L + 0 /* was rn2(20) */); 2660. if (otmp->cursed) 2661. rotted += 2L; 2662. else if (otmp->blessed) 2663. rotted -= 2L; 2664. } 2665. } 2666. 2667. /* 2668. * These problems with food should be checked in 2669. * order from most detrimental to least detrimental. 2670. */ 2671. buf[0] = '\0'; 2672. if (cadaver && rotted > 5L && !Sick_resistance) { 2673. /* Tainted meat */ 2674. Snprintf(buf, sizeof buf, "%s like %s could be tainted!", 2675. foodsmell, it_or_they); 2676. } else if (stoneorslime) { 2677. Snprintf(buf, sizeof buf, 2678. "%s like %s could be something very dangerous!", 2679. foodsmell, it_or_they); 2680. } else if (cadaver && rotted > 5L && Sick_resistance) { 2681. /* Tainted meat with Sick_resistance (testing for that is 2682. redundant; we don't get this far for !Sick_resistance) 2683. needs to be done now even though there is no danger because 2684. it can't match after the rotten (cadaver && rotted > 3) test */ 2685. Snprintf(buf, sizeof buf, "%s like %s could be tainted.", 2686. foodsmell, it_or_they); 2687. } else if (otmp->orotten || (cadaver && rotted > 3L)) { 2688. /* Rotten */ 2689. Snprintf(buf, sizeof buf, "%s like %s could be rotten!", 2690. foodsmell, it_or_they); 2691. } else if (cadaver && poisonous(&mons[mnum]) && !Poison_resistance) { 2692. /* poisonous */ 2693. Snprintf(buf, sizeof buf, "%s like %s might be poisonous!", 2694. foodsmell, it_or_they); 2695. } else if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) { 2696. /* causes sleep, for long enough to be dangerous */ 2697. Snprintf(buf, sizeof buf, "%s like %s might have been poisoned.", 2698. foodsmell, it_or_they); 2699. } else if (cadaver && !vegetarian(&mons[mnum]) 2700. && !u.uconduct.unvegetarian && Role_if(PM_MONK)) { 2701. Snprintf(buf, sizeof buf, "%s unhealthy.", foodsmell); 2702. } else if (cadaver && acidic(&mons[mnum]) && !Acid_resistance) { 2703. Snprintf(buf, sizeof buf, "%s rather acidic.", foodsmell); 2704. } else if (Upolyd && u.umonnum == PM_RUST_MONSTER && is_metallic(otmp) 2705. && otmp->oerodeproof) { 2706. Snprintf(buf, sizeof buf, "%s disgusting to you right now.", 2707. foodsmell); 2708. 2709. /* 2710. * Breaks conduct, but otherwise safe. 2711. */ 2712. } else if (!u.uconduct.unvegan 2713. && ((material == LEATHER || material == BONE 2714. || material == DRAGON_HIDE || material == WAX) 2715. || (cadaver && !vegan(&mons[mnum])))) { 2716. Snprintf(buf, sizeof buf, "%s foul and unfamiliar to you.", 2717. foodsmell); 2718. } else if (!u.uconduct.unvegetarian 2719. && ((material == LEATHER || material == BONE 2720. || material == DRAGON_HIDE) 2721. || (cadaver && !vegetarian(&mons[mnum])))) { 2722. Snprintf(buf, sizeof buf, "%s unfamiliar to you.", foodsmell); 2723. } 2724. 2725. if (*buf) { 2726. Snprintf(eos(buf), sizeof buf - strlen(buf), " Eat %s anyway?", 2727. (otmp->quan == 1L) ? "it" : "one"); 2728. return (yn_function(buf, ynchars, 'n', TRUE) == 'n') ? 1 : 2; 2729. } 2730. return 0; 2731. } 2732. 2733. staticfn int 2734. doeat_nonfood(struct obj *otmp) 2735. { 2736. int basenutrit; /* nutrition of full item */ 2737. int ll_conduct = 0; 2738. boolean nodelicious = FALSE; 2739. int material; 2740. 2741. svc.context.victual.reqtime = 1; 2742. svc.context.victual.piece = otmp; 2743. svc.context.victual.o_id = otmp->o_id; 2744. /* Don't split it, we don't need to if it's 1 move */ 2745. svc.context.victual.usedtime = 0; 2746. svc.context.victual.canchoke = (u.uhs == SATIATED); 2747. /* Note: gold weighs 1 pt. for each 1000 pieces (see 2748. pickup.c) so gold and non-gold is consistent. */ 2749. if (otmp->oclass == COIN_CLASS) 2750. basenutrit = ((otmp->quan > 200000L) ? 2000 2751. : (int) (otmp->quan / 100L)); 2752. else if (otmp->oclass == BALL_CLASS || otmp->oclass == CHAIN_CLASS) 2753. basenutrit = weight(otmp); 2754. /* oc_nutrition is usually weight anyway */ 2755. else 2756. basenutrit = objects[otmp->otyp].oc_nutrition; 2757. #ifdef MAIL_STRUCTURES 2758. if (otmp->otyp == SCR_MAIL) { 2759. basenutrit = 0; 2760. nodelicious = TRUE; 2761. } 2762. #endif 2763. svc.context.victual.nmod = basenutrit; 2764. svc.context.victual.eating = 1; /* needed for lesshungry() */ 2765. 2766. if (!u.uconduct.food++) { 2767. ll_conduct++; 2768. livelog_printf(LL_CONDUCT, "ate for the first time (%s)", 2769. food_xname(otmp, FALSE)); 2770. } 2771. material = objects[otmp->otyp].oc_material; 2772. if (material == LEATHER || material == BONE 2773. || material == DRAGON_HIDE || material == WAX) { 2774. if (!u.uconduct.unvegan++ && !ll_conduct) { 2775. livelog_printf(LL_CONDUCT, 2776. "consumed animal products for the first time, by eating %s", 2777. an(food_xname(otmp, FALSE))); 2778. ll_conduct++; 2779. } 2780. if (material != WAX) { 2781. if (!u.uconduct.unvegetarian && !ll_conduct) 2782. livelog_printf(LL_CONDUCT, 2783. "tasted meat by-products for the first time, by eating %s", 2784. an(food_xname(otmp, FALSE))); 2785. violated_vegetarian(); 2786. } 2787. } 2788. 2789. if (otmp->cursed) { 2790. (void) rottenfood(otmp); 2791. nodelicious = TRUE; 2792. } else if (objects[otmp->otyp].oc_material == PAPER) 2793. nodelicious = TRUE; 2794. 2795. if (otmp->oclass == WEAPON_CLASS && otmp->opoisoned) { 2796. pline("Ecch - that must have been poisonous!"); 2797. if (!Poison_resistance) { 2798. poison_strdmg(rnd(4), rnd(15), xname(otmp), KILLED_BY_AN); 2799. } else 2800. You("seem unaffected by the poison."); 2801. } else if (!nodelicious) { 2802. pline("%s%s is delicious!", 2803. (obj_is_pname(otmp) 2804. && otmp->oartifact < ART_ORB_OF_DETECTION) 2805. ? "" 2806. : "This ", 2807. (otmp->oclass == COIN_CLASS) 2808. ? foodword(otmp) 2809. : singular(otmp, xname)); 2810. } 2811. eatspecial(); 2812. return ECMD_TIME; 2813. } 2814. 2815. /* the #eat command */ 2816. int 2817. doeat(void) 2818. { 2819. struct obj *otmp; 2820. int basenutrit; /* nutrition of full item */ 2821. boolean dont_start = FALSE, 2822. already_partly_eaten; 2823. int ll_conduct = 0; 2824. 2825. if (Strangled) { 2826. pline("If you can't breathe air, how can you consume solids?"); 2827. return ECMD_OK; 2828. } 2829. if (!(otmp = floorfood("eat", 0))) 2830. return ECMD_OK; 2831. if (check_capacity((char *) 0)) 2832. return ECMD_OK; 2833. 2834. if (u.uedibility) { 2835. int res = edibility_prompts(otmp); 2836. 2837. if (res) { 2838. Your( 2839. "%s stops tingling and your sense of smell returns to normal.", 2840. body_part(NOSE)); 2841. u.uedibility = 0; 2842. if (res == 1) 2843. return ECMD_OK; 2844. } 2845. } 2846. 2847. /* from floorfood(), &hands_obj means iron bars at current spot */ 2848. if (otmp == &hands_obj) { 2849. /* hero in metallivore form is eating [diggable] iron bars 2850. at current location so skip the other assorted checks; 2851. operates as if digging rather than via the eat occupation */ 2852. if (still_chewing(u.ux, u.uy) && levl[u.ux][u.uy].typ == IRONBARS) { 2853. /* this is verbose, but player will see the hero rather than the 2854. bars so wouldn't know that more turns of eating are required */ 2855. You("pause to swallow."); 2856. } 2857. return ECMD_TIME; 2858. } 2859. /* We have to make non-foods take 1 move to eat, unless we want to 2860. * do ridiculous amounts of coding to deal with partly eaten plate 2861. * mails, players who polymorph back to human in the middle of their 2862. * metallic meal, etc.... 2863. */ 2864. if (!is_edible(otmp)) { 2865. You("cannot eat that!"); 2866. return ECMD_OK; 2867. } else if ((otmp->owornmask & (W_ARMOR | W_TOOL | W_AMUL | W_SADDLE)) 2868. != 0) { 2869. /* let them eat rings */ 2870. You_cant("eat %s you're wearing.", something); 2871. return ECMD_OK; 2872. } else if (!(carried(otmp) ? retouch_object(&otmp, FALSE) 2873. : touch_artifact(otmp, &gy.youmonst))) { 2874. return ECMD_TIME; /* got blasted so use a turn */ 2875. } 2876. if (is_metallic(otmp) && u.umonnum == PM_RUST_MONSTER 2877. && otmp->oerodeproof) { 2878. otmp->rknown = TRUE; 2879. if (otmp->quan > 1L) { 2880. if (!carried(otmp)) 2881. (void) splitobj(otmp, otmp->quan - 1L); 2882. else 2883. otmp = splitobj(otmp, 1L); 2884. } 2885. pline("Ulch - that %s was rustproofed!", xname(otmp)); 2886. /* The regurgitated object's rustproofing is gone now */ 2887. otmp->oerodeproof = 0; 2888. make_stunned((HStun & TIMEOUT) + (long) rn2(10), TRUE); 2889. /* 2890. * We don't expect rust monsters to be wielding welded weapons 2891. * or wearing cursed rings which were rustproofed, but guard 2892. * against the possibility just in case. 2893. */ 2894. if (welded(otmp) || (otmp->cursed && (otmp->owornmask & W_RING))) { 2895. set_bknown(otmp, 1); /* for ring; welded() does this for weapon */ 2896. You("spit out %s.", the(xname(otmp))); 2897. } else { 2898. You("spit %s out onto the %s.", the(xname(otmp)), 2899. surface(u.ux, u.uy)); 2900. if (carried(otmp)) { 2901. /* no need to check for leash in use; it's not metallic */ 2902. if (otmp->owornmask) 2903. remove_worn_item(otmp, FALSE); 2904. freeinv(otmp); 2905. dropy(otmp); 2906. } 2907. stackobj(otmp); 2908. } 2909. return ECMD_TIME; 2910. } 2911. /* KMH -- Slow digestion is... indigestible */ 2912. if (otmp->otyp == RIN_SLOW_DIGESTION) { 2913. pline("This ring is indigestible!"); 2914. (void) rottenfood(otmp); 2915. if (otmp->dknown) 2916. trycall(otmp); 2917. return ECMD_TIME; 2918. } 2919. if (otmp->oclass != FOOD_CLASS) 2920. return doeat_nonfood(otmp); 2921. 2922. 2923. if (otmp == svc.context.victual.piece) { 2924. boolean one_bite_left = (svc.context.victual.usedtime + 1 2925. >= svc.context.victual.reqtime); 2926. 2927. /* If they weren't able to choke, they don't suddenly become able to 2928. * choke just because they were interrupted. On the other hand, if 2929. * they were able to choke before, if they lost food it's possible 2930. * they shouldn't be able to choke now. 2931. */ 2932. if (u.uhs != SATIATED) 2933. svc.context.victual.canchoke = 0; 2934. svc.context.victual.o_id = 0; 2935. otmp = touchfood(otmp); 2936. if (otmp) { 2937. svc.context.victual.piece = otmp; 2938. svc.context.victual.o_id = otmp->o_id; 2939. } else { 2940. do_reset_eat(); 2941. } 2942. /* if there's only one bite left, there sometimes won't be any 2943. "you finish eating" message when done; use different wording 2944. for resuming with one bite remaining instead of trying to 2945. determine whether or not "you finish" is going to be given */ 2946. You("%s your meal.", 2947. !one_bite_left ? "resume" : "consume the last bite of"); 2948. if (otmp) 2949. start_eating(otmp, FALSE); 2950. return ECMD_TIME; 2951. } 2952. 2953. /* nothing in progress - so try to find something. */ 2954. /* tins are a special case */ 2955. /* tins must also check conduct separately in case they're discarded */ 2956. if (otmp->otyp == TIN) { 2957. start_tin(otmp); 2958. return ECMD_TIME; 2959. } 2960. 2961. /* KMH, conduct */ 2962. if (!u.uconduct.food++) { 2963. livelog_printf(LL_CONDUCT, "ate for the first time - %s", 2964. food_xname(otmp, FALSE)); 2965. ll_conduct++; 2966. } 2967. 2968. already_partly_eaten = otmp->oeaten ? TRUE : FALSE; 2969. otmp = touchfood(otmp); 2970. if (otmp) { 2971. svc.context.victual.piece = otmp; 2972. svc.context.victual.o_id = otmp->o_id; 2973. svc.context.victual.usedtime = 0; 2974. } else { 2975. do_reset_eat(); 2976. return ECMD_TIME; 2977. } 2978. 2979. /* Now we need to calculate delay and nutritional info. 2980. * The base nutrition calculated here and in eatcorpse() accounts 2981. * for normal vs. rotten food. The reqtime and nutrit values are 2982. * then adjusted in accordance with the amount of food left. 2983. */ 2984. if (otmp->otyp == CORPSE || otmp->globby) { 2985. int tmp = eatcorpse(otmp); 2986. 2987. if (tmp == 2) { 2988. /* used up */ 2989. svc.context.victual = zero_victual; /* victual.piece=0, .o_id=0 */ 2990. return ECMD_TIME; 2991. } else if (tmp) 2992. dont_start = TRUE; 2993. /* if not used up, eatcorpse sets up reqtime and may modify oeaten */ 2994. } else { 2995. /* No checks for WAX, LEATHER, BONE, DRAGON_HIDE. These are 2996. * all handled in the != FOOD_CLASS case, above. 2997. */ 2998. switch (objects[otmp->otyp].oc_material) { 2999. case FLESH: 3000. if (!u.uconduct.unvegan++ && !ll_conduct) { 3001. livelog_printf(LL_CONDUCT, 3002. "consumed animal products for the first time, by eating %s", 3003. an(food_xname(otmp, FALSE))); 3004. ll_conduct++; 3005. } 3006. if (otmp->otyp != EGG) { 3007. if (!u.uconduct.unvegetarian && !ll_conduct) 3008. livelog_printf(LL_CONDUCT, 3009. "tasted meat for the first time, by eating %s", 3010. an(food_xname(otmp, FALSE))); 3011. 3012. violated_vegetarian(); 3013. } 3014. break; 3015. default: 3016. if (otmp->otyp == PANCAKE || otmp->otyp == FORTUNE_COOKIE /*eggs*/ 3017. || otmp->otyp == CREAM_PIE || otmp->otyp == CANDY_BAR /*milk*/ 3018. || otmp->otyp == LUMP_OF_ROYAL_JELLY) 3019. if (!u.uconduct.unvegan++ && !ll_conduct) 3020. livelog_printf(LL_CONDUCT, 3021. "consumed animal products (%s) for the first time", 3022. food_xname(otmp, FALSE)); 3023. break; 3024. } 3025. 3026. svc.context.victual.reqtime = objects[otmp->otyp].oc_delay; 3027. if (otmp->otyp != FORTUNE_COOKIE 3028. && (otmp->cursed || (!nonrotting_food(otmp->otyp) 3029. && (svm.moves - otmp->age) 3030. > (otmp->blessed ? 50L : 30L) 3031. && (otmp->orotten || !rn2(7))))) { 3032. if (rottenfood(otmp)) { 3033. otmp->orotten = TRUE; 3034. dont_start = TRUE; 3035. } 3036. consume_oeaten(otmp, 1); /* oeaten >>= 1 */ 3037. } else if (!already_partly_eaten) { 3038. if (!fprefx(otmp)) { 3039. do_reset_eat(); 3040. return ECMD_TIME; 3041. } 3042. } else { 3043. You("%s %s.", 3044. (svc.context.victual.reqtime == 1) ? "eat" : "begin eating", 3045. doname(otmp)); 3046. } 3047. } 3048. 3049. /* re-calc the nutrition */ 3050. basenutrit = (int) obj_nutrition(otmp); 3051. 3052. debugpline3( 3053. "before rounddiv: victual.reqtime == %d, oeaten == %d, basenutrit == %d", 3054. svc.context.victual.reqtime, otmp->oeaten, basenutrit); 3055. 3056. svc.context.victual.reqtime 3057. = (basenutrit == 0) ? 0 3058. : rounddiv(svc.context.victual.reqtime * (long) otmp->oeaten, 3059. basenutrit); 3060. 3061. debugpline1("after rounddiv: victual.reqtime == %d", 3062. svc.context.victual.reqtime); 3063. /* 3064. * calculate the modulo value (nutrit. units per round eating) 3065. * note: this isn't exact - you actually lose a little nutrition due 3066. * to this method. 3067. * TODO: add in a "remainder" value to be given at the end of the meal. 3068. */ 3069. if (svc.context.victual.reqtime == 0 || otmp->oeaten == 0) 3070. /* possible if most has been eaten before */ 3071. svc.context.victual.nmod = 0; 3072. else if ((int) otmp->oeaten >= svc.context.victual.reqtime) 3073. svc.context.victual.nmod = -((int) otmp->oeaten 3074. / svc.context.victual.reqtime); 3075. else 3076. svc.context.victual.nmod = svc.context.victual.reqtime % otmp->oeaten; 3077. svc.context.victual.canchoke = (u.uhs == SATIATED); 3078. 3079. if (!dont_start) 3080. start_eating(otmp, already_partly_eaten); 3081. else 3082. otmp->owt = weight(otmp); 3083. return ECMD_TIME; 3084. } 3085. 3086. /* getobj callback for object to be opened with a tin opener */ 3087. staticfn int 3088. tinopen_ok(struct obj *obj) 3089. { 3090. if (obj && obj->otyp == TIN) 3091. return GETOBJ_SUGGEST; 3092. 3093. return GETOBJ_EXCLUDE; 3094. } 3095. 3096. 3097. int 3098. use_tin_opener(struct obj *obj) 3099. { 3100. struct obj *otmp; 3101. int res = ECMD_OK; 3102. 3103. if (!carrying(TIN)) { 3104. You("have no tin to open."); 3105. return ECMD_OK; 3106. } 3107. 3108. if (obj != uwep) { 3109. if (obj->cursed && obj->bknown) { 3110. char qbuf[QBUFSZ]; 3111. 3112. if (ynq(safe_qbuf(qbuf, "Really wield ", "?", 3113. obj, doname, thesimpleoname, "that")) != 'y') 3114. return ECMD_OK; 3115. } 3116. if (!wield_tool(obj, "use")) 3117. return ECMD_OK; 3118. res = ECMD_TIME; 3119. } 3120. 3121. otmp = getobj("open", tinopen_ok, GETOBJ_NOFLAGS); 3122. if (!otmp) 3123. return (res|ECMD_CANCEL); 3124. 3125. start_tin(otmp); 3126. return ECMD_TIME; 3127. } 3128. 3129. /* Take a single bite from a piece of food, checking for choking and 3130. * modifying usedtime. Returns 1 if they choked and survived, 0 otherwise. 3131. */ 3132. staticfn int 3133. bite(void) 3134. { 3135. /* hack to pacify static analyzer incorporated into gcc 12.2 */ 3136. sa_victual(&svc.context.victual); 3137. 3138. if (svc.context.victual.canchoke && u.uhunger >= 2000) { 3139. choke(svc.context.victual.piece); 3140. return 1; 3141. } 3142. if (svc.context.victual.doreset) { 3143. do_reset_eat(); 3144. return 0; 3145. } 3146. gf.force_save_hs = TRUE; 3147. if (svc.context.victual.nmod < 0) { 3148. lesshungry(adj_victual_nutrition(/*-svc.context.victual.nmod*/)); 3149. consume_oeaten(svc.context.victual.piece, 3150. svc.context.victual.nmod); /* -= -nmod */ 3151. } else if (svc.context.victual.nmod > 0 3152. && (svc.context.victual.usedtime % svc.context.victual.nmod)) { 3153. lesshungry(1); 3154. consume_oeaten(svc.context.victual.piece, -1); /* -= 1 */ 3155. } 3156. gf.force_save_hs = FALSE; 3157. recalc_wt(); 3158. return 0; 3159. } 3160. 3161. /* as time goes by - called by moveloop(every move) & domove(melee attack) */ 3162. void 3163. gethungry(void) 3164. { 3165. int accessorytime; 3166. 3167. if (u.uinvulnerable || iflags.debug_hunger) 3168. return; /* you don't feel hungrier */ 3169. 3170. /* being polymorphed into a creature which doesn't eat prevents 3171. this first uhunger decrement, but to stay in such form the hero 3172. will need to wear an Amulet of Unchanging so still burn a small 3173. amount of nutrition in the 'moves % 20' ring/amulet check below */ 3174. if ((!Unaware || !rn2(10)) /* slow metabolic rate while asleep */ 3175. && (carnivorous(gy.youmonst.data) 3176. || herbivorous(gy.youmonst.data) 3177. || metallivorous(gy.youmonst.data)) 3178. && !Slow_digestion) 3179. u.uhunger--; /* ordinary food consumption */ 3180. 3181. /* 3182. * 5.0: trigger is randomized instead of (moves % N). Makes 3183. * ring juggling (using the 'time' option to see the turn counter 3184. * in order to time swapping of a pair of rings of slow digestion, 3185. * wearing one on one hand, then putting on the other and taking 3186. * off the first, then vice versa, over and over and over and ... 3187. * to avoid any hunger from wearing a ring) become ineffective. 3188. * Also causes melee-induced hunger to vary from turn-based hunger 3189. * instead of just replicating that. 3190. */ 3191. accessorytime = rn2(20); /* rn2(20) replaces (int) (svm.moves % 20L) */ 3192. if (accessorytime % 2) { /* odd */ 3193. /* Regeneration uses up food, unless due to an artifact */ 3194. if ((HRegeneration & ~FROMFORM) 3195. || (ERegeneration & ~(W_ARTI | W_WEP))) 3196. u.uhunger--; 3197. if (near_capacity() > SLT_ENCUMBER) 3198. u.uhunger--; 3199. } else { /* even */ 3200. if (Hunger) 3201. u.uhunger--; 3202. /* Conflict uses up food too */ 3203. if (HConflict || (EConflict & (~W_ARTI))) 3204. u.uhunger--; 3205. /* 3206. * +0 charged rings don't do anything, so don't affect hunger. 3207. * Slow digestion cancels movement and melee hunger but still 3208. * causes ring hunger. 3209. * Possessing the real Amulet imposes a separate hunger penalty 3210. * from wearing an amulet (so gets a double penalty when worn). 3211. * 3212. * 5.0.0: Worn meat rings don't affect hunger. 3213. * Same with worn cheap plastic imitation of the Amulet. 3214. * +0 ring of protection might do something (enhanced "magical 3215. * cancellation") if hero doesn't have protection from some 3216. * other source (cloak or second ring). 3217. * 3218. * [If wearing duplicate rings whose effects don't stack, 3219. * should they both consume nutrition, or just one of them? 3220. * Two +0 rings of protection are treated as if only one, 3221. * but this could apply to most rings.] 3222. */ 3223. switch (accessorytime) { /* note: use even cases among 0..19 only */ 3224. case 0: 3225. /* 5.0: if not wearing a ring of slow digestion, obtaining 3226. that property from worn armor (white dragon scales/mail) 3227. causes the armor to burn nutrition; since it's not 3228. actually a ring, we don't check for it on the ring 3229. turns; because of that, wearing two (non-slow digestion) 3230. rings plus the armor consumes more nutrition that one 3231. non-slow digestion ring plus ring of slow digestion */ 3232. if (Slow_digestion 3233. && (!uright || uright->otyp != RIN_SLOW_DIGESTION) 3234. && (!uleft || uleft->otyp != RIN_SLOW_DIGESTION)) 3235. u.uhunger--; 3236. break; 3237. case 4: 3238. if (uleft && uleft->otyp != MEAT_RING 3239. /* more hungry if +/- is nonzero or +/- doesn't apply or 3240. +0 ring of protection is only source of protection; 3241. need to check whether both rings are +0 protection or 3242. they'd both slip by the "is there another source?" test, 3243. but don't do that for both rings or they will both be 3244. treated as supplying "MC" when only one matters; 3245. note: amulet of guarding overrides both +0 rings and 3246. is caught by the (EProtection & ~W_RINGx) == 0L tests */ 3247. && (uleft->spe 3248. || !objects[uleft->otyp].oc_charged 3249. || (uleft->otyp == RIN_PROTECTION 3250. && ((EProtection & ~W_RINGL) == 0L 3251. || ((EProtection & ~W_RINGL) == W_RINGR 3252. && uright && uright->otyp == RIN_PROTECTION 3253. && !uright->spe))))) 3254. u.uhunger--; 3255. break; 3256. case 8: 3257. if (uamul && uamul->otyp != FAKE_AMULET_OF_YENDOR) 3258. u.uhunger--; 3259. break; 3260. case 12: 3261. if (uright && uright->otyp != MEAT_RING 3262. && (uright->spe 3263. || !objects[uright->otyp].oc_charged 3264. || (uright->otyp == RIN_PROTECTION 3265. && (EProtection & ~W_RINGR) == 0L))) 3266. u.uhunger--; 3267. break; 3268. case 16: 3269. if (u.uhave.amulet) 3270. u.uhunger--; 3271. break; 3272. default: 3273. break; 3274. } 3275. } 3276. newuhs(TRUE); 3277. } 3278. 3279. /* called after vomiting and after performing feats of magic */ 3280. void 3281. morehungry(int num) 3282. { 3283. u.uhunger -= num; 3284. newuhs(TRUE); 3285. } 3286. 3287. /* called after eating (and after drinking fruit juice) */ 3288. void 3289. lesshungry(int num) 3290. { 3291. /* See comments in newuhs() for discussion on force_save_hs */ 3292. boolean iseating = (go.occupation == eatfood) || gf.force_save_hs; 3293. 3294. debugpline1("lesshungry(%d)", num); 3295. u.uhunger += num; 3296. if (u.uhunger >= 2000) { 3297. if (!iseating || svc.context.victual.canchoke) { 3298. if (iseating) { 3299. choke(svc.context.victual.piece); 3300. reset_eat(); 3301. } else { 3302. choke((go.occupation == opentin) ? svc.context.tin.tin : 0); 3303. /* no reset_eat() */ 3304. } 3305. } 3306. } else { 3307. /* Have lesshungry() report when you're nearly full so all eating 3308. * warns when you're about to choke. 3309. */ 3310. if (u.uhunger >= 1500 && !Hunger 3311. && (!svc.context.victual.eating 3312. || (svc.context.victual.eating 3313. && !svc.context.victual.fullwarn))) { 3314. pline("You're having a hard time getting all of it down."); 3315. gn.nomovemsg = "You're finally finished."; 3316. if (!svc.context.victual.eating) { 3317. gm.multi = -2; 3318. } else { 3319. svc.context.victual.fullwarn = 1; 3320. if (svc.context.victual.canchoke 3321. && (svc.context.victual.reqtime 3322. - svc.context.victual.usedtime) > 1) { 3323. /* food with one bite left will not survive a stop */ 3324. if (!paranoid_query(ParanoidEating, "Continue eating?")) { 3325. reset_eat(); 3326. gn.nomovemsg = (char *) 0; 3327. } 3328. } 3329. } 3330. } 3331. } 3332. newuhs(FALSE); 3333. } 3334. 3335. staticfn int 3336. unfaint(void) 3337. { 3338. (void) Hear_again(); 3339. if (u.uhs > FAINTING) 3340. u.uhs = FAINTING; 3341. stop_occupation(); 3342. disp.botl = TRUE; 3343. return 0; 3344. } 3345. 3346. boolean 3347. is_fainted(void) 3348. { 3349. return (boolean) (u.uhs == FAINTED); 3350. } 3351. 3352. /* call when a faint must be prematurely terminated */ 3353. void 3354. reset_faint(void) 3355. { 3356. if (ga.afternmv == unfaint) 3357. unmul("You revive."); 3358. } 3359. 3360. /* compute and comment on your (new?) hunger status */ 3361. void 3362. newuhs(boolean incr) 3363. { 3364. unsigned newhs; 3365. static unsigned save_hs; 3366. static boolean saved_hs = FALSE; 3367. int h = u.uhunger; 3368. 3369. newhs = (h > 1000) 3370. ? SATIATED 3371. : (h > 150) ? NOT_HUNGRY 3372. : (h > 50) ? HUNGRY : (h > 0) ? WEAK : FAINTING; 3373. 3374. /* While you're eating, you may pass from WEAK to HUNGRY to NOT_HUNGRY. 3375. * This should not produce the message "you only feel hungry now"; 3376. * that message should only appear if HUNGRY is an endpoint. Therefore 3377. * we check to see if we're in the middle of eating. If so, we save 3378. * the first hunger status, and at the end of eating we decide what 3379. * message to print based on the _entire_ meal, not on each little bit. 3380. */ 3381. /* It is normally possible to check if you are in the middle of a meal 3382. * by checking occupation == eatfood, but there is one special case: 3383. * start_eating() can call bite() for your first bite before it 3384. * sets the occupation. 3385. * Anyone who wants to get that case to work _without_ an ugly static 3386. * force_save_hs variable, feel free. 3387. */ 3388. /* Note: If you become a certain hunger status in the middle of the 3389. * meal, and still have that same status at the end of the meal, 3390. * this will incorrectly print the associated message at the end of 3391. * the meal instead of the middle. Such a case is currently 3392. * impossible, but could become possible if a message for SATIATED 3393. * were added or if HUNGRY and WEAK were separated by a big enough 3394. * gap to fit two bites. 3395. */ 3396. if (go.occupation == eatfood || gf.force_save_hs) { 3397. if (!saved_hs) { 3398. save_hs = u.uhs; 3399. saved_hs = TRUE; 3400. } 3401. u.uhs = newhs; 3402. return; 3403. } else { 3404. if (saved_hs) { 3405. u.uhs = save_hs; 3406. saved_hs = FALSE; 3407. } 3408. } 3409. 3410. if (newhs == FAINTING) { 3411. /* u,uhunger is likely to be negative at this point */ 3412. int uhunger_div_by_10 = sgn(u.uhunger) * ((abs(u.uhunger) + 5) / 10); 3413. 3414. if (is_fainted()) 3415. newhs = FAINTED; 3416. if (u.uhs <= WEAK || rn2(20 - uhunger_div_by_10) >= 19) { 3417. if (!is_fainted() && gm.multi >= 0 /* %% */) { 3418. int duration = 10 - uhunger_div_by_10; 3419. 3420. /* stop what you're doing, then faint */ 3421. stop_occupation(); 3422. You("faint from lack of food."); 3423. incr_itimeout(&HDeaf, duration); 3424. disp.botl = TRUE; 3425. nomul(-duration); 3426. gm.multi_reason = "fainted from lack of food"; 3427. gn.nomovemsg = "You regain consciousness."; 3428. ga.afternmv = unfaint; 3429. newhs = FAINTED; 3430. if (!Levitation) 3431. selftouch("Falling, you"); 3432. } 3433. 3434. /* this used to be -(200 + 20 * Con) but that was when being asleep 3435. suppressed per-turn uhunger decrement but being fainted didn't; 3436. now uhunger becomes more negative at a slower rate */ 3437. } else if (u.uhunger < -(100 + 10 * (int) ACURR(A_CON))) { 3438. u.uhs = STARVED; 3439. disp.botl = TRUE; 3440. bot(); 3441. You("die from starvation."); 3442. svk.killer.format = KILLED_BY; 3443. Strcpy(svk.killer.name, "starvation"); 3444. done(STARVING); 3445. /* if we return, we lifesaved, and that calls newuhs */ 3446. return; 3447. } 3448. } 3449. 3450. if (newhs != u.uhs) { 3451. if (newhs >= WEAK && u.uhs < WEAK) { 3452. /* this used to be losestr(1) which had the potential to 3453. be fatal (still handled below) by reducing HP if it 3454. tried to take base strength below minimum of 3 */ 3455. ATEMP(A_STR) = -1; /* temporary loss overrides Fixed_abil */ 3456. /* defer context.botl status update until after hunger message */ 3457. } else if (newhs < WEAK && u.uhs >= WEAK) { 3458. /* this used to be losestr(-1) which could be abused by 3459. becoming weak while wearing ring of sustain ability, 3460. removing ring, eating to 'restore' strength which boosted 3461. strength by a point each time the cycle was performed; 3462. substituting "while polymorphed" for sustain ability and 3463. "rehumanize" for ring removal might have done that too */ 3464. ATEMP(A_STR) = 0; /* repair of loss also overrides Fixed_abil */ 3465. /* defer context.botl status update until after hunger message */ 3466. } 3467. 3468. switch (newhs) { 3469. case HUNGRY: 3470. if (Hallucination) { 3471. You(!incr ? "now have a lesser case of the munchies." 3472. : "are getting the munchies."); 3473. } else 3474. You("%s.", !incr ? "only feel hungry now" 3475. : (u.uhunger < 145) ? "feel hungry" 3476. : "are beginning to feel hungry"); 3477. if (incr && go.occupation 3478. && (go.occupation != eatfood && go.occupation != opentin)) 3479. stop_occupation(); 3480. end_running(TRUE); 3481. break; 3482. case WEAK: 3483. if (Hallucination) 3484. pline(!incr ? "You still have the munchies." 3485. : "The munchies are interfering with your motor capabilities."); 3486. else if (incr && (Role_if(PM_WIZARD) || Race_if(PM_ELF) 3487. || Role_if(PM_VALKYRIE))) 3488. pline("%s needs food, badly!", 3489. (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE)) 3490. ? gu.urole.name.m 3491. : "Elf"); 3492. else 3493. You("%s weak.", !incr ? "are still" 3494. : (u.uhunger < 45) ? "feel" 3495. : "are beginning to feel"); 3496. if (incr && go.occupation 3497. && (go.occupation != eatfood && go.occupation != opentin)) 3498. stop_occupation(); 3499. end_running(TRUE); 3500. break; 3501. } 3502. u.uhs = newhs; 3503. disp.botl = TRUE; 3504. bot(); 3505. if ((Upolyd ? u.mh : u.uhp) < 1) { 3506. You("die from hunger and exhaustion."); 3507. svk.killer.format = KILLED_BY; 3508. Strcpy(svk.killer.name, "exhaustion"); 3509. done(STARVING); 3510. return; 3511. } 3512. } 3513. } 3514. 3515. /* getobj callback for object to eat - effectively just wraps is_edible() */ 3516. staticfn int 3517. eat_ok(struct obj *obj) 3518. { 3519. /* 'getobj_else' will be non-zero if floor food is present and 3520. player declined to eat that; used to insert "else" into 3521. "you don't have anything [else] to eat" if not carrying any food */ 3522. if (!obj) 3523. return getobj_else ? GETOBJ_EXCLUDE_NONINVENT : GETOBJ_EXCLUDE; 3524. 3525. if (is_edible(obj)) 3526. return GETOBJ_SUGGEST; 3527. 3528. /* make sure to exclude, not downplay, gold (if not is_edible) in order to 3529. * produce the "You cannot eat gold" message in getobj */ 3530. if (obj->oclass == COIN_CLASS) 3531. return GETOBJ_EXCLUDE; 3532. 3533. return GETOBJ_EXCLUDE_SELECTABLE; 3534. } 3535. 3536. /* getobj callback for object to be offered (corpses and things that look like 3537. * the Amulet only */ 3538. staticfn int 3539. offer_ok(struct obj *obj) 3540. { 3541. if (!obj) 3542. return getobj_else ? GETOBJ_EXCLUDE_NONINVENT : GETOBJ_EXCLUDE; 3543. 3544. if (obj->oclass != FOOD_CLASS && obj->oclass != AMULET_CLASS) 3545. return GETOBJ_EXCLUDE; 3546. 3547. if (obj->otyp != CORPSE && obj->otyp != AMULET_OF_YENDOR 3548. && obj->otyp != FAKE_AMULET_OF_YENDOR) 3549. return GETOBJ_EXCLUDE_SELECTABLE; 3550. 3551. /* suppress corpses on astral, amulets elsewhere 3552. * (!astral && amulet) || (astral && !amulet) */ 3553. if (Is_astralevel(&u.uz) ^ (obj->oclass == AMULET_CLASS)) 3554. return GETOBJ_DOWNPLAY; 3555. 3556. return GETOBJ_SUGGEST; 3557. } 3558. 3559. /* getobj callback for object to be tinned */ 3560. staticfn int 3561. tin_ok(struct obj *obj) 3562. { 3563. if (!obj) 3564. return getobj_else ? GETOBJ_EXCLUDE_NONINVENT : GETOBJ_EXCLUDE; 3565. 3566. if (obj->oclass != FOOD_CLASS) 3567. return GETOBJ_EXCLUDE; 3568. 3569. if (obj->otyp != CORPSE || !tinnable(obj)) 3570. return GETOBJ_EXCLUDE_SELECTABLE; 3571. 3572. return GETOBJ_SUGGEST; 3573. } 3574. 3575. /* Returns an object representing food. 3576. * Object may be either on floor or in inventory. 3577. */ 3578. struct obj * 3579. floorfood( 3580. const char *verb, 3581. int corpsecheck) /* 0, no check, 1, corpses, 2, tinnable corpses */ 3582. { 3583. struct obj *otmp; 3584. char qbuf[QBUFSZ]; 3585. char c; 3586. struct permonst *uptr = gy.youmonst.data; 3587. boolean feeding = !strcmp(verb, "eat"), /* corpsecheck==0 */ 3588. offering = !strcmp(verb, "sacrifice"); /* corpsecheck==1 */ 3589. 3590. getobj_else = 0; /* haven't asked about floor food; is used to vary 3591. * "you don't have anything [else] to eat" when 3592. * floor food has been declined and inventory lacks 3593. * any suitable items */ 3594. /* if we can't touch floor objects then use invent food only; 3595. same when 'm' prefix is used--for #eat, it means "skip floor food" */ 3596. if (iflags.menu_requested 3597. || !can_reach_floor(TRUE) || (feeding && u.usteed) 3598. || (is_pool_or_lava(u.ux, u.uy) 3599. && (Wwalking || is_clinger(uptr) || (Flying && !Breathless)))) 3600. goto skipfloor; 3601. 3602. if (feeding && metallivorous(uptr)) { 3603. struct obj *gold; 3604. struct trap *ttmp = t_at(u.ux, u.uy); 3605. 3606. if (ttmp && ttmp->tseen && ttmp->ttyp == BEAR_TRAP) { 3607. boolean u_in_beartrap = (u.utrap && u.utraptype == TT_BEARTRAP); 3608. 3609. /* If not already stuck in the trap, perhaps there should 3610. be a chance to becoming trapped? Probably not, because 3611. then the trap would just get eaten on the _next_ turn... */ 3612. Sprintf(qbuf, "There is a bear trap here (%s); eat it?", 3613. u_in_beartrap ? "holding you" : "armed"); 3614. if ((c = yn_function(qbuf, ynqchars, 'n', TRUE)) == 'y') { 3615. struct obj *beartrap; 3616. 3617. deltrap(ttmp); 3618. if (u_in_beartrap) 3619. reset_utrap(TRUE); 3620. beartrap = mksobj(BEARTRAP, TRUE, FALSE); 3621. Sprintf(qbuf,"You only manage to %s the bear trap.", 3622. u_in_beartrap ? "free yourself from" : "disarm"); 3623. if (check_capacity(qbuf) && beartrap) { 3624. obj_extract_self(beartrap); 3625. dropy(beartrap); /* put it on the floor */ 3626. return (struct obj *) 0; 3627. } 3628. return beartrap; 3629. } else if (c == 'q') { 3630. return (struct obj *) 0; 3631. } 3632. ++getobj_else; 3633. } 3634. if (levl[u.ux][u.uy].typ == IRONBARS) { 3635. /* already verified that hero is metallivorous above */ 3636. boolean nodig = (levl[u.ux][u.uy].wall_info & W_NONDIGGABLE) != 0; 3637. 3638. c = 'n'; 3639. Strcpy(qbuf, "There are iron bars here"); 3640. if (nodig || u.uhunger > 1500) { 3641. pline("%s but you %s eat them.", qbuf, 3642. nodig ? "cannot" : "are too full to"); 3643. } else { 3644. Strcat(qbuf, (!svc.context.digging.chew 3645. || !u_at(svc.context.digging.pos.x, 3646. svc.context.digging.pos.y) 3647. || !on_level(&svc.context.digging.level, &u.uz)) 3648. ? "; eat them?" 3649. : "; resume eating them?"); 3650. c = yn_function(qbuf, ynqchars, 'n', TRUE); 3651. } 3652. if (c == 'y') 3653. return &hands_obj; 3654. else if (c == 'q') 3655. return (struct obj *) 0; 3656. ++getobj_else; 3657. } 3658. if (uptr != &mons[PM_RUST_MONSTER] 3659. && (gold = g_at(u.ux, u.uy)) != 0) { 3660. if (gold->quan == 1L) 3661. Sprintf(qbuf, "There is 1 gold piece here; eat it?"); 3662. else 3663. Sprintf(qbuf, "There are %ld gold pieces here; eat them?", 3664. gold->quan); 3665. if ((c = yn_function(qbuf, ynqchars, 'n', TRUE)) == 'y') { 3666. return gold; 3667. } else if (c == 'q') { 3668. return (struct obj *) 0; 3669. } 3670. ++getobj_else; 3671. } 3672. } 3673. 3674. /* Is there some food (probably a heavy corpse) here on the ground? */ 3675. for (otmp = svl.level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) { 3676. if (corpsecheck 3677. ? (otmp->otyp == CORPSE 3678. && (corpsecheck == 1 || tinnable(otmp))) 3679. : feeding ? (otmp->oclass != COIN_CLASS && is_edible(otmp)) 3680. : otmp->oclass == FOOD_CLASS) { 3681. char qsfx[QBUFSZ]; 3682. boolean one = (otmp->quan == 1L); 3683. 3684. /* if blind and without gloves, attempting to eat (or tin or 3685. offer) a cockatrice corpse is fatal before asking whether 3686. or not to use it; otherwise, 'm<dir>' followed by 'e' could 3687. be used to locate cockatrice corpses without touching them */ 3688. if (otmp->otyp == CORPSE && will_feel_cockatrice(otmp, FALSE)) { 3689. feel_cockatrice(otmp, FALSE); 3690. /* if life-saved (or poly'd into stone golem), terminate 3691. attempt to eat off floor */ 3692. return (struct obj *) 0; 3693. } 3694. /* "There is <an object> here; <verb> it?" or 3695. "There are <N objects> here; <verb> one?" */ 3696. Sprintf(qbuf, "There %s ", otense(otmp, "are")); 3697. Sprintf(qsfx, " here; %s %s?", verb, one ? "it" : "one"); 3698. (void) safe_qbuf(qbuf, qbuf, qsfx, otmp, doname, ansimpleoname, 3699. one ? something : (const char *) "things"); 3700. if ((c = yn_function(qbuf, ynqchars, 'n', TRUE)) == 'y') 3701. return otmp; 3702. else if (c == 'q') 3703. return (struct obj *) 0; 3704. ++getobj_else; 3705. } 3706. } 3707. 3708. skipfloor: 3709. /* We cannot use GETOBJ_PROMPT since we don't want a prompt in the case 3710. where nothing edible is being carried. */ 3711. if (feeding) { 3712. otmp = getobj("eat", eat_ok, GETOBJ_NOFLAGS); 3713. } else if (offering) { 3714. otmp = getobj("sacrifice", offer_ok, GETOBJ_NOFLAGS); 3715. } else if (corpsecheck == 2) { 3716. otmp = getobj(verb, tin_ok, GETOBJ_NOFLAGS); 3717. } else { 3718. impossible("floorfood: unknown request (%s)", verb); 3719. otmp = (struct obj *) 0; 3720. } 3721. if (otmp && corpsecheck && !(offering && otmp->oclass == AMULET_CLASS)) { 3722. if (otmp->otyp != CORPSE || (corpsecheck == 2 && !tinnable(otmp))) { 3723. You_cant("%s that!", verb); 3724. otmp = (struct obj *) 0; 3725. } 3726. } 3727. /* resetting 'getobj_else' here isn't essential; it will be cleared the 3728. next time it needs to be used */ 3729. getobj_else = 0; 3730. return otmp; 3731. } 3732. 3733. /* Side effects of vomiting */ 3734. /* added nomul (MRS) - it makes sense, you're too busy being sick! */ 3735. void 3736. vomit(void) /* A good idea from David Neves */ 3737. { 3738. boolean spewed = FALSE; 3739. 3740. if (cantvomit(gy.youmonst.data)) { 3741. /* doesn't cure food poisoning; message assumes that we aren't 3742. dealing with some esoteric body_part() */ 3743. Your("jaw gapes convulsively."); 3744. } else { 3745. if (Sick && (u.usick_type & SICK_VOMITABLE) != 0) 3746. make_sick(0L, (char *) 0, TRUE, SICK_VOMITABLE); 3747. /* if not enough in stomach to actually vomit then dry heave; 3748. vomiting_dialog() gives a vomit message when its countdown 3749. reaches 0, but only if u.uhs < FAINTING (and !cantvomit()) */ 3750. if (u.uhs >= FAINTING) 3751. Your("%s heaves convulsively!", body_part(STOMACH)); 3752. else 3753. spewed = TRUE; 3754. } 3755. 3756. /* nomul()/You_can_move_again used to be unconditional, which was 3757. viable while eating but not for Vomiting countdown where hero might 3758. be immobilized for some other reason at the time vomit() is called */ 3759. if (gm.multi >= -2) { 3760. nomul(-2); 3761. gm.multi_reason = "vomiting"; 3762. gn.nomovemsg = You_can_move_again; 3763. } 3764. 3765. if (spewed) { 3766. struct attack 3767. *mattk = attacktype_fordmg(gy.youmonst.data, AT_BREA, AD_ACID); 3768. 3769. /* currently, only yellow dragons can breathe acid */ 3770. if (mattk) { 3771. You("breathe acid on yourself..."); /* [why?] */ 3772. ubreatheu(mattk); 3773. } 3774. /* vomiting on an altar is, all things considered, rather impolite */ 3775. if (IS_ALTAR(levl[u.ux][u.uy].typ)) 3776. altar_wrath(u.ux, u.uy); 3777. /* if poly'd into acidic form, stomach acid is stronger than normal */ 3778. if (acidic(gy.youmonst.data)) { 3779. /* TODO: if there's a web here, destroy that too (before ice) */ 3780. if (is_ice(u.ux, u.uy)) 3781. melt_ice(u.ux, u.uy, 3782. "Your stomach acid melts straight through the ice!"); 3783. } 3784. } 3785. } 3786. 3787. int 3788. eaten_stat(int base, struct obj *obj) 3789. { 3790. long uneaten_amt, full_amount; 3791. 3792. /* get full_amount first; obj_nutrition() might modify obj->oeaten */ 3793. full_amount = (long) obj_nutrition(obj); 3794. uneaten_amt = (long) obj->oeaten; 3795. if (uneaten_amt > full_amount) { 3796. impossible( 3797. "partly eaten food (%ld) more nutritious than untouched food (%ld)", 3798. uneaten_amt, full_amount); 3799. uneaten_amt = full_amount; 3800. } 3801. 3802. base = (int) (full_amount ? (long) base * uneaten_amt / full_amount : 0L); 3803. return (base < 1) ? 1 : base; 3804. } 3805. 3806. /* reduce obj's oeaten field, making sure it never hits or passes 0 */ 3807. void 3808. consume_oeaten(struct obj *obj, int amt) 3809. { 3810. if (!obj_nutrition(obj)) { 3811. char itembuf[40]; 3812. int otyp = obj->otyp; 3813. 3814. if (otyp == CORPSE || otyp == EGG || otyp == TIN) { 3815. Strcpy(itembuf, (otyp == CORPSE) ? "corpse" 3816. : (otyp == EGG) ? "egg" 3817. : (otyp == TIN) ? "tin" : "other?"); 3818. Sprintf(eos(itembuf), " [%d]", obj->corpsenm); 3819. } else { 3820. Sprintf(itembuf, "%d", otyp); 3821. } 3822. impossible( 3823. "oeaten: attempting to set 0 nutrition food (%s) partially eaten", 3824. itembuf); 3825. return; 3826. } 3827. 3828. /* 3829. * This is a hack to try to squelch several long standing mystery 3830. * food bugs. A better solution would be to rewrite the entire 3831. * victual handling mechanism from scratch using a less complex 3832. * model. Alternatively, this routine could call done_eating() 3833. * or food_disappears() but its callers would need revisions to 3834. * cope with svc.context.victual.piece unexpectedly going away. 3835. * 3836. * Multi-turn eating operates by setting the food's oeaten field 3837. * to its full nutritional value and then running a counter which 3838. * independently keeps track of whether there is any food left. 3839. * The oeaten field can reach exactly zero on the last turn, and 3840. * the object isn't removed from inventory until the next turn 3841. * when the "you finish eating" message gets delivered, so the 3842. * food would be restored to the status of untouched during that 3843. * interval. This resulted in unexpected encumbrance messages 3844. * at the end of a meal (if near enough to a threshold) and would 3845. * yield full food if there was an interruption on the critical 3846. * turn. Also, there have been reports over the years of food 3847. * becoming massively heavy or producing unlimited satiation; 3848. * this would occur if reducing oeaten via subtraction attempted 3849. * to drop it below 0 since its unsigned type would produce a 3850. * huge positive value instead. So far, no one has figured out 3851. * _why_ that inappropriate subtraction might sometimes happen. 3852. */ 3853. 3854. if (amt > 0) { 3855. /* bit shift to divide the remaining amount of food */ 3856. obj->oeaten >>= amt; 3857. } else { 3858. /* simple decrement; value is negative so we actually add it */ 3859. if ((int) obj->oeaten > -amt) 3860. obj->oeaten += amt; 3861. else 3862. obj->oeaten = 0; 3863. } 3864. 3865. /* mustn't let partly-eaten drop all the way to 0 or the item would 3866. become restored to untouched; set to no bites left */ 3867. if (obj->oeaten == 0) { 3868. if (obj == svc.context.victual.piece) /* always true unless wishing */ 3869. svc.context.victual.reqtime = svc.context.victual.usedtime; 3870. obj->oeaten = 1; /* smallest possible positive value */ 3871. } 3872. } 3873. 3874. /* called when eatfood occupation has been interrupted, 3875. or in the case of theft, is about to be interrupted */ 3876. boolean 3877. maybe_finished_meal(boolean stopping) 3878. { 3879. /* in case consume_oeaten() has decided that the food is all gone */ 3880. if (go.occupation == eatfood 3881. && svc.context.victual.usedtime >= svc.context.victual.reqtime) { 3882. if (stopping) 3883. go.occupation = 0; /* for do_reset_eat */ 3884. /* eatfood() calls done_eating() to use up svc.context.victual.piece */ 3885. (void) eatfood(); 3886. return TRUE; 3887. } 3888. return FALSE; 3889. } 3890. 3891. /* called by revive(); sort of the opposite of maybe_finished_meal() */ 3892. void 3893. cant_finish_meal(struct obj *corpse) 3894. { 3895. /* 3896. * When a corpse gets resurrected, the makemon() for that might 3897. * call stop_occupation(). If that happens, prevent it from using 3898. * up the corpse via maybe_finished_meal() when there's not enough 3899. * left for another bite. revive() needs continued access to the 3900. * corpse and will delete it when done. 3901. */ 3902. if (go.occupation == eatfood && svc.context.victual.piece == corpse) { 3903. /* normally performed by done_eating() */ 3904. svc.context.victual = zero_victual; /* victual.piece = 0, .o_id = 0 */ 3905. 3906. if (!corpse->oeaten) 3907. corpse->oeaten = 1; /* [see consume_oeaten()] */ 3908. go.occupation = donull; /* any non-Null other than eatfood() */ 3909. stop_occupation(); 3910. newuhs(FALSE); 3911. } 3912. } 3913. 3914. /* Tin of <something> to the rescue? Decide whether current occupation 3915. is an attempt to eat a tin of something capable of saving hero's life. 3916. We don't care about consumption of non-tinned food here because special 3917. effects there take place on first bite rather than at end of occupation. 3918. [Popeye the Sailor gets out of trouble by eating tins of spinach. :-] */ 3919. boolean 3920. Popeye(int threat) 3921. { 3922. struct obj *otin; 3923. int mndx; 3924. 3925. if (go.occupation != opentin) 3926. return FALSE; 3927. otin = svc.context.tin.tin; 3928. /* make sure hero still has access to tin */ 3929. if (!carried(otin) 3930. && (!obj_here(otin, u.ux, u.uy) || !can_reach_floor(TRUE))) 3931. return FALSE; 3932. /* unknown tin is assumed to be helpful */ 3933. if (!otin->known) 3934. return TRUE; 3935. /* known tin is helpful if it will stop life-threatening problem */ 3936. mndx = otin->corpsenm; 3937. switch (threat) { 3938. /* note: not used; hunger code bypasses stop_occupation() when eating */ 3939. case HUNGER: 3940. return (boolean) (mndx != NON_PM || otin->spe == 1); 3941. /* flesh from lizards and acidic critters stops petrification */ 3942. case STONED: 3943. return (boolean) (ismnum(mndx) 3944. && (mndx == PM_LIZARD || acidic(&mons[mndx]))); 3945. /* polymorph into a fiery monster */ 3946. case SLIMED: 3947. return (boolean) polyfood(otin); 3948. /* no tins can cure these (yet?) */ 3949. case SICK: 3950. case VOMITING: 3951. break; 3952. default: 3953. break; 3954. } 3955. return FALSE; 3956. } 3957. 3958. /* the hero has swallowed a monster whole as a purple worm or similar, and has 3959. finished digesting its corpse (called via ga.afternmv) */ 3960. int 3961. Finish_digestion(void) 3962. { 3963. if (gc.corpsenm_digested != NON_PM) { 3964. cpostfx(gc.corpsenm_digested); 3965. gc.corpsenm_digested = NON_PM; 3966. } 3967. return 0; 3968. } 3969. 3970. /*eat.c*/