Source:NetHack 3.4.3/src/eat.c

From NetHackWiki
(Redirected from Source:Ref/Hear again)
Jump to: navigation, search

Below is the full text to src/eat.c from NetHack 3.4.3. To link to a particular line, write [[eat.c#line123]], for example.

Top of file[edit]

  1. /*	SCCS Id: @(#)eat.c	3.4	2003/02/13	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

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. #include "hack.h"
  2. /* #define DEBUG */	/* uncomment to enable new eat code debugging */
  3.  
  4. #ifdef DEBUG
  5. # ifdef WIZARD
  6. #define debugpline	if (wizard) pline
  7. # else
  8. #define debugpline	pline
  9. # endif
  10. #endif
  11.  
  12. STATIC_PTR int NDECL(eatmdone);
  13. STATIC_PTR int NDECL(eatfood);
  14. STATIC_PTR void FDECL(costly_tin, (const char*));
  15. STATIC_PTR int NDECL(opentin);
  16. STATIC_PTR int NDECL(unfaint);
  17.  
  18. #ifdef OVLB
  19. STATIC_DCL const char *FDECL(food_xname, (struct obj *,BOOLEAN_P));
  20. STATIC_DCL void FDECL(choke, (struct obj *));
  21. STATIC_DCL void NDECL(recalc_wt);
  22. STATIC_DCL struct obj *FDECL(touchfood, (struct obj *));
  23. STATIC_DCL void NDECL(do_reset_eat);
  24. STATIC_DCL void FDECL(done_eating, (BOOLEAN_P));
  25. STATIC_DCL void FDECL(cprefx, (int));
  26. STATIC_DCL int FDECL(intrinsic_possible, (int,struct permonst *));
  27. STATIC_DCL void FDECL(givit, (int,struct permonst *));
  28. STATIC_DCL void FDECL(cpostfx, (int));
  29. STATIC_DCL void FDECL(start_tin, (struct obj *));
  30. STATIC_DCL int FDECL(eatcorpse, (struct obj *));
  31. STATIC_DCL void FDECL(start_eating, (struct obj *));
  32. STATIC_DCL void FDECL(fprefx, (struct obj *));
  33. STATIC_DCL void FDECL(accessory_has_effect, (struct obj *));
  34. STATIC_DCL void FDECL(fpostfx, (struct obj *));
  35. STATIC_DCL int NDECL(bite);
  36. STATIC_DCL int FDECL(edibility_prompts, (struct obj *));
  37. STATIC_DCL int FDECL(rottenfood, (struct obj *));
  38. STATIC_DCL void NDECL(eatspecial);
  39. STATIC_DCL void FDECL(eataccessory, (struct obj *));
  40. STATIC_DCL const char *FDECL(foodword, (struct obj *));
  41. STATIC_DCL boolean FDECL(maybe_cannibal, (int,BOOLEAN_P));
  42.  
  43. char msgbuf[BUFSZ];
  44.  
  45. #endif /* OVLB */
  46.  
  47. /* hunger texts used on bottom line (each 8 chars long) */
  48. #define SATIATED	0
  49. #define NOT_HUNGRY	1
  50. #define HUNGRY		2
  51. #define WEAK		3
  52. #define FAINTING	4
  53. #define FAINTED		5
  54. #define STARVED		6

The actual strings are defined in the hu_stat array below.

  1. /* also used to see if you're allowed to eat cats and dogs */
  2. #define CANNIBAL_ALLOWED() (Role_if(PM_CAVEMAN) || Race_if(PM_ORC))
  3.  
  4. #ifndef OVLB
  5.  
  6. STATIC_DCL NEARDATA const char comestibles[];
  7. STATIC_DCL NEARDATA const char allobj[];
  8. STATIC_DCL boolean force_save_hs;
  9.  
  10. #else
  11.  
  12. STATIC_OVL NEARDATA const char comestibles[] = { FOOD_CLASS, 0 };
  13.  
  14. /* Gold must come first for getobj(). */
  15. STATIC_OVL NEARDATA const char allobj[] = {
  16. 	COIN_CLASS, WEAPON_CLASS, ARMOR_CLASS, POTION_CLASS, SCROLL_CLASS,
  17. 	WAND_CLASS, RING_CLASS, AMULET_CLASS, FOOD_CLASS, TOOL_CLASS,
  18. 	GEM_CLASS, ROCK_CLASS, BALL_CLASS, CHAIN_CLASS, SPBOOK_CLASS, 0 };
  19.  
  20. STATIC_OVL boolean force_save_hs = FALSE;
  21.  
  22. const char *hu_stat[] = {
  23. 	"Satiated",
  24. 	"        ",
  25. 	"Hungry  ",
  26. 	"Weak    ",
  27. 	"Fainting",
  28. 	"Fainted ",
  29. 	"Starved "
  30. };
  31.  
  32. #endif /* OVLB */

is_edible[edit]

  1. #ifdef OVL1
  2.  
  3. /*
  4. * Decide whether a particular object can be eaten by the possibly
  5. * polymorphed character.  Not used for monster checks.
  6. */
  7. boolean
  8. is_edible(obj)
  9. register struct obj *obj;
  10. {
  11. 	/* protect invocation tools but not Rider corpses (handled elsewhere)*/
  12. /* if (obj->oclass != FOOD_CLASS && obj_resists(obj, 0, 0)) */
  13. 	if (objects[obj->otyp].oc_unique)
  14. 		return FALSE;
  15. 	/* above also prevents the Amulet from being eaten, so we must never
  16. 	   allow fake amulets to be eaten either [which is already the case] */
  17.  
  18. 	if (metallivorous(youmonst.data) && is_metallic(obj) &&
  19. 	    (youmonst.data != &mons[PM_RUST_MONSTER] || is_rustprone(obj)))
  20. 		return TRUE;

Rust monsters can only eat metallic items if the item is also rustable. Other metallivorous monsters (rock moles, xorn) can eat any metallic item.

  1. 	if (u.umonnum == PM_GELATINOUS_CUBE && is_organic(obj) &&
  2. 		/* [g.cubes can eat containers and retain all contents
  3. 		    as engulfed items, but poly'd player can't do that] */
  4. 	    !Has_contents(obj))
  5. 		return TRUE;

Gelatinous cubes can eat any organic object except containers.

  1. /* return((boolean)(!!index(comestibles, obj->oclass))); */
  2. 	return (boolean)(obj->oclass == FOOD_CLASS);

Otherwise, the player can only eat food objects.

  1. }
  2.  
  3. #endif /* OVL1 */

init_uhunger[edit]

  1. #ifdef OVLB
  2.  
  3. void
  4. init_uhunger()
  5. {
  6. 	u.uhunger = 900;
  7. 	u.uhs = NOT_HUNGRY;
  8. }

More definitions[edit]

  1. static const struct { const char *txt; int nut; } tintxts[] = {
  2. 	{"deep fried",	 60},
  3. 	{"pickled",	 40},
  4. 	{"soup made from", 20},
  5. 	{"pureed",	500},
  6. #define ROTTEN_TIN 4
  7. 	{"rotten",	-50},
  8. #define HOMEMADE_TIN 5
  9. 	{"homemade",	 50},
  10. 	{"stir fried",   80},
  11. 	{"candied",      100},
  12. 	{"boiled",       50},
  13. 	{"dried",        55},
  14. 	{"szechuan",     70},
  15. #define FRENCH_FRIED_TIN 11
  16. 	{"french fried", 40},
  17. 	{"sauteed",      95},
  18. 	{"broiled",      80},
  19. 	{"smoked",       50},
  20. 	{"", 0}
  21. };
  22. #define TTSZ	SIZE(tintxts)
  23.  
  24. static NEARDATA struct {
  25. 	struct	obj *tin;
  26. 	int	usedtime, reqtime;
  27. } tin;
  28.  
  29. static NEARDATA struct {
  30. 	struct	obj *piece;	/* the thing being eaten, or last thing that
  31. 				 * was partially eaten, unless that thing was
  32. 				 * a tin, which uses the tin structure above,
  33. 				 * in which case this should be 0 */
  34. 	/* doeat() initializes these when piece is valid */
  35. 	int	usedtime,	/* turns spent eating */
  36. 		reqtime;	/* turns required to eat */
  37. 	int	nmod;		/* coded nutrition per turn */
  38. 	Bitfield(canchoke,1);	/* was satiated at beginning */
  39.  
  40. 	/* start_eating() initializes these */
  41. 	Bitfield(fullwarn,1);	/* have warned about being full */
  42. 	Bitfield(eating,1);	/* victual currently being eaten */
  43. 	Bitfield(doreset,1);	/* stop eating at end of turn */
  44. } victual;
  45.  
  46. static char *eatmbuf = 0;	/* set by cpostfx() */

eatmdone[edit]

  1. STATIC_PTR
  2. int
  3. eatmdone()		/* called after mimicing is over */
  4. {
  5. 	/* release `eatmbuf' */
  6. 	if (eatmbuf) {
  7. 	    if (nomovemsg == eatmbuf) nomovemsg = 0;
  8. 	    free((genericptr_t)eatmbuf),  eatmbuf = 0;
  9. 	}
  10. 	/* update display */
  11. 	if (youmonst.m_ap_type) {
  12. 	    youmonst.m_ap_type = M_AP_NOTHING;
  13. 	    newsym(u.ux,u.uy);
  14. 	}
  15. 	return 0;
  16. }

food_xname[edit]

  1. /* ``[the(] singular(food, xname) [)]'' with awareness of unique monsters */
  2. STATIC_OVL const char *
  3. food_xname(food, the_pfx)
  4. struct obj *food;
  5. boolean the_pfx;
  6. {
  7. 	const char *result;
  8. 	int mnum = food->corpsenm;
  9.  
  10. 	if (food->otyp == CORPSE && (mons[mnum].geno & G_UNIQ)) {
  11. 	    /* grab xname()'s modifiable return buffer for our own use */
  12. 	    char *bufp = xname(food);
  13. 	    Sprintf(bufp, "%s%s corpse",
  14. 		    (the_pfx && !type_is_pname(&mons[mnum])) ? "the " : "",
  15. 		    s_suffix(mons[mnum].mname));
  16. 	    result = bufp;
  17. 	} else {
  18. 	    /* the ordinary case */
  19. 	    result = singular(food, xname);
  20. 	    if (the_pfx) result = the(result);
  21. 	}
  22. 	return result;
  23. }

choke[edit]

  1. /* Created by GAN 01/28/87
  2. * Amended by AKP 09/22/87: if not hard, don't choke, just vomit.
  3. * Amended by 3.  06/12/89: if not hard, sometimes choke anyway, to keep risk.
  4. *		  11/10/89: if hard, rarely vomit anyway, for slim chance.
  5. */
  6. STATIC_OVL void
  7. choke(food)	/* To a full belly all food is bad. (It.) */
  8. 	register struct obj *food;
  9. {
  10. 	/* only happens if you were satiated */
  11. 	if (u.uhs != SATIATED) {
  12. 		if (!food || food->otyp != AMULET_OF_STRANGULATION)
  13. 			return;
  14. 	} else if (Role_if(PM_KNIGHT) && u.ualign.type == A_LAWFUL) {
  15. 			adjalign(-1);		/* gluttony is unchivalrous */
  16. 			You_feel("like a glutton!");
  17. 	}
  18.  
  19. 	exercise(A_CON, FALSE);
  20.  
  21. 	if (Breathless || (!Strangled && !rn2(20))) {
  22. 		/* choking by eating AoS doesn't involve stuffing yourself */
  23. 		if (food && food->otyp == AMULET_OF_STRANGULATION) {
  24. 			You("choke, but recover your composure.");
  25. 			return;
  26. 		}
  27. 		You("stuff yourself and then vomit voluminously.");
  28. 		morehungry(1000);	/* you just got *very* sick! */
  29. 		nomovemsg = 0;
  30. 		vomit();
  31. 	} else {
  32. 		killer_format = KILLED_BY_AN;
  33. 		/*
  34. 		 * Note all "killer"s below read "Choked on %s" on the
  35. 		 * high score list & tombstone.  So plan accordingly.
  36. 		 */
  37. 		if(food) {
  38. 			You("choke over your %s.", foodword(food));
  39. 			if (food->oclass == COIN_CLASS) {
  40. 				killer = "a very rich meal";
  41. 			} else {
  42. 				killer = food_xname(food, FALSE);
  43. 				if (food->otyp == CORPSE &&
  44. 				    (mons[food->corpsenm].geno & G_UNIQ)) {
  45. 				    if (!type_is_pname(&mons[food->corpsenm]))
  46. 					killer = the(killer);
  47. 				    killer_format = KILLED_BY;
  48. 				}
  49. 			}
  50. 		} else {
  51. 			You("choke over it.");
  52. 			killer = "quick snack";
  53. 		}
  54. 		You("die...");
  55. 		done(CHOKING);
  56. 	}
  57. }

recalc_wt[edit]

  1. /* modify object wt. depending on time spent consuming it */
  2. STATIC_OVL void
  3. recalc_wt()
  4. {
  5. 	struct obj *piece = victual.piece;
  6.  
  7. #ifdef DEBUG
  8. 	debugpline("Old weight = %d", piece->owt);
  9. 	debugpline("Used time = %d, Req'd time = %d",
  10. 		victual.usedtime, victual.reqtime);
  11. #endif
  12. 	piece->owt = weight(piece);
  13. #ifdef DEBUG
  14. 	debugpline("New weight = %d", piece->owt);
  15. #endif
  16. }

reset_eat[edit]

  1. void
  2. reset_eat()		/* called when eating interrupted by an event */
  3. {
  4. /* we only set a flag here - the actual reset process is done after
  5. * the round is spent eating.
  6. */
  7. 	if(victual.eating && !victual.doreset) {
  8. #ifdef DEBUG
  9. 	    debugpline("reset_eat...");
  10. #endif
  11. 	    victual.doreset = TRUE;
  12. 	}
  13. 	return;
  14. }

touchfood[edit]

  1. STATIC_OVL struct obj *
  2. touchfood(otmp)
  3. register struct obj *otmp;
  4. {
  5. 	if (otmp->quan > 1L) {
  6. 	    if(!carried(otmp))
  7. 		(void) splitobj(otmp, otmp->quan - 1L);
  8. 	    else
  9. 		otmp = splitobj(otmp, 1L);
  10. #ifdef DEBUG
  11. 	    debugpline("split object,");
  12. #endif
  13. 	}
  14.  
  15. 	if (!otmp->oeaten) {
  16. 	    if(((!carried(otmp) && costly_spot(otmp->ox, otmp->oy) &&
  17. 		 !otmp->no_charge)
  18. 		 || otmp->unpaid)) {
  19. 		/* create a dummy duplicate to put on bill */
  20. 		verbalize("You bit it, you bought it!");
  21. 		bill_dummy_object(otmp);
  22. 	    }
  23. 	    otmp->oeaten = (otmp->otyp == CORPSE ?
  24. 				mons[otmp->corpsenm].cnutrit :
  25. 				objects[otmp->otyp].oc_nutrition);
  26. 	}
  27.  
  28. 	if (carried(otmp)) {
  29. 	    freeinv(otmp);
  30. 	    if (inv_cnt() >= 52) {
  31. 		sellobj_state(SELL_DONTSELL);
  32. 		dropy(otmp);
  33. 		sellobj_state(SELL_NORMAL);
  34. 	    } else {
  35. 		otmp->oxlth++;		/* hack to prevent merge */
  36. 		otmp = addinv(otmp);
  37. 		otmp->oxlth--;
  38. 	    }
  39. 	}
  40. 	return(otmp);
  41. }

food_disappears[edit]

  1. /* When food decays, in the middle of your meal, we don't want to dereference
  2. * any dangling pointers, so set it to null (which should still trigger
  3. * do_reset_eat() at the beginning of eatfood()) and check for null pointers
  4. * in do_reset_eat().
  5. */
  6. void
  7. food_disappears(obj)
  8. register struct obj *obj;
  9. {
  10. 	if (obj == victual.piece) victual.piece = (struct obj *)0;
  11. 	if (obj->timed) obj_stop_timers(obj);
  12. }

food_substitution[edit]

  1. /* renaming an object usually results in it having a different address;
  2. so the sequence start eating/opening, get interrupted, name the food,
  3. resume eating/opening would restart from scratch */
  4. void
  5. food_substitution(old_obj, new_obj)
  6. struct obj *old_obj, *new_obj;
  7. {
  8. 	if (old_obj == victual.piece) victual.piece = new_obj;
  9. 	if (old_obj == tin.tin) tin.tin = new_obj;
  10. }

do_reset_eat[edit]

  1. STATIC_OVL void
  2. do_reset_eat()
  3. {
  4. #ifdef DEBUG
  5. 	debugpline("do_reset_eat...");
  6. #endif
  7. 	if (victual.piece) {
  8. 		victual.piece = touchfood(victual.piece);
  9. 		recalc_wt();
  10. 	}
  11. 	victual.fullwarn = victual.eating = victual.doreset = FALSE;
  12. 	/* Do not set canchoke to FALSE; if we continue eating the same object
  13. 	 * we need to know if canchoke was set when they started eating it the
  14. 	 * previous time.  And if we don't continue eating the same object
  15. 	 * canchoke always gets recalculated anyway.
  16. 	 */
  17. 	stop_occupation();
  18. 	newuhs(FALSE);
  19. }

eatfood[edit]

  1. STATIC_PTR
  2. int
  3. eatfood()		/* called each move during eating process */
  4. {
  5. 	if(!victual.piece ||
  6. 	 (!carried(victual.piece) && !obj_here(victual.piece, u.ux, u.uy))) {
  7. 		/* maybe it was stolen? */
  8. 		do_reset_eat();
  9. 		return(0);
  10. 	}
  11. 	if(!victual.eating) return(0);
  12.  
  13. 	if(++victual.usedtime <= victual.reqtime) {
  14. 	    if(bite()) return(0);
  15. 	    return(1);	/* still busy */
  16. 	} else {	/* done */
  17. 	    done_eating(TRUE);
  18. 	    return(0);
  19. 	}
  20. }

done_eating[edit]

  1. STATIC_OVL void
  2. done_eating(message)
  3. boolean message;
  4. {
  5. 	victual.piece->in_use = TRUE;
  6. 	occupation = 0; /* do this early, so newuhs() knows we're done */
  7. 	newuhs(FALSE);
  8. 	if (nomovemsg) {
  9. 		if (message) pline(nomovemsg);
  10. 		nomovemsg = 0;
  11. 	} else if (message)
  12. 		You("finish eating %s.", food_xname(victual.piece, TRUE));
  13.  
  14. 	if(victual.piece->otyp == CORPSE)
  15. 		cpostfx(victual.piece->corpsenm);
  16. 	else
  17. 		fpostfx(victual.piece);
  18.  
  19. 	if (carried(victual.piece)) useup(victual.piece);
  20. 	else useupf(victual.piece, 1L);
  21. 	victual.piece = (struct obj *) 0;
  22. 	victual.fullwarn = victual.eating = victual.doreset = FALSE;
  23. }

maybe_cannibal[edit]

  1. STATIC_OVL boolean
  2. maybe_cannibal(pm, allowmsg)
  3. int pm;
  4. boolean allowmsg;
  5. {
  6. 	if (!CANNIBAL_ALLOWED() && your_race(&mons[pm])) {
  7. 		if (allowmsg) {
  8. 			if (Upolyd)
  9. 				You("have a bad feeling deep inside.");
  10. 			You("cannibal!  You will regret this!");
  11. 		}
  12. 		HAggravate_monster |= FROMOUTSIDE;
  13. 		change_luck(-rn1(4,2));		/* -5..-2 */
  14. 		return TRUE;
  15. 	}
  16. 	return FALSE;
  17. }

cprefx[edit]

  1. STATIC_OVL void
  2. cprefx(pm)
  3. register int pm;
  4. {
  5. 	(void) maybe_cannibal(pm,TRUE);
  6. 	if (touch_petrifies(&mons[pm]) || pm == PM_MEDUSA) {
  7. 	    if (!Stone_resistance &&
  8. 		!(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))) {
  9. 		Sprintf(killer_buf, "tasting %s meat", mons[pm].mname);
  10. 		killer_format = KILLED_BY;
  11. 		killer = killer_buf;
  12. 		You("turn to stone.");
  13. 		done(STONING);
  14. 		if (victual.piece)
  15. 		    victual.eating = FALSE;
  16. 		return; /* lifesaved */
  17. 	    }
  18. 	}
  19.  
  20. 	switch(pm) {
  21. 	    case PM_LITTLE_DOG:
  22. 	    case PM_DOG:
  23. 	    case PM_LARGE_DOG:
  24. 	    case PM_KITTEN:
  25. 	    case PM_HOUSECAT:
  26. 	    case PM_LARGE_CAT:
  27. 		if (!CANNIBAL_ALLOWED()) {
  28. 		    You_feel("that eating the %s was a bad idea.", mons[pm].mname);
  29. 		    HAggravate_monster |= FROMOUTSIDE;
  30. 		}
  31. 		break;
  32. 	    case PM_LIZARD:
  33. 		if (Stoned) fix_petrification();
  34. 		break;
  35. 	    case PM_DEATH:
  36. 	    case PM_PESTILENCE:
  37. 	    case PM_FAMINE:
  38. 		{ char buf[BUFSZ];
  39. 		    pline("Eating that is instantly fatal.");
  40. 		    Sprintf(buf, "unwisely ate the body of %s",
  41. 			    mons[pm].mname);
  42. 		    killer = buf;
  43. 		    killer_format = NO_KILLER_PREFIX;
  44. 		    done(DIED);
  45. 		    /* It so happens that since we know these monsters */
  46. 		    /* cannot appear in tins, victual.piece will always */
  47. 		    /* be what we want, which is not generally true. */
  48. 		    if (revive_corpse(victual.piece))
  49. 			victual.piece = (struct obj *)0;
  50. 		    return;
  51. 		}
  52. 	    case PM_GREEN_SLIME:
  53. 		if (!Slimed && !Unchanging && !flaming(youmonst.data) &&
  54. 			youmonst.data != &mons[PM_GREEN_SLIME]) {
  55. 		    You("don't feel very well.");
  56. 		    Slimed = 10L;
  57. 		    flags.botl = 1;
  58. 		}
  59. 		/* Fall through */
  60. 	    default:
  61. 		if (acidic(&mons[pm]) && Stoned)
  62. 		    fix_petrification();
  63. 		break;
  64. 	}
  65. }

fix_petrification[edit]

  1. void
  2. fix_petrification()
  3. {
  4. 	Stoned = 0;
  5. 	delayed_killer = 0;
  6. 	if (Hallucination)
  7. 	    pline("What a pity - you just ruined a future piece of %sart!",
  8. 		  ACURR(A_CHA) > 15 ? "fine " : "");
  9. 	else
  10. 	    You_feel("limber!");
  11. }

intrinsic_possible[edit]

  1. /*
  2. * If you add an intrinsic that can be gotten by eating a monster, add it
  3. * to intrinsic_possible() and givit().  (It must already be in prop.h to
  4. * be an intrinsic property.)
  5. * It would be very easy to make the intrinsics not try to give you one
  6. * that you already had by checking to see if you have it in
  7. * intrinsic_possible() instead of givit().
  8. */
  9.  
  10. /* intrinsic_possible() returns TRUE iff a monster can give an intrinsic. */
  11. STATIC_OVL int
  12. intrinsic_possible(type, ptr)
  13. int type;
  14. register struct permonst *ptr;
  15. {
  16. 	switch (type) {
  17. 	    case FIRE_RES:
  18. #ifdef DEBUG
  19. 		if (ptr->mconveys & MR_FIRE) {
  20. 			debugpline("can get fire resistance");
  21. 			return(TRUE);
  22. 		} else  return(FALSE);
  23. #else
  24. 		return(ptr->mconveys & MR_FIRE);
  25. #endif
  26. 	    case SLEEP_RES:
  27. #ifdef DEBUG
  28. 		if (ptr->mconveys & MR_SLEEP) {
  29. 			debugpline("can get sleep resistance");
  30. 			return(TRUE);
  31. 		} else  return(FALSE);
  32. #else
  33. 		return(ptr->mconveys & MR_SLEEP);
  34. #endif
  35. 	    case COLD_RES:
  36. #ifdef DEBUG
  37. 		if (ptr->mconveys & MR_COLD) {
  38. 			debugpline("can get cold resistance");
  39. 			return(TRUE);
  40. 		} else  return(FALSE);
  41. #else
  42. 		return(ptr->mconveys & MR_COLD);
  43. #endif
  44. 	    case DISINT_RES:
  45. #ifdef DEBUG
  46. 		if (ptr->mconveys & MR_DISINT) {
  47. 			debugpline("can get disintegration resistance");
  48. 			return(TRUE);
  49. 		} else  return(FALSE);
  50. #else
  51. 		return(ptr->mconveys & MR_DISINT);
  52. #endif
  53. 	    case SHOCK_RES:	/* shock (electricity) resistance */
  54. #ifdef DEBUG
  55. 		if (ptr->mconveys & MR_ELEC) {
  56. 			debugpline("can get shock resistance");
  57. 			return(TRUE);
  58. 		} else  return(FALSE);
  59. #else
  60. 		return(ptr->mconveys & MR_ELEC);
  61. #endif
  62. 	    case POISON_RES:
  63. #ifdef DEBUG
  64. 		if (ptr->mconveys & MR_POISON) {
  65. 			debugpline("can get poison resistance");
  66. 			return(TRUE);
  67. 		} else  return(FALSE);
  68. #else
  69. 		return(ptr->mconveys & MR_POISON);
  70. #endif
  71. 	    case TELEPORT:
  72. #ifdef DEBUG
  73. 		if (can_teleport(ptr)) {
  74. 			debugpline("can get teleport");
  75. 			return(TRUE);
  76. 		} else  return(FALSE);
  77. #else
  78. 		return(can_teleport(ptr));
  79. #endif
  80. 	    case TELEPORT_CONTROL:
  81. #ifdef DEBUG
  82. 		if (control_teleport(ptr)) {
  83. 			debugpline("can get teleport control");
  84. 			return(TRUE);
  85. 		} else  return(FALSE);
  86. #else
  87. 		return(control_teleport(ptr));
  88. #endif
  89. 	    case TELEPAT:
  90. #ifdef DEBUG
  91. 		if (telepathic(ptr)) {
  92. 			debugpline("can get telepathy");
  93. 			return(TRUE);
  94. 		} else  return(FALSE);
  95. #else
  96. 		return(telepathic(ptr));
  97. #endif
  98. 	    default:
  99. 		return(FALSE);
  100. 	}
  101. 	/*NOTREACHED*/
  102. }

givit[edit]

  1. /* givit() tries to give you an intrinsic based on the monster's level
  2. * and what type of intrinsic it is trying to give you.
  3. */
  4. STATIC_OVL void
  5. givit(type, ptr)
  6. int type;
  7. register struct permonst *ptr;
  8. {
  9. 	register int chance;
  10.  
  11. #ifdef DEBUG
  12. 	debugpline("Attempting to give intrinsic %d", type);
  13. #endif
  14. 	/* some intrinsics are easier to get than others */
  15. 	switch (type) {
  16. 		case POISON_RES:
  17. 			if ((ptr == &mons[PM_KILLER_BEE] ||
  18. 					ptr == &mons[PM_SCORPION]) && !rn2(4))
  19. 				chance = 1;
  20. 			else
  21. 				chance = 15;
  22. 			break;
  23. 		case TELEPORT:
  24. 			chance = 10;
  25. 			break;
  26. 		case TELEPORT_CONTROL:
  27. 			chance = 12;
  28. 			break;
  29. 		case TELEPAT:
  30. 			chance = 1;
  31. 			break;
  32. 		default:
  33. 			chance = 15;
  34. 			break;
  35. 	}
  36.  
  37. 	if (ptr->mlevel <= rn2(chance))
  38. 		return;		/* failed die roll */
  39.  
  40. 	switch (type) {
  41. 	    case FIRE_RES:
  42. #ifdef DEBUG
  43. 		debugpline("Trying to give fire resistance");
  44. #endif
  45. 		if(!(HFire_resistance & FROMOUTSIDE)) {
  46. 			You(Hallucination ? "be chillin'." :
  47. 			    "feel a momentary chill.");
  48. 			HFire_resistance |= FROMOUTSIDE;
  49. 		}
  50. 		break;
  51. 	    case SLEEP_RES:
  52. #ifdef DEBUG
  53. 		debugpline("Trying to give sleep resistance");
  54. #endif
  55. 		if(!(HSleep_resistance & FROMOUTSIDE)) {
  56. 			You_feel("wide awake.");
  57. 			HSleep_resistance |= FROMOUTSIDE;
  58. 		}
  59. 		break;
  60. 	    case COLD_RES:
  61. #ifdef DEBUG
  62. 		debugpline("Trying to give cold resistance");
  63. #endif
  64. 		if(!(HCold_resistance & FROMOUTSIDE)) {
  65. 			You_feel("full of hot air.");
  66. 			HCold_resistance |= FROMOUTSIDE;
  67. 		}
  68. 		break;
  69. 	    case DISINT_RES:
  70. #ifdef DEBUG
  71. 		debugpline("Trying to give disintegration resistance");
  72. #endif
  73. 		if(!(HDisint_resistance & FROMOUTSIDE)) {
  74. 			You_feel(Hallucination ?
  75. 			    "totally together, man." :
  76. 			    "very firm.");
  77. 			HDisint_resistance |= FROMOUTSIDE;
  78. 		}
  79. 		break;
  80. 	    case SHOCK_RES:	/* shock (electricity) resistance */
  81. #ifdef DEBUG
  82. 		debugpline("Trying to give shock resistance");
  83. #endif
  84. 		if(!(HShock_resistance & FROMOUTSIDE)) {
  85. 			if (Hallucination)
  86. 				You_feel("grounded in reality.");
  87. 			else
  88. 				Your("health currently feels amplified!");
  89. 			HShock_resistance |= FROMOUTSIDE;
  90. 		}
  91. 		break;
  92. 	    case POISON_RES:
  93. #ifdef DEBUG
  94. 		debugpline("Trying to give poison resistance");
  95. #endif
  96. 		if(!(HPoison_resistance & FROMOUTSIDE)) {
  97. 			You_feel(Poison_resistance ?
  98. 				 "especially healthy." : "healthy.");
  99. 			HPoison_resistance |= FROMOUTSIDE;
  100. 		}
  101. 		break;
  102. 	    case TELEPORT:
  103. #ifdef DEBUG
  104. 		debugpline("Trying to give teleport");
  105. #endif
  106. 		if(!(HTeleportation & FROMOUTSIDE)) {
  107. 			You_feel(Hallucination ? "diffuse." :
  108. 			    "very jumpy.");
  109. 			HTeleportation |= FROMOUTSIDE;
  110. 		}
  111. 		break;
  112. 	    case TELEPORT_CONTROL:
  113. #ifdef DEBUG
  114. 		debugpline("Trying to give teleport control");
  115. #endif
  116. 		if(!(HTeleport_control & FROMOUTSIDE)) {
  117. 			You_feel(Hallucination ?
  118. 			    "centered in your personal space." :
  119. 			    "in control of yourself.");
  120. 			HTeleport_control |= FROMOUTSIDE;
  121. 		}
  122. 		break;
  123. 	    case TELEPAT:
  124. #ifdef DEBUG
  125. 		debugpline("Trying to give telepathy");
  126. #endif
  127. 		if(!(HTelepat & FROMOUTSIDE)) {
  128. 			You_feel(Hallucination ?
  129. 			    "in touch with the cosmos." :
  130. 			    "a strange mental acuity.");
  131. 			HTelepat |= FROMOUTSIDE;
  132. 			/* If blind, make sure monsters show up. */
  133. 			if (Blind) see_monsters();
  134. 		}
  135. 		break;
  136. 	    default:
  137. #ifdef DEBUG
  138. 		debugpline("Tried to give an impossible intrinsic");
  139. #endif
  140. 		break;
  141. 	}
  142. }

cpostfx[edit]

  1. STATIC_OVL void
  2. cpostfx(pm)		/* called after completely consuming a corpse */
  3. register int pm;
  4. {
  5. 	register int tmp = 0;
  6. 	boolean catch_lycanthropy = FALSE;
  7.  
  8. 	/* in case `afternmv' didn't get called for previously mimicking
  9. 	   gold, clean up now to avoid `eatmbuf' memory leak */
  10. 	if (eatmbuf) (void)eatmdone();
  11.  
  12. 	switch(pm) {
  13. 	    case PM_NEWT:
  14. 		/* MRKR: "eye of newt" may give small magical energy boost */
  15. 		if (rn2(3) || 3 * u.uen <= 2 * u.uenmax) {
  16. 		    int old_uen = u.uen;
  17. 		    u.uen += rnd(3);
  18. 		    if (u.uen > u.uenmax) {
  19. 			if (!rn2(3)) u.uenmax++;
  20. 			u.uen = u.uenmax;
  21. 		    }
  22. 		    if (old_uen != u.uen) {
  23. 			    You_feel("a mild buzz.");
  24. 			    flags.botl = 1;
  25. 		    }
  26. 		}
  27. 		break;
  28. 	    case PM_WRAITH:
  29. 		pluslvl(FALSE);
  30. 		break;
  31. 	    case PM_HUMAN_WERERAT:
  32. 		catch_lycanthropy = TRUE;
  33. 		u.ulycn = PM_WERERAT;
  34. 		break;
  35. 	    case PM_HUMAN_WEREJACKAL:
  36. 		catch_lycanthropy = TRUE;
  37. 		u.ulycn = PM_WEREJACKAL;
  38. 		break;
  39. 	    case PM_HUMAN_WEREWOLF:
  40. 		catch_lycanthropy = TRUE;
  41. 		u.ulycn = PM_WEREWOLF;
  42. 		break;
  43. 	    case PM_NURSE:
  44. 		if (Upolyd) u.mh = u.mhmax;
  45. 		else u.uhp = u.uhpmax;
  46. 		flags.botl = 1;
  47. 		break;
  48. 	    case PM_STALKER:
  49. 		if(!Invis) {
  50. 			set_itimeout(&HInvis, (long)rn1(100, 50));
  51. 			if (!Blind && !BInvis) self_invis_message();
  52. 		} else {
  53. 			if (!(HInvis & INTRINSIC)) You_feel("hidden!");
  54. 			HInvis |= FROMOUTSIDE;
  55. 			HSee_invisible |= FROMOUTSIDE;
  56. 		}
  57. 		newsym(u.ux, u.uy);
  58. 		/* fall into next case */
  59. 	    case PM_YELLOW_LIGHT:
  60. 		/* fall into next case */
  61. 	    case PM_GIANT_BAT:
  62. 		make_stunned(HStun + 30,FALSE);
  63. 		/* fall into next case */
  64. 	    case PM_BAT:
  65. 		make_stunned(HStun + 30,FALSE);
  66. 		break;
  67. 	    case PM_GIANT_MIMIC:
  68. 		tmp += 10;
  69. 		/* fall into next case */
  70. 	    case PM_LARGE_MIMIC:
  71. 		tmp += 20;
  72. 		/* fall into next case */
  73. 	    case PM_SMALL_MIMIC:
  74. 		tmp += 20;
  75. 		if (youmonst.data->mlet != S_MIMIC && !Unchanging) {
  76. 		    char buf[BUFSZ];
  77. 		    You_cant("resist the temptation to mimic %s.",
  78. 			Hallucination ? "an orange" : "a pile of gold");
  79. #ifdef STEED
  80. /* A pile of gold can't ride. */
  81. 		    if (u.usteed) dismount_steed(DISMOUNT_FELL);
  82. #endif
  83. 		    nomul(-tmp);
  84. 		    Sprintf(buf, Hallucination ?
  85. 			"You suddenly dread being peeled and mimic %s again!" :
  86. 			"You now prefer mimicking %s again.",
  87. 			an(Upolyd ? youmonst.data->mname : urace.noun));
  88. 		    eatmbuf = strcpy((char *) alloc(strlen(buf) + 1), buf);
  89. 		    nomovemsg = eatmbuf;
  90. 		    afternmv = eatmdone;
  91. 		    /* ??? what if this was set before? */
  92. 		    youmonst.m_ap_type = M_AP_OBJECT;
  93. 		    youmonst.mappearance = Hallucination ? ORANGE : GOLD_PIECE;
  94. 		    newsym(u.ux,u.uy);
  95. 		    curs_on_u();
  96. 		    /* make gold symbol show up now */
  97. 		    display_nhwindow(WIN_MAP, TRUE);
  98. 		}
  99. 		break;
  100. 	    case PM_QUANTUM_MECHANIC:
  101. 		Your("velocity suddenly seems very uncertain!");
  102. 		if (HFast & INTRINSIC) {
  103. 			HFast &= ~INTRINSIC;
  104. 			You("seem slower.");
  105. 		} else {
  106. 			HFast |= FROMOUTSIDE;
  107. 			You("seem faster.");
  108. 		}
  109. 		break;
  110. 	    case PM_LIZARD:
  111. 		if (HStun > 2)  make_stunned(2L,FALSE);
  112. 		if (HConfusion > 2)  make_confused(2L,FALSE);
  113. 		break;
  114. 	    case PM_CHAMELEON:
  115. 	    case PM_DOPPELGANGER:
  116. 	 /* case PM_SANDESTIN: */
  117. 		if (!Unchanging) {
  118. 		    You_feel("a change coming over you.");
  119. 		    polyself(FALSE);
  120. 		}
  121. 		break;
  122. 	    case PM_MIND_FLAYER:
  123. 	    case PM_MASTER_MIND_FLAYER:
  124. 		if (ABASE(A_INT) < ATTRMAX(A_INT)) {
  125. 			if (!rn2(2)) {
  126. 				pline("Yum! That was real brain food!");
  127. 				(void) adjattrib(A_INT, 1, FALSE);
  128. 				break;	/* don't give them telepathy, too */
  129. 			}
  130. 		}
  131. 		else {
  132. 			pline("For some reason, that tasted bland.");
  133. 		}
  134. 		/* fall through to default case */
  135. 	    default: {
  136. 		register struct permonst *ptr = &mons[pm];
  137. 		int i, count;
  138.  
  139. 		if (dmgtype(ptr, AD_STUN) || dmgtype(ptr, AD_HALU) ||
  140. 		    pm == PM_VIOLET_FUNGUS) {
  141. 			pline ("Oh wow!  Great stuff!");
  142. 			make_hallucinated(HHallucination + 200,FALSE,0L);
  143. 		}
  144. 		if(is_giant(ptr)) gainstr((struct obj *)0, 0);
  145.  
  146. 		/* Check the monster for all of the intrinsics.  If this
  147. 		 * monster can give more than one, pick one to try to give
  148. 		 * from among all it can give.
  149. 		 *
  150. 		 * If a monster can give 4 intrinsics then you have
  151. 		 * a 1/1 * 1/2 * 2/3 * 3/4 = 1/4 chance of getting the first,
  152. 		 * a 1/2 * 2/3 * 3/4 = 1/4 chance of getting the second,
  153. 		 * a 1/3 * 3/4 = 1/4 chance of getting the third,
  154. 		 * and a 1/4 chance of getting the fourth.
  155. 		 *
  156. 		 * And now a proof by induction:
  157. 		 * it works for 1 intrinsic (1 in 1 of getting it)
  158. 		 * for 2 you have a 1 in 2 chance of getting the second,
  159. 		 *	otherwise you keep the first
  160. 		 * for 3 you have a 1 in 3 chance of getting the third,
  161. 		 *	otherwise you keep the first or the second
  162. 		 * for n+1 you have a 1 in n+1 chance of getting the (n+1)st,
  163. 		 *	otherwise you keep the previous one.
  164. 		 * Elliott Kleinrock, October 5, 1990
  165. 		 */
  166.  
  167. 		 count = 0;	/* number of possible intrinsics */
  168. 		 tmp = 0;	/* which one we will try to give */
  169. 		 for (i = 1; i <= LAST_PROP; i++) {
  170. 			if (intrinsic_possible(i, ptr)) {
  171. 				count++;
  172. 				/* a 1 in count chance of replacing the old
  173. 				 * one with this one, and a count-1 in count
  174. 				 * chance of keeping the old one.  (note
  175. 				 * that 1 in 1 and 0 in 1 are what we want
  176. 				 * for the first one
  177. 				 */
  178. 				if (!rn2(count)) {
  179. #ifdef DEBUG
  180. 					debugpline("Intrinsic %d replacing %d",
  181. 								i, tmp);
  182. #endif
  183. 					tmp = i;
  184. 				}
  185. 			}
  186. 		 }
  187.  
  188. 		 /* if any found try to give them one */
  189. 		 if (count) givit(tmp, ptr);
  190. 	    }
  191. 	    break;
  192. 	}
  193.  
  194. 	if (catch_lycanthropy && defends(AD_WERE, uwep)) {
  195. 	    if (!touch_artifact(uwep, &youmonst)) {
  196. 		dropx(uwep);
  197. 		uwepgone();
  198. 	    }
  199. 	}
  200.  
  201. 	return;
  202. }

violated_vegetarian[edit]

  1. void
  2. violated_vegetarian()
  3. {
  4. u.uconduct.unvegetarian++;
  5. if (Role_if(PM_MONK)) {
  6. 	You_feel("guilty.");
  7. 	adjalign(-1);
  8. }
  9. return;
  10. }

costly_tin[edit]

  1. /* common code to check and possibly charge for 1 context.tin.tin,
  2. * will split() context.tin.tin if necessary */
  3. STATIC_PTR
  4. void
  5. costly_tin(verb)
  6. 	const char* verb;		/* if 0, the verb is "open" */
  7. {
  8. 	if(((!carried(tin.tin) &&
  9. 	     costly_spot(tin.tin->ox, tin.tin->oy) &&
  10. 	     !tin.tin->no_charge)
  11. 	    || tin.tin->unpaid)) {
  12. 	    verbalize("You %s it, you bought it!", verb ? verb : "open");
  13. 	    if(tin.tin->quan > 1L) tin.tin = splitobj(tin.tin, 1L);
  14. 	    bill_dummy_object(tin.tin);
  15. 	}
  16. }

opentin[edit]

  1. STATIC_PTR
  2. int
  3. opentin()		/* called during each move whilst opening a tin */
  4. {
  5. 	register int r;
  6. 	const char *what;
  7. 	int which;
  8.  
  9. 	if(!carried(tin.tin) && !obj_here(tin.tin, u.ux, u.uy))
  10. 					/* perhaps it was stolen? */
  11. 		return(0);		/* %% probably we should use tinoid */
  12. 	if(tin.usedtime++ >= 50) {
  13. 		You("give up your attempt to open the tin.");
  14. 		return(0);
  15. 	}
  16. 	if(tin.usedtime < tin.reqtime)
  17. 		return(1);		/* still busy */
  18. 	if(tin.tin->otrapped ||
  19. 	   (tin.tin->cursed && tin.tin->spe != -1 && !rn2(8))) {
  20. 		b_trapped("tin", 0);
  21. 		costly_tin("destroyed");
  22. 		goto use_me;
  23. 	}
  24. 	You("succeed in opening the tin.");
  25. 	if(tin.tin->spe != 1) {
  26. 	    if (tin.tin->corpsenm == NON_PM) {
  27. 		pline("It turns out to be empty.");
  28. 		tin.tin->dknown = tin.tin->known = TRUE;
  29. 		costly_tin((const char*)0);
  30. 		goto use_me;
  31. 	    }
  32. 	    r = tin.tin->cursed ? ROTTEN_TIN :	/* always rotten if cursed */
  33. 		    (tin.tin->spe == -1) ? HOMEMADE_TIN :  /* player made it */
  34. 			rn2(TTSZ-1);		/* else take your pick */
  35. 	    if (r == ROTTEN_TIN && (tin.tin->corpsenm == PM_LIZARD ||
  36. 			tin.tin->corpsenm == PM_LICHEN))
  37. 		r = HOMEMADE_TIN;		/* lizards don't rot */
  38. 	    else if (tin.tin->spe == -1 && !tin.tin->blessed && !rn2(7))
  39. 		r = ROTTEN_TIN;			/* some homemade tins go bad */
  40. 	    which = 0;	/* 0=>plural, 1=>as-is, 2=>"the" prefix */
  41. 	    if (Hallucination) {
  42. 		what = rndmonnam();
  43. 	    } else {
  44. 		what = mons[tin.tin->corpsenm].mname;
  45. 		if (mons[tin.tin->corpsenm].geno & G_UNIQ)
  46. 		    which = type_is_pname(&mons[tin.tin->corpsenm]) ? 1 : 2;
  47. 	    }
  48. 	    if (which == 0) what = makeplural(what);
  49. 	    pline("It smells like %s%s.", (which == 2) ? "the " : "", what);
  50. 	    if (yn("Eat it?") == 'n') {
  51. 		if (!Hallucination) tin.tin->dknown = tin.tin->known = TRUE;
  52. 		if (flags.verbose) You("discard the open tin.");
  53. 		costly_tin((const char*)0);
  54. 		goto use_me;
  55. 	    }
  56. 	    /* in case stop_occupation() was called on previous meal */
  57. 	    victual.piece = (struct obj *)0;
  58. 	    victual.fullwarn = victual.eating = victual.doreset = FALSE;
  59.  
  60. 	    You("consume %s %s.", tintxts[r].txt,
  61. 			mons[tin.tin->corpsenm].mname);
  62.  
  63. 	    /* KMH, conduct */
  64. 	    u.uconduct.food++;
  65. 	    if (!vegan(&mons[tin.tin->corpsenm]))
  66. 		u.uconduct.unvegan++;
  67. 	    if (!vegetarian(&mons[tin.tin->corpsenm]))
  68. 		violated_vegetarian();
  69.  
  70. 	    tin.tin->dknown = tin.tin->known = TRUE;
  71. 	    cprefx(tin.tin->corpsenm); cpostfx(tin.tin->corpsenm);
  72.  
  73. 	    /* charge for one at pre-eating cost */
  74. 	    costly_tin((const char*)0);
  75.  
  76. 	    /* check for vomiting added by GAN 01/16/87 */
  77. 	    if(tintxts[r].nut < 0) make_vomiting((long)rn1(15,10), FALSE);
  78. 	    else lesshungry(tintxts[r].nut);
  79.  
  80. 	    if(r == 0 || r == FRENCH_FRIED_TIN) {
  81. 	        /* Assume !Glib, because you can't open tins when Glib. */
  82. 		incr_itimeout(&Glib, rnd(15));
  83. 		pline("Eating deep fried food made your %s very slippery.",
  84. 		      makeplural(body_part(FINGER)));
  85. 	    }
  86. 	} else {
  87. 	    if (tin.tin->cursed)
  88. 		pline("It contains some decaying%s%s substance.",
  89. 			Blind ? "" : " ", Blind ? "" : hcolor(NH_GREEN));
  90. 	    else
  91. 		pline("It contains spinach.");
  92.  
  93. 	    if (yn("Eat it?") == 'n') {
  94. 		if (!Hallucination && !tin.tin->cursed)
  95. 		    tin.tin->dknown = tin.tin->known = TRUE;
  96. 		if (flags.verbose)
  97. 		    You("discard the open tin.");
  98. 		costly_tin((const char*)0);
  99. 		goto use_me;
  100. 	    }
  101.  
  102. 	    tin.tin->dknown = tin.tin->known = TRUE;
  103. 	    costly_tin((const char*)0);
  104.  
  105. 	    if (!tin.tin->cursed)
  106. 		pline("This makes you feel like %s!",
  107. 		      Hallucination ? "Swee'pea" : "Popeye");
  108. 	    lesshungry(600);
  109. 	    gainstr(tin.tin, 0);
  110. 	    u.uconduct.food++;
  111. 	}
  112. use_me:
  113. 	if (carried(tin.tin)) useup(tin.tin);
  114. 	else useupf(tin.tin, 1L);
  115. 	tin.tin = (struct obj *) 0;
  116. 	return(0);
  117. }

start_tin[edit]

  1. STATIC_OVL void
  2. start_tin(otmp)		/* called when starting to open a tin */
  3. 	register struct obj *otmp;
  4. {
  5. 	register int tmp;
  6.  
  7. 	if (metallivorous(youmonst.data)) {
  8. 		You("bite right into the metal tin...");
  9. 		tmp = 1;
  10. 	} else if (nolimbs(youmonst.data)) {
  11. 		You("cannot handle the tin properly to open it.");
  12. 		return;
  13. 	} else if (otmp->blessed) {
  14. 		pline_The("tin opens like magic!");
  15. 		tmp = 1;
  16. 	} else if(uwep) {
  17. 		switch(uwep->otyp) {
  18. 		case TIN_OPENER:
  19. 			tmp = 1;
  20. 			break;
  21. 		case DAGGER:
  22. 		case SILVER_DAGGER:
  23. 		case ELVEN_DAGGER:
  24. 		case ORCISH_DAGGER:
  25. 		case ATHAME:
  26. 		case CRYSKNIFE:
  27. 			tmp = 3;
  28. 			break;
  29. 		case PICK_AXE:
  30. 		case AXE:
  31. 			tmp = 6;
  32. 			break;
  33. 		default:
  34. 			goto no_opener;
  35. 		}
  36. 		pline("Using your %s you try to open the tin.",
  37. 			aobjnam(uwep, (char *)0));
  38. 	} else {
  39. no_opener:
  40. 		pline("It is not so easy to open this tin.");
  41. 		if(Glib) {
  42. 			pline_The("tin slips from your %s.",
  43. 			      makeplural(body_part(FINGER)));
  44. 			if(otmp->quan > 1L) {
  45. 			    otmp = splitobj(otmp, 1L);
  46. 			}
  47. 			if (carried(otmp)) dropx(otmp);
  48. 			else stackobj(otmp);
  49. 			return;
  50. 		}
  51. 		tmp = rn1(1 + 500/((int)(ACURR(A_DEX) + ACURRSTR)), 10);
  52. 	}
  53. 	tin.reqtime = tmp;
  54. 	tin.usedtime = 0;
  55. 	tin.tin = otmp;
  56. 	set_occupation(opentin, "opening the tin", 0);
  57. 	return;
  58. }

Hear_again[edit]

  1. int
  2. Hear_again()		/* called when waking up after fainting */
  3. {
  4. 	flags.soundok = 1;
  5. 	return 0;
  6. }

rottenfood[edit]

  1. /* called on the "first bite" of rotten food */
  2. STATIC_OVL int
  3. rottenfood(obj)
  4. struct obj *obj;
  5. {
  6. 	pline("Blecch!  Rotten %s!", foodword(obj));
  7. 	if(!rn2(4)) {
  8. 		if (Hallucination) You_feel("rather trippy.");
  9. 		else You_feel("rather %s.", body_part(LIGHT_HEADED));
  10. 		make_confused(HConfusion + d(2,4),FALSE);
  11. 	} else if(!rn2(4) && !Blind) {
  12. 		pline("Everything suddenly goes dark.");
  13. 		make_blinded((long)d(2,10),FALSE);
  14. 		if (!Blind) Your(vision_clears);
  15. 	} else if(!rn2(3)) {
  16. 		const char *what, *where;
  17. 		if (!Blind)
  18. 		    what = "goes",  where = "dark";
  19. 		else if (Levitation || Is_airlevel(&u.uz) ||
  20. 			 Is_waterlevel(&u.uz))
  21. 		    what = "you lose control of",  where = "yourself";
  22. 		else
  23. 		    what = "you slap against the", where =
  24. #ifdef STEED
  25. 			   (u.usteed) ? "saddle" :
  26. #endif
  27. 			   surface(u.ux,u.uy);
  28. 		pline_The("world spins and %s %s.", what, where);
  29. 		flags.soundok = 0;
  30. 		nomul(-rnd(10));
  31. 		nomovemsg = "You are conscious again.";
  32. 		afternmv = Hear_again;
  33. 		return(1);
  34. 	}
  35. 	return(0);
  36. }

eatcorpse[edit]

  1. STATIC_OVL int
  2. eatcorpse(otmp)		/* called when a corpse is selected as food */
  3. 	register struct obj *otmp;
  4. {
  5. 	int tp = 0, mnum = otmp->corpsenm;
  6. 	long rotted = 0L;
  7. 	boolean uniq = !!(mons[mnum].geno & G_UNIQ);
  8. 	int retcode = 0;
  9. 	boolean stoneable = (touch_petrifies(&mons[mnum]) && !Stone_resistance &&
  10. 				!poly_when_stoned(youmonst.data));
  11.  
  12. 	/* KMH, conduct */
  13. 	if (!vegan(&mons[mnum])) u.uconduct.unvegan++;
  14. 	if (!vegetarian(&mons[mnum])) violated_vegetarian();
  15.  
  16. 	if (mnum != PM_LIZARD && mnum != PM_LICHEN) {
  17. 		long age = peek_at_iced_corpse_age(otmp);
  18.  
  19. 		rotted = (monstermoves - age)/(10L + rn2(20));
  20. 		if (otmp->cursed) rotted += 2L;
  21. 		else if (otmp->blessed) rotted -= 2L;
  22. 	}
  23.  
  24. 	if (mnum != PM_ACID_BLOB && !stoneable && rotted > 5L) {
  25. 		boolean cannibal = maybe_cannibal(mnum, FALSE);
  26. 		pline("Ulch - that %s was tainted%s!",
  27. 		      mons[mnum].mlet == S_FUNGUS ? "fungoid vegetation" :
  28. 		      !vegetarian(&mons[mnum]) ? "meat" : "protoplasm",
  29. 		      cannibal ? " cannibal" : "");
  30. 		if (Sick_resistance) {
  31. 			pline("It doesn't seem at all sickening, though...");
  32. 		} else {
  33. 			char buf[BUFSZ];
  34. 			long sick_time;
  35.  
  36. 			sick_time = (long) rn1(10, 10);
  37. 			/* make sure new ill doesn't result in improvement */
  38. 			if (Sick && (sick_time > Sick))
  39. 			    sick_time = (Sick > 1L) ? Sick - 1L : 1L;
  40. 			if (!uniq)
  41. 			    Sprintf(buf, "rotted %s", corpse_xname(otmp,TRUE));
  42. 			else
  43. 			    Sprintf(buf, "%s%s rotted corpse",
  44. 				    !type_is_pname(&mons[mnum]) ? "the " : "",
  45. 				    s_suffix(mons[mnum].mname));
  46. 			make_sick(sick_time, buf, TRUE, SICK_VOMITABLE);
  47. 		}
  48. 		if (carried(otmp)) useup(otmp);
  49. 		else useupf(otmp, 1L);
  50. 		return(2);
  51. 	} else if (acidic(&mons[mnum]) && !Acid_resistance) {
  52. 		tp++;
  53. 		You("have a very bad case of stomach acid."); /* not body_part() */
  54. 		losehp(rnd(15), "acidic corpse", KILLED_BY_AN);
  55. 	} else if (poisonous(&mons[mnum]) && rn2(5)) {
  56. 		tp++;
  57. 		pline("Ecch - that must have been poisonous!");
  58. 		if(!Poison_resistance) {
  59. 			losestr(rnd(4));
  60. 			losehp(rnd(15), "poisonous corpse", KILLED_BY_AN);
  61. 		} else	You("seem unaffected by the poison.");
  62. 	/* now any corpse left too long will make you mildly ill */
  63. 	} else if ((rotted > 5L || (rotted > 3L && rn2(5)))
  64. 					&& !Sick_resistance) {
  65. 		tp++;
  66. 		You_feel("%ssick.", (Sick) ? "very " : "");
  67. 		losehp(rnd(8), "cadaver", KILLED_BY_AN);
  68. 	}
  69.  
  70. 	/* delay is weight dependent */
  71. 	victual.reqtime = 3 + (mons[mnum].cwt >> 6);
  72.  
  73. 	if (!tp && mnum != PM_LIZARD && mnum != PM_LICHEN &&
  74. 			(otmp->orotten || !rn2(7))) {
  75. 	    if (rottenfood(otmp)) {
  76. 		otmp->orotten = TRUE;
  77. 		(void)touchfood(otmp);
  78. 		retcode = 1;
  79. 	    }
  80.  
  81. 	    if (!mons[otmp->corpsenm].cnutrit) {
  82. 		/* no nutrution: rots away, no message if you passed out */
  83. 		if (!retcode) pline_The("corpse rots away completely.");
  84. 		if (carried(otmp)) useup(otmp);
  85. 		else useupf(otmp, 1L);
  86. 		retcode = 2;
  87. 	    }
  88.  
  89. 	    if (!retcode) consume_oeaten(otmp, 2);	/* oeaten >>= 2 */
  90. 	} else {
  91. 	    pline("%s%s %s!",
  92. 		  !uniq ? "This " : !type_is_pname(&mons[mnum]) ? "The " : "",
  93. 		  food_xname(otmp, FALSE),
  94. 		  (vegan(&mons[mnum]) ?
  95. 		   (!carnivorous(youmonst.data) && herbivorous(youmonst.data)) :
  96. 		   (carnivorous(youmonst.data) && !herbivorous(youmonst.data)))
  97. 		  ? "is delicious" : "tastes terrible");
  98. 	}
  99.  
  100. 	return(retcode);
  101. }

start_eating[edit]

  1. STATIC_OVL void
  2. start_eating(otmp)		/* called as you start to eat */
  3. 	register struct obj *otmp;
  4. {
  5. #ifdef DEBUG
  6. 	debugpline("start_eating: %lx (victual = %lx)", otmp, victual.piece);
  7. 	debugpline("reqtime = %d", victual.reqtime);
  8. 	debugpline("(original reqtime = %d)", objects[otmp->otyp].oc_delay);
  9. 	debugpline("nmod = %d", victual.nmod);
  10. 	debugpline("oeaten = %d", otmp->oeaten);
  11. #endif
  12. 	victual.fullwarn = victual.doreset = FALSE;
  13. 	victual.eating = TRUE;
  14.  
  15. 	if (otmp->otyp == CORPSE) {
  16. 	    cprefx(victual.piece->corpsenm);
  17. 	    if (!victual.piece || !victual.eating) {
  18. 		/* rider revived, or died and lifesaved */
  19. 		return;
  20. 	    }
  21. 	}
  22.  
  23. 	if (bite()) return;
  24.  
  25. 	if (++victual.usedtime >= victual.reqtime) {
  26. 	    /* print "finish eating" message if they just resumed -dlc */
  27. 	    done_eating(victual.reqtime > 1 ? TRUE : FALSE);
  28. 	    return;
  29. 	}
  30.  
  31. 	Sprintf(msgbuf, "eating %s", food_xname(otmp, TRUE));
  32. 	set_occupation(eatfood, msgbuf, 0);
  33. }

fprefx[edit]

  1. /*
  2. * called on "first bite" of (non-corpse) food.
  3. * used for non-rotten non-tin non-corpse food
  4. */
  5. STATIC_OVL void
  6. fprefx(otmp)
  7. struct obj *otmp;
  8. {
  9. 	switch(otmp->otyp) {
  10. 	    case FOOD_RATION:
  11. 		if(u.uhunger <= 200)
  12. 		    pline(Hallucination ? "Oh wow, like, superior, man!" :
  13. 			  "That food really hit the spot!");
  14. 		else if(u.uhunger <= 700) pline("That satiated your %s!",
  15. 						body_part(STOMACH));
  16. 		break;
  17. 	    case TRIPE_RATION:
  18. 		if (carnivorous(youmonst.data) && !humanoid(youmonst.data))
  19. 		    pline("That tripe ration was surprisingly good!");
  20. 		else if (maybe_polyd(is_orc(youmonst.data), Race_if(PM_ORC)))
  21. 		    pline(Hallucination ? "Tastes great! Less filling!" :
  22. 			  "Mmm, tripe... not bad!");
  23. 		else {
  24. 		    pline("Yak - dog food!");
  25. 		    more_experienced(1,0);
  26. 		    newexplevel();
  27. 		    /* not cannibalism, but we use similar criteria
  28. 		       for deciding whether to be sickened by this meal */
  29. 		    if (rn2(2) && !CANNIBAL_ALLOWED())
  30. 			make_vomiting((long)rn1(victual.reqtime, 14), FALSE);
  31. 		}
  32. 		break;
  33. 	    case MEATBALL:
  34. 	    case MEAT_STICK:
  35. 	    case HUGE_CHUNK_OF_MEAT:
  36. 	    case MEAT_RING:
  37. 		goto give_feedback;
  38. 	     /* break; */
  39. 	    case CLOVE_OF_GARLIC:
  40. 		if (is_undead(youmonst.data)) {
  41. 			make_vomiting((long)rn1(victual.reqtime, 5), FALSE);
  42. 			break;
  43. 		}
  44. 		/* Fall through otherwise */
  45. 	    default:
  46. 		if (otmp->otyp==SLIME_MOLD && !otmp->cursed
  47. 			&& otmp->spe == current_fruit)
  48. 		    pline("My, that was a %s %s!",
  49. 			  Hallucination ? "primo" : "yummy",
  50. 			  singular(otmp, xname));
  51. 		else
  52. #ifdef UNIX
  53. 		if (otmp->otyp == APPLE || otmp->otyp == PEAR) {
  54. 		    if (!Hallucination) pline("Core dumped.");
  55. 		    else {
  56. /* This is based on an old Usenet joke, a fake a.out manual page */
  57. 			int x = rnd(100);
  58. 			if (x <= 75)
  59. 			    pline("Segmentation fault -- core dumped.");
  60. 			else if (x <= 99)
  61. 			    pline("Bus error -- core dumped.");
  62. 			else pline("Yo' mama -- core dumped.");
  63. 		    }
  64. 		} else
  65. #endif
  66. #ifdef MAC	/* KMH -- Why should Unix have all the fun? */
  67. 		if (otmp->otyp == APPLE) {
  68. 			pline("Delicious!  Must be a Macintosh!");
  69. 		} else
  70. #endif
  71. 		if (otmp->otyp == EGG && stale_egg(otmp)) {
  72. 		    pline("Ugh.  Rotten egg.");	/* perhaps others like it */
  73. 		    make_vomiting(Vomiting+d(10,4), TRUE);
  74. 		} else
  75. give_feedback:
  76. 		    pline("This %s is %s", singular(otmp, xname),
  77. 		      otmp->cursed ? (Hallucination ? "grody!" : "terrible!") :
  78. 		      (otmp->otyp == CRAM_RATION
  79. 		      || otmp->otyp == K_RATION
  80. 		      || otmp->otyp == C_RATION)
  81. 		      ? "bland." :
  82. 		      Hallucination ? "gnarly!" : "delicious!");
  83. 		break;
  84. 	}
  85. }

accessory_has_effect[edit]

  1. STATIC_OVL void
  2. accessory_has_effect(otmp)
  3. struct obj *otmp;
  4. {
  5. 	pline("Magic spreads through your body as you digest the %s.",
  6. 	    otmp->oclass == RING_CLASS ? "ring" : "amulet");
  7. }

eataccessory[edit]

  1. STATIC_OVL void
  2. eataccessory(otmp)
  3. struct obj *otmp;
  4. {
  5. 	int typ = otmp->otyp;
  6. 	long oldprop;
  7.  
  8. 	/* Note: rings are not so common that this is unbalancing. */
  9. 	/* (How often do you even _find_ 3 rings of polymorph in a game?) */
  10. 	oldprop = u.uprops[objects[typ].oc_oprop].intrinsic;
  11. 	if (otmp == uleft || otmp == uright) {
  12. 	    Ring_gone(otmp);
  13. 	    if (u.uhp <= 0) return; /* died from sink fall */
  14. 	}
  15. 	otmp->known = otmp->dknown = 1; /* by taste */
  16. 	if (!rn2(otmp->oclass == RING_CLASS ? 3 : 5)) {
  17. 	  switch (otmp->otyp) {
  18. 	    default:
  19. 	        if (!objects[typ].oc_oprop) break; /* should never happen */
  20.  
  21. 		if (!(u.uprops[objects[typ].oc_oprop].intrinsic & FROMOUTSIDE))
  22. 		    accessory_has_effect(otmp);
  23.  
  24. 		u.uprops[objects[typ].oc_oprop].intrinsic |= FROMOUTSIDE;
  25.  
  26. 		switch (typ) {
  27. 		  case RIN_SEE_INVISIBLE:
  28. 		    set_mimic_blocking();
  29. 		    see_monsters();
  30. 		    if (Invis && !oldprop && !ESee_invisible &&
  31. 				!perceives(youmonst.data) && !Blind) {
  32. 			newsym(u.ux,u.uy);
  33. 			pline("Suddenly you can see yourself.");
  34. 			makeknown(typ);
  35. 		    }
  36. 		    break;
  37. 		  case RIN_INVISIBILITY:
  38. 		    if (!oldprop && !EInvis && !BInvis &&
  39. 					!See_invisible && !Blind) {
  40. 			newsym(u.ux,u.uy);
  41. 			Your("body takes on a %s transparency...",
  42. 				Hallucination ? "normal" : "strange");
  43. 			makeknown(typ);
  44. 		    }
  45. 		    break;
  46. 		  case RIN_PROTECTION_FROM_SHAPE_CHAN:
  47. 		    rescham();
  48. 		    break;
  49. 		  case RIN_LEVITATION:
  50. 		    /* undo the `.intrinsic |= FROMOUTSIDE' done above */
  51. 		    u.uprops[LEVITATION].intrinsic = oldprop;
  52. 		    if (!Levitation) {
  53. 			float_up();
  54. 			incr_itimeout(&HLevitation, d(10,20));
  55. 			makeknown(typ);
  56. 		    }
  57. 		    break;
  58. 		}
  59. 		break;
  60. 	    case RIN_ADORNMENT:
  61. 		accessory_has_effect(otmp);
  62. 		if (adjattrib(A_CHA, otmp->spe, -1))
  63. 		    makeknown(typ);
  64. 		break;
  65. 	    case RIN_GAIN_STRENGTH:
  66. 		accessory_has_effect(otmp);
  67. 		if (adjattrib(A_STR, otmp->spe, -1))
  68. 		    makeknown(typ);
  69. 		break;
  70. 	    case RIN_GAIN_CONSTITUTION:
  71. 		accessory_has_effect(otmp);
  72. 		if (adjattrib(A_CON, otmp->spe, -1))
  73. 		    makeknown(typ);
  74. 		break;
  75. 	    case RIN_INCREASE_ACCURACY:
  76. 		accessory_has_effect(otmp);
  77. 		u.uhitinc += otmp->spe;
  78. 		break;
  79. 	    case RIN_INCREASE_DAMAGE:
  80. 		accessory_has_effect(otmp);
  81. 		u.udaminc += otmp->spe;
  82. 		break;
  83. 	    case RIN_PROTECTION:
  84. 		accessory_has_effect(otmp);
  85. 		HProtection |= FROMOUTSIDE;
  86. 		u.ublessed += otmp->spe;
  87. 		flags.botl = 1;
  88. 		break;
  89. 	    case RIN_FREE_ACTION:
  90. 		/* Give sleep resistance instead */
  91. 		if (!(HSleep_resistance & FROMOUTSIDE))
  92. 		    accessory_has_effect(otmp);
  93. 		if (!Sleep_resistance)
  94. 		    You_feel("wide awake.");
  95. 		HSleep_resistance |= FROMOUTSIDE;
  96. 		break;
  97. 	    case AMULET_OF_CHANGE:
  98. 		accessory_has_effect(otmp);
  99. 		makeknown(typ);
  100. 		change_sex();
  101. 		You("are suddenly very %s!",
  102. 		    flags.female ? "feminine" : "masculine");
  103. 		flags.botl = 1;
  104. 		break;
  105. 	    case AMULET_OF_UNCHANGING:
  106. 		/* un-change: it's a pun */
  107. 		if (!Unchanging && Upolyd) {
  108. 		    accessory_has_effect(otmp);
  109. 		    makeknown(typ);
  110. 		    rehumanize();
  111. 		}
  112. 		break;
  113. 	    case AMULET_OF_STRANGULATION: /* bad idea! */
  114. 		/* no message--this gives no permanent effect */
  115. 		choke(otmp);
  116. 		break;
  117. 	    case AMULET_OF_RESTFUL_SLEEP: /* another bad idea! */
  118. 		if (!(HSleeping & FROMOUTSIDE))
  119. 		    accessory_has_effect(otmp);
  120. 		HSleeping = FROMOUTSIDE | rnd(100);
  121. 		break;
  122. 	    case RIN_SUSTAIN_ABILITY:
  123. 	    case AMULET_OF_LIFE_SAVING:
  124. 	    case AMULET_OF_REFLECTION: /* nice try */
  125. 	    /* can't eat Amulet of Yendor or fakes,
  126. 	     * and no oc_prop even if you could -3.
  127. 	     */
  128. 		break;
  129. 	  }
  130. 	}
  131. }

eatspecial[edit]

  1. STATIC_OVL void
  2. eatspecial() /* called after eating non-food */
  3. {
  4. 	register struct obj *otmp = victual.piece;
  5.  
  6. 	/* lesshungry wants an occupation to handle choke messages correctly */
  7. 	set_occupation(eatfood, "eating non-food", 0);
  8. 	lesshungry(victual.nmod);
  9. 	occupation = 0;
  10. 	victual.piece = (struct obj *)0;
  11. 	victual.eating = 0;
  12. 	if (otmp->oclass == COIN_CLASS) {
  13. #ifdef GOLDOBJ
  14. 		if (carried(otmp))
  15. 		    useupall(otmp);
  16. #else
  17. 		if (otmp->where == OBJ_FREE)
  18. 		    dealloc_obj(otmp);
  19. #endif
  20. 		else
  21. 		    useupf(otmp, otmp->quan);
  22. 		return;
  23. 	}
  24. 	if (otmp->oclass == POTION_CLASS) {
  25. 		otmp->quan++; /* dopotion() does a useup() */
  26. 		(void)dopotion(otmp);
  27. 	}
  28. 	if (otmp->oclass == RING_CLASS || otmp->oclass == AMULET_CLASS)
  29. 		eataccessory(otmp);
  30. 	else if (otmp->otyp == LEASH && otmp->leashmon)
  31. 		o_unleash(otmp);
  32.  
  33. 	/* KMH -- idea by "Tommy the Terrorist" */
  34. 	if ((otmp->otyp == TRIDENT) && !otmp->cursed)
  35. 	{
  36. 		pline(Hallucination ? "Four out of five dentists agree." :
  37. 				"That was pure chewing satisfaction!");
  38. 		exercise(A_WIS, TRUE);
  39. 	}
  40. 	if ((otmp->otyp == FLINT) && !otmp->cursed)
  41. 	{
  42. 		pline("Yabba-dabba delicious!");
  43. 		exercise(A_CON, TRUE);
  44. 	}
  45.  
  46. 	if (otmp == uwep && otmp->quan == 1L) uwepgone();
  47. 	if (otmp == uquiver && otmp->quan == 1L) uqwepgone();
  48. 	if (otmp == uswapwep && otmp->quan == 1L) uswapwepgone();
  49.  
  50. 	if (otmp == uball) unpunish();
  51. 	if (otmp == uchain) unpunish(); /* but no useup() */
  52. 	else if (carried(otmp)) useup(otmp);
  53. 	else useupf(otmp, 1L);
  54. }

foodword[edit]

  1. /* NOTE: the order of these words exactly corresponds to the
  2. order of oc_material values #define'd in objclass.h. */
  3. static const char *foodwords[] = {
  4. 	"meal", "liquid", "wax", "food", "meat",
  5. 	"paper", "cloth", "leather", "wood", "bone", "scale",
  6. 	"metal", "metal", "metal", "silver", "gold", "platinum", "mithril",
  7. 	"plastic", "glass", "rich food", "stone"
  8. };
  9.  
  10. STATIC_OVL const char *
  11. foodword(otmp)
  12. register struct obj *otmp;
  13. {
  14. 	if (otmp->oclass == FOOD_CLASS) return "food";
  15. 	if (otmp->oclass == GEM_CLASS &&
  16. 	    objects[otmp->otyp].oc_material == GLASS &&
  17. 	    otmp->dknown)
  18. 		makeknown(otmp->otyp);
  19. 	return foodwords[objects[otmp->otyp].oc_material];
  20. }

fpostfx[edit]

  1. STATIC_OVL void
  2. fpostfx(otmp)		/* called after consuming (non-corpse) food */
  3. register struct obj *otmp;
  4. {
  5. 	switch(otmp->otyp) {
  6. 	    case SPRIG_OF_WOLFSBANE:
  7. 		if (u.ulycn >= LOW_PM || is_were(youmonst.data))
  8. 		    you_unwere(TRUE);
  9. 		break;
  10. 	    case CARROT:
  11. 		make_blinded((long)u.ucreamed,TRUE);
  12. 		break;
  13. 	    case FORTUNE_COOKIE:
  14. 		outrumor(bcsign(otmp), BY_COOKIE);
  15. 		if (!Blind) u.uconduct.literate++;
  16. 		break;
  17. 	    case LUMP_OF_ROYAL_JELLY:
  18. 		/* This stuff seems to be VERY healthy! */
  19. 		gainstr(otmp, 1);
  20. 		if (Upolyd) {
  21. 		    u.mh += otmp->cursed ? -rnd(20) : rnd(20);
  22. 		    if (u.mh > u.mhmax) {
  23. 			if (!rn2(17)) u.mhmax++;
  24. 			u.mh = u.mhmax;
  25. 		    } else if (u.mh <= 0) {
  26. 			rehumanize();
  27. 		    }
  28. 		} else {
  29. 		    u.uhp += otmp->cursed ? -rnd(20) : rnd(20);
  30. 		    if (u.uhp > u.uhpmax) {
  31. 			if(!rn2(17)) u.uhpmax++;
  32. 			u.uhp = u.uhpmax;
  33. 		    } else if (u.uhp <= 0) {
  34. 			killer_format = KILLED_BY_AN;
  35. 			killer = "rotten lump of royal jelly";
  36. 			done(POISONING);
  37. 		    }
  38. 		}
  39. 		if(!otmp->cursed) heal_legs();
  40. 		break;
  41. 	    case EGG:
  42. 		if (touch_petrifies(&mons[otmp->corpsenm])) {
  43. 		    if (!Stone_resistance &&
  44. 			!(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))) {
  45. 			if (!Stoned) Stoned = 5;
  46. 			killer_format = KILLED_BY_AN;
  47. 			Sprintf(killer_buf, "%s egg", mons[otmp->corpsenm].mname);
  48. 			delayed_killer = killer_buf;
  49. 		    }
  50. 		}
  51. 		break;
  52. 	    case EUCALYPTUS_LEAF:
  53. 		if (Sick && !otmp->cursed)
  54. 		    make_sick(0L, (char *)0, TRUE, SICK_ALL);
  55. 		if (Vomiting && !otmp->cursed)
  56. 		    make_vomiting(0L, TRUE);
  57. 		break;
  58. 	}
  59. 	return;
  60. }

edibility_prompts[edit]

  1. /*
  2. * return 0 if the food was not dangerous.
  3. * return 1 if the food was dangerous and you chose to stop.
  4. * return 2 if the food was dangerous and you chose to eat it anyway.
  5. */
  6. STATIC_OVL int
  7. edibility_prompts(otmp)
  8. struct obj *otmp;
  9. {
  10. 	/* blessed food detection granted you a one-use
  11. 	   ability to detect food that is unfit for consumption
  12. 	   or dangerous and avoid it. */
  13.  
  14. 	char buf[BUFSZ], foodsmell[BUFSZ],
  15. 	     it_or_they[QBUFSZ], eat_it_anyway[QBUFSZ];
  16. 	boolean cadaver = (otmp->otyp == CORPSE),
  17. 		stoneorslime = FALSE;
  18. 	int material = objects[otmp->otyp].oc_material,
  19. 	    mnum = otmp->corpsenm;
  20. 	long rotted = 0L;
  21.  
  22. 	Strcpy(foodsmell, Tobjnam(otmp, "smell"));
  23. 	Strcpy(it_or_they, (otmp->quan == 1L) ? "it" : "they");
  24. 	Sprintf(eat_it_anyway, "Eat %s anyway?",
  25. 		(otmp->quan == 1L) ? "it" : "one");
  26.  
  27. 	if (cadaver || otmp->otyp == EGG || otmp->otyp == TIN) {
  28. 		/* These checks must match those in eatcorpse() */
  29. 		stoneorslime = (touch_petrifies(&mons[mnum]) &&
  30. 				!Stone_resistance &&
  31. 				!poly_when_stoned(youmonst.data));
  32.  
  33. 		if (mnum == PM_GREEN_SLIME)
  34. 		    stoneorslime = (!Unchanging && !flaming(youmonst.data) &&
  35. 			youmonst.data != &mons[PM_GREEN_SLIME]);
  36.  
  37. 		if (cadaver && mnum != PM_LIZARD && mnum != PM_LICHEN) {
  38. 			long age = peek_at_iced_corpse_age(otmp);
  39. 			/* worst case rather than random
  40. 			   in this calculation to force prompt */
  41. 			rotted = (monstermoves - age)/(10L + 0 /* was rn2(20) */);
  42. 			if (otmp->cursed) rotted += 2L;
  43. 			else if (otmp->blessed) rotted -= 2L;
  44. 		}
  45. 	}
  46.  
  47. 	/*
  48. 	 * These problems with food should be checked in
  49. 	 * order from most detrimental to least detrimental.
  50. 	 */
  51.  
  52. 	if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && !Sick_resistance) {
  53. 		/* Tainted meat */
  54. 		Sprintf(buf, "%s like %s could be tainted! %s",
  55. 			foodsmell, it_or_they, eat_it_anyway);
  56. 		if (yn_function(buf,ynchars,'n')=='n') return 1;
  57. 		else return 2;
  58. 	}
  59. 	if (stoneorslime) {
  60. 		Sprintf(buf, "%s like %s could be something very dangerous! %s",
  61. 			foodsmell, it_or_they, eat_it_anyway);
  62. 		if (yn_function(buf,ynchars,'n')=='n') return 1;
  63. 		else return 2;
  64. 	}
  65. 	if (otmp->orotten || (cadaver && rotted > 3L)) {
  66. 		/* Rotten */
  67. 		Sprintf(buf, "%s like %s could be rotten! %s",
  68. 			foodsmell, it_or_they, eat_it_anyway);
  69. 		if (yn_function(buf,ynchars,'n')=='n') return 1;
  70. 		else return 2;
  71. 	}
  72. 	if (cadaver && poisonous(&mons[mnum]) && !Poison_resistance) {
  73. 		/* poisonous */
  74. 		Sprintf(buf, "%s like %s might be poisonous! %s",
  75. 			foodsmell, it_or_they, eat_it_anyway);
  76. 		if (yn_function(buf,ynchars,'n')=='n') return 1;
  77. 		else return 2;
  78. 	}
  79. 	if (cadaver && !vegetarian(&mons[mnum]) &&
  80. 	    !u.uconduct.unvegetarian && Role_if(PM_MONK)) {
  81. 		Sprintf(buf, "%s unhealthy. %s",
  82. 			foodsmell, eat_it_anyway);
  83. 		if (yn_function(buf,ynchars,'n')=='n') return 1;
  84. 		else return 2;
  85. 	}
  86. 	if (cadaver && acidic(&mons[mnum]) && !Acid_resistance) {
  87. 		Sprintf(buf, "%s rather acidic. %s",
  88. 			foodsmell, eat_it_anyway);
  89. 		if (yn_function(buf,ynchars,'n')=='n') return 1;
  90. 		else return 2;
  91. 	}
  92. 	if (Upolyd && u.umonnum == PM_RUST_MONSTER &&
  93. 	    is_metallic(otmp) && otmp->oerodeproof) {
  94. 		Sprintf(buf, "%s disgusting to you right now. %s",
  95. 			foodsmell, eat_it_anyway);
  96. 		if (yn_function(buf,ynchars,'n')=='n') return 1;
  97. 		else return 2;
  98. 	}
  99.  
  100. 	/*
  101. 	 * Breaks conduct, but otherwise safe.
  102. 	 */
  103.  
  104. 	if (!u.uconduct.unvegan &&
  105. 	    ((material == LEATHER || material == BONE ||
  106. 	      material == DRAGON_HIDE || material == WAX) ||
  107. 	     (cadaver && !vegan(&mons[mnum])))) {
  108. 		Sprintf(buf, "%s foul and unfamiliar to you. %s",
  109. 			foodsmell, eat_it_anyway);
  110. 		if (yn_function(buf,ynchars,'n')=='n') return 1;
  111. 		else return 2;
  112. 	}
  113. 	if (!u.uconduct.unvegetarian &&
  114. 	    ((material == LEATHER || material == BONE ||
  115. 	      material == DRAGON_HIDE) ||
  116. 	     (cadaver && !vegetarian(&mons[mnum])))) {
  117. 		Sprintf(buf, "%s unfamiliar to you. %s",
  118. 			foodsmell, eat_it_anyway);
  119. 		if (yn_function(buf,ynchars,'n')=='n') return 1;
  120. 		else return 2;
  121. 	}
  122.  
  123. 	if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && Sick_resistance) {
  124. 		/* Tainted meat with Sick_resistance */
  125. 		Sprintf(buf, "%s like %s could be tainted! %s",
  126. 			foodsmell, it_or_they, eat_it_anyway);
  127. 		if (yn_function(buf,ynchars,'n')=='n') return 1;
  128. 		else return 2;
  129. 	}
  130. 	return 0;
  131. }

doeat[edit]

  1. int
  2. doeat()		/* generic "eat" command funtion (see cmd.c) */
  3. {
  4. 	register struct obj *otmp;
  5. 	int basenutrit;			/* nutrition of full item */
  6. 	boolean dont_start = FALSE;
  7.  
  8. 	if (Strangled) {
  9. 		pline("If you can't breathe air, how can you consume solids?");
  10. 		return 0;
  11. 	}
  12. 	if (!(otmp = floorfood("eat", 0))) return 0;
  13. 	if (check_capacity((char *)0)) return 0;
  14.  
  15. 	if (u.uedibility) {
  16. 		int res = edibility_prompts(otmp);
  17. 		if (res) {
  18. 		    Your("%s stops tingling and your sense of smell returns to normal.",
  19. 			body_part(NOSE));
  20. 		    u.uedibility = 0;
  21. 		    if (res == 1) return 0;
  22. 		}
  23. 	}
  24.  
  25. 	/* We have to make non-foods take 1 move to eat, unless we want to
  26. 	 * do ridiculous amounts of coding to deal with partly eaten plate
  27. 	 * mails, players who polymorph back to human in the middle of their
  28. 	 * metallic meal, etc....
  29. 	 */
  30. 	if (!is_edible(otmp)) {
  31. 	    You("cannot eat that!");
  32. 	    return 0;
  33. 	} else if ((otmp->owornmask & (W_ARMOR|W_TOOL|W_AMUL
  34. #ifdef STEED
  35. 			|W_SADDLE
  36. #endif
  37. 			)) != 0) {
  38. 	    /* let them eat rings */
  39. 	    You_cant("eat %s you're wearing.", something);
  40. 	    return 0;
  41. 	}
  42. 	if (is_metallic(otmp) &&
  43. 	    u.umonnum == PM_RUST_MONSTER && otmp->oerodeproof) {
  44. 	    	otmp->rknown = TRUE;
  45. 		if (otmp->quan > 1L) {
  46. 		    if(!carried(otmp))
  47. 			(void) splitobj(otmp, otmp->quan - 1L);
  48. 		    else
  49. 			otmp = splitobj(otmp, 1L);
  50. 		}
  51. 		pline("Ulch - That %s was rustproofed!", xname(otmp));
  52. 		/* The regurgitated object's rustproofing is gone now */
  53. 		otmp->oerodeproof = 0;
  54. 		make_stunned(HStun + rn2(10), TRUE);
  55. 		You("spit %s out onto the %s.", the(xname(otmp)),
  56. 			surface(u.ux, u.uy));
  57. 		if (carried(otmp)) {
  58. 			freeinv(otmp);
  59. 			dropy(otmp);
  60. 		}
  61. 		stackobj(otmp);
  62. 		return 1;
  63. 	}
  64. 	/* KMH -- Slow digestion is... indigestible */
  65. 	if (otmp->otyp == RIN_SLOW_DIGESTION) {
  66. 		pline("This ring is indigestible!");
  67. 		(void) rottenfood(otmp);
  68. 		if (otmp->dknown && !objects[otmp->otyp].oc_name_known
  69. 				&& !objects[otmp->otyp].oc_uname)
  70. 			docall(otmp);
  71. 		return (1);
  72. 	}
  73. 	if (otmp->oclass != FOOD_CLASS) {
  74. 	    int material;
  75. 	    victual.reqtime = 1;
  76. 	    victual.piece = otmp;
  77. 		/* Don't split it, we don't need to if it's 1 move */
  78. 	    victual.usedtime = 0;
  79. 	    victual.canchoke = (u.uhs == SATIATED);
  80. 		/* Note: gold weighs 1 pt. for each 1000 pieces (see */
  81. 		/* pickup.c) so gold and non-gold is consistent. */
  82. 	    if (otmp->oclass == COIN_CLASS)
  83. 		basenutrit = ((otmp->quan > 200000L) ? 2000
  84. 			: (int)(otmp->quan/100L));
  85. 	    else if(otmp->oclass == BALL_CLASS || otmp->oclass == CHAIN_CLASS)
  86. 		basenutrit = weight(otmp);
  87. 	    /* oc_nutrition is usually weight anyway */
  88. 	    else basenutrit = objects[otmp->otyp].oc_nutrition;
  89. 	    victual.nmod = basenutrit;
  90. 	    victual.eating = TRUE; /* needed for lesshungry() */
  91.  
  92. 	    material = objects[otmp->otyp].oc_material;
  93. 	    if (material == LEATHER ||
  94. 		material == BONE || material == DRAGON_HIDE) {
  95. 		u.uconduct.unvegan++;
  96. 		violated_vegetarian();
  97. 	    } else if (material == WAX)
  98. 		u.uconduct.unvegan++;
  99. 	    u.uconduct.food++;
  100.  
  101. 	    if (otmp->cursed)
  102. 		(void) rottenfood(otmp);
  103.  
  104. 	    if (otmp->oclass == WEAPON_CLASS && otmp->opoisoned) {
  105. 		pline("Ecch - that must have been poisonous!");
  106. 		if(!Poison_resistance) {
  107. 		    losestr(rnd(4));
  108. 		    losehp(rnd(15), xname(otmp), KILLED_BY_AN);
  109. 		} else
  110. 		    You("seem unaffected by the poison.");
  111. 	    } else if (!otmp->cursed)
  112. 		pline("This %s is delicious!",
  113. 		      otmp->oclass == COIN_CLASS ? foodword(otmp) :
  114. 		      singular(otmp, xname));
  115.  
  116. 	    eatspecial();
  117. 	    return 1;
  118. 	}
  119.  
  120. 	if(otmp == victual.piece) {
  121. 	/* If they weren't able to choke, they don't suddenly become able to
  122. 	 * choke just because they were interrupted.  On the other hand, if
  123. 	 * they were able to choke before, if they lost food it's possible
  124. 	 * they shouldn't be able to choke now.
  125. 	 */
  126. 	    if (u.uhs != SATIATED) victual.canchoke = FALSE;
  127. 	    victual.piece = touchfood(otmp);
  128. 	    You("resume your meal.");
  129. 	    start_eating(victual.piece);
  130. 	    return(1);
  131. 	}
  132.  
  133. 	/* nothing in progress - so try to find something. */
  134. 	/* tins are a special case */
  135. 	/* tins must also check conduct separately in case they're discarded */
  136. 	if(otmp->otyp == TIN) {
  137. 	    start_tin(otmp);
  138. 	    return(1);
  139. 	}
  140.  
  141. 	/* KMH, conduct */
  142. 	u.uconduct.food++;
  143.  
  144. 	victual.piece = otmp = touchfood(otmp);
  145. 	victual.usedtime = 0;
  146.  
  147. 	/* Now we need to calculate delay and nutritional info.
  148. 	 * The base nutrition calculated here and in eatcorpse() accounts
  149. 	 * for normal vs. rotten food.  The reqtime and nutrit values are
  150. 	 * then adjusted in accordance with the amount of food left.
  151. 	 */
  152. 	if(otmp->otyp == CORPSE) {
  153. 	    int tmp = eatcorpse(otmp);
  154. 	    if (tmp == 2) {
  155. 		/* used up */
  156. 		victual.piece = (struct obj *)0;
  157. 		return(1);
  158. 	    } else if (tmp)
  159. 		dont_start = TRUE;
  160. 	    /* if not used up, eatcorpse sets up reqtime and may modify
  161. 	     * oeaten */
  162. 	} else {
  163. 	    /* No checks for WAX, LEATHER, BONE, DRAGON_HIDE.  These are
  164. 	     * all handled in the != FOOD_CLASS case, above */
  165. 	    switch (objects[otmp->otyp].oc_material) {
  166. 	    case FLESH:
  167. 		u.uconduct.unvegan++;
  168. 		if (otmp->otyp != EGG) {
  169. 		    violated_vegetarian();
  170. 		}
  171. 		break;
  172.  
  173. 	    default:
  174. 		if (otmp->otyp == PANCAKE ||
  175. 		    otmp->otyp == FORTUNE_COOKIE || /* eggs */
  176. 		    otmp->otyp == CREAM_PIE ||
  177. 		    otmp->otyp == CANDY_BAR || /* milk */
  178. 		    otmp->otyp == LUMP_OF_ROYAL_JELLY)
  179. 		    u.uconduct.unvegan++;
  180. 		break;
  181. 	    }
  182.  
  183. 	    victual.reqtime = objects[otmp->otyp].oc_delay;
  184. 	    if (otmp->otyp != FORTUNE_COOKIE &&
  185. 		(otmp->cursed ||
  186. 		 (((monstermoves - otmp->age) > (int) otmp->blessed ? 50:30) &&
  187. 		(otmp->orotten || !rn2(7))))) {
  188.  
  189. 		if (rottenfood(otmp)) {
  190. 		    otmp->orotten = TRUE;
  191. 		    dont_start = TRUE;
  192. 		}
  193. 		consume_oeaten(otmp, 1);	/* oeaten >>= 1 */
  194. 	    } else fprefx(otmp);
  195. 	}
  196.  
  197. 	/* re-calc the nutrition */
  198. 	if (otmp->otyp == CORPSE) basenutrit = mons[otmp->corpsenm].cnutrit;
  199. 	else basenutrit = objects[otmp->otyp].oc_nutrition;
  200.  
  201. #ifdef DEBUG
  202. 	debugpline("before rounddiv: victual.reqtime == %d", victual.reqtime);
  203. 	debugpline("oeaten == %d, basenutrit == %d", otmp->oeaten, basenutrit);
  204. #endif
  205. 	victual.reqtime = (basenutrit == 0 ? 0 :
  206. 		rounddiv(victual.reqtime * (long)otmp->oeaten, basenutrit));
  207. #ifdef DEBUG
  208. 	debugpline("after rounddiv: victual.reqtime == %d", victual.reqtime);
  209. #endif
  210. 	/* calculate the modulo value (nutrit. units per round eating)
  211. 	 * note: this isn't exact - you actually lose a little nutrition
  212. 	 *	 due to this method.
  213. 	 * TODO: add in a "remainder" value to be given at the end of the
  214. 	 *	 meal.
  215. 	 */
  216. 	if (victual.reqtime == 0 || otmp->oeaten == 0)
  217. 	    /* possible if most has been eaten before */
  218. 	    victual.nmod = 0;
  219. 	else if ((int)otmp->oeaten >= victual.reqtime)
  220. 	    victual.nmod = -((int)otmp->oeaten / victual.reqtime);
  221. 	else
  222. 	    victual.nmod = victual.reqtime % otmp->oeaten;
  223. 	victual.canchoke = (u.uhs == SATIATED);
  224.  
  225. 	if (!dont_start) start_eating(otmp);
  226. 	return(1);
  227. }

bite[edit]

  1. /* Take a single bite from a piece of food, checking for choking and
  2. * modifying usedtime.  Returns 1 if they choked and survived, 0 otherwise.
  3. */
  4. STATIC_OVL int
  5. bite()
  6. {
  7. 	if(victual.canchoke && u.uhunger >= 2000) {
  8. 		choke(victual.piece);
  9. 		return 1;
  10. 	}
  11. 	if (victual.doreset) {
  12. 		do_reset_eat();
  13. 		return 0;
  14. 	}
  15. 	force_save_hs = TRUE;
  16. 	if(victual.nmod < 0) {
  17. 		lesshungry(-victual.nmod);
  18. 		consume_oeaten(victual.piece, victual.nmod); /* -= -nmod */
  19. 	} else if(victual.nmod > 0 && (victual.usedtime % victual.nmod)) {
  20. 		lesshungry(1);
  21. 		consume_oeaten(victual.piece, -1);		  /* -= 1 */
  22. 	}
  23. 	force_save_hs = FALSE;
  24. 	recalc_wt();
  25. 	return 0;
  26. }
  27.  
  28. #endif /* OVLB */

gethungry[edit]

  1. #ifdef OVL0
  2.  
  3. void
  4. gethungry()	/* as time goes by - called by moveloop() and domove() */
  5. {
  6. 	if (u.uinvulnerable) return;	/* you don't feel hungrier */
  7.  
  8. 	if ((!u.usleep || !rn2(10))	/* slow metabolic rate while asleep */
  9. 		&& (carnivorous(youmonst.data) || herbivorous(youmonst.data))
  10. 		&& !Slow_digestion)
  11. 	    u.uhunger--;		/* ordinary food consumption */
  12.  
  13. 	if (moves % 2) {	/* odd turns */
  14. 	    /* Regeneration uses up food, unless due to an artifact */
  15. 	    if (HRegeneration || ((ERegeneration & (~W_ART)) &&
  16. 				(ERegeneration != W_WEP || !uwep->oartifact)))
  17. 			u.uhunger--;
  18. 	    if (near_capacity() > SLT_ENCUMBER) u.uhunger--;
  19. 	} else {		/* even turns */
  20. 	    if (Hunger) u.uhunger--;
  21. 	    /* Conflict uses up food too */
  22. 	    if (HConflict || (EConflict & (~W_ARTI))) u.uhunger--;
  23. 	    /* +0 charged rings don't do anything, so don't affect hunger */
  24. 	    /* Slow digestion still uses ring hunger */
  25. 	    switch ((int)(moves % 20)) {	/* note: use even cases only */
  26. 	     case  4: if (uleft &&
  27. 			  (uleft->spe || !objects[uleft->otyp].oc_charged))
  28. 			    u.uhunger--;
  29. 		    break;
  30. 	     case  8: if (uamul) u.uhunger--;
  31. 		    break;
  32. 	     case 12: if (uright &&
  33. 			  (uright->spe || !objects[uright->otyp].oc_charged))
  34. 			    u.uhunger--;
  35. 		    break;
  36. 	     case 16: if (u.uhave.amulet) u.uhunger--;
  37. 		    break;
  38. 	     default: break;
  39. 	    }
  40. 	}
  41. 	newuhs(TRUE);
  42. }
  43.  
  44. #endif /* OVL0 */

morehungry[edit]

  1. #ifdef OVLB
  2.  
  3. void
  4. morehungry(num)	/* called after vomiting and after performing feats of magic */
  5. register int num;
  6. {
  7. 	u.uhunger -= num;
  8. 	newuhs(TRUE);
  9. }

lesshungry[edit]

  1. void
  2. lesshungry(num)	/* called after eating (and after drinking fruit juice) */
  3. register int num;
  4. {
  5. 	/* See comments in newuhs() for discussion on force_save_hs */
  6. 	boolean iseating = (occupation == eatfood) || force_save_hs;
  7. #ifdef DEBUG
  8. 	debugpline("lesshungry(%d)", num);
  9. #endif
  10. 	u.uhunger += num;
  11. 	if(u.uhunger >= 2000) {
  12. 	    if (!iseating || victual.canchoke) {
  13. 		if (iseating) {
  14. 		    choke(victual.piece);
  15. 		    reset_eat();
  16. 		} else
  17. 		    choke(occupation == opentin ? tin.tin : (struct obj *)0);
  18. 		/* no reset_eat() */
  19. 	    }
  20. 	} else {
  21. 	    /* Have lesshungry() report when you're nearly full so all eating
  22. 	     * warns when you're about to choke.
  23. 	     */
  24. 	    if (u.uhunger >= 1500) {
  25. 		if (!victual.eating || (victual.eating && !victual.fullwarn)) {
  26. 		    pline("You're having a hard time getting all of it down.");
  27. 		    nomovemsg = "You're finally finished.";
  28. 		    if (!victual.eating)
  29. 			multi = -2;
  30. 		    else {
  31. 			victual.fullwarn = TRUE;
  32. 			if (victual.canchoke && victual.reqtime > 1) {
  33. 			    /* a one-gulp food will not survive a stop */
  34. 			    if (yn_function("Stop eating?",ynchars,'y')=='y') {
  35. 				reset_eat();
  36. 				nomovemsg = (char *)0;
  37. 			    }
  38. 			}
  39. 		    }
  40. 		}
  41. 	    }
  42. 	}
  43. 	newuhs(FALSE);
  44. }

unfaint[edit]

  1. STATIC_PTR
  2. int
  3. unfaint()
  4. {
  5. 	(void) Hear_again();
  6. 	if(u.uhs > FAINTING)
  7. 		u.uhs = FAINTING;
  8. 	stop_occupation();
  9. 	flags.botl = 1;
  10. 	return 0;
  11. }
  12.  
  13. #endif /* OVLB */

is_fainted[edit]

  1. #ifdef OVL0
  2.  
  3. boolean
  4. is_fainted()
  5. {
  6. 	return((boolean)(u.uhs == FAINTED));
  7. }

reset_faint[edit]

  1. void
  2. reset_faint()	/* call when a faint must be prematurely terminated */
  3. {
  4. 	if(is_fainted()) nomul(0);
  5. }

sync_hunger[edit]

  1. #if 0
  2. void
  3. sync_hunger()
  4. {
  5.  
  6. 	if(is_fainted()) {
  7.  
  8. 		flags.soundok = 0;
  9. 		nomul(-10+(u.uhunger/10));
  10. 		nomovemsg = "You regain consciousness.";
  11. 		afternmv = unfaint;
  12. 	}
  13. }
  14. #endif

newuhs[edit]

  1. void
  2. newuhs(incr)		/* compute and comment on your (new?) hunger status */
  3. boolean incr;
  4. {
  5. 	unsigned newhs;
  6. 	static unsigned save_hs;
  7. 	static boolean saved_hs = FALSE;
  8. 	int h = u.uhunger;
  9.  
  10. 	newhs = (h > 1000) ? SATIATED :
  11. 		(h > 150) ? NOT_HUNGRY :
  12. 		(h > 50) ? HUNGRY :
  13. 		(h > 0) ? WEAK : FAINTING;
  14.  
  15. 	/* While you're eating, you may pass from WEAK to HUNGRY to NOT_HUNGRY.
  16. 	 * This should not produce the message "you only feel hungry now";
  17. 	 * that message should only appear if HUNGRY is an endpoint.  Therefore
  18. 	 * we check to see if we're in the middle of eating.  If so, we save
  19. 	 * the first hunger status, and at the end of eating we decide what
  20. 	 * message to print based on the _entire_ meal, not on each little bit.
  21. 	 */
  22. 	/* It is normally possible to check if you are in the middle of a meal
  23. 	 * by checking occupation == eatfood, but there is one special case:
  24. 	 * start_eating() can call bite() for your first bite before it
  25. 	 * sets the occupation.
  26. 	 * Anyone who wants to get that case to work _without_ an ugly static
  27. 	 * force_save_hs variable, feel free.
  28. 	 */
  29. 	/* Note: If you become a certain hunger status in the middle of the
  30. 	 * meal, and still have that same status at the end of the meal,
  31. 	 * this will incorrectly print the associated message at the end of
  32. 	 * the meal instead of the middle.  Such a case is currently
  33. 	 * impossible, but could become possible if a message for SATIATED
  34. 	 * were added or if HUNGRY and WEAK were separated by a big enough
  35. 	 * gap to fit two bites.
  36. 	 */
  37. 	if (occupation == eatfood || force_save_hs) {
  38. 		if (!saved_hs) {
  39. 			save_hs = u.uhs;
  40. 			saved_hs = TRUE;
  41. 		}
  42. 		u.uhs = newhs;
  43. 		return;
  44. 	} else {
  45. 		if (saved_hs) {
  46. 			u.uhs = save_hs;
  47. 			saved_hs = FALSE;
  48. 		}
  49. 	}
  50.  
  51. 	if(newhs == FAINTING) {
  52. 		if(is_fainted()) newhs = FAINTED;
  53. 		if(u.uhs <= WEAK || rn2(20-u.uhunger/10) >= 19) {
  54. 			if(!is_fainted() && multi >= 0 /* %% */) {
  55. 				/* stop what you're doing, then faint */
  56. 				stop_occupation();
  57. 				You("faint from lack of food.");
  58. 				flags.soundok = 0;
  59. 				nomul(-10+(u.uhunger/10));
  60. 				nomovemsg = "You regain consciousness.";
  61. 				afternmv = unfaint;
  62. 				newhs = FAINTED;
  63. 			}
  64. 		} else
  65. 		if(u.uhunger < -(int)(200 + 20*ACURR(A_CON))) {
  66. 			u.uhs = STARVED;
  67. 			flags.botl = 1;
  68. 			bot();
  69. 			You("die from starvation.");
  70. 			killer_format = KILLED_BY;
  71. 			killer = "starvation";
  72. 			done(STARVING);
  73. 			/* if we return, we lifesaved, and that calls newuhs */
  74. 			return;
  75. 		}
  76. 	}
  77.  
  78. 	if(newhs != u.uhs) {
  79. 		if(newhs >= WEAK && u.uhs < WEAK)
  80. 			losestr(1);	/* this may kill you -- see below */
  81. 		else if(newhs < WEAK && u.uhs >= WEAK)
  82. 			losestr(-1);
  83. 		switch(newhs){
  84. 		case HUNGRY:
  85. 			if (Hallucination) {
  86. 			    You((!incr) ?
  87. 				"now have a lesser case of the munchies." :
  88. 				"are getting the munchies.");
  89. 			} else
  90. 			    You((!incr) ? "only feel hungry now." :
  91. 				  (u.uhunger < 145) ? "feel hungry." :
  92. 				   "are beginning to feel hungry.");
  93. 			if (incr && occupation &&
  94. 			    (occupation != eatfood && occupation != opentin))
  95. 			    stop_occupation();
  96. 			break;
  97. 		case WEAK:
  98. 			if (Hallucination)
  99. 			    pline((!incr) ?
  100. 				  "You still have the munchies." :
  101. "The munchies are interfering with your motor capabilities.");
  102. 			else if (incr &&
  103. 				(Role_if(PM_WIZARD) || Race_if(PM_ELF) ||
  104. 				 Role_if(PM_VALKYRIE)))
  105. 			    pline("%s needs food, badly!",
  106. 				  (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE)) ?
  107. 				  urole.name.m : "Elf");
  108. 			else
  109. 			    You((!incr) ? "feel weak now." :
  110. 				  (u.uhunger < 45) ? "feel weak." :
  111. 				   "are beginning to feel weak.");
  112. 			if (incr && occupation &&
  113. 			    (occupation != eatfood && occupation != opentin))
  114. 			    stop_occupation();
  115. 			break;
  116. 		}
  117. 		u.uhs = newhs;
  118. 		flags.botl = 1;
  119. 		bot();
  120. 		if ((Upolyd ? u.mh : u.uhp) < 1) {
  121. 			You("die from hunger and exhaustion.");
  122. 			killer_format = KILLED_BY;
  123. 			killer = "exhaustion";
  124. 			done(STARVING);
  125. 			return;
  126. 		}
  127. 	}
  128. }
  129.  
  130. #endif /* OVL0 */

floorfood[edit]

  1. #ifdef OVLB
  2.  
  3. /* Returns an object representing food.  Object may be either on floor or
  4. * in inventory.
  5. */
  6. struct obj *
  7. floorfood(verb,corpsecheck)	/* get food from floor or pack */
  8. 	const char *verb;
  9. 	int corpsecheck; /* 0, no check, 1, corpses, 2, tinnable corpses */
  10. {
  11. 	register struct obj *otmp;
  12. 	char qbuf[QBUFSZ];
  13. 	char c;
  14. 	boolean feeding = (!strcmp(verb, "eat"));
  15.  
  16. 	/* if we can't touch floor objects then use invent food only */
  17. 	if (!can_reach_floor() ||
  18. #ifdef STEED
  19. 		(feeding && u.usteed) || /* can't eat off floor while riding */
  20. #endif
  21. 		((is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy)) &&
  22. 		    (Wwalking || is_clinger(youmonst.data) ||
  23. 			(Flying && !Breathless))))
  24. 	    goto skipfloor;
  25.  
  26. 	if (feeding && metallivorous(youmonst.data)) {
  27. 	    struct obj *gold;
  28. 	    struct trap *ttmp = t_at(u.ux, u.uy);
  29.  
  30. 	    if (ttmp && ttmp->tseen && ttmp->ttyp == BEAR_TRAP) {
  31. 		/* If not already stuck in the trap, perhaps there should
  32. 		   be a chance to becoming trapped?  Probably not, because
  33. 		   then the trap would just get eaten on the _next_ turn... */
  34. 		Sprintf(qbuf, "There is a bear trap here (%s); eat it?",
  35. 			(u.utrap && u.utraptype == TT_BEARTRAP) ?
  36. 				"holding you" : "armed");
  37. 		if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') {
  38. 		    u.utrap = u.utraptype = 0;
  39. 		    deltrap(ttmp);
  40. 		    return mksobj(BEARTRAP, TRUE, FALSE);
  41. 		} else if (c == 'q') {
  42. 		    return (struct obj *)0;
  43. 		}
  44. 	    }
  45.  
  46. 	    if (youmonst.data != &mons[PM_RUST_MONSTER] &&
  47. 		(gold = g_at(u.ux, u.uy)) != 0) {
  48. 		if (gold->quan == 1L)
  49. 		    Sprintf(qbuf, "There is 1 gold piece here; eat it?");
  50. 		else
  51. 		    Sprintf(qbuf, "There are %ld gold pieces here; eat them?",
  52. 			    gold->quan);
  53. 		if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') {
  54. 		    return gold;
  55. 		} else if (c == 'q') {
  56. 		    return (struct obj *)0;
  57. 		}
  58. 	    }
  59. 	}
  60.  
  61. 	/* Is there some food (probably a heavy corpse) here on the ground? */
  62. 	for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) {
  63. 		if(corpsecheck ?
  64. 		(otmp->otyp==CORPSE && (corpsecheck == 1 || tinnable(otmp))) :
  65. 		    feeding ? (otmp->oclass != COIN_CLASS && is_edible(otmp)) :
  66. 						otmp->oclass==FOOD_CLASS) {
  67. 			Sprintf(qbuf, "There %s %s here; %s %s?",
  68. 				otense(otmp, "are"),
  69. 				doname(otmp), verb,
  70. 				(otmp->quan == 1L) ? "it" : "one");
  71. 			if((c = yn_function(qbuf,ynqchars,'n')) == 'y')
  72. 				return(otmp);
  73. 			else if(c == 'q')
  74. 				return((struct obj *) 0);
  75. 		}
  76. 	}
  77.  
  78. skipfloor:
  79. 	/* We cannot use ALL_CLASSES since that causes getobj() to skip its
  80. 	 * "ugly checks" and we need to check for inedible items.
  81. 	 */
  82. 	otmp = getobj(feeding ? (const char *)allobj :
  83. 				(const char *)comestibles, verb);
  84. 	if (corpsecheck && otmp)
  85. 	    if (otmp->otyp != CORPSE || (corpsecheck == 2 && !tinnable(otmp))) {
  86. 		You_cant("%s that!", verb);
  87. 		return (struct obj *)0;
  88. 	    }
  89. 	return otmp;
  90. }

vomit[edit]

  1. /* Side effects of vomiting */
  2. /* added nomul (MRS) - it makes sense, you're too busy being sick! */
  3. void
  4. vomit()		/* A good idea from David Neves */
  5. {
  6. 	make_sick(0L, (char *) 0, TRUE, SICK_VOMITABLE);
  7. 	nomul(-2);
  8. }

eaten_stat[edit]

  1. int
  2. eaten_stat(base, obj)
  3. register int base;
  4. register struct obj *obj;
  5. {
  6. 	long uneaten_amt, full_amount;
  7.  
  8. 	uneaten_amt = (long)obj->oeaten;
  9. 	full_amount = (obj->otyp == CORPSE) ? (long)mons[obj->corpsenm].cnutrit
  10. 					: (long)objects[obj->otyp].oc_nutrition;
  11. 	if (uneaten_amt > full_amount) {
  12. 	    impossible(
  13. 	  "partly eaten food (%ld) more nutritious than untouched food (%ld)",
  14. 		       uneaten_amt, full_amount);
  15. 	    uneaten_amt = full_amount;
  16. 	}
  17.  
  18. 	base = (int)(full_amount ? (long)base * uneaten_amt / full_amount : 0L);
  19. 	return (base < 1) ? 1 : base;
  20. }

consume_oeaten[edit]

  1. /* reduce obj's oeaten field, making sure it never hits or passes 0 */
  2. void
  3. consume_oeaten(obj, amt)
  4. struct obj *obj;
  5. int amt;
  6. {
  7. /*
  8. * This is a hack to try to squelch several long standing mystery
  9. * food bugs.  A better solution would be to rewrite the entire
  10. * victual handling mechanism from scratch using a less complex
  11. * model.  Alternatively, this routine could call done_eating()
  12. * or food_disappears() but its callers would need revisions to
  13. * cope with victual.piece unexpectedly going away.
  14. *
  15. * Multi-turn eating operates by setting the food's oeaten field
  16. * to its full nutritional value and then running a counter which
  17. * independently keeps track of whether there is any food left.
  18. * The oeaten field can reach exactly zero on the last turn, and
  19. * the object isn't removed from inventory until the next turn
  20. * when the "you finish eating" message gets delivered, so the
  21. * food would be restored to the status of untouched during that
  22. * interval.  This resulted in unexpected encumbrance messages
  23. * at the end of a meal (if near enough to a threshold) and would
  24. * yield full food if there was an interruption on the critical
  25. * turn.  Also, there have been reports over the years of food
  26. * becoming massively heavy or producing unlimited satiation;
  27. * this would occur if reducing oeaten via subtraction attempted
  28. * to drop it below 0 since its unsigned type would produce a
  29. * huge positive value instead.  So far, no one has figured out
  30. * _why_ that inappropriate subtraction might sometimes happen.
  31. */
  32.  
  33. if (amt > 0) {
  34. 	/* bit shift to divide the remaining amount of food */
  35. 	obj->oeaten >>= amt;
  36. } else {
  37. 	/* simple decrement; value is negative so we actually add it */
  38. 	if ((int) obj->oeaten > -amt)
  39. 	    obj->oeaten += amt;
  40. 	else
  41. 	    obj->oeaten = 0;
  42. }
  43.  
  44. if (obj->oeaten == 0) {
  45. 	if (obj == victual.piece)	/* always true unless wishing... */
  46. 	    victual.reqtime = victual.usedtime;	/* no bites left */
  47. 	obj->oeaten = 1;	/* smallest possible positive value */
  48. }
  49. }
  50.  
  51. #endif /* OVLB */

maybe_finished_meal[edit]

  1. #ifdef OVL1
  2.  
  3. /* called when eatfood occupation has been interrupted,
  4. or in the case of theft, is about to be interrupted */
  5. boolean
  6. maybe_finished_meal(stopping)
  7. boolean stopping;
  8. {
  9. 	/* in case consume_oeaten() has decided that the food is all gone */
  10. 	if (occupation == eatfood && victual.usedtime >= victual.reqtime) {
  11. 	    if (stopping) occupation = 0;	/* for do_reset_eat */
  12. 	    (void) eatfood(); /* calls done_eating() to use up victual.piece */
  13. 	    return TRUE;
  14. 	}
  15. 	return FALSE;
  16. }
  17.  
  18. #endif /* OVL1 */
  19.  
  20. /*eat.c*/