Source:NetHack 3.4.3/src/pickup.c

From NetHackWiki
(Redirected from Pickup.c)
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)pickup.c	3.4	2003/07/27	*/
  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. /*
  2. *	Contains code for picking objects up, and container use.
  3. */
  4.  
  5. #include "hack.h"
  6.  
  7. STATIC_DCL void FDECL(simple_look, (struct obj *,BOOLEAN_P));
  8. #ifndef GOLDOBJ
  9. STATIC_DCL boolean FDECL(query_classes, (char *,boolean *,boolean *,
  10. 		const char *,struct obj *,BOOLEAN_P,BOOLEAN_P,int *));
  11. #else
  12. STATIC_DCL boolean FDECL(query_classes, (char *,boolean *,boolean *,
  13. 		const char *,struct obj *,BOOLEAN_P,int *));
  14. #endif
  15. STATIC_DCL void FDECL(check_here, (BOOLEAN_P));
  16. STATIC_DCL boolean FDECL(n_or_more, (struct obj *));
  17. STATIC_DCL boolean FDECL(all_but_uchain, (struct obj *));
  18. #if 0 /* not used */
  19. STATIC_DCL boolean FDECL(allow_cat_no_uchain, (struct obj *));
  20. #endif
  21. STATIC_DCL int FDECL(autopick, (struct obj*, int, menu_item **));
  22. STATIC_DCL int FDECL(count_categories, (struct obj *,int));
  23. STATIC_DCL long FDECL(carry_count,
  24. 		      (struct obj *,struct obj *,long,BOOLEAN_P,int *,int *));
  25. STATIC_DCL int FDECL(lift_object, (struct obj *,struct obj *,long *,BOOLEAN_P));
  26. STATIC_DCL boolean FDECL(mbag_explodes, (struct obj *,int));
  27. STATIC_PTR int FDECL(in_container,(struct obj *));
  28. STATIC_PTR int FDECL(ck_bag,(struct obj *));
  29. STATIC_PTR int FDECL(out_container,(struct obj *));
  30. STATIC_DCL long FDECL(mbag_item_gone, (int,struct obj *));
  31. STATIC_DCL void FDECL(observe_quantum_cat, (struct obj *));
  32. STATIC_DCL int FDECL(menu_loot, (int, struct obj *, BOOLEAN_P));
  33. STATIC_DCL int FDECL(in_or_out_menu, (const char *,struct obj *, BOOLEAN_P, BOOLEAN_P));
  34. STATIC_DCL int FDECL(container_at, (int, int, BOOLEAN_P));
  35. STATIC_DCL boolean FDECL(able_to_loot, (int, int));
  36. STATIC_DCL boolean FDECL(mon_beside, (int, int));
  37.  
  38. /* define for query_objlist() and autopickup() */
  39. #define FOLLOW(curr, flags) \
  40. (((flags) & BY_NEXTHERE) ? (curr)->nexthere : (curr)->nobj)
  41.  
  42. /*
  43. *  How much the weight of the given container will change when the given
  44. *  object is removed from it.  This calculation must match the one used
  45. *  by weight() in mkobj.c.
  46. */
  47. #define DELTA_CWT(cont,obj)		\
  48. ((cont)->cursed ? (obj)->owt * 2 :	\
  49. 		      1 + ((obj)->owt / ((cont)->blessed ? 4 : 2)))
  50. #define GOLD_WT(n)		(((n) + 50L) / 100L)
  51. /* if you can figure this out, give yourself a hearty pat on the back... */
  52. #define GOLD_CAPACITY(w,n)	(((w) * -100L) - ((n) + 50L) - 1L)
  53.  
  54. static const char moderateloadmsg[] = "You have a little trouble lifting";
  55. static const char nearloadmsg[] = "You have much trouble lifting";
  56. static const char overloadmsg[] = "You have extreme difficulty lifting";

simple_look[edit]

  1. /* BUG: this lets you look at cockatrice corpses while blind without
  2. touching them */
  3. /* much simpler version of the look-here code; used by query_classes() */
  4. STATIC_OVL void
  5. simple_look(otmp, here)
  6. struct obj *otmp;	/* list of objects */
  7. boolean here;		/* flag for type of obj list linkage */
  8. {
  9. 	/* Neither of the first two cases is expected to happen, since
  10. 	 * we're only called after multiple classes of objects have been
  11. 	 * detected, hence multiple objects must be present.
  12. 	 */
  13. 	if (!otmp) {
  14. 	    impossible("simple_look(null)");
  15. 	} else if (!(here ? otmp->nexthere : otmp->nobj)) {
  16. 	    pline("%s", doname(otmp));
  17. 	} else {
  18. 	    winid tmpwin = create_nhwindow(NHW_MENU);
  19. 	    putstr(tmpwin, 0, "");
  20. 	    do {
  21. 		putstr(tmpwin, 0, doname(otmp));
  22. 		otmp = here ? otmp->nexthere : otmp->nobj;
  23. 	    } while (otmp);
  24. 	    display_nhwindow(tmpwin, TRUE);
  25. 	    destroy_nhwindow(tmpwin);
  26. 	}
  27. }

collect_obj_classes[edit]

  1. #ifndef GOLDOBJ
  2. int
  3. collect_obj_classes(ilets, otmp, here, incl_gold, filter, itemcount)
  4. char ilets[];
  5. register struct obj *otmp;
  6. boolean here, incl_gold;
  7. boolean FDECL((*filter),(OBJ_P));
  8. int *itemcount;
  9. #else
  10. int
  11. collect_obj_classes(ilets, otmp, here, filter, itemcount)
  12. char ilets[];
  13. register struct obj *otmp;
  14. boolean here;
  15. boolean FDECL((*filter),(OBJ_P));
  16. int *itemcount;
  17. #endif
  18. {
  19. 	register int iletct = 0;
  20. 	register char c;
  21.  
  22. 	*itemcount = 0;
  23. #ifndef GOLDOBJ
  24. 	if (incl_gold)
  25. 	    ilets[iletct++] = def_oc_syms[COIN_CLASS];
  26. #endif
  27. 	ilets[iletct] = '\0'; /* terminate ilets so that index() will work */
  28. 	while (otmp) {
  29. 	    c = def_oc_syms[(int)otmp->oclass];
  30. 	    if (!index(ilets, c) && (!filter || (*filter)(otmp)))
  31. 		ilets[iletct++] = c,  ilets[iletct] = '\0';
  32. 	    *itemcount += 1;
  33. 	    otmp = here ? otmp->nexthere : otmp->nobj;
  34. 	}
  35.  
  36. 	return iletct;
  37. }

query_classes[edit]

  1. /*
  2. * Suppose some '?' and '!' objects are present, but '/' objects aren't:
  3. *	"a" picks all items without further prompting;
  4. *	"A" steps through all items, asking one by one;
  5. *	"?" steps through '?' items, asking, and ignores '!' ones;
  6. *	"/" becomes 'A', since no '/' present;
  7. *	"?a" or "a?" picks all '?' without further prompting;
  8. *	"/a" or "a/" becomes 'A' since there aren't any '/'
  9. *	    (bug fix:  3.1.0 thru 3.1.3 treated it as "a");
  10. *	"?/a" or "a?/" or "/a?",&c picks all '?' even though no '/'
  11. *	    (ie, treated as if it had just been "?a").
  12. */
  13. #ifndef GOLDOBJ
  14. STATIC_OVL boolean
  15. query_classes(oclasses, one_at_a_time, everything, action, objs,
  16. 	      here, incl_gold, menu_on_demand)
  17. char oclasses[];
  18. boolean *one_at_a_time, *everything;
  19. const char *action;
  20. struct obj *objs;
  21. boolean here, incl_gold;
  22. int *menu_on_demand;
  23. #else
  24. STATIC_OVL boolean
  25. query_classes(oclasses, one_at_a_time, everything, action, objs,
  26. 	      here, menu_on_demand)
  27. char oclasses[];
  28. boolean *one_at_a_time, *everything;
  29. const char *action;
  30. struct obj *objs;
  31. boolean here;
  32. int *menu_on_demand;
  33. #endif
  34. {
  35. 	char ilets[20], inbuf[BUFSZ];
  36. 	int iletct, oclassct;
  37. 	boolean not_everything;
  38. 	char qbuf[QBUFSZ];
  39. 	boolean m_seen;
  40. 	int itemcount;
  41.  
  42. 	oclasses[oclassct = 0] = '\0';
  43. 	*one_at_a_time = *everything = m_seen = FALSE;
  44. 	iletct = collect_obj_classes(ilets, objs, here,
  45. #ifndef GOLDOBJ
  46. 				     incl_gold,
  47. #endif
  48. 				     (boolean FDECL((*),(OBJ_P))) 0, &itemcount);
  49. 	if (iletct == 0) {
  50. 		return FALSE;
  51. 	} else if (iletct == 1) {
  52. 		oclasses[0] = def_char_to_objclass(ilets[0]);
  53. 		oclasses[1] = '\0';
  54. 		if (itemcount && menu_on_demand) {
  55. 			ilets[iletct++] = 'm';
  56. 			*menu_on_demand = 0;
  57. 			ilets[iletct] = '\0';
  58. 		}
  59. 	} else  {	/* more than one choice available */
  60. 		const char *where = 0;
  61. 		register char sym, oc_of_sym, *p;
  62. 		/* additional choices */
  63. 		ilets[iletct++] = ' ';
  64. 		ilets[iletct++] = 'a';
  65. 		ilets[iletct++] = 'A';
  66. 		ilets[iletct++] = (objs == invent ? 'i' : ':');
  67. 		if (menu_on_demand) {
  68. 			ilets[iletct++] = 'm';
  69. 			*menu_on_demand = 0;
  70. 		}
  71. 		ilets[iletct] = '\0';
  72. ask_again:
  73. 		oclasses[oclassct = 0] = '\0';
  74. 		*one_at_a_time = *everything = FALSE;
  75. 		not_everything = FALSE;
  76. 		Sprintf(qbuf,"What kinds of thing do you want to %s? [%s]",
  77. 			action, ilets);
  78. 		getlin(qbuf,inbuf);
  79. 		if (*inbuf == '\033') return FALSE;
  80.  
  81. 		for (p = inbuf; (sym = *p++); ) {
  82. 		    /* new A function (selective all) added by GAN 01/09/87 */
  83. 		    if (sym == ' ') continue;
  84. 		    else if (sym == 'A') *one_at_a_time = TRUE;
  85. 		    else if (sym == 'a') *everything = TRUE;
  86. 		    else if (sym == ':') {
  87. 			simple_look(objs, here);  /* dumb if objs==invent */
  88. 			goto ask_again;
  89. 		    } else if (sym == 'i') {
  90. 			(void) display_inventory((char *)0, TRUE);
  91. 			goto ask_again;
  92. 		    } else if (sym == 'm') {
  93. 			m_seen = TRUE;
  94. 		    } else {
  95. 			oc_of_sym = def_char_to_objclass(sym);
  96. 			if (index(ilets,sym)) {
  97. 			    add_valid_menu_class(oc_of_sym);
  98. 			    oclasses[oclassct++] = oc_of_sym;
  99. 			    oclasses[oclassct] = '\0';
  100. 			} else {
  101. 			    if (!where)
  102. 				where = !strcmp(action,"pick up")  ? "here" :
  103. 					!strcmp(action,"take out") ?
  104. 							    "inside" : "";
  105. 			    if (*where)
  106. 				There("are no %c's %s.", sym, where);
  107. 			    else
  108. 				You("have no %c's.", sym);
  109. 			    not_everything = TRUE;
  110. 			}
  111. 		    }
  112. 		}
  113. 		if (m_seen && menu_on_demand) {
  114. 			*menu_on_demand = (*everything || !oclassct) ? -2 : -3;
  115. 			return FALSE;
  116. 		}
  117. 		if (!oclassct && (!*everything || not_everything)) {
  118. 		    /* didn't pick anything,
  119. 		       or tried to pick something that's not present */
  120. 		    *one_at_a_time = TRUE;	/* force 'A' */
  121. 		    *everything = FALSE;	/* inhibit 'a' */
  122. 		}
  123. 	}
  124. 	return TRUE;
  125. }

check_here[edit]

  1. /* look at the objects at our location, unless there are too many of them */
  2. STATIC_OVL void
  3. check_here(picked_some)
  4. boolean picked_some;
  5. {
  6. 	register struct obj *obj;
  7. 	register int ct = 0;
  8.  
  9. 	/* count the objects here */
  10. 	for (obj = level.objects[u.ux][u.uy]; obj; obj = obj->nexthere) {
  11. 	    if (obj != uchain)
  12. 		ct++;
  13. 	}
  14.  
  15. 	/* If there are objects here, take a look. */
  16. 	if (ct) {
  17. 	    if (flags.run) nomul(0);
  18. 	    flush_screen(1);
  19. 	    (void) look_here(ct, picked_some);
  20. 	} else {
  21. 	    read_engr_at(u.ux,u.uy);
  22. 	}
  23. }

n_or_more[edit]

  1. /* Value set by query_objlist() for n_or_more(). */
  2. static long val_for_n_or_more;
  3.  
  4. /* query_objlist callback: return TRUE if obj's count is >= reference value */
  5. STATIC_OVL boolean
  6. n_or_more(obj)
  7. struct obj *obj;
  8. {
  9. if (obj == uchain) return FALSE;
  10. return (obj->quan >= val_for_n_or_more);
  11. }

add_valid_menu_class[edit]

  1. /* List of valid menu classes for query_objlist() and allow_category callback */
  2. static char valid_menu_classes[MAXOCLASSES + 2];
  3.  
  4. void
  5. add_valid_menu_class(c)
  6. int c;
  7. {
  8. 	static int vmc_count = 0;
  9.  
  10. 	if (c == 0)  /* reset */
  11. 	  vmc_count = 0;
  12. 	else
  13. 	  valid_menu_classes[vmc_count++] = (char)c;
  14. 	valid_menu_classes[vmc_count] = '\0';
  15. }

all_but_uchain[edit]

  1. /* query_objlist callback: return TRUE if not uchain */
  2. STATIC_OVL boolean
  3. all_but_uchain(obj)
  4. struct obj *obj;
  5. {
  6. return (obj != uchain);
  7. }

allow_all[edit]

  1. /* query_objlist callback: return TRUE */
  2. /*ARGSUSED*/
  3. boolean
  4. allow_all(obj)
  5. struct obj *obj;
  6. {
  7. return TRUE;
  8. }

allow_category[edit]

  1. boolean
  2. allow_category(obj)
  3. struct obj *obj;
  4. {
  5. if (Role_if(PM_PRIEST)) obj->bknown = TRUE;
  6. if (((index(valid_menu_classes,'u') != (char *)0) && obj->unpaid) ||
  7. 	(index(valid_menu_classes, obj->oclass) != (char *)0))
  8. 	return TRUE;
  9. else if (((index(valid_menu_classes,'U') != (char *)0) &&
  10. 	(obj->oclass != COIN_CLASS && obj->bknown && !obj->blessed && !obj->cursed)))
  11. 	return TRUE;
  12. else if (((index(valid_menu_classes,'B') != (char *)0) &&
  13. 	(obj->oclass != COIN_CLASS && obj->bknown && obj->blessed)))
  14. 	return TRUE;
  15. else if (((index(valid_menu_classes,'C') != (char *)0) &&
  16. 	(obj->oclass != COIN_CLASS && obj->bknown && obj->cursed)))
  17. 	return TRUE;
  18. else if (((index(valid_menu_classes,'X') != (char *)0) &&
  19. 	(obj->oclass != COIN_CLASS && !obj->bknown)))
  20. 	return TRUE;
  21. else
  22. 	return FALSE;
  23. }

allow_cat_no_uchain[edit]

  1. #if 0 /* not used */
  2. /* query_objlist callback: return TRUE if valid category (class), no uchain */
  3. STATIC_OVL boolean
  4. allow_cat_no_uchain(obj)
  5. struct obj *obj;
  6. {
  7. if ((obj != uchain) &&
  8. 	(((index(valid_menu_classes,'u') != (char *)0) && obj->unpaid) ||
  9. 	(index(valid_menu_classes, obj->oclass) != (char *)0)))
  10. 	return TRUE;
  11. else
  12. 	return FALSE;
  13. }
  14. #endif

is_worn_by_type[edit]

  1. /* query_objlist callback: return TRUE if valid class and worn */
  2. boolean
  3. is_worn_by_type(otmp)
  4. register struct obj *otmp;
  5. {
  6. 	return((boolean)(!!(otmp->owornmask &
  7. 			(W_ARMOR | W_RING | W_AMUL | W_TOOL | W_WEP | W_SWAPWEP | W_QUIVER)))
  8. 	        && (index(valid_menu_classes, otmp->oclass) != (char *)0));
  9. }

pickup[edit]

  1. /*
  2. * Have the hero pick things from the ground
  3. * or a monster's inventory if swallowed.
  4. *
  5. * Arg what:
  6. *	>0  autopickup
  7. *	=0  interactive
  8. *	<0  pickup count of something
  9. *
  10. * Returns 1 if tried to pick something up, whether
  11. * or not it succeeded.
  12. */
  13. int
  14. pickup(what)
  15. int what;		/* should be a long */
  16. {
  17. 	int i, n, res, count, n_tried = 0, n_picked = 0;
  18. 	menu_item *pick_list = (menu_item *) 0;
  19. 	boolean autopickup = what > 0;
  20. 	struct obj *objchain;
  21. 	int traverse_how;
  22.  
  23. 	if (what < 0)		/* pick N of something */
  24. 	    count = -what;
  25. 	else			/* pick anything */
  26. 	    count = 0;
  27.  
  28. 	if (!u.uswallow) {
  29. 		struct trap *ttmp = t_at(u.ux, u.uy);
  30. 		/* no auto-pick if no-pick move, nothing there, or in a pool */
  31. 		if (autopickup && (flags.nopick || !OBJ_AT(u.ux, u.uy) ||
  32. 			(is_pool(u.ux, u.uy) && !Underwater) || is_lava(u.ux, u.uy))) {
  33. 			read_engr_at(u.ux, u.uy);
  34. 			return (0);
  35. 		}
  36.  
  37. 		/* no pickup if levitating & not on air or water level */
  38. 		if (!can_reach_floor()) {
  39. 		    if ((multi && !flags.run) || (autopickup && !flags.pickup))
  40. 			read_engr_at(u.ux, u.uy);
  41. 		    return (0);
  42. 		}
  43. 		if (ttmp && ttmp->tseen) {
  44. 		    /* Allow pickup from holes and trap doors that you escaped
  45. 		     * from because that stuff is teetering on the edge just
  46. 		     * like you, but not pits, because there is an elevation
  47. 		     * discrepancy with stuff in pits.
  48. 		     */
  49. 		    if ((ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT) &&
  50. 			(!u.utrap || (u.utrap && u.utraptype != TT_PIT))) {
  51. 			read_engr_at(u.ux, u.uy);
  52. 			return(0);
  53. 		    }
  54. 		}
  55. 		/* multi && !flags.run means they are in the middle of some other
  56. 		 * action, or possibly paralyzed, sleeping, etc.... and they just
  57. 		 * teleported onto the object.  They shouldn't pick it up.
  58. 		 */
  59. 		if ((multi && !flags.run) || (autopickup && !flags.pickup)) {
  60. 		    check_here(FALSE);
  61. 		    return (0);
  62. 		}
  63. 		if (notake(youmonst.data)) {
  64. 		    if (!autopickup)
  65. 			You("are physically incapable of picking anything up.");
  66. 		    else
  67. 			check_here(FALSE);
  68. 		    return (0);
  69. 		}
  70.  
  71. 		/* if there's anything here, stop running */
  72. 		if (OBJ_AT(u.ux,u.uy) && flags.run && flags.run != 8 && !flags.nopick) nomul(0);
  73. 	}
  74.  
  75. 	add_valid_menu_class(0);	/* reset */
  76. 	if (!u.uswallow) {
  77. 		objchain = level.objects[u.ux][u.uy];
  78. 		traverse_how = BY_NEXTHERE;
  79. 	} else {
  80. 		objchain = u.ustuck->minvent;
  81. 		traverse_how = 0;	/* nobj */
  82. 	}
  83. 	/*
  84. 	 * Start the actual pickup process.  This is split into two main
  85. 	 * sections, the newer menu and the older "traditional" methods.
  86. 	 * Automatic pickup has been split into its own menu-style routine
  87. 	 * to make things less confusing.
  88. 	 */
  89. 	if (autopickup) {
  90. 	    n = autopick(objchain, traverse_how, &pick_list);
  91. 	    goto menu_pickup;
  92. 	}
  93.  
  94. 	if (flags.menu_style != MENU_TRADITIONAL || iflags.menu_requested) {
  95.  
  96. 	    /* use menus exclusively */
  97. 	    if (count) {	/* looking for N of something */
  98. 		char buf[QBUFSZ];
  99. 		Sprintf(buf, "Pick %d of what?", count);
  100. 		val_for_n_or_more = count;	/* set up callback selector */
  101. 		n = query_objlist(buf, objchain,
  102. 			    traverse_how|AUTOSELECT_SINGLE|INVORDER_SORT,
  103. 			    &pick_list, PICK_ONE, n_or_more);
  104. 		/* correct counts, if any given */
  105. 		for (i = 0; i < n; i++)
  106. 		    pick_list[i].count = count;
  107. 	    } else {
  108. 		n = query_objlist("Pick up what?", objchain,
  109. 			traverse_how|AUTOSELECT_SINGLE|INVORDER_SORT|FEEL_COCKATRICE,
  110. 			&pick_list, PICK_ANY, all_but_uchain);
  111. 	    }
  112. menu_pickup:
  113. 	    n_tried = n;
  114. 	    for (n_picked = i = 0 ; i < n; i++) {
  115. 		res = pickup_object(pick_list[i].item.a_obj,pick_list[i].count,
  116. 					FALSE);
  117. 		if (res < 0) break;	/* can't continue */
  118. 		n_picked += res;
  119. 	    }
  120. 	    if (pick_list) free((genericptr_t)pick_list);
  121.  
  122. 	} else {
  123. 	    /* old style interface */
  124. 	    int ct = 0;
  125. 	    long lcount;
  126. 	    boolean all_of_a_type, selective;
  127. 	    char oclasses[MAXOCLASSES];
  128. 	    struct obj *obj, *obj2;
  129.  
  130. 	    oclasses[0] = '\0';		/* types to consider (empty for all) */
  131. 	    all_of_a_type = TRUE;	/* take all of considered types */
  132. 	    selective = FALSE;		/* ask for each item */
  133.  
  134. 	    /* check for more than one object */
  135. 	    for (obj = objchain;
  136. 		  obj; obj = (traverse_how == BY_NEXTHERE) ? obj->nexthere : obj->nobj)
  137. 		ct++;
  138.  
  139. 	    if (ct == 1 && count) {
  140. 		/* if only one thing, then pick it */
  141. 		obj = objchain;
  142. 		lcount = min(obj->quan, (long)count);
  143. 		n_tried++;
  144. 		if (pickup_object(obj, lcount, FALSE) > 0)
  145. 		    n_picked++;	/* picked something */
  146. 		goto end_query;
  147.  
  148. 	    } else if (ct >= 2) {
  149. 		int via_menu = 0;
  150.  
  151. 		There("are %s objects here.",
  152. 		      (ct <= 10) ? "several" : "many");
  153. 		if (!query_classes(oclasses, &selective, &all_of_a_type,
  154. 				   "pick up", objchain,
  155. 				   traverse_how == BY_NEXTHERE,
  156. #ifndef GOLDOBJ
  157. 				   FALSE,
  158. #endif
  159. 				   &via_menu)) {
  160. 		    if (!via_menu) return (0);
  161. 		    n = query_objlist("Pick up what?",
  162. 				  objchain,
  163. 				  traverse_how|(selective ? 0 : INVORDER_SORT),
  164. 				  &pick_list, PICK_ANY,
  165. 				  via_menu == -2 ? allow_all : allow_category);
  166. 		    goto menu_pickup;
  167. 		}
  168. 	    }
  169.  
  170. 	    for (obj = objchain; obj; obj = obj2) {
  171. 		if (traverse_how == BY_NEXTHERE)
  172. 			obj2 = obj->nexthere;	/* perhaps obj will be picked up */
  173. 		else
  174. 			obj2 = obj->nobj;
  175. 		lcount = -1L;
  176.  
  177. 		if (!selective && oclasses[0] && !index(oclasses,obj->oclass))
  178. 		    continue;
  179.  
  180. 		if (!all_of_a_type) {
  181. 		    char qbuf[BUFSZ];
  182. 		    Sprintf(qbuf, "Pick up %s?",
  183. 			safe_qbuf("", sizeof("Pick up ?"), doname(obj),
  184. 					an(simple_typename(obj->otyp)), "something"));
  185. 		    switch ((obj->quan < 2L) ? ynaq(qbuf) : ynNaq(qbuf)) {
  186. 		    case 'q': goto end_query;	/* out 2 levels */
  187. 		    case 'n': continue;
  188. 		    case 'a':
  189. 			all_of_a_type = TRUE;
  190. 			if (selective) {
  191. 			    selective = FALSE;
  192. 			    oclasses[0] = obj->oclass;
  193. 			    oclasses[1] = '\0';
  194. 			}
  195. 			break;
  196. 		    case '#':	/* count was entered */
  197. 			if (!yn_number) continue; /* 0 count => No */
  198. 			lcount = (long) yn_number;
  199. 			if (lcount > obj->quan) lcount = obj->quan;
  200. 			/* fall thru */
  201. 		    default:	/* 'y' */
  202. 			break;
  203. 		    }
  204. 		}
  205. 		if (lcount == -1L) lcount = obj->quan;
  206.  
  207. 		n_tried++;
  208. 		if ((res = pickup_object(obj, lcount, FALSE)) < 0) break;
  209. 		n_picked += res;
  210. 	    }
  211. end_query:
  212. 	    ;	/* semicolon needed by brain-damaged compilers */
  213. 	}
  214.  
  215. 	if (!u.uswallow) {
  216. 		if (!OBJ_AT(u.ux,u.uy)) u.uundetected = 0;
  217.  
  218. 		/* position may need updating (invisible hero) */
  219. 		if (n_picked) newsym(u.ux,u.uy);
  220.  
  221. 		/* see whether there's anything else here, after auto-pickup is done */
  222. 		if (autopickup) check_here(n_picked > 0);
  223. 	}
  224. 	return (n_tried > 0);
  225. }

is_autopickup_exception[edit]

  1. #ifdef AUTOPICKUP_EXCEPTIONS
  2. boolean
  3. is_autopickup_exception(obj, grab)
  4. struct obj *obj;
  5. boolean grab;	 /* forced pickup, rather than forced leave behind? */
  6. {
  7. 	/*
  8. 	 *  Does the text description of this match an exception?
  9. 	 */
  10. 	char *objdesc = makesingular(doname(obj));
  11. 	struct autopickup_exception *ape = (grab) ?
  12. 					iflags.autopickup_exceptions[AP_GRAB] :
  13. 					iflags.autopickup_exceptions[AP_LEAVE];
  14. 	while (ape) {
  15. 		if (pmatch(ape->pattern, objdesc)) return TRUE;
  16. 		ape = ape->next;
  17. 	}
  18. 	return FALSE;
  19. }
  20. #endif /* AUTOPICKUP_EXCEPTIONS */

autopick[edit]

  1. /*
  2. * Pick from the given list using flags.pickup_types.  Return the number
  3. * of items picked (not counts).  Create an array that returns pointers
  4. * and counts of the items to be picked up.  If the number of items
  5. * picked is zero, the pickup list is left alone.  The caller of this
  6. * function must free the pickup list.
  7. */
  8. STATIC_OVL int
  9. autopick(olist, follow, pick_list)
  10. struct obj *olist;	/* the object list */
  11. int follow;		/* how to follow the object list */
  12. menu_item **pick_list;	/* list of objects and counts to pick up */
  13. {
  14. 	menu_item *pi;	/* pick item */
  15. 	struct obj *curr;
  16. 	int n;
  17. 	const char *otypes = flags.pickup_types;
  18.  
  19. 	/* first count the number of eligible items */
  20. 	for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow))
  21.  
  22.  
  23. #ifndef AUTOPICKUP_EXCEPTIONS
  24. 	    if (!*otypes || index(otypes, curr->oclass))
  25. #else
  26. 	    if ((!*otypes || index(otypes, curr->oclass) ||
  27. 		 is_autopickup_exception(curr, TRUE)) &&
  28. 	    	 !is_autopickup_exception(curr, FALSE))
  29. #endif
  30. 		n++;
  31.  
  32. 	if (n) {
  33. 	    *pick_list = pi = (menu_item *) alloc(sizeof(menu_item) * n);
  34. 	    for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow))
  35. #ifndef AUTOPICKUP_EXCEPTIONS
  36. 		if (!*otypes || index(otypes, curr->oclass)) {
  37. #else
  38. 	    if ((!*otypes || index(otypes, curr->oclass) ||
  39. 		 is_autopickup_exception(curr, TRUE)) &&
  40. 	    	 !is_autopickup_exception(curr, FALSE)) {
  41. #endif
  42. 		    pi[n].item.a_obj = curr;
  43. 		    pi[n].count = curr->quan;
  44. 		    n++;
  45. 		}
  46. 	}
  47. 	return n;
  48. }

query_objlist[edit]

  1. /*
  2. * Put up a menu using the given object list.  Only those objects on the
  3. * list that meet the approval of the allow function are displayed.  Return
  4. * a count of the number of items selected, as well as an allocated array of
  5. * menu_items, containing pointers to the objects selected and counts.  The
  6. * returned counts are guaranteed to be in bounds and non-zero.
  7. *
  8. * Query flags:
  9. *	BY_NEXTHERE	  - Follow object list via nexthere instead of nobj.
  10. *	AUTOSELECT_SINGLE - Don't ask if only 1 object qualifies - just
  11. *			    use it.
  12. *	USE_INVLET	  - Use object's invlet.
  13. *	INVORDER_SORT	  - Use hero's pack order.
  14. *	SIGNAL_NOMENU	  - Return -1 rather than 0 if nothing passes "allow".
  15. */
  16. int
  17. query_objlist(qstr, olist, qflags, pick_list, how, allow)
  18. const char *qstr;		/* query string */
  19. struct obj *olist;		/* the list to pick from */
  20. int qflags;			/* options to control the query */
  21. menu_item **pick_list;		/* return list of items picked */
  22. int how;			/* type of query */
  23. boolean FDECL((*allow), (OBJ_P));/* allow function */
  24. {
  25. 	int n;
  26. 	winid win;
  27. 	struct obj *curr, *last;
  28. 	char *pack;
  29. 	anything any;
  30. 	boolean printed_type_name;
  31.  
  32. 	*pick_list = (menu_item *) 0;
  33. 	if (!olist) return 0;
  34.  
  35. 	/* count the number of items allowed */
  36. 	for (n = 0, last = 0, curr = olist; curr; curr = FOLLOW(curr, qflags))
  37. 	    if ((*allow)(curr)) {
  38. 		last = curr;
  39. 		n++;
  40. 	    }
  41.  
  42. 	if (n == 0)	/* nothing to pick here */
  43. 	    return (qflags & SIGNAL_NOMENU) ? -1 : 0;
  44.  
  45. 	if (n == 1 && (qflags & AUTOSELECT_SINGLE)) {
  46. 	    *pick_list = (menu_item *) alloc(sizeof(menu_item));
  47. 	    (*pick_list)->item.a_obj = last;
  48. 	    (*pick_list)->count = last->quan;
  49. 	    return 1;
  50. 	}
  51.  
  52. 	win = create_nhwindow(NHW_MENU);
  53. 	start_menu(win);
  54. 	any.a_obj = (struct obj *) 0;
  55.  
  56. 	/*
  57. 	 * Run through the list and add the objects to the menu.  If
  58. 	 * INVORDER_SORT is set, we'll run through the list once for
  59. 	 * each type so we can group them.  The allow function will only
  60. 	 * be called once per object in the list.
  61. 	 */
  62. 	pack = flags.inv_order;
  63. 	do {
  64. 	    printed_type_name = FALSE;
  65. 	    for (curr = olist; curr; curr = FOLLOW(curr, qflags)) {
  66. 		if ((qflags & FEEL_COCKATRICE) && curr->otyp == CORPSE &&
  67. 		     will_feel_cockatrice(curr, FALSE)) {
  68. 			destroy_nhwindow(win);	/* stop the menu and revert */
  69. 			(void) look_here(0, FALSE);
  70. 			return 0;
  71. 		}
  72. 		if ((!(qflags & INVORDER_SORT) || curr->oclass == *pack)
  73. 							&& (*allow)(curr)) {
  74.  
  75. 		    /* if sorting, print type name (once only) */
  76. 		    if (qflags & INVORDER_SORT && !printed_type_name) {
  77. 			any.a_obj = (struct obj *) 0;
  78. 			add_menu(win, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
  79. 					let_to_name(*pack, FALSE), MENU_UNSELECTED);
  80. 			printed_type_name = TRUE;
  81. 		    }
  82.  
  83. 		    any.a_obj = curr;
  84. 		    add_menu(win, obj_to_glyph(curr), &any,
  85. 			    qflags & USE_INVLET ? curr->invlet : 0,
  86. 			    def_oc_syms[(int)objects[curr->otyp].oc_class],
  87. 			    ATR_NONE, doname(curr), MENU_UNSELECTED);
  88. 		}
  89. 	    }
  90. 	    pack++;
  91. 	} while (qflags & INVORDER_SORT && *pack);
  92.  
  93. 	end_menu(win, qstr);
  94. 	n = select_menu(win, how, pick_list);
  95. 	destroy_nhwindow(win);
  96.  
  97. 	if (n > 0) {
  98. 	    menu_item *mi;
  99. 	    int i;
  100.  
  101. 	    /* fix up counts:  -1 means no count used => pick all */
  102. 	    for (i = 0, mi = *pick_list; i < n; i++, mi++)
  103. 		if (mi->count == -1L || mi->count > mi->item.a_obj->quan)
  104. 		    mi->count = mi->item.a_obj->quan;
  105. 	} else if (n < 0) {
  106. 	    n = 0;	/* caller's don't expect -1 */
  107. 	}
  108. 	return n;
  109. }

query_category[edit]

  1. /*
  2. * allow menu-based category (class) selection (for Drop,take off etc.)
  3. *
  4. */
  5. int
  6. query_category(qstr, olist, qflags, pick_list, how)
  7. const char *qstr;		/* query string */
  8. struct obj *olist;		/* the list to pick from */
  9. int qflags;			/* behaviour modification flags */
  10. menu_item **pick_list;		/* return list of items picked */
  11. int how;			/* type of query */
  12. {
  13. 	int n;
  14. 	winid win;
  15. 	struct obj *curr;
  16. 	char *pack;
  17. 	anything any;
  18. 	boolean collected_type_name;
  19. 	char invlet;
  20. 	int ccount;
  21. 	boolean do_unpaid = FALSE;
  22. 	boolean do_blessed = FALSE, do_cursed = FALSE, do_uncursed = FALSE,
  23. 	    do_buc_unknown = FALSE;
  24. 	int num_buc_types = 0;
  25.  
  26. 	*pick_list = (menu_item *) 0;
  27. 	if (!olist) return 0;
  28. 	if ((qflags & UNPAID_TYPES) && count_unpaid(olist)) do_unpaid = TRUE;
  29. 	if ((qflags & BUC_BLESSED) && count_buc(olist, BUC_BLESSED)) {
  30. 	    do_blessed = TRUE;
  31. 	    num_buc_types++;
  32. 	}
  33. 	if ((qflags & BUC_CURSED) && count_buc(olist, BUC_CURSED)) {
  34. 	    do_cursed = TRUE;
  35. 	    num_buc_types++;
  36. 	}
  37. 	if ((qflags & BUC_UNCURSED) && count_buc(olist, BUC_UNCURSED)) {
  38. 	    do_uncursed = TRUE;
  39. 	    num_buc_types++;
  40. 	}
  41. 	if ((qflags & BUC_UNKNOWN) && count_buc(olist, BUC_UNKNOWN)) {
  42. 	    do_buc_unknown = TRUE;
  43. 	    num_buc_types++;
  44. 	}
  45.  
  46. 	ccount = count_categories(olist, qflags);
  47. 	/* no point in actually showing a menu for a single category */
  48. 	if (ccount == 1 && !do_unpaid && num_buc_types <= 1 && !(qflags & BILLED_TYPES)) {
  49. 	    for (curr = olist; curr; curr = FOLLOW(curr, qflags)) {
  50. 		if ((qflags & WORN_TYPES) &&
  51. 		    !(curr->owornmask & (W_ARMOR|W_RING|W_AMUL|W_TOOL|W_WEP|W_SWAPWEP|W_QUIVER)))
  52. 		    continue;
  53. 		break;
  54. 	    }
  55. 	    if (curr) {
  56. 		*pick_list = (menu_item *) alloc(sizeof(menu_item));
  57. 		(*pick_list)->item.a_int = curr->oclass;
  58. 		return 1;
  59. 	    } else {
  60. #ifdef DEBUG
  61. 		impossible("query_category: no single object match");
  62. #endif
  63. 	    }
  64. 	    return 0;
  65. 	}
  66.  
  67. 	win = create_nhwindow(NHW_MENU);
  68. 	start_menu(win);
  69. 	pack = flags.inv_order;
  70. 	if ((qflags & ALL_TYPES) && (ccount > 1)) {
  71. 		invlet = 'a';
  72. 		any.a_void = 0;
  73. 		any.a_int = ALL_TYPES_SELECTED;
  74. 		add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
  75. 		       (qflags & WORN_TYPES) ? "All worn types" : "All types",
  76. 			MENU_UNSELECTED);
  77. 		invlet = 'b';
  78. 	} else
  79. 		invlet = 'a';
  80. 	do {
  81. 	    collected_type_name = FALSE;
  82. 	    for (curr = olist; curr; curr = FOLLOW(curr, qflags)) {
  83. 		if (curr->oclass == *pack) {
  84. 		   if ((qflags & WORN_TYPES) &&
  85. 		   		!(curr->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL |
  86. 		    	W_WEP | W_SWAPWEP | W_QUIVER)))
  87. 			 continue;
  88. 		   if (!collected_type_name) {
  89. 			any.a_void = 0;
  90. 			any.a_int = curr->oclass;
  91. 			add_menu(win, NO_GLYPH, &any, invlet++,
  92. 				def_oc_syms[(int)objects[curr->otyp].oc_class],
  93. 				ATR_NONE, let_to_name(*pack, FALSE),
  94. 				MENU_UNSELECTED);
  95. 			collected_type_name = TRUE;
  96. 		   }
  97. 		}
  98. 	    }
  99. 	    pack++;
  100. 	    if (invlet >= 'u') {
  101. 		impossible("query_category: too many categories");
  102. 		return 0;
  103. 	    }
  104. 	} while (*pack);
  105. 	/* unpaid items if there are any */
  106. 	if (do_unpaid) {
  107. 		invlet = 'u';
  108. 		any.a_void = 0;
  109. 		any.a_int = 'u';
  110. 		add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
  111. 			"Unpaid items", MENU_UNSELECTED);
  112. 	}
  113. 	/* billed items: checked by caller, so always include if BILLED_TYPES */
  114. 	if (qflags & BILLED_TYPES) {
  115. 		invlet = 'x';
  116. 		any.a_void = 0;
  117. 		any.a_int = 'x';
  118. 		add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
  119. 			 "Unpaid items already used up", MENU_UNSELECTED);
  120. 	}
  121. 	if (qflags & CHOOSE_ALL) {
  122. 		invlet = 'A';
  123. 		any.a_void = 0;
  124. 		any.a_int = 'A';
  125. 		add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
  126. 			(qflags & WORN_TYPES) ?
  127. 			"Auto-select every item being worn" :
  128. 			"Auto-select every item", MENU_UNSELECTED);
  129. 	}
  130. 	/* items with b/u/c/unknown if there are any */
  131. 	if (do_blessed) {
  132. 		invlet = 'B';
  133. 		any.a_void = 0;
  134. 		any.a_int = 'B';
  135. 		add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
  136. 			"Items known to be Blessed", MENU_UNSELECTED);
  137. 	}
  138. 	if (do_cursed) {
  139. 		invlet = 'C';
  140. 		any.a_void = 0;
  141. 		any.a_int = 'C';
  142. 		add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
  143. 			"Items known to be Cursed", MENU_UNSELECTED);
  144. 	}
  145. 	if (do_uncursed) {
  146. 		invlet = 'U';
  147. 		any.a_void = 0;
  148. 		any.a_int = 'U';
  149. 		add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
  150. 			"Items known to be Uncursed", MENU_UNSELECTED);
  151. 	}
  152. 	if (do_buc_unknown) {
  153. 		invlet = 'X';
  154. 		any.a_void = 0;
  155. 		any.a_int = 'X';
  156. 		add_menu(win, NO_GLYPH, &any, invlet, 0, ATR_NONE,
  157. 			"Items of unknown B/C/U status",
  158. 			MENU_UNSELECTED);
  159. 	}
  160. 	end_menu(win, qstr);
  161. 	n = select_menu(win, how, pick_list);
  162. 	destroy_nhwindow(win);
  163. 	if (n < 0)
  164. 	    n = 0;	/* caller's don't expect -1 */
  165. 	return n;
  166. }

count_categories[edit]

  1. STATIC_OVL int
  2. count_categories(olist, qflags)
  3. struct obj *olist;
  4. int qflags;
  5. {
  6. 	char *pack;
  7. 	boolean counted_category;
  8. 	int ccount = 0;
  9. 	struct obj *curr;
  10.  
  11. 	pack = flags.inv_order;
  12. 	do {
  13. 	    counted_category = FALSE;
  14. 	    for (curr = olist; curr; curr = FOLLOW(curr, qflags)) {
  15. 		if (curr->oclass == *pack) {
  16. 		   if ((qflags & WORN_TYPES) &&
  17. 		    	!(curr->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL |
  18. 		    	W_WEP | W_SWAPWEP | W_QUIVER)))
  19. 			 continue;
  20. 		   if (!counted_category) {
  21. 			ccount++;
  22. 			counted_category = TRUE;
  23. 		   }
  24. 		}
  25. 	    }
  26. 	    pack++;
  27. 	} while (*pack);
  28. 	return ccount;
  29. }

carry_count[edit]

  1. /* could we carry `obj'? if not, could we carry some of it/them? */
  2. STATIC_OVL long
  3. carry_count(obj, container, count, telekinesis, wt_before, wt_after)
  4. struct obj *obj, *container;	/* object to pick up, bag it's coming out of */
  5. long count;
  6. boolean telekinesis;
  7. int *wt_before, *wt_after;
  8. {
  9. boolean adjust_wt = container && carried(container),
  10. 	    is_gold = obj->oclass == COIN_CLASS;
  11. int wt, iw, ow, oow;
  12. long qq, savequan;
  13. #ifdef GOLDOBJ
  14. long umoney = money_cnt(invent);
  15. #endif
  16. unsigned saveowt;
  17. const char *verb, *prefx1, *prefx2, *suffx;
  18. char obj_nambuf[BUFSZ], where[BUFSZ];
  19.  
  20. savequan = obj->quan;
  21. saveowt = obj->owt;
  22.  
  23. iw = max_capacity();
  24.  
  25. if (count != savequan) {
  26. 	obj->quan = count;
  27. 	obj->owt = (unsigned)weight(obj);
  28. }
  29. wt = iw + (int)obj->owt;
  30. if (adjust_wt)
  31. 	wt -= (container->otyp == BAG_OF_HOLDING) ?
  32. 		(int)DELTA_CWT(container, obj) : (int)obj->owt;
  33. #ifndef GOLDOBJ
  34. if (is_gold)	/* merged gold might affect cumulative weight */
  35. 	wt -= (GOLD_WT(u.ugold) + GOLD_WT(count) - GOLD_WT(u.ugold + count));
  36. #else
  37. /* This will go with silver+copper & new gold weight */
  38. if (is_gold)	/* merged gold might affect cumulative weight */
  39. 	wt -= (GOLD_WT(umoney) + GOLD_WT(count) - GOLD_WT(umoney + count));
  40. #endif
  41. if (count != savequan) {
  42. 	obj->quan = savequan;
  43. 	obj->owt = saveowt;
  44. }
  45. *wt_before = iw;
  46. *wt_after  = wt;
  47.  
  48. if (wt < 0)
  49. 	return count;
  50.  
  51. /* see how many we can lift */
  52. if (is_gold) {
  53. #ifndef GOLDOBJ
  54. 	iw -= (int)GOLD_WT(u.ugold);
  55. 	if (!adjust_wt) {
  56. 	    qq = GOLD_CAPACITY((long)iw, u.ugold);
  57. 	} else {
  58. 	    oow = 0;
  59. 	    qq = 50L - (u.ugold % 100L) - 1L;
  60. #else
  61. 	iw -= (int)GOLD_WT(umoney);
  62. 	if (!adjust_wt) {
  63. 	    qq = GOLD_CAPACITY((long)iw, umoney);
  64. 	} else {
  65. 	    oow = 0;
  66. 	    qq = 50L - (umoney % 100L) - 1L;
  67. #endif
  68. 	    if (qq < 0L) qq += 100L;
  69. 	    for ( ; qq <= count; qq += 100L) {
  70. 		obj->quan = qq;
  71. 		obj->owt = (unsigned)GOLD_WT(qq);
  72. #ifndef GOLDOBJ
  73. 		ow = (int)GOLD_WT(u.ugold + qq);
  74. #else
  75. 		ow = (int)GOLD_WT(umoney + qq);
  76. #endif
  77. 		ow -= (container->otyp == BAG_OF_HOLDING) ?
  78. 			(int)DELTA_CWT(container, obj) : (int)obj->owt;
  79. 		if (iw + ow >= 0) break;
  80. 		oow = ow;
  81. 	    }
  82. 	    iw -= oow;
  83. 	    qq -= 100L;
  84. 	}
  85. 	if (qq < 0L) qq = 0L;
  86. 	else if (qq > count) qq = count;
  87. #ifndef GOLDOBJ
  88. 	wt = iw + (int)GOLD_WT(u.ugold + qq);
  89. #else
  90. 	wt = iw + (int)GOLD_WT(umoney + qq);
  91. #endif
  92. } else if (count > 1 || count < obj->quan) {
  93. 	/*
  94. 	 * Ugh. Calc num to lift by changing the quan of of the
  95. 	 * object and calling weight.
  96. 	 *
  97. 	 * This works for containers only because containers
  98. 	 * don't merge.		-dean
  99. 	 */
  100. 	for (qq = 1L; qq <= count; qq++) {
  101. 	    obj->quan = qq;
  102. 	    obj->owt = (unsigned)(ow = weight(obj));
  103. 	    if (adjust_wt)
  104. 		ow -= (container->otyp == BAG_OF_HOLDING) ?
  105. 			(int)DELTA_CWT(container, obj) : (int)obj->owt;
  106. 	    if (iw + ow >= 0)
  107. 		break;
  108. 	    wt = iw + ow;
  109. 	}
  110. 	--qq;
  111. } else {
  112. 	/* there's only one, and we can't lift it */
  113. 	qq = 0L;
  114. }
  115. obj->quan = savequan;
  116. obj->owt = saveowt;
  117.  
  118. if (qq < count) {
  119. 	/* some message will be given */
  120. 	Strcpy(obj_nambuf, doname(obj));
  121. 	if (container) {
  122. 	    Sprintf(where, "in %s", the(xname(container)));
  123. 	    verb = "carry";
  124. 	} else {
  125. 	    Strcpy(where, "lying here");
  126. 	    verb = telekinesis ? "acquire" : "lift";
  127. 	}
  128. } else {
  129. 	/* lint supppression */
  130. 	*obj_nambuf = *where = '\0';
  131. 	verb = "";
  132. }
  133. /* we can carry qq of them */
  134. if (qq > 0) {
  135. 	if (qq < count)
  136. 	    You("can only %s %s of the %s %s.",
  137. 		verb, (qq == 1L) ? "one" : "some", obj_nambuf, where);
  138. 	*wt_after = wt;
  139. 	return qq;
  140. }
  141.  
  142. if (!container) Strcpy(where, "here");  /* slightly shorter form */
  143. #ifndef GOLDOBJ
  144. if (invent || u.ugold) {
  145. #else
  146. if (invent || umoney) {
  147. #endif
  148. 	prefx1 = "you cannot ";
  149. 	prefx2 = "";
  150. 	suffx  = " any more";
  151. } else {
  152. 	prefx1 = (obj->quan == 1L) ? "it " : "even one ";
  153. 	prefx2 = "is too heavy for you to ";
  154. 	suffx  = "";
  155. }
  156. There("%s %s %s, but %s%s%s%s.",
  157. 	  otense(obj, "are"), obj_nambuf, where,
  158. 	  prefx1, prefx2, verb, suffx);
  159.  
  160. /* *wt_after = iw; */
  161. return 0L;
  162. }

lift_object[edit]

  1. /* determine whether character is able and player is willing to carry `obj' */
  2. STATIC_OVL
  3. int 
  4. lift_object(obj, container, cnt_p, telekinesis)
  5. struct obj *obj, *container;	/* object to pick up, bag it's coming out of */
  6. long *cnt_p;
  7. boolean telekinesis;
  8. {
  9. int result, old_wt, new_wt, prev_encumbr, next_encumbr;
  10.  
  11. if (obj->otyp == BOULDER && In_sokoban(&u.uz)) {
  12. 	You("cannot get your %s around this %s.",
  13. 			body_part(HAND), xname(obj));
  14. 	return -1;
  15. }
  16. if (obj->otyp == LOADSTONE ||
  17. 	    (obj->otyp == BOULDER && throws_rocks(youmonst.data)))
  18. 	return 1;		/* lift regardless of current situation */
  19.  
  20. *cnt_p = carry_count(obj, container, *cnt_p, telekinesis, &old_wt, &new_wt);
  21. if (*cnt_p < 1L) {
  22. 	result = -1;	/* nothing lifted */
  23. #ifndef GOLDOBJ
  24. } else if (obj->oclass != COIN_CLASS && inv_cnt() >= 52 &&
  25. 		!merge_choice(invent, obj)) {
  26. #else
  27. } else if (inv_cnt() >= 52 && !merge_choice(invent, obj)) {
  28. #endif
  29. 	Your("knapsack cannot accommodate any more items.");
  30. 	result = -1;	/* nothing lifted */
  31. } else {
  32. 	result = 1;
  33. 	prev_encumbr = near_capacity();
  34. 	if (prev_encumbr < flags.pickup_burden)
  35. 		prev_encumbr = flags.pickup_burden;
  36. 	next_encumbr = calc_capacity(new_wt - old_wt);
  37. 	if (next_encumbr > prev_encumbr) {
  38. 	    if (telekinesis) {
  39. 		result = 0;	/* don't lift */
  40. 	    } else {
  41. 		char qbuf[BUFSZ];
  42. 		long savequan = obj->quan;
  43.  
  44. 		obj->quan = *cnt_p;
  45. 		Strcpy(qbuf,
  46. 			(next_encumbr > HVY_ENCUMBER) ? overloadmsg :
  47. 			(next_encumbr > MOD_ENCUMBER) ? nearloadmsg :
  48. 			moderateloadmsg);
  49. 		Sprintf(eos(qbuf), " %s. Continue?",
  50. 			safe_qbuf(qbuf, sizeof(" . Continue?"),
  51. 				doname(obj), an(simple_typename(obj->otyp)), "something"));
  52. 		obj->quan = savequan;
  53. 		switch (ynq(qbuf)) {
  54. 		case 'q':  result = -1; break;
  55. 		case 'n':  result =  0; break;
  56. 		default:   break;	/* 'y' => result == 1 */
  57. 		}
  58. 		clear_nhwindow(WIN_MESSAGE);
  59. 	    }
  60. 	}
  61. }
  62.  
  63. if (obj->otyp == SCR_SCARE_MONSTER && result <= 0 && !container)
  64. 	obj->spe = 0;
  65. return result;
  66. }

safe_qbuf[edit]

  1. /* To prevent qbuf overflow in prompts use planA only
  2. * if it fits, or planB if PlanA doesn't fit,
  3. * finally using the fallback as a last resort.
  4. * last_restort is expected to be very short.
  5. */
  6. const char *
  7. safe_qbuf(qbuf, padlength, planA, planB, last_resort)
  8. const char *qbuf, *planA, *planB, *last_resort;
  9. unsigned padlength;
  10. {
  11. 	/* convert size_t (or int for ancient systems) to ordinary unsigned */
  12. 	unsigned len_qbuf = (unsigned)strlen(qbuf),
  13. 	         len_planA = (unsigned)strlen(planA),
  14. 	         len_planB = (unsigned)strlen(planB),
  15. 	         len_lastR = (unsigned)strlen(last_resort);
  16. 	unsigned textleft = QBUFSZ - (len_qbuf + padlength);
  17.  
  18. 	if (len_lastR >= textleft) {
  19. 	    impossible("safe_qbuf: last_resort too large at %u characters.",
  20. 		       len_lastR);
  21. 	    return "";
  22. 	}
  23. 	return (len_planA < textleft) ? planA :
  24. 		    (len_planB < textleft) ? planB : last_resort;
  25. }

pickup_object[edit]

  1. /*
  2. * Pick up <count> of obj from the ground and add it to the hero's inventory.
  3. * Returns -1 if caller should break out of its loop, 0 if nothing picked
  4. * up, 1 if otherwise.
  5. */
  6. int
  7. pickup_object(obj, count, telekinesis)
  8. struct obj *obj;
  9. long count;
  10. boolean telekinesis;	/* not picking it up directly by hand */
  11. {
  12. 	int res, nearload;
  13. #ifndef GOLDOBJ
  14. 	const char *where = (obj->ox == u.ux && obj->oy == u.uy) ?
  15. 			    "here" : "there";
  16. #endif
  17.  
  18. 	if (obj->quan < count) {
  19. 	    impossible("pickup_object: count %ld > quan %ld?",
  20. 		count, obj->quan);
  21. 	    return 0;
  22. 	}
  23.  
  24. 	/* In case of auto-pickup, where we haven't had a chance
  25. 	   to look at it yet; affects docall(SCR_SCARE_MONSTER). */
  26. 	if (!Blind)
  27. #ifdef INVISIBLE_OBJECTS
  28. 		if (!obj->oinvis || See_invisible)
  29. #endif
  30. 		obj->dknown = 1;
  31.  
  32. 	if (obj == uchain) {    /* do not pick up attached chain */
  33. 	    return 0;
  34. 	} else if (obj->oartifact && !touch_artifact(obj,&youmonst)) {
  35. 	    return 0;
  36. #ifndef GOLDOBJ
  37. 	} else if (obj->oclass == COIN_CLASS) {
  38. 	    /* Special consideration for gold pieces... */
  39. 	    long iw = (long)max_capacity() - GOLD_WT(u.ugold);
  40. 	    long gold_capacity = GOLD_CAPACITY(iw, u.ugold);
  41.  
  42. 	    if (gold_capacity <= 0L) {
  43. 		pline(
  44. 	       "There %s %ld gold piece%s %s, but you cannot carry any more.",
  45. 		      otense(obj, "are"),
  46. 		      obj->quan, plur(obj->quan), where);
  47. 		return 0;
  48. 	    } else if (gold_capacity < count) {
  49. 		You("can only %s %s of the %ld gold pieces lying %s.",
  50. 		    telekinesis ? "acquire" : "carry",
  51. 		    gold_capacity == 1L ? "one" : "some", obj->quan, where);
  52. 		pline("%s %ld gold piece%s.",
  53. 		    nearloadmsg, gold_capacity, plur(gold_capacity));
  54. 		u.ugold += gold_capacity;
  55. 		obj->quan -= gold_capacity;
  56. 		costly_gold(obj->ox, obj->oy, gold_capacity);
  57. 	    } else {
  58. 		u.ugold += count;
  59. 		if ((nearload = near_capacity()) != 0)
  60. 		    pline("%s %ld gold piece%s.",
  61. 			  nearload < MOD_ENCUMBER ?
  62. 			  moderateloadmsg : nearloadmsg,
  63. 			  count, plur(count));
  64. 		else
  65. 		    prinv((char *) 0, obj, count);
  66. 		costly_gold(obj->ox, obj->oy, count);
  67. 		if (count == obj->quan)
  68. 		    delobj(obj);
  69. 		else
  70. 		    obj->quan -= count;
  71. 	    }
  72. 	    flags.botl = 1;
  73. 	    if (flags.run) nomul(0);
  74. 	    return 1;
  75. #endif
  76. 	} else if (obj->otyp == CORPSE) {
  77. 	    if ( (touch_petrifies(&mons[obj->corpsenm])) && !uarmg
  78. 				&& !Stone_resistance && !telekinesis) {
  79. 		if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))
  80. 		    display_nhwindow(WIN_MESSAGE, FALSE);
  81. 		else {
  82. 			char kbuf[BUFSZ];
  83.  
  84. 			Strcpy(kbuf, an(corpse_xname(obj, TRUE)));
  85. 			pline("Touching %s is a fatal mistake.", kbuf);
  86. 			instapetrify(kbuf);
  87. 		    return -1;
  88. 		}
  89. 	    } else if (is_rider(&mons[obj->corpsenm])) {
  90. 		pline("At your %s, the corpse suddenly moves...",
  91. 			telekinesis ? "attempted acquisition" : "touch");
  92. 		(void) revive_corpse(obj);
  93. 		exercise(A_WIS, FALSE);
  94. 		return -1;
  95. 	    }
  96. 	} else  if (obj->otyp == SCR_SCARE_MONSTER) {
  97. 	    if (obj->blessed) obj->blessed = 0;
  98. 	    else if (!obj->spe && !obj->cursed) obj->spe = 1;
  99. 	    else {
  100. 		pline_The("scroll%s %s to dust as you %s %s up.",
  101. 			plur(obj->quan), otense(obj, "turn"),
  102. 			telekinesis ? "raise" : "pick",
  103. 			(obj->quan == 1L) ? "it" : "them");
  104. 		if (!(objects[SCR_SCARE_MONSTER].oc_name_known) &&
  105. 				    !(objects[SCR_SCARE_MONSTER].oc_uname))
  106. 		    docall(obj);
  107. 		useupf(obj, obj->quan);
  108. 		return 1;	/* tried to pick something up and failed, but
  109. 				   don't want to terminate pickup loop yet   */
  110. 	    }
  111. 	}
  112.  
  113. 	if ((res = lift_object(obj, (struct obj *)0, &count, telekinesis)) <= 0)
  114. 	    return res;
  115.  
  116. #ifdef GOLDOBJ
  117. /* Whats left of the special case for gold :-) */
  118. 	if (obj->oclass == COIN_CLASS) flags.botl = 1;
  119. #endif
  120. 	if (obj->quan != count && obj->otyp != LOADSTONE)
  121. 	    obj = splitobj(obj, count);
  122.  
  123. 	obj = pick_obj(obj);
  124.  
  125. 	if (uwep && uwep == obj) mrg_to_wielded = TRUE;
  126. 	nearload = near_capacity();
  127. 	prinv(nearload == SLT_ENCUMBER ? moderateloadmsg : (char *) 0,
  128. 	      obj, count);
  129. 	mrg_to_wielded = FALSE;
  130. 	return 1;
  131. }

pick_obj[edit]

  1. /*
  2. * Do the actual work of picking otmp from the floor or monster's interior
  3. * and putting it in the hero's inventory.  Take care of billing.  Return a
  4. * pointer to the object where otmp ends up.  This may be different
  5. * from otmp because of merging.
  6. *
  7. * Gold never reaches this routine unless GOLDOBJ is defined.
  8. */
  9. struct obj *
  10. pick_obj(otmp)
  11. struct obj *otmp;
  12. {
  13. 	obj_extract_self(otmp);
  14. 	if (!u.uswallow && otmp != uball && costly_spot(otmp->ox, otmp->oy)) {
  15. 	    char saveushops[5], fakeshop[2];
  16.  
  17. 	    /* addtobill cares about your location rather than the object's;
  18. 	       usually they'll be the same, but not when using telekinesis
  19. 	       (if ever implemented) or a grappling hook */
  20. 	    Strcpy(saveushops, u.ushops);
  21. 	    fakeshop[0] = *in_rooms(otmp->ox, otmp->oy, SHOPBASE);
  22. 	    fakeshop[1] = '\0';
  23. 	    Strcpy(u.ushops, fakeshop);
  24. 	    /* sets obj->unpaid if necessary */
  25. 	    addtobill(otmp, TRUE, FALSE, FALSE);
  26. 	    Strcpy(u.ushops, saveushops);
  27. 	    /* if you're outside the shop, make shk notice */
  28. 	    if (!index(u.ushops, *fakeshop))
  29. 		remote_burglary(otmp->ox, otmp->oy);
  30. 	}
  31. 	if (otmp->no_charge)	/* only applies to objects outside invent */
  32. 	    otmp->no_charge = 0;
  33. 	newsym(otmp->ox, otmp->oy);
  34. 	return addinv(otmp);	/* might merge it with other objects */
  35. }

encumber_msg[edit]

  1. /*
  2. * prints a message if encumbrance changed since the last check and
  3. * returns the new encumbrance value (from near_capacity()).
  4. */
  5. int
  6. encumber_msg()
  7. {
  8. static int oldcap = UNENCUMBERED;
  9. int newcap = near_capacity();
  10.  
  11. if(oldcap < newcap) {
  12. 	switch(newcap) {
  13. 	case 1: Your("movements are slowed slightly because of your load.");
  14. 		break;
  15. 	case 2: You("rebalance your load.  Movement is difficult.");
  16. 		break;
  17. 	case 3: You("%s under your heavy load.  Movement is very hard.",
  18. 		    stagger(youmonst.data, "stagger"));
  19. 		break;
  20. 	default: You("%s move a handspan with this load!",
  21. 		     newcap == 4 ? "can barely" : "can't even");
  22. 		break;
  23. 	}
  24. 	flags.botl = 1;
  25. } else if(oldcap > newcap) {
  26. 	switch(newcap) {
  27. 	case 0: Your("movements are now unencumbered.");
  28. 		break;
  29. 	case 1: Your("movements are only slowed slightly by your load.");
  30. 		break;
  31. 	case 2: You("rebalance your load.  Movement is still difficult.");
  32. 		break;
  33. 	case 3: You("%s under your load.  Movement is still very hard.",
  34. 		    stagger(youmonst.data, "stagger"));
  35. 		break;
  36. 	}
  37. 	flags.botl = 1;
  38. }
  39.  
  40. oldcap = newcap;
  41. return (newcap);
  42. }

container_at[edit]

  1. /* Is there a container at x,y. Optional: return count of containers at x,y */
  2. STATIC_OVL int
  3. container_at(x, y, countem)
  4. int x,y;
  5. boolean countem;
  6. {
  7. 	struct obj *cobj, *nobj;
  8. 	int container_count = 0;
  9.  
  10. 	for(cobj = level.objects[x][y]; cobj; cobj = nobj) {
  11. 		nobj = cobj->nexthere;
  12. 		if(Is_container(cobj)) {
  13. 			container_count++;
  14. 			if (!countem) break;
  15. 		}
  16. 	}
  17. 	return container_count;
  18. }

able_to_loot[edit]

  1. STATIC_OVL boolean
  2. able_to_loot(x, y)
  3. int x, y;
  4. {
  5. 	if (!can_reach_floor()) {
  6. #ifdef STEED
  7. 		if (u.usteed && P_SKILL(P_RIDING) < P_BASIC)
  8. 			rider_cant_reach(); /* not skilled enough to reach */
  9. 		else
  10. #endif
  11. 			You("cannot reach the %s.", surface(x, y));
  12. 		return FALSE;
  13. 	} else if (is_pool(x, y) || is_lava(x, y)) {
  14. 		/* at present, can't loot in water even when Underwater */
  15. 		You("cannot loot things that are deep in the %s.",
  16. 		    is_lava(x, y) ? "lava" : "water");
  17. 		return FALSE;
  18. 	} else if (nolimbs(youmonst.data)) {
  19. 		pline("Without limbs, you cannot loot anything.");
  20. 		return FALSE;
  21. 	} else if (!freehand()) {
  22. 		pline("Without a free %s, you cannot loot anything.",
  23. 			body_part(HAND));
  24. 		return FALSE;
  25. 	}
  26. 	return TRUE;
  27. }

mon_beside[edit]

  1. STATIC_OVL boolean
  2. mon_beside(x,y)
  3. int x, y;
  4. {
  5. 	int i,j,nx,ny;
  6. 	for(i = -1; i <= 1; i++)
  7. 	    for(j = -1; j <= 1; j++) {
  8. 	    	nx = x + i;
  9. 	    	ny = y + j;
  10. 		if(isok(nx, ny) && MON_AT(nx, ny))
  11. 			return TRUE;
  12. 	    }
  13. 	return FALSE;
  14. }

doloot[edit]

  1. int
  2. doloot()	/* loot a container on the floor or loot saddle from mon. */
  3. {
  4. register struct obj *cobj, *nobj;
  5. register int c = -1;
  6. int timepassed = 0;
  7. coord cc;
  8. boolean underfoot = TRUE;
  9. const char *dont_find_anything = "don't find anything";
  10. struct monst *mtmp;
  11. char qbuf[BUFSZ];
  12. int prev_inquiry = 0;
  13. boolean prev_loot = FALSE;
  14.  
  15. if (check_capacity((char *)0)) {
  16. 	/* "Can't do that while carrying so much stuff." */
  17. 	return 0;
  18. }
  19. if (nohands(youmonst.data)) {
  20. 	You("have no hands!");	/* not `body_part(HAND)' */
  21. 	return 0;
  22. }
  23. cc.x = u.ux; cc.y = u.uy;
  24.  
  25. lootcont:
  26.  
  27. if (container_at(cc.x, cc.y, FALSE)) {
  28. 	boolean any = FALSE;
  29.  
  30. 	if (!able_to_loot(cc.x, cc.y)) return 0;
  31. 	for (cobj = level.objects[cc.x][cc.y]; cobj; cobj = nobj) {
  32. 	    nobj = cobj->nexthere;
  33.  
  34. 	    if (Is_container(cobj)) {
  35. 		Sprintf(qbuf, "There is %s here, loot it?",
  36. 			safe_qbuf("", sizeof("There is  here, loot it?"),
  37. 			     doname(cobj), an(simple_typename(cobj->otyp)),
  38. 			     "a container"));
  39. 		c = ynq(qbuf);
  40. 		if (c == 'q') return (timepassed);
  41. 		if (c == 'n') continue;
  42. 		any = TRUE;
  43.  
  44. 		if (cobj->olocked) {
  45. 		    pline("Hmmm, it seems to be locked.");
  46. 		    continue;
  47. 		}
  48. 		if (cobj->otyp == BAG_OF_TRICKS) {
  49. 		    int tmp;
  50. 		    You("carefully open the bag...");
  51. 		    pline("It develops a huge set of teeth and bites you!");
  52. 		    tmp = rnd(10);
  53. 		    if (Half_physical_damage) tmp = (tmp+1) / 2;
  54. 		    losehp(tmp, "carnivorous bag", KILLED_BY_AN);
  55. 		    makeknown(BAG_OF_TRICKS);
  56. 		    timepassed = 1;
  57. 		    continue;
  58. 		}
  59.  
  60. 		You("carefully open %s...", the(xname(cobj)));
  61. 		timepassed |= use_container(cobj, 0);
  62. 		if (multi < 0) return 1;		/* chest trap */
  63. 	    }
  64. 	}
  65. 	if (any) c = 'y';
  66. } else if (Confusion) {
  67. #ifndef GOLDOBJ
  68. 	if (u.ugold){
  69. 	    long contribution = rnd((int)min(LARGEST_INT,u.ugold));
  70. 	    struct obj *goldob = mkgoldobj(contribution);
  71. #else
  72. 	struct obj *goldob;
  73. 	/* Find a money object to mess with */
  74. 	for (goldob = invent; goldob; goldob = goldob->nobj) {
  75. 	    if (goldob->oclass == COIN_CLASS) break;
  76. 	}
  77. 	if (goldob){
  78. 	    long contribution = rnd((int)min(LARGEST_INT, goldob->quan));
  79. 	    if (contribution < goldob->quan)
  80. 		goldob = splitobj(goldob, contribution);
  81. 	    freeinv(goldob);
  82. #endif
  83. 	    if (IS_THRONE(levl[u.ux][u.uy].typ)){
  84. 		struct obj *coffers;
  85. 		int pass;
  86. 		/* find the original coffers chest, or any chest */
  87. 		for (pass = 2; pass > -1; pass -= 2)
  88. 		    for (coffers = fobj; coffers; coffers = coffers->nobj)
  89. 			if (coffers->otyp == CHEST && coffers->spe == pass)
  90. 			    goto gotit;	/* two level break */
  91. gotit:
  92. 		if (coffers) {
  93. 	    verbalize("Thank you for your contribution to reduce the debt.");
  94. 		    (void) add_to_container(coffers, goldob);
  95. 		    coffers->owt = weight(coffers);
  96. 		} else {
  97. 		    struct monst *mon = makemon(courtmon(),
  98. 					    u.ux, u.uy, NO_MM_FLAGS);
  99. 		    if (mon) {
  100. #ifndef GOLDOBJ
  101. 			mon->mgold += goldob->quan;
  102. 			delobj(goldob);
  103. 			pline("The exchequer accepts your contribution.");
  104. 		    } else {
  105. 			dropx(goldob);
  106. 		    }
  107. 		}
  108. 	    } else {
  109. 		dropx(goldob);
  110. #else
  111. 			add_to_minv(mon, goldob);
  112. 			pline("The exchequer accepts your contribution.");
  113. 		    } else {
  114. 			dropy(goldob);
  115. 		    }
  116. 		}
  117. 	    } else {
  118. 		dropy(goldob);
  119. #endif
  120. 		pline("Ok, now there is loot here.");
  121. 	    }
  122. 	}
  123. } else if (IS_GRAVE(levl[cc.x][cc.y].typ)) {
  124. 	You("need to dig up the grave to effectively loot it...");
  125. }
  126. /*
  127. * 3.3.1 introduced directional looting for some things.
  128. */
  129. if (c != 'y' && mon_beside(u.ux, u.uy)) {
  130. 	if (!get_adjacent_loc("Loot in what direction?", "Invalid loot location",
  131. 			u.ux, u.uy, &cc)) return 0;
  132. 	if (cc.x == u.ux && cc.y == u.uy) {
  133. 	    underfoot = TRUE;
  134. 	    if (container_at(cc.x, cc.y, FALSE))
  135. 		goto lootcont;
  136. 	} else
  137. 	    underfoot = FALSE;
  138. 	if (u.dz < 0) {
  139. 	    You("%s to loot on the %s.", dont_find_anything,
  140. 		ceiling(cc.x, cc.y));
  141. 	    timepassed = 1;
  142. 	    return timepassed;
  143. 	}
  144. 	mtmp = m_at(cc.x, cc.y);
  145. 	if (mtmp) timepassed = loot_mon(mtmp, &prev_inquiry, &prev_loot);
  146.  
  147. 	/* Preserve pre-3.3.1 behaviour for containers.
  148. 	 * Adjust this if-block to allow container looting
  149. 	 * from one square away to change that in the future.
  150. 	 */
  151. 	if (!underfoot) {
  152. 	    if (container_at(cc.x, cc.y, FALSE)) {
  153. 		if (mtmp) {
  154. 		    You_cant("loot anything %sthere with %s in the way.",
  155. 			    prev_inquiry ? "else " : "", mon_nam(mtmp));
  156. 		    return timepassed;
  157. 		} else {
  158. 		    You("have to be at a container to loot it.");
  159. 		}
  160. 	    } else {
  161. 		You("%s %sthere to loot.", dont_find_anything,
  162. 			(prev_inquiry || prev_loot) ? "else " : "");
  163. 		return timepassed;
  164. 	    }
  165. 	}
  166. } else if (c != 'y' && c != 'n') {
  167. 	You("%s %s to loot.", dont_find_anything,
  168. 		    underfoot ? "here" : "there");
  169. }
  170. return (timepassed);
  171. }

loot_mon[edit]

  1. /* loot_mon() returns amount of time passed.
  2. */
  3. int
  4. loot_mon(mtmp, passed_info, prev_loot)
  5. struct monst *mtmp;
  6. int *passed_info;
  7. boolean *prev_loot;
  8. {
  9. int c = -1;
  10. int timepassed = 0;
  11. #ifdef STEED
  12. struct obj *otmp;
  13. char qbuf[QBUFSZ];
  14.  
  15. /* 3.3.1 introduced the ability to remove saddle from a steed             */
  16. /* 	*passed_info is set to TRUE if a loot query was given.               */
  17. /*	*prev_loot is set to TRUE if something was actually acquired in here. */
  18. if (mtmp && mtmp != u.usteed && (otmp = which_armor(mtmp, W_SADDLE))) {
  19. 	long unwornmask;
  20. 	if (passed_info) *passed_info = 1;
  21. 	Sprintf(qbuf, "Do you want to remove the saddle from %s?",
  22. 		x_monnam(mtmp, ARTICLE_THE, (char *)0, SUPPRESS_SADDLE, FALSE));
  23. 	if ((c = yn_function(qbuf, ynqchars, 'n')) == 'y') {
  24. 		if (nolimbs(youmonst.data)) {
  25. 		    You_cant("do that without limbs."); /* not body_part(HAND) */
  26. 		    return (0);
  27. 		}
  28. 		if (otmp->cursed) {
  29. 		    You("can't. The saddle seems to be stuck to %s.",
  30. 			x_monnam(mtmp, ARTICLE_THE, (char *)0,
  31. 				SUPPRESS_SADDLE, FALSE));
  32.  
  33. 		    /* the attempt costs you time */
  34. 			return (1);
  35. 		}
  36. 		obj_extract_self(otmp);
  37. 		if ((unwornmask = otmp->owornmask) != 0L) {
  38. 		    mtmp->misc_worn_check &= ~unwornmask;
  39. 		    otmp->owornmask = 0L;
  40. 		    update_mon_intrinsics(mtmp, otmp, FALSE, FALSE);
  41. 		}
  42. 		otmp = hold_another_object(otmp, "You drop %s!", doname(otmp),
  43. 					(const char *)0);
  44. 		timepassed = rnd(3);
  45. 		if (prev_loot) *prev_loot = TRUE;
  46. 	} else if (c == 'q') {
  47. 		return (0);
  48. 	}
  49. }
  50. #endif	/* STEED */
  51. /* 3.4.0 introduced the ability to pick things up from within swallower's stomach */
  52. if (u.uswallow) {
  53. 	int count = passed_info ? *passed_info : 0;
  54. 	timepassed = pickup(count);
  55. }
  56. return timepassed;
  57. }

mbag_explodes[edit]

  1. /*
  2. * Decide whether an object being placed into a magic bag will cause
  3. * it to explode.  If the object is a bag itself, check recursively.
  4. */
  5. STATIC_OVL boolean
  6. mbag_explodes(obj, depthin)
  7. struct obj *obj;
  8. int depthin;
  9. {
  10. /* these won't cause an explosion when they're empty */
  11. if ((obj->otyp == WAN_CANCELLATION || obj->otyp == BAG_OF_TRICKS) &&
  12. 	    obj->spe <= 0)
  13. 	return FALSE;
  14.  
  15. /* odds: 1/1, 2/2, 3/4, 4/8, 5/16, 6/32, 7/64, 8/128, 9/128, 10/128,... */
  16. if ((Is_mbag(obj) || obj->otyp == WAN_CANCELLATION) &&
  17. 	(rn2(1 << (depthin > 7 ? 7 : depthin)) <= depthin))
  18. 	return TRUE;
  19. else if (Has_contents(obj)) {
  20. 	struct obj *otmp;
  21.  
  22. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj)
  23. 	    if (mbag_explodes(otmp, depthin+1)) return TRUE;
  24. }
  25. return FALSE;
  26. }

in_container[edit]

  1. /* A variable set in use_container(), to be used by the callback routines   */
  2. /* in_container(), and out_container() from askchain() and use_container(). */
  3. static NEARDATA struct obj *current_container;
  4. #define Icebox (current_container->otyp == ICE_BOX)
  5.  
  6. /* Returns: -1 to stop, 1 item was inserted, 0 item was not inserted. */
  7. STATIC_PTR int
  8. in_container(obj)
  9. register struct obj *obj;
  10. {
  11. 	boolean floor_container = !carried(current_container);
  12. 	boolean was_unpaid = FALSE;
  13. 	char buf[BUFSZ];
  14.  
  15. 	if (!current_container) {
  16. 		impossible("<in> no current_container?");
  17. 		return 0;
  18. 	} else if (obj == uball || obj == uchain) {
  19. 		You("must be kidding.");
  20. 		return 0;
  21. 	} else if (obj == current_container) {
  22. 		pline("That would be an interesting topological exercise.");
  23. 		return 0;
  24. 	} else if (obj->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) {
  25. 		Norep("You cannot %s %s you are wearing.",
  26. 			Icebox ? "refrigerate" : "stash", something);
  27. 		return 0;
  28. 	} else if ((obj->otyp == LOADSTONE) && obj->cursed) {
  29. 		obj->bknown = 1;
  30. 	      pline_The("stone%s won't leave your person.", plur(obj->quan));
  31. 		return 0;
  32. 	} else if (obj->otyp == AMULET_OF_YENDOR ||
  33. 		   obj->otyp == CANDELABRUM_OF_INVOCATION ||
  34. 		   obj->otyp == BELL_OF_OPENING ||
  35. 		   obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  36. 	/* Prohibit Amulets in containers; if you allow it, monsters can't
  37. 	 * steal them.  It also becomes a pain to check to see if someone
  38. 	 * has the Amulet.  Ditto for the Candelabrum, the Bell and the Book.
  39. 	 */
  40. 	    pline("%s cannot be confined in such trappings.", The(xname(obj)));
  41. 	    return 0;
  42. 	} else if (obj->otyp == LEASH && obj->leashmon != 0) {
  43. 		pline("%s attached to your pet.", Tobjnam(obj, "are"));
  44. 		return 0;
  45. 	} else if (obj == uwep) {
  46. 		if (welded(obj)) {
  47. 			weldmsg(obj);
  48. 			return 0;
  49. 		}
  50. 		setuwep((struct obj *) 0);
  51. 		if (uwep) return 0;	/* unwielded, died, rewielded */
  52. 	} else if (obj == uswapwep) {
  53. 		setuswapwep((struct obj *) 0);
  54. 		if (uswapwep) return 0;     /* unwielded, died, rewielded */
  55. 	} else if (obj == uquiver) {
  56. 		setuqwep((struct obj *) 0);
  57. 		if (uquiver) return 0;     /* unwielded, died, rewielded */
  58. 	}
  59.  
  60. 	if (obj->otyp == CORPSE) {
  61. 	    if ( (touch_petrifies(&mons[obj->corpsenm])) && !uarmg
  62. 		 && !Stone_resistance) {
  63. 		if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))
  64. 		    display_nhwindow(WIN_MESSAGE, FALSE);
  65. 		else {
  66. 		    char kbuf[BUFSZ];
  67.  
  68. 		    Strcpy(kbuf, an(corpse_xname(obj, TRUE)));
  69. 		    pline("Touching %s is a fatal mistake.", kbuf);
  70. 		    instapetrify(kbuf);
  71. 		    return -1;
  72. 		}
  73. 	    }
  74. 	}
  75.  
  76. 	/* boxes, boulders, and big statues can't fit into any container */
  77. 	if (obj->otyp == ICE_BOX || Is_box(obj) || obj->otyp == BOULDER ||
  78. 		(obj->otyp == STATUE && bigmonst(&mons[obj->corpsenm]))) {
  79. 		/*
  80. 		 *  xname() uses a static result array.  Save obj's name
  81. 		 *  before current_container's name is computed.  Don't
  82. 		 *  use the result of strcpy() within You() --- the order
  83. 		 *  of evaluation of the parameters is undefined.
  84. 		 */
  85. 		Strcpy(buf, the(xname(obj)));
  86. 		You("cannot fit %s into %s.", buf,
  87. 		    the(xname(current_container)));
  88. 		return 0;
  89. 	}
  90.  
  91. 	freeinv(obj);
  92.  
  93. 	if (obj_is_burning(obj))	/* this used to be part of freeinv() */
  94. 		(void) snuff_lit(obj);
  95.  
  96. 	if (floor_container && costly_spot(u.ux, u.uy)) {
  97. 	    if (current_container->no_charge && !obj->unpaid) {
  98. 		/* don't sell when putting the item into your own container */
  99. 		obj->no_charge = 1;
  100. 	    } else if (obj->oclass != COIN_CLASS) {
  101. 		/* sellobj() will take an unpaid item off the shop bill
  102. 		 * note: coins are handled later */
  103. 		was_unpaid = obj->unpaid ? TRUE : FALSE;
  104. 		sellobj_state(SELL_DELIBERATE);
  105. 		sellobj(obj, u.ux, u.uy);
  106. 		sellobj_state(SELL_NORMAL);
  107. 	    }
  108. 	}
  109. 	if (Icebox && !age_is_relative(obj)) {
  110. 		obj->age = monstermoves - obj->age; /* actual age */
  111. 		/* stop any corpse timeouts when frozen */
  112. 		if (obj->otyp == CORPSE && obj->timed) {
  113. 			long rot_alarm = stop_timer(ROT_CORPSE, (genericptr_t)obj);
  114. 			(void) stop_timer(REVIVE_MON, (genericptr_t)obj);
  115. 			/* mark a non-reviving corpse as such */
  116. 			if (rot_alarm) obj->norevive = 1;
  117. 		}
  118. 	} else if (Is_mbag(current_container) && mbag_explodes(obj, 0)) {
  119. 		/* explicitly mention what item is triggering the explosion */
  120. 		pline(
  121. 	      "As you put %s inside, you are blasted by a magical explosion!",
  122. 		      doname(obj));
  123. 		/* did not actually insert obj yet */
  124. 		if (was_unpaid) addtobill(obj, FALSE, FALSE, TRUE);
  125. 		obfree(obj, (struct obj *)0);
  126. 		delete_contents(current_container);
  127. 		if (!floor_container)
  128. 			useup(current_container);
  129. 		else if (obj_here(current_container, u.ux, u.uy))
  130. 			useupf(current_container, obj->quan);
  131. 		else
  132. 			panic("in_container:  bag not found.");
  133.  
  134. 		losehp(d(6,6),"magical explosion", KILLED_BY_AN);
  135. 		current_container = 0;	/* baggone = TRUE; */
  136. 	}
  137.  
  138. 	if (current_container) {
  139. 	    Strcpy(buf, the(xname(current_container)));
  140. 	    You("put %s into %s.", doname(obj), buf);
  141.  
  142. 	    /* gold in container always needs to be added to credit */
  143. 	    if (floor_container && obj->oclass == COIN_CLASS)
  144. 		sellobj(obj, current_container->ox, current_container->oy);
  145. 	    (void) add_to_container(current_container, obj);
  146. 	    current_container->owt = weight(current_container);
  147. 	}
  148. 	/* gold needs this, and freeinv() many lines above may cause
  149. 	 * the encumbrance to disappear from the status, so just always
  150. 	 * update status immediately.
  151. 	 */
  152. 	bot();
  153.  
  154. 	return(current_container ? 1 : -1);
  155. }

ck_bag[edit]

  1. STATIC_PTR int
  2. ck_bag(obj)
  3. struct obj *obj;
  4. {
  5. 	return current_container && obj != current_container;
  6. }

out_container[edit]

  1. /* Returns: -1 to stop, 1 item was removed, 0 item was not removed. */
  2. STATIC_PTR int
  3. out_container(obj)
  4. register struct obj *obj;
  5. {
  6. 	register struct obj *otmp;
  7. 	boolean is_gold = (obj->oclass == COIN_CLASS);
  8. 	int res, loadlev;
  9. 	long count;
  10.  
  11. 	if (!current_container) {
  12. 		impossible("<out> no current_container?");
  13. 		return -1;
  14. 	} else if (is_gold) {
  15. 		obj->owt = weight(obj);
  16. 	}
  17.  
  18. 	if(obj->oartifact && !touch_artifact(obj,&youmonst)) return 0;
  19.  
  20. 	if (obj->otyp == CORPSE) {
  21. 	    if ( (touch_petrifies(&mons[obj->corpsenm])) && !uarmg
  22. 		 && !Stone_resistance) {
  23. 		if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))
  24. 		    display_nhwindow(WIN_MESSAGE, FALSE);
  25. 		else {
  26. 		    char kbuf[BUFSZ];
  27.  
  28. 		    Strcpy(kbuf, an(corpse_xname(obj, TRUE)));
  29. 		    pline("Touching %s is a fatal mistake.", kbuf);
  30. 		    instapetrify(kbuf);
  31. 		    return -1;
  32. 		}
  33. 	    }
  34. 	}
  35.  
  36. 	count = obj->quan;
  37. 	if ((res = lift_object(obj, current_container, &count, FALSE)) <= 0)
  38. 	    return res;
  39.  
  40. 	if (obj->quan != count && obj->otyp != LOADSTONE)
  41. 	    obj = splitobj(obj, count);
  42.  
  43. 	/* Remove the object from the list. */
  44. 	obj_extract_self(obj);
  45. 	current_container->owt = weight(current_container);
  46.  
  47. 	if (Icebox && !age_is_relative(obj)) {
  48. 		obj->age = monstermoves - obj->age; /* actual age */
  49. 		if (obj->otyp == CORPSE)
  50. 			start_corpse_timeout(obj);
  51. 	}
  52. 	/* simulated point of time */
  53.  
  54. 	if(!obj->unpaid && !carried(current_container) &&
  55. 	     costly_spot(current_container->ox, current_container->oy)) {
  56. 		obj->ox = current_container->ox;
  57. 		obj->oy = current_container->oy;
  58. 		addtobill(obj, FALSE, FALSE, FALSE);
  59. 	}
  60. 	if (is_pick(obj) && !obj->unpaid && *u.ushops && shop_keeper(*u.ushops))
  61. 		verbalize("You sneaky cad! Get out of here with that pick!");
  62.  
  63. 	otmp = addinv(obj);
  64. 	loadlev = near_capacity();
  65. 	prinv(loadlev ?
  66. 	      (loadlev < MOD_ENCUMBER ?
  67. 	       "You have a little trouble removing" :
  68. 	       "You have much trouble removing") : (char *)0,
  69. 	      otmp, count);
  70.  
  71. 	if (is_gold) {
  72. #ifndef GOLDOBJ
  73. 		dealloc_obj(obj);
  74. #endif
  75. 		bot();	/* update character's gold piece count immediately */
  76. 	}
  77. 	return 1;
  78. }

mbag_item_gone[edit]

  1. /* an object inside a cursed bag of holding is being destroyed */
  2. STATIC_OVL long
  3. mbag_item_gone(held, item)
  4. int held;
  5. struct obj *item;
  6. {
  7. struct monst *shkp;
  8. long loss = 0L;
  9.  
  10. if (item->dknown)
  11. 	pline("%s %s vanished!", Doname2(item), otense(item, "have"));
  12. else
  13. 	You("%s %s disappear!", Blind ? "notice" : "see", doname(item));
  14.  
  15. if (*u.ushops && (shkp = shop_keeper(*u.ushops)) != 0) {
  16. 	if (held ? (boolean) item->unpaid : costly_spot(u.ux, u.uy))
  17. 	    loss = stolen_value(item, u.ux, u.uy,
  18. 				(boolean)shkp->mpeaceful, TRUE);
  19. }
  20. obfree(item, (struct obj *) 0);
  21. return loss;
  22. }

observe_quantum_cat[edit]

  1. STATIC_OVL void
  2. observe_quantum_cat(box)
  3. struct obj *box;
  4. {
  5. static NEARDATA const char sc[] = "Schroedinger's Cat";
  6. struct obj *deadcat;
  7. struct monst *livecat;
  8. xchar ox, oy;
  9.  
  10. box->spe = 0;		/* box->owt will be updated below */
  11. if (get_obj_location(box, &ox, &oy, 0))
  12. 	box->ox = ox, box->oy = oy;	/* in case it's being carried */
  13.  
  14. /* this isn't really right, since any form of observation
  15. (telepathic or monster/object/food detection) ought to
  16. force the determination of alive vs dead state; but basing
  17. it just on opening the box is much simpler to cope with */
  18. livecat = rn2(2) ? makemon(&mons[PM_HOUSECAT],
  19. 			       box->ox, box->oy, NO_MINVENT) : 0;
  20. if (livecat) {
  21. 	livecat->mpeaceful = 1;
  22. 	set_malign(livecat);
  23. 	if (!canspotmon(livecat))
  24. 	    You("think %s brushed your %s.", something, body_part(FOOT));
  25. 	else
  26. 	    pline("%s inside the box is still alive!", Monnam(livecat));
  27. 	(void) christen_monst(livecat, sc);
  28. } else {
  29. 	deadcat = mk_named_object(CORPSE, &mons[PM_HOUSECAT],
  30. 				  box->ox, box->oy, sc);
  31. 	if (deadcat) {
  32. 	    obj_extract_self(deadcat);
  33. 	    (void) add_to_container(box, deadcat);
  34. 	}
  35. 	pline_The("%s inside the box is dead!",
  36. 	    Hallucination ? rndmonnam() : "housecat");
  37. }
  38. box->owt = weight(box);
  39. return;
  40. }
  41.  
  42. #undef Icebox

use_container[edit]

  1. int
  2. use_container(obj, held)
  3. register struct obj *obj;
  4. register int held;
  5. {
  6. 	struct obj *curr, *otmp;
  7. #ifndef GOLDOBJ
  8. 	struct obj *u_gold = (struct obj *)0;
  9. #endif
  10. 	boolean one_by_one, allflag, quantum_cat = FALSE,
  11. 		loot_out = FALSE, loot_in = FALSE;
  12. 	char select[MAXOCLASSES+1];
  13. 	char qbuf[BUFSZ], emptymsg[BUFSZ], pbuf[QBUFSZ];
  14. 	long loss = 0L;
  15. 	int cnt = 0, used = 0,
  16. 	    menu_on_request;
  17.  
  18. 	emptymsg[0] = '\0';
  19. 	if (nohands(youmonst.data)) {
  20. 		You("have no hands!");	/* not `body_part(HAND)' */
  21. 		return 0;
  22. 	} else if (!freehand()) {
  23. 		You("have no free %s.", body_part(HAND));
  24. 		return 0;
  25. 	}
  26. 	if (obj->olocked) {
  27. 	    pline("%s to be locked.", Tobjnam(obj, "seem"));
  28. 	    if (held) You("must put it down to unlock.");
  29. 	    return 0;
  30. 	} else if (obj->otrapped) {
  31. 	    if (held) You("open %s...", the(xname(obj)));
  32. 	    (void) chest_trap(obj, HAND, FALSE);
  33. 	    /* even if the trap fails, you've used up this turn */
  34. 	    if (multi >= 0) {	/* in case we didn't become paralyzed */
  35. 		nomul(-1);
  36. 		nomovemsg = "";
  37. 	    }
  38. 	    return 1;
  39. 	}
  40. 	current_container = obj;	/* for use by in/out_container */
  41.  
  42. 	if (obj->spe == 1) {
  43. 	    observe_quantum_cat(obj);
  44. 	    used = 1;
  45. 	    quantum_cat = TRUE;	/* for adjusting "it's empty" message */
  46. 	}
  47. 	/* Count the number of contained objects. Sometimes toss objects if */
  48. 	/* a cursed magic bag.						    */
  49. 	for (curr = obj->cobj; curr; curr = otmp) {
  50. 	    otmp = curr->nobj;
  51. 	    if (Is_mbag(obj) && obj->cursed && !rn2(13)) {
  52. 		obj_extract_self(curr);
  53. 		loss += mbag_item_gone(held, curr);
  54. 		used = 1;
  55. 	    } else {
  56. 		cnt++;
  57. 	    }
  58. 	}
  59.  
  60. 	if (loss)	/* magic bag lost some shop goods */
  61. 	    You("owe %ld %s for lost merchandise.", loss, currency(loss));
  62. 	obj->owt = weight(obj);	/* in case any items were lost */
  63.  
  64. 	if (!cnt)
  65. 	    Sprintf(emptymsg, "%s is %sempty.", Yname2(obj),
  66. 		    quantum_cat ? "now " : "");
  67.  
  68. 	if (cnt || flags.menu_style == MENU_FULL) {
  69. 	    Strcpy(qbuf, "Do you want to take something out of ");
  70. 	    Sprintf(eos(qbuf), "%s?",
  71. 		    safe_qbuf(qbuf, 1, yname(obj), ysimple_name(obj), "it"));
  72. 	    if (flags.menu_style != MENU_TRADITIONAL) {
  73. 		if (flags.menu_style == MENU_FULL) {
  74. 		    int t;
  75. 		    char menuprompt[BUFSZ];
  76. 		    boolean outokay = (cnt != 0);
  77. #ifndef GOLDOBJ
  78. 		    boolean inokay = (invent != 0) || (u.ugold != 0);
  79. #else
  80. 		    boolean inokay = (invent != 0);
  81. #endif
  82. 		    if (!outokay && !inokay) {
  83. 			pline("%s", emptymsg);
  84. 			You("don't have anything to put in.");
  85. 			return used;
  86. 		    }
  87. 		    menuprompt[0] = '\0';
  88. 		    if (!cnt) Sprintf(menuprompt, "%s ", emptymsg);
  89. 		    Strcat(menuprompt, "Do what?");
  90. 		    t = in_or_out_menu(menuprompt, current_container, outokay, inokay);
  91. 		    if (t <= 0) return 0;
  92. 		    loot_out = (t & 0x01) != 0;
  93. 		    loot_in  = (t & 0x02) != 0;
  94. 		} else {	/* MENU_COMBINATION or MENU_PARTIAL */
  95. 		    loot_out = (yn_function(qbuf, "ynq", 'n') == 'y');
  96. 		}
  97. 		if (loot_out) {
  98. 		    add_valid_menu_class(0);	/* reset */
  99. 		    used |= menu_loot(0, current_container, FALSE) > 0;
  100. 		}
  101. 	    } else {
  102. 		/* traditional code */
  103. ask_again2:
  104. 		menu_on_request = 0;
  105. 		add_valid_menu_class(0);	/* reset */
  106. 		Strcpy(pbuf, ":ynq");
  107. 		if (cnt) Strcat(pbuf, "m");
  108. 		switch (yn_function(qbuf, pbuf, 'n')) {
  109. 		case ':':
  110. 		    container_contents(current_container, FALSE, FALSE);
  111. 		    goto ask_again2;
  112. 		case 'y':
  113. 		    if (query_classes(select, &one_by_one, &allflag,
  114. 				      "take out", current_container->cobj,
  115. 				      FALSE,
  116. #ifndef GOLDOBJ
  117. 				      FALSE,
  118. #endif
  119. 				      &menu_on_request)) {
  120. 			if (askchain((struct obj **)&current_container->cobj,
  121. 				     (one_by_one ? (char *)0 : select),
  122. 				     allflag, out_container,
  123. 				     (int FDECL((*),(OBJ_P)))0,
  124. 				     0, "nodot"))
  125. 			    used = 1;
  126. 		    } else if (menu_on_request < 0) {
  127. 			used |= menu_loot(menu_on_request,
  128. 					  current_container, FALSE) > 0;
  129. 		    }
  130. 		    /*FALLTHRU*/
  131. 		case 'n':
  132. 		    break;
  133. 		case 'm':
  134. 		    menu_on_request = -2; /* triggers ALL_CLASSES */
  135. 		    used |= menu_loot(menu_on_request, current_container, FALSE) > 0;
  136. 		    break;
  137. 		case 'q':
  138. 		default:
  139. 		    return used;
  140. 		}
  141. 	    }
  142. 	} else {
  143. 	    pline("%s", emptymsg);		/* <whatever> is empty. */
  144. 	}
  145.  
  146. #ifndef GOLDOBJ
  147. 	if (!invent && u.ugold == 0) {
  148. #else
  149. 	if (!invent) {
  150. #endif
  151. 	    /* nothing to put in, but some feedback is necessary */
  152. 	    You("don't have anything to put in.");
  153. 	    return used;
  154. 	}
  155. 	if (flags.menu_style != MENU_FULL) {
  156. 	    Sprintf(qbuf, "Do you wish to put %s in?", something);
  157. 	    Strcpy(pbuf, ynqchars);
  158. 	    if (flags.menu_style == MENU_TRADITIONAL && invent && inv_cnt() > 0)
  159. 		Strcat(pbuf, "m");
  160. 	    switch (yn_function(qbuf, pbuf, 'n')) {
  161. 		case 'y':
  162. 		    loot_in = TRUE;
  163. 		    break;
  164. 		case 'n':
  165. 		    break;
  166. 		case 'm':
  167. 		    add_valid_menu_class(0);	  /* reset */
  168. 		    menu_on_request = -2; /* triggers ALL_CLASSES */
  169. 		    used |= menu_loot(menu_on_request, current_container, TRUE) > 0;
  170. 		    break;
  171. 		case 'q':
  172. 		default:
  173. 		    return used;
  174. 	    }
  175. 	}
  176. 	/*
  177. 	 * Gone: being nice about only selecting food if we know we are
  178. 	 * putting things in an ice chest.
  179. 	 */
  180. 	if (loot_in) {
  181. #ifndef GOLDOBJ
  182. 	    if (u.ugold) {
  183. 		/*
  184. 		 * Hack: gold is not in the inventory, so make a gold object
  185. 		 * and put it at the head of the inventory list.
  186. 		 */
  187. 		u_gold = mkgoldobj(u.ugold);	/* removes from u.ugold */
  188. 		u_gold->in_use = TRUE;
  189. 		u.ugold = u_gold->quan;		/* put the gold back */
  190. 		assigninvlet(u_gold);		/* might end up as NOINVSYM */
  191. 		u_gold->nobj = invent;
  192. 		invent = u_gold;
  193. 	    }
  194. #endif
  195. 	    add_valid_menu_class(0);	  /* reset */
  196. 	    if (flags.menu_style != MENU_TRADITIONAL) {
  197. 		used |= menu_loot(0, current_container, TRUE) > 0;
  198. 	    } else {
  199. 		/* traditional code */
  200. 		menu_on_request = 0;
  201. 		if (query_classes(select, &one_by_one, &allflag, "put in",
  202. 				   invent, FALSE,
  203. #ifndef GOLDOBJ
  204. 				   (u.ugold != 0L),
  205. #endif
  206. 				   &menu_on_request)) {
  207. 		    (void) askchain((struct obj **)&invent,
  208. 				    (one_by_one ? (char *)0 : select), allflag,
  209. 				    in_container, ck_bag, 0, "nodot");
  210. 		    used = 1;
  211. 		} else if (menu_on_request < 0) {
  212. 		    used |= menu_loot(menu_on_request,
  213. 				      current_container, TRUE) > 0;
  214. 		}
  215. 	    }
  216. 	}
  217.  
  218. #ifndef GOLDOBJ
  219. 	if (u_gold && invent && invent->oclass == COIN_CLASS) {
  220. 	    /* didn't stash [all of] it */
  221. 	    u_gold = invent;
  222. 	    invent = u_gold->nobj;
  223. 	    u_gold->in_use = FALSE;
  224. 	    dealloc_obj(u_gold);
  225. 	}
  226. #endif
  227. 	return used;
  228. }

menu_loot[edit]

  1. /* Loot a container (take things out, put things in), using a menu. */
  2. STATIC_OVL int
  3. menu_loot(retry, container, put_in)
  4. int retry;
  5. struct obj *container;
  6. boolean put_in;
  7. {
  8. int n, i, n_looted = 0;
  9. boolean all_categories = TRUE, loot_everything = FALSE;
  10. char buf[BUFSZ];
  11. const char *takeout = "Take out", *putin = "Put in";
  12. struct obj *otmp, *otmp2;
  13. menu_item *pick_list;
  14. int mflags, res;
  15. long count;
  16.  
  17. if (retry) {
  18. 	all_categories = (retry == -2);
  19. } else if (flags.menu_style == MENU_FULL) {
  20. 	all_categories = FALSE;
  21. 	Sprintf(buf,"%s what type of objects?", put_in ? putin : takeout);
  22. 	mflags = put_in ? ALL_TYPES | BUC_ALLBKNOWN | BUC_UNKNOWN :
  23. 		          ALL_TYPES | CHOOSE_ALL | BUC_ALLBKNOWN | BUC_UNKNOWN;
  24. 	n = query_category(buf, put_in ? invent : container->cobj,
  25. 			   mflags, &pick_list, PICK_ANY);
  26. 	if (!n) return 0;
  27. 	for (i = 0; i < n; i++) {
  28. 	    if (pick_list[i].item.a_int == 'A')
  29. 		loot_everything = TRUE;
  30. 	    else if (pick_list[i].item.a_int == ALL_TYPES_SELECTED)
  31. 		all_categories = TRUE;
  32. 	    else
  33. 		add_valid_menu_class(pick_list[i].item.a_int);
  34. 	}
  35. 	free((genericptr_t) pick_list);
  36. }
  37.  
  38. if (loot_everything) {
  39. 	for (otmp = container->cobj; otmp; otmp = otmp2) {
  40. 	    otmp2 = otmp->nobj;
  41. 	    res = out_container(otmp);
  42. 	    if (res < 0) break;
  43. 	}
  44. } else {
  45. 	mflags = INVORDER_SORT;
  46. 	if (put_in && flags.invlet_constant) mflags |= USE_INVLET;
  47. 	Sprintf(buf,"%s what?", put_in ? putin : takeout);
  48. 	n = query_objlist(buf, put_in ? invent : container->cobj,
  49. 			  mflags, &pick_list, PICK_ANY,
  50. 			  all_categories ? allow_all : allow_category);
  51. 	if (n) {
  52. 		n_looted = n;
  53. 		for (i = 0; i < n; i++) {
  54. 		    otmp = pick_list[i].item.a_obj;
  55. 		    count = pick_list[i].count;
  56. 		    if (count > 0 && count < otmp->quan) {
  57. 			otmp = splitobj(otmp, count);
  58. 			/* special split case also handled by askchain() */
  59. 		    }
  60. 		    res = put_in ? in_container(otmp) : out_container(otmp);
  61. 		    if (res < 0) {
  62. 			if (otmp != pick_list[i].item.a_obj) {
  63. 			    /* split occurred, merge again */
  64. 			    (void) merged(&pick_list[i].item.a_obj, &otmp);
  65. 			}
  66. 			break;
  67. 		    }
  68. 		}
  69. 		free((genericptr_t)pick_list);
  70. 	}
  71. }
  72. return n_looted;
  73. }

in_or_out_menu[edit]

  1. STATIC_OVL int
  2. in_or_out_menu(prompt, obj, outokay, inokay)
  3. const char *prompt;
  4. struct obj *obj;
  5. boolean outokay, inokay;
  6. {
  7. winid win;
  8. anything any;
  9. menu_item *pick_list;
  10. char buf[BUFSZ];
  11. int n;
  12. const char *menuselector = iflags.lootabc ? "abc" : "oib";
  13.  
  14. any.a_void = 0;
  15. win = create_nhwindow(NHW_MENU);
  16. start_menu(win);
  17. if (outokay) {
  18. 	any.a_int = 1;
  19. 	Sprintf(buf,"Take %s out of %s", something, the(xname(obj)));
  20. 	add_menu(win, NO_GLYPH, &any, *menuselector, 0, ATR_NONE,
  21. 			buf, MENU_UNSELECTED);
  22. }
  23. menuselector++;
  24. if (inokay) {
  25. 	any.a_int = 2;
  26. 	Sprintf(buf,"Put %s into %s", something, the(xname(obj)));
  27. 	add_menu(win, NO_GLYPH, &any, *menuselector, 0, ATR_NONE, buf, MENU_UNSELECTED);
  28. }
  29. menuselector++;
  30. if (outokay && inokay) {
  31. 	any.a_int = 3;
  32. 	add_menu(win, NO_GLYPH, &any, *menuselector, 0, ATR_NONE,
  33. 			"Both of the above", MENU_UNSELECTED);
  34. }
  35. end_menu(win, prompt);
  36. n = select_menu(win, PICK_ONE, &pick_list);
  37. destroy_nhwindow(win);
  38. if (n > 0) {
  39. 	n = pick_list[0].item.a_int;
  40. 	free((genericptr_t) pick_list);
  41. }
  42. return n;
  43. }
  44.  
  45. /*pickup.c*/