Source:NetHack 3.4.0/invent.c

Below is the full text to invent.c from the source code of NetHack 3.4.0. To link to a particular line, write [[NetHack 3.4.0/invent.c#line123 ]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)invent.c	3.4	2002/02/23	*/ 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    #include "hack.h"  6.    #include "artifact.h"  7. 8.   #define NOINVSYM	'#' 9.   #define CONTAINED_SYM	'>'	/* designator for inside a container */ 10.   11.   #ifdef OVL1 12.  STATIC_DCL void NDECL(reorder_invent); 13.  STATIC_DCL boolean FDECL(mergable,(struct obj *,struct obj *)); 14.  STATIC_DCL void FDECL(invdisp_nothing, (const char *,const char *)); 15.  STATIC_DCL boolean FDECL(worn_wield_only, (struct obj *)); 16.  STATIC_DCL boolean FDECL(only_here, (struct obj *)); 17.  #endif /* OVL1 */ 18.  STATIC_DCL void FDECL(compactify,(char *)); 19.  STATIC_DCL boolean FDECL(taking_off, (const char *)); 20.  STATIC_DCL boolean FDECL(putting_on, (const char *)); 21.  STATIC_PTR int FDECL(ckunpaid,(struct obj *)); 22.  STATIC_PTR int FDECL(ckvalidcat,(struct obj *)); 23.  static char FDECL(display_pickinv, (const char *,BOOLEAN_P, long *)); 24.  #ifdef OVLB 25.  STATIC_DCL boolean FDECL(this_type_only, (struct obj *)); 26.  STATIC_DCL void NDECL(dounpaid); 27.  STATIC_DCL struct obj *FDECL(find_unpaid,(struct obj *,struct obj **)); 28.  STATIC_DCL void FDECL(menu_identify, (int)); 29.  STATIC_DCL boolean FDECL(tool_in_use, (struct obj *)); 30.  #endif /* OVLB */ 31.  STATIC_DCL char FDECL(obj_to_let,(struct obj *)); 32.   33.   #ifdef OVLB 34.   35.   static int lastinvnr = 51;	/* 0 ... 51 (never saved&restored) */ 36.   37.   #ifdef WIZARD 38.  /* wizards can wish for venom, which will become an invisible inventory 39.   * item without this. putting it in inv_order would mean venom would 40.   * suddenly become a choice for all the inventory-class commands, which 41.   * would probably cause mass confusion. the test for inventory venom 42.   * is only WIZARD and not wizard because the wizard can leave venom lying 43.   * around on a bones level for normal players to find. 44.   */  45.   static char venom_inv[] = { VENOM_CLASS, 0 };	/* (constant) */ 46.  #endif 47.   48.   void 49.  assigninvlet(otmp) 50.  register struct obj *otmp; 51.  {  52.   	boolean inuse[52]; 53.  	register int i;  54. register struct obj *obj; 55.   56.   #ifdef GOLDOBJ 57.          /* There is only one of these in inventory... */        58.           if (otmp->oclass == GOLD_CLASS) { 59.  	    otmp->invlet = GOLD_SYM; 60.  	    return; 61.  	}  62.   #endif 63.   64.   	for(i = 0; i < 52; i++) inuse[i] = FALSE; 65.  	for(obj = invent; obj; obj = obj->nobj) if(obj != otmp) { 66.  		i = obj->invlet; 67.  		if('a' <= i && i <= 'z') inuse[i - 'a'] = TRUE; else 68.  		if('A' <= i && i <= 'Z') inuse[i - 'A' + 26] = TRUE; 69.  		if(i == otmp->invlet) otmp->invlet = 0; 70.  	}  71.   	if((i = otmp->invlet) &&  72.   	    (('a' <= i && i <= 'z') || ('A' <= i && i <= 'Z'))) 73.  		return; 74.  	for(i = lastinvnr+1; i != lastinvnr; i++) { 75.  		if(i == 52) { i = -1; continue; } 76.  		if(!inuse[i]) break; 77.  	}  78.   	otmp->invlet = (inuse[i] ? NOINVSYM :  79.   			(i < 26) ? ('a'+i) : ('A'+i-26)); 80.  	lastinvnr = i;  81. } 82.    83.   #endif /* OVLB */ 84.  #ifdef OVL1 85.   86.   /* note: assumes ASCII; toggling a bit puts lowercase in front of uppercase */ 87.  #define inv_rank(o) ((o)->invlet ^ 040) 88.   89.   /* sort the inventory; used by addinv and doorganize */ 90.  STATIC_OVL void 91.  reorder_invent 92.  {  93.   	struct obj *otmp, *prev, *next; 94.  	boolean need_more_sorting; 95.   96.   	do { 97.  	    /*  98.   	     * We expect at most one item to be out of order, so this 99.  	     * isn't nearly as inefficient as it may first appear. 100. 	     */  101.  	    need_more_sorting = FALSE; 102. 	    for (otmp = invent, prev = 0; otmp; ) { 103. 		next = otmp->nobj; 104. 		if (next && inv_rank(next) < inv_rank(otmp)) { 105. 		    need_more_sorting = TRUE; 106. 		    if (prev) prev->nobj = next; 107. 		    else      invent = next; 108. 		    otmp->nobj = next->nobj; 109. 		    next->nobj = otmp; 110. 		    prev = next; 111. 		} else { 112. 		    prev = otmp; 113. 		    otmp = next; 114. 		}  115.  	    }  116.  	} while (need_more_sorting); 117. }  118.   119.  #undef inv_rank 120.  121.  /* scan a list of objects to see whether another object will merge with 122.    one of them; used in pickup.c when all 52 inventory slots are in use, 123.    to figure out whether another object could still be picked up */ 124. struct obj * 125. merge_choice(objlist, obj) 126. struct obj *objlist, *obj; 127. {  128.  	struct monst *shkp; 129. 	int save_nocharge; 130.  131.  	if (obj->otyp == SCR_SCARE_MONSTER)	/* punt on these */ 132. 	    return (struct obj *)0; 133. 	/* if this is an item on the shop floor, the attributes it will 134. 	   have when carried are different from what they are now; prevent 135. 	   that from eliciting an incorrect result from mergable */ 136. 	save_nocharge = obj->no_charge; 137. 	if (objlist == invent && obj->where == OBJ_FLOOR &&  138.  		(shkp = shop_keeper(inside_shop(obj->ox, obj->oy))) != 0) { 139. 	    if (obj->no_charge) obj->no_charge = 0; 140. 	    /* A billable object won't have its `unpaid' bit set, so would 141. 	       erroneously seem to be a candidate to merge with a similar 142. 	       ordinary object. That's no good, because once it's really 143. 	       picked up, it won't merge after all. It might merge with 144. 	       another unpaid object, but we can't check that here (depends  145.  	       too much upon shk's bill) and if it doesn't merge it would 146. 	       end up in the '#' overflow inventory slot, so reject it now. */ 147.  	    else if (inhishop(shkp)) return (struct obj *)0; 148. 	}  149.  	while (objlist) { 150. 	    if (mergable(objlist, obj)) break; 151. 	    objlist = objlist->nobj; 152. 	}  153.  	obj->no_charge = save_nocharge; 154. 	return objlist; 155. }  156.   157.  /* merge obj with otmp and delete obj if types agree */ 158. int 159. merged(potmp, pobj) 160. struct obj **potmp, **pobj; 161. {  162.  	register struct obj *otmp = *potmp, *obj = *pobj; 163.  164.  	if(mergable(otmp, obj)) { 165. 		/* Approximate age: we do it this way because if we were to  166. * do it "accurately" (merge only when ages are identical) 167. 		 * we'd wind up never merging any corpses. 168. 		 * otmp->age = otmp->age*(1-proportion) + obj->age*proportion; 169. 		 *  170.  		 * Don't do the age manipulation if lit.  We would need 171. 		 * to stop the burn on both items, then merge the age, 172. 		 * then restart the burn. 173. 		 */  174.  		if (!obj->lamplit) 175. 		    otmp->age = ((otmp->age*otmp->quan) + (obj->age*obj->quan)) 176. 			    / (otmp->quan + obj->quan); 177.  178.  		otmp->quan += obj->quan; 179. #ifdef GOLDOBJ 180.                 /* temporary special case for gold objects!!!! */ 181.  #endif 182. 		if (otmp->oclass == GOLD_CLASS) otmp->owt = weight(otmp); 183. 		else otmp->owt += obj->owt; 184. 		if(!otmp->onamelth && obj->onamelth) 185. 			otmp = *potmp = oname(otmp, ONAME(obj)); 186. 		obj_extract_self(obj); 187.  188.  		/* really should merge the timeouts */ 189. 		if (obj->lamplit) obj_merge_light_sources(obj, otmp); 190. 		if (obj->timed) obj_stop_timers(obj);	/* follows lights */ 191.  192.  		/* fixup for `#adjust' merging wielded darts, daggers, &c */ 193. 		if (obj->owornmask && carried(otmp)) { 194. 		    long wmask = otmp->owornmask | obj->owornmask; 195.  196.  		    /* Both the items might be worn in competing slots; 197. 		       merger preference (regardless of which is which): 198. 			 primary weapon + alternate weapon -> primary weapon; 199. 			 primary weapon + quiver -> primary weapon; 200. 			 alternate weapon + quiver -> alternate weapon. 201. 		       (Prior to 3.3.0, it was not possible for the two  202.  		       stacks to be worn in different slots and `obj'  203.  		       didn't need to be unworn when merging.) */ 204. 		    if (wmask & W_WEP) wmask = W_WEP; 205. 		    else if (wmask & W_SWAPWEP) wmask = W_SWAPWEP; 206. 		    else if (wmask & W_QUIVER) wmask = W_QUIVER; 207. 		    else { 208. 			impossible("merging strangely worn items (%lx)", wmask); 209. 			wmask = otmp->owornmask; 210. 		    }  211.  		    if ((otmp->owornmask & ~wmask) != 0L) setnotworn(otmp); 212. 		    setworn(otmp, wmask); 213. 		    setnotworn(obj); 214. 		}  215.  #if 0 216. 		/* (this should not be necessary, since items  217.  		    already in a monster's inventory don't ever get  218.  		    merged into other objects [only vice versa]) */ 219. 		else if (obj->owornmask && mcarried(otmp)) { 220. 		    if (obj == MON_WEP(otmp->ocarry)) { 221. 			MON_WEP(otmp->ocarry) = otmp; 222. 			otmp->owornmask = W_WEP; 223. 		    }  224.  		}  225.  #endif /*0*/ 226.  227.  		obfree(obj,otmp);	/* free(obj), bill->otmp */ 228. 		return(1); 229. 	}  230.  	return 0; 231. }  232.   233.  /*  234.  Adjust hero intrinsics as if this object was being added to the hero's  235. inventory. Called _before_ the object has been added to the hero's 236. inventory. 237.  238.  This is called when adding objects to the hero's inventory normally (via  239.  addinv) or when an object in the hero's inventory has been polymorphed 240. in-place. 241.  242.  It may be valid to merge this code with with addinv_core2. 243. */  244.  void 245. addinv_core1(obj) 246. struct obj *obj; 247. {  248.  	if (obj->oclass == GOLD_CLASS) { 249. #ifndef GOLDOBJ 250. 		u.ugold += obj->quan; 251. #else 252. 		flags.botl = 1; 253. #endif 254. 	} else if (obj->otyp == AMULET_OF_YENDOR) { 255. 		if (u.uhave.amulet) impossible("already have amulet?"); 256. 		u.uhave.amulet = 1; 257. 	} else if (obj->otyp == CANDELABRUM_OF_INVOCATION) { 258. 		if (u.uhave.menorah) impossible("already have candelabrum?"); 259. 		u.uhave.menorah = 1; 260. 	} else if (obj->otyp == BELL_OF_OPENING) { 261. 		if (u.uhave.bell) impossible("already have silver bell?"); 262. 		u.uhave.bell = 1; 263. 	} else if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { 264. 		if (u.uhave.book) impossible("already have the book?"); 265. 		u.uhave.book = 1; 266. 	} else if (obj->oartifact) { 267. 		if (is_quest_artifact(obj)) { 268. 		    if (u.uhave.questart) 269. 			impossible("already have quest artifact?"); 270. 		    u.uhave.questart = 1; 271. 		    artitouch; 272. 		}  273.  		set_artifact_intrinsic(obj, 1, W_ART); 274. 	}  275.  }  276.   277.  /*  278.  Adjust hero intrinsics as if this object was being added to the hero's  279. inventory. Called _after_ the object has been added to the hero's 280. inventory. 281.  282.  This is called when adding objects to the hero's inventory normally (via  283.  addinv) or when an object in the hero's inventory has been polymorphed 284. in-place. 285. */  286.  void 287. addinv_core2(obj) 288. struct obj *obj; 289. {  290.  	if (obj->otyp == LUCKSTONE ||  291.  	    (obj->oartifact && spec_ability(obj, SPFX_LUCK))) { 292. 		/* new luckstone must be in inventory by this point 293. 		 * for correct calculation */ 294. 		set_moreluck; 295. 	}  296.  }  297.   298.  /*  299.  Add obj to the hero's inventory. Make sure the object is "free". 300. Adjust hero attributes as necessary. 301. */  302.  struct obj * 303. addinv(obj) 304. struct obj *obj; 305. {  306.  	struct obj *otmp, *prev; 307.  308.  	if (obj->where != OBJ_FREE) 309. 	    panic("addinv: obj not free"); 310. 	obj->no_charge = 0;	/* not meaningful for invent */ 311.  312.  	addinv_core1(obj); 313. #ifndef GOLDOBJ 314. 	/* if handed gold, we're done */ 315. 	if (obj->oclass == GOLD_CLASS) 316. 	    return obj; 317. #endif 318.  319.  	/* merge if possible; find end of chain in the process */ 320. 	for (prev = 0, otmp = invent; otmp; prev = otmp, otmp = otmp->nobj) 321. 	    if (merged(&otmp, &obj)) { 322. 		obj = otmp; 323. 		goto added; 324. 	    }  325.  	/* didn't merge, so insert into chain */ 326. 	if (flags.invlet_constant || !prev) { 327. 	    if (flags.invlet_constant) assigninvlet(obj); 328. 	    obj->nobj = invent;		/* insert at beginning */ 329. 	    invent = obj; 330. 	    if (flags.invlet_constant) reorder_invent; 331. 	} else { 332. 	    prev->nobj = obj;		/* insert at end */ 333. 	    obj->nobj = 0; 334. 	}  335.  	obj->where = OBJ_INVENT; 336.  337.  added: 338. 	addinv_core2(obj); 339. 	carry_obj_effects(obj);		/* carrying affects the obj */ 340. 	update_inventory; 341. 	return(obj); 342. }  343.   344.  /*  345.   * Some objects are affected by being carried. 346.  * Make those adjustments here. Called _after_ the object 347.  * has been added to the hero's or monster's inventory, 348.  * and after hero's intrinsics have been updated. 349.  */  350.  void 351. carry_obj_effects(obj) 352. struct obj *obj; 353. {  354.  	/* Cursed figurines can spontaneously transform 355. 	   when carried. */ 356.  	if (obj->otyp == FIGURINE) { 357. 		if (obj->cursed  358.  	    	    && obj->corpsenm != NON_PM  359.  	    	    && !dead_species(obj->corpsenm,TRUE)) { 360. 			attach_fig_transform_timeout(obj); 361. 		    }  362.  	}  363.  }  364.   365.  #endif /* OVL1 */ 366. #ifdef OVLB 367.  368.  /* Add an item to the inventory unless we're fumbling, and give a message. 369.  * If there aren't any free inventory slots, we'll drop it instead. 370.  * If both success and failure messages are NULL, then we're just doing the 371.  * fumbling/slot-limit checking for a silent grab. 372.  */  373.  struct obj * 374. hold_another_object(obj, drop_fmt, drop_arg, hold_msg) 375. struct obj *obj; 376. const char *drop_fmt, *drop_arg, *hold_msg; 377. {  378.  	char buf[BUFSZ]; 379.  380.  	if (!Blind) obj->dknown = 1;	/* maximize mergibility */ 381. 	if (Fumbling) { 382. 		if (drop_fmt) pline(drop_fmt, drop_arg); 383. 		dropy(obj); 384. 	} else { 385. 		long oquan = obj->quan; 386. 		int prev_encumbr = near_capacity;	/* before addinv */ 387. 		/* encumbrance only matters if it would now become worse 388. 		   than max( current_value, stressed ) */ 389. 		if (prev_encumbr < MOD_ENCUMBER) prev_encumbr = MOD_ENCUMBER; 390. 		if (drop_arg) { 391. 			/* addinv may redraw the entire inventory, overwriting 392. 			 * drop_arg when it comes from something like doname 393. 			 */  394.  			Strcpy(buf, drop_arg); 395. 			drop_arg = buf; 396. 		}  397.  		obj = addinv(obj); 398. 		if (inv_cnt > 52  399.  		    || ((obj->otyp != LOADSTONE || !obj->cursed) 400. 			&& near_capacity > prev_encumbr)) { 401. 			if (drop_fmt) pline(drop_fmt, drop_arg); 402. 			/* undo any merge which took place */ 403. 			if (obj->quan > oquan) { 404. 			    obj = splitobj(obj, oquan); 405. 			}  406.  			dropx(obj); 407. 		} else { 408. 			if (flags.autoquiver && !uquiver &&  409.  			    (is_missile(obj) || 410. 			     (uwep && ammo_and_launcher(obj, uwep)))) 411. 			    setuqwep(obj); 412. 			if (hold_msg || drop_fmt) prinv(hold_msg, obj, oquan); 413. 		}  414.  	}  415.  	return obj; 416. }  417.   418.  /* useup all of an item regardless of its quantity */ 419. void 420. useupall(obj) 421. struct obj *obj; 422. {  423.  	setnotworn(obj); 424. 	freeinv(obj); 425. 	obfree(obj, (struct obj *)0);	/* deletes contents also */ 426. }  427.   428.  void 429. useup(obj) 430. register struct obj *obj; 431. {  432.  	/*  Note:  This works correctly for containers because they */ 433. 	/*	   (containers) don't merge. */ 434.  	if (obj->quan > 1L) { 435. 		obj->in_use = FALSE;	/* no longer in use */ 436. 		obj->quan--; 437. 		obj->owt = weight(obj); 438. 		update_inventory; 439. 	} else { 440. 		useupall(obj); 441. 	}  442.  }  443.   444.  #endif /* OVLB */ 445. #ifdef OVL3 446.  447.  /*  448.  Adjust hero's attributes as if this object was being removed from the 449. hero's inventory. This should only be called from freeinv and 450. where we are polymorphing an object already in the hero's inventory. 451.  452.  Should think of a better name...  453. */ 454.  void 455. freeinv_core(obj) 456. struct obj *obj; 457. {  458.  	if (obj->oclass == GOLD_CLASS) { 459. #ifndef GOLDOBJ 460. 		u.ugold -= obj->quan; 461. #endif 462. 		flags.botl = 1; 463. 		return; 464. 	} else if (obj->otyp == AMULET_OF_YENDOR) { 465. 		if (!u.uhave.amulet) impossible("don't have amulet?"); 466. 		u.uhave.amulet = 0; 467. 	} else if (obj->otyp == CANDELABRUM_OF_INVOCATION) { 468. 		if (!u.uhave.menorah) impossible("don't have candelabrum?"); 469. 		u.uhave.menorah = 0; 470. 	} else if (obj->otyp == BELL_OF_OPENING) { 471. 		if (!u.uhave.bell) impossible("don't have silver bell?"); 472. 		u.uhave.bell = 0; 473. 	} else if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { 474. 		if (!u.uhave.book) impossible("don't have the book?"); 475. 		u.uhave.book = 0; 476. 	} else if (obj->oartifact) { 477. 		if (is_quest_artifact(obj)) { 478. 		    if (!u.uhave.questart) 479. 			impossible("don't have quest artifact?"); 480. 		    u.uhave.questart = 0; 481. 		}  482.  		set_artifact_intrinsic(obj, 0, W_ART); 483. 	}  484.   485.  	if (obj->otyp == LOADSTONE) { 486. 		curse(obj); 487. 	} else if (obj->otyp == LUCKSTONE ||  488.  		    (obj->oartifact && spec_ability(obj, SPFX_LUCK))) { 489. 		set_moreluck; 490. 		flags.botl = 1; 491. 	} else if (obj->otyp == FIGURINE && obj->timed) { 492. 		(void) stop_timer(FIG_TRANSFORM, (genericptr_t) obj); 493. 	}  494.  }  495.   496.  /* remove an object from the hero's inventory */ 497. void 498. freeinv(obj) 499. register struct obj *obj; 500. {  501.  	extract_nobj(obj, &invent); 502. 	freeinv_core(obj); 503. 	update_inventory; 504. }  505.   506.  void 507. delallobj(x, y)  508. int x, y; 509. { 510.  	struct obj *otmp, *otmp2; 511.  512.  	for (otmp = level.objects[x][y]; otmp; otmp = otmp2) { 513. 		if (otmp == uball) 514. 			unpunish; 515. 		/* after unpunish, or might get deallocated chain */ 516. 		otmp2 = otmp->nexthere; 517. 		if (otmp == uchain) 518. 			continue; 519. 		delobj(otmp); 520. 	}  521.  }  522.   523.  #endif /* OVL3 */ 524. #ifdef OVL2 525.  526.  /* destroy object in fobj chain (if unpaid, it remains on the bill) */ 527. void 528. delobj(obj) 529. register struct obj *obj; 530. {  531.  	boolean update_map; 532.  533.  	if (obj->otyp == AMULET_OF_YENDOR ||  534.  			obj->otyp == CANDELABRUM_OF_INVOCATION ||  535.  			obj->otyp == BELL_OF_OPENING ||  536.  			obj->otyp == SPE_BOOK_OF_THE_DEAD) { 537. 		/* player might be doing something stupid, but we  538. * can't guarantee that. assume special artifacts 539. 		 * are indestructible via drawbridges, and exploding 540. 		 * chests, and golem creation, and ...  541. */ 542.  		return; 543. 	}  544.  	update_map = (obj->where == OBJ_FLOOR); 545. 	obj_extract_self(obj); 546. 	if (update_map) newsym(obj->ox, obj->oy); 547. 	obfree(obj, (struct obj *) 0);	/* frees contents also */ 548. }  549.   550.  #endif /* OVL2 */ 551. #ifdef OVL0 552.  553.  struct obj * 554. sobj_at(n,x,y) 555. register int n, x, y;  556. { 557.  	register struct obj *otmp; 558.  559.  	for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) 560. 		if(otmp->otyp == n)  561. return(otmp); 562. 	return((struct obj *)0); 563. }  564.   565.  #endif /* OVL0 */ 566. #ifdef OVLB 567.  568.  struct obj * 569. carrying(type) 570. register int type; 571. {  572.  	register struct obj *otmp; 573.  574.  	for(otmp = invent; otmp; otmp = otmp->nobj) 575. 		if(otmp->otyp == type) 576. 			return(otmp); 577. 	return((struct obj *) 0); 578. }  579.   580.  const char * 581. currency(amount) 582. long amount; 583. {  584.  	if (amount == 1L) return "zorkmid"; 585. 	else return "zorkmids"; 586. }  587.   588.  boolean 589. have_lizard 590. {  591.  	register struct obj *otmp; 592.  593.  	for(otmp = invent; otmp; otmp = otmp->nobj) 594. 		if(otmp->otyp == CORPSE && otmp->corpsenm == PM_LIZARD) 595. 			return(TRUE); 596. 	return(FALSE); 597. }  598.   599.  struct obj * 600. o_on(id, objchn) 601. unsigned int id; 602. register struct obj *objchn; 603. {  604.  	struct obj *temp; 605.  606.  	while(objchn) { 607. 		if(objchn->o_id == id) return(objchn); 608. 		if (Has_contents(objchn) && (temp = o_on(id,objchn->cobj))) 609. 			return temp; 610. 		objchn = objchn->nobj; 611. 	}  612.  	return((struct obj *) 0); 613. }  614.   615.  boolean 616. obj_here(obj, x, y)  617. register struct obj *obj; 618. int x, y;  619. { 620.  	register struct obj *otmp; 621.  622.  	for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) 623. 		if(obj == otmp) return(TRUE); 624. 	return(FALSE); 625. }  626.   627.  #endif /* OVLB */ 628. #ifdef OVL2 629.  630.  struct obj * 631. g_at(x,y) 632. register int x, y;  633. { 634.  	register struct obj *obj = level.objects[x][y]; 635. 	while(obj) { 636. 	    if (obj->oclass == GOLD_CLASS) return obj; 637. 	    obj = obj->nexthere; 638. 	}  639.  	return((struct obj *)0); 640. }  641.   642.  #endif /* OVL2 */ 643. #ifdef OVLB 644. #ifndef GOLDOBJ 645. /* Make a gold object from the hero's gold. */ 646.  struct obj * 647. mkgoldobj(q) 648. register long q;  649. { 650.  	register struct obj *otmp; 651.  652.  	otmp = mksobj(GOLD_PIECE, FALSE, FALSE); 653. 	u.ugold -= q;  654. otmp->quan = q; 655. otmp->owt = weight(otmp); 656. 	flags.botl = 1; 657. 	return(otmp); 658. }  659.  #endif 660. #endif /* OVLB */ 661. #ifdef OVL1 662.  663.  STATIC_OVL void 664. compactify(buf) 665. register char *buf; 666. /* compact a string of inventory letters by dashing runs of letters */ 667. {  668.  	register int i1 = 1, i2 = 1; 669. 	register char ilet, ilet1, ilet2; 670.  671.  	ilet2 = buf[0]; 672. 	ilet1 = buf[1]; 673. 	buf[++i2] = buf[++i1]; 674. 	ilet = buf[i1]; 675. 	while(ilet) { 676. 		if(ilet == ilet1+1) { 677. 			if(ilet1 == ilet2+1) 678. 				buf[i2 - 1] = ilet1 = '-'; 679. 			else if(ilet2 == '-') { 680. 				buf[i2 - 1] = ++ilet1; 681. 				buf[i2] = buf[++i1]; 682. 				ilet = buf[i1]; 683. 				continue; 684. 			}  685.  		}  686.  		ilet2 = ilet1; 687. 		ilet1 = ilet; 688. 		buf[++i2] = buf[++i1]; 689. 		ilet = buf[i1]; 690. 	}  691.  }  692.   693.  /* match the prompt for either 'T' or 'R' command */ 694. STATIC_OVL boolean 695. taking_off(action) 696. const char *action; 697. {  698.      return !strcmp(action, "take off") || !strcmp(action, "remove"); 699. }  700.   701.  /* match the prompt for either 'W' or 'P' command */ 702. STATIC_OVL boolean 703. putting_on(action) 704. const char *action; 705. {  706.      return !strcmp(action, "wear") || !strcmp(action, "put on"); 707. }  708.   709.  /*  710.   * getobj returns: 711.  *	struct obj *xxx:	object to do something with. 712.  *	(struct obj *) 0	error return: no object. 713.  *	&zeroobj		explicitly no object (as in w-). 714. #ifdef GOLDOBJ 715. !!!! test if gold can be used in unusual ways (eaten etc.) 716. !!!! may be able to remove "usegold" 717. #endif 718.  */  719.  struct obj * 720. getobj(let,word) 721. register const char *let,*word; 722. {  723.  	register struct obj *otmp; 724. 	register char ilet; 725. 	char buf[BUFSZ], qbuf[QBUFSZ]; 726. 	char lets[BUFSZ], altlets[BUFSZ], *ap; 727. 	register int foo = 0; 728. 	register char *bp = buf; 729. 	xchar allowcnt = 0;	/* 0, 1 or 2 */ 730. #ifndef GOLDOBJ 731. 	boolean allowgold = FALSE;	/* can't use gold because they don't have any */ 732. #endif 733. 	boolean usegold = FALSE;	/* can't use gold because its illegal */ 734. 	boolean allowall = FALSE; 735. 	boolean allownone = FALSE; 736. 	xchar foox = 0; 737. 	long cnt; 738. 	boolean prezero = FALSE; 739. 	long dummymask; 740.  741.  	if(*let == ALLOW_COUNT) let++, allowcnt = 1; 742. #ifndef GOLDOBJ 743. 	if(*let == GOLD_CLASS) let++, 744. 		usegold = TRUE, allowgold = (u.ugold ? TRUE : FALSE); 745. #else 746. 	if(*let == GOLD_CLASS) let++, usegold = TRUE; 747. #endif 748.  749.  	/* Equivalent of an "ugly check" for gold */ 750. 	if (usegold && !strcmp(word, "eat") && !metallivorous(youmonst.data)) 751. #ifndef GOLDOBJ 752. 		usegold = allowgold = FALSE; 753. #else 754. 		usegold = FALSE; 755. #endif 756.  757.  	if(*let == ALL_CLASSES) let++, allowall = TRUE; 758. 	if(*let == ALLOW_NONE) let++, allownone = TRUE; 759. 	/* "ugly check" for reading fortune cookies, part 1 */ 760. 	/* The normal 'ugly check' keeps the object on the inventory list. 761. 	 * We don't want to do that for shirts/cookies, so the check for 762. 	 * them is handled a bit differently (and also requires that we set  763.  	 * allowall in the caller) 764. 	 */  765.  	if(allowall && !strcmp(word, "read")) allowall = FALSE; 766.  767.  	if(allownone) *bp++ = '-'; 768. #ifndef GOLDOBJ 769. 	if(allowgold) *bp++ = def_oc_syms[GOLD_CLASS]; 770. #endif 771. 	if(bp > buf && bp[-1] == '-') *bp++ = ' '; 772. 	ap = altlets; 773.  774.  	ilet = 'a'; 775. 	for (otmp = invent; otmp; otmp = otmp->nobj) { 776. 	    if (!flags.invlet_constant) 777. #ifdef GOLDOBJ 778. 		if (otmp->invlet != GOLD_SYM) /* don't reassign this */ 779. #endif 780. 		otmp->invlet = ilet;	/* reassign */ 781. 	    if (!*let || index(let, otmp->oclass)  782.  #ifdef GOLDOBJ  783.  		|| (usegold && otmp->invlet == GOLD_SYM)  784.  #endif  785.  		) { 786. 		register int otyp = otmp->otyp; 787. 		bp[foo++] = otmp->invlet; 788.  789.  		/* ugly check: remove inappropriate things */ 790. 		if ((taking_off(word) && 791. 		    (!(otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))  792.  		     || (otmp==uarm && uarmc)  793.  #ifdef TOURIST  794.  		     || (otmp==uarmu && (uarm || uarmc))  795.  #endif  796.  		    ))  797.  		|| (putting_on(word) && 798. 		     (otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)))  799.  							/* already worn */  800.  		|| (!strcmp(word, "wield") && 801. 		    (otmp->owornmask & W_WEP))  802.  		|| (!strcmp(word, "ready") && 803. 		    (otmp->owornmask & (W_WEP | W_SWAPWEP | W_QUIVER)))  804.  		    ) { 805. 			foo--; 806. 			foox++; 807. 		}  808.   809.  		/* Second ugly check; unlike the first it won't trigger an  810. * "else" in "you don't have anything else to ___". 811. 		 */  812.  		else if ((putting_on(word) && 813. 		    ((otmp->oclass == FOOD_CLASS && otmp->otyp != MEAT_RING) ||  814.  		    (otmp->oclass == TOOL_CLASS && 815. 		     otyp != BLINDFOLD && otyp != TOWEL && otyp != LENSES)))  816.  		|| (!strcmp(word, "wield") && 817. 		    (otmp->oclass == TOOL_CLASS && !is_weptool(otmp)))  818.  		|| (!strcmp(word, "eat") && !is_edible(otmp))  819.  		|| (!strcmp(word, "sacrifice") && 820. 		    (otyp != CORPSE &&  821.  		     otyp != AMULET_OF_YENDOR && otyp != FAKE_AMULET_OF_YENDOR))  822.  		|| (!strcmp(word, "write with") && 823. 		    (otmp->oclass == TOOL_CLASS &&  824.  		     otyp != MAGIC_MARKER && otyp != TOWEL))  825.  		|| (!strcmp(word, "tin") && 826. 		    (otyp != CORPSE || !tinnable(otmp)))  827.  		|| (!strcmp(word, "rub") && 828. 		    ((otmp->oclass == TOOL_CLASS && 829. 		      otyp != OIL_LAMP && otyp != MAGIC_LAMP && 830. 		      otyp != BRASS_LANTERN) ||  831.  		     (otmp->oclass == GEM_CLASS && !is_graystone(otmp))))  832.  		|| ((!strcmp(word, "use or apply") ||  833.  			!strcmp(word, "untrap with")) && 834. 		     /* Picks, axes, pole-weapons, bullwhips */ 835. 		    ((otmp->oclass == WEAPON_CLASS && !is_pick(otmp) && 836. 		      !is_pole(otmp) && otyp != BULLWHIP)  837.  		|| (otmp->oclass == POTION_CLASS && 838. 		     /* only applicable potion is oil, and it will only 839. 			be offered as a choice when already discovered */ 840. 		     (otyp != POT_OIL || !otmp->dknown ||  841.  		      !objects[POT_OIL].oc_name_known))  842.  		|| (otmp->oclass == GEM_CLASS && !is_graystone(otmp))))  843.  		|| (!strcmp(word, "invoke") && 844. 		    (!otmp->oartifact && !objects[otyp].oc_unique &&  845.  		     (otyp != FAKE_AMULET_OF_YENDOR || otmp->known) &&  846.  		     otyp != CRYSTAL_BALL &&	/* #invoke synonym for apply */  847.  		   /* note: presenting the possibility of invoking non-artifact  848.  		      mirrors and/or lamps is a simply a cruel deception... */  849.  		     otyp != MIRROR && otyp != MAGIC_LAMP &&  850.  		     (otyp != OIL_LAMP ||	/* don't list known oil lamp */ 851. 		      (otmp->dknown && objects[OIL_LAMP].oc_name_known))))  852.  		|| (!strcmp(word, "untrap with") && 853. 		    (otmp->oclass == TOOL_CLASS && otyp != CAN_OF_GREASE))  854.  		|| (!strcmp(word, "charge") && !is_chargeable(otmp))  855.  		    ) 856. 			foo--; 857. 		/* ugly check for unworn armor that can't be worn */ 858. 		else if (putting_on(word) && *let == ARMOR_CLASS &&  859.  			 !canwearobj(otmp, &dummymask, FALSE)) { 860. 			foo--; 861. 			allowall = TRUE; 862. 			*ap++ = otmp->invlet; 863. 		}  864.  	    } else { 865.  866.  		/* "ugly check" for reading fortune cookies, part 2 */ 867. 		if ((!strcmp(word, "read") && 868. 		    (otmp->otyp == FORTUNE_COOKIE  869.  #ifdef TOURIST  870.  			|| otmp->otyp == T_SHIRT  871.  #endif  872.  		    ))) 873. 			allowall = TRUE; 874. 	    }  875.   876.  	    if(ilet == 'z') ilet = 'A'; else ilet++; 877. 	}  878.  	bp[foo] = 0; 879. 	if(foo == 0 && bp > buf && bp[-1] == ' ') *--bp = 0; 880. 	Strcpy(lets, bp);	/* necessary since we destroy buf */ 881. 	if(foo > 5)			/* compactify string */ 882. 		compactify(bp); 883. 	*ap = '\0'; 884.  885.  #ifndef GOLDOBJ 886. 	if(!foo && !allowall && !allowgold && !allownone) { 887. #else 888. 	if(!foo && !allowall && !allownone) { 889. #endif 890. 		You("don't have anything %sto %s.",  891.  			foox ? "else " : "", word); 892. 		return((struct obj *)0); 893. 	}  894.  	for { 895. 		cnt = 0; 896. 		if (allowcnt == 2) allowcnt = 1;  /* abort previous count */ 897. 		if(!buf[0]) { 898. 			Sprintf(qbuf, "What do you want to %s? [*]", word); 899. 		} else { 900. 			Sprintf(qbuf, "What do you want to %s? [%s or ?*]",  901.  				word, buf); 902. 		}  903.  #ifdef REDO 904. 		if (in_doagain) 905. 		    ilet = readchar; 906. 		else 907. #endif 908. 		    ilet = yn_function(qbuf, (char *)0, '\0'); 909. 		if(ilet == '0') prezero = TRUE; 910. 		while(digit(ilet) && allowcnt) { 911. #ifdef REDO 912. 			if (ilet != '?' && ilet != '*')	savech(ilet); 913. #endif 914. 			cnt = 10*cnt + (ilet - '0'); 915. 			allowcnt = 2;	/* signal presence of cnt */ 916. 			ilet = readchar; 917. 		}  918.  		if(digit(ilet)) { 919. 			pline("No count allowed with this command."); 920. 			continue; 921. 		}  922.  		if(index(quitchars,ilet)) { 923. 		    if(flags.verbose) 924. 			pline(Never_mind); 925. 		    return((struct obj *)0); 926. 		}  927.  		if(ilet == '-') { 928. 			return(allownone ? &zeroobj : (struct obj *) 0); 929. 		}  930.  		if(ilet == def_oc_syms[GOLD_CLASS]) { 931. 			if (!usegold) { 932. 			    You("cannot %s gold.", word); 933. 			    return(struct obj *)0; 934. #ifndef GOLDOBJ 935. 			} else if (!allowgold) { 936. 				You("are not carrying any gold."); 937. 				return(struct obj *)0; 938. #endif 939. 			}  940.  			if(cnt == 0 && prezero) return((struct obj *)0); 941. 			/* Historic note: early Nethack had a bug which was 942. 			 * first reported for Larn, where trying to drop 2^32-n 943. 			 * gold pieces was allowed, and did interesting things 944. 			 * to your money supply. The LRS is the tax bureau 945. 			 * from Larn. 946. 			 */  947.  			if(cnt < 0) { 948. 	pline_The("LRS would be very interested to know you have that much."); 949. 				return(struct obj *)0; 950. 			}  951.   952.  #ifndef GOLDOBJ 953. 			if(!(allowcnt == 2 && cnt < u.ugold)) 954. 				cnt = u.ugold; 955. 			return(mkgoldobj(cnt)); 956. #endif 957. 		}  958.  		if(ilet == '?' || ilet == '*') { 959. 		    char *allowed_choices = (ilet == '?') ? lets : (char *)0; 960. 		    long ctmp = 0; 961.  962.  		    if (ilet == '?' && !*lets && *altlets) 963. 			allowed_choices = altlets; 964. 		    ilet = display_pickinv(allowed_choices, TRUE,  965.  					   allowcnt ? &ctmp : (long *)0); 966. 		    if(!ilet) continue; 967. 		    if (allowcnt && ctmp >= 0) { 968. 			cnt = ctmp; 969. 			if (!cnt) prezero = TRUE; 970. 			allowcnt = 2; 971. 		    }  972.  		    if(ilet == '\033') { 973. 			if(flags.verbose) 974. 			    pline(Never_mind); 975. 			return((struct obj *)0); 976. 		    }  977.  		    /* they typed a letter (not a space) at the prompt */ 978. 		}  979.  		if(allowcnt == 2 && !strcmp(word,"throw")) { 980. 		    /* permit counts for throwing gold, but don't accept 981. 		     * counts for other things since the throw code will 982. 		     * split off a single item anyway */ 983. #ifdef GOLDOBJ 984. 		    if (ilet != def_oc_syms[GOLD_CLASS]) 985. #endif 986. 			allowcnt = 1; 987. 		    if(cnt == 0 && prezero) return((struct obj *)0); 988. 		    if(cnt > 1) { 989. 			You("can only throw one item at a time."); 990. 			continue; 991. 		    }  992.  		}  993.  #ifdef GOLDOBJ 994. 		flags.botl = 1; /* May have changed the amount of money */ 995. #endif 996. #ifdef REDO 997. 		savech(ilet); 998. #endif 999. 		for (otmp = invent; otmp; otmp = otmp->nobj) 1000. 			if (otmp->invlet == ilet) break; 1001. 		if(!otmp) { 1002. 			You("don't have that object."); 1003. #ifdef REDO 1004. 			if (in_doagain) return((struct obj *) 0); 1005. #endif 1006. 			continue; 1007. 		} else if (cnt < 0 || otmp->quan < cnt) { 1008. 			You("don't have that many! You have only %ld.",  1009. 			    otmp->quan); 1010. #ifdef REDO 1011. 			if (in_doagain) return((struct obj *) 0); 1012. #endif 1013. 			continue; 1014. 		} 1015. 		break; 1016. 	} 1017. 	if(!allowall && let && !index(let,otmp->oclass)  1018. #ifdef GOLDOBJ  1019. 	   && !(usegold && otmp->oclass == GOLD_CLASS)  1020. #endif  1021. 	   ) { 1022. 		pline(silly_thing_to, word); 1023. 		return((struct obj *)0); 1024. 	} 1025. 	if(allowcnt == 2) {	/* cnt given */ 1026. 	   if(cnt == 0) return (struct obj *)0; 1027. 	   if(cnt != otmp->quan) { 1028. 		otmp = splitobj(otmp, cnt); 1029. 		/* Very ugly kludge necessary to prevent someone from trying 1030. 		 * to drop one of several loadstones and having the loadstone 1031. 		 * now be separate. 1032. 		 */ 1033. 		if (!strcmp(word, "drop") &&  1034. 		    otmp->otyp == LOADSTONE && otmp->cursed) 1035. 		   otmp->corpsenm = otmp->invlet; 1036. 	   }  1037. 	}  1038. 	return(otmp); 1039. } 1040.  1041. #endif /* OVL1 */ 1042. #ifdef OVLB 1043. 1044. STATIC_PTR int 1045. ckvalidcat(otmp) 1046. register struct obj *otmp; 1047. { 1048. 	/* use allow_category from pickup.c */ 1049. 	return((int)allow_category(otmp)); 1050. } 1051.  1052. STATIC_PTR int 1053. ckunpaid(otmp) 1054. register struct obj *otmp; 1055. { 1056. 	return((int)(otmp->unpaid)); 1057. } 1058.  1059. boolean 1060. wearing_armor 1061. { 1062. 	return((boolean)(uarm || uarmc || uarmf || uarmg || uarmh || uarms 1063. #ifdef TOURIST 1064. 		|| uarmu 1065. #endif 1066. 		)); 1067. }  1068.  1069. boolean 1070. is_worn(otmp) 1071. register struct obj *otmp; 1072. { 1073.     return((boolean)(!!(otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL | 1074. #ifdef STEED 1075. 			W_SADDLE | 1076. #endif 1077. 			W_WEP | W_SWAPWEP | W_QUIVER)))); 1078. } 1079.  1080. static NEARDATA const char removeables[] = 1081. 	{ ARMOR_CLASS, WEAPON_CLASS, RING_CLASS, AMULET_CLASS, TOOL_CLASS, 0 }; 1082. 1083. /* interactive version of getobj - used for Drop, Identify and */ 1084. /* Takeoff (A). Return the number of times fn was called successfully */ 1085. /* If combo is TRUE, we just use this to get a category list */ 1086. int 1087. ggetobj(word, fn, mx, combo, resultflags) 1088. const char *word; 1089. int FDECL((*fn),(OBJ_P)), mx; 1090. boolean combo;		/* combination menu flag */ 1091. unsigned *resultflags; 1092. { 1093. 	int FDECL((*ckfn),(OBJ_P)) = (int FDECL((*),(OBJ_P))) 0; 1094. 	boolean FDECL((*filter),(OBJ_P)) = (boolean FDECL((*),(OBJ_P))) 0; 1095. 	boolean takeoff, ident, allflag, m_seen; 1096. #ifndef GOLDOBJ 1097. 	int oletct, iletct, allowgold, unpaid, oc_of_sym; 1098. #else 1099. 	int oletct, iletct, unpaid, oc_of_sym; 1100. #endif 1101. 	char sym, *ip, olets[MAXOCLASSES+5], ilets[MAXOCLASSES+5]; 1102. 	char buf[BUFSZ], qbuf[QBUFSZ]; 1103. 1104. 	if (resultflags) *resultflags = 0; 1105. #ifndef GOLDOBJ 1106. 	allowgold = (u.ugold && !strcmp(word, "drop")) ? 1 : 0; 1107. #endif 1108. 	takeoff = ident = allflag = m_seen = FALSE; 1109. #ifndef GOLDOBJ 1110. 	if(!invent && !allowgold){ 1111. #else 1112. 	if(!invent){ 1113. #endif 1114. 		You("have nothing to %s.", word); 1115. 		return(0); 1116. 	} 1117. 	add_valid_menu_class(0);	/* reset */ 1118. 	if (taking_off(word)) { 1119. 	   takeoff = TRUE; 1120. 	   filter = is_worn; 1121. 	} else if (!strcmp(word, "identify")) { 1122. 	   ident = TRUE; 1123. 	   filter = not_fully_identified; 1124. 	} 1125.  1126. 	iletct = collect_obj_classes(ilets, invent,  1127. 				     	FALSE,  1128. #ifndef GOLDOBJ  1129. 					(allowgold != 0),  1130. #endif  1131. 					filter); 1132. 	unpaid = count_unpaid(invent); 1133. 1134. 	if (ident && !iletct) { 1135. 	   return -1;		/* no further identifications */ 1136. 	} else if (!takeoff && (unpaid || invent)) { 1137. 	   ilets[iletct++] = ' '; 1138. 	   if (unpaid) ilets[iletct++] = 'u'; 1139. 	   if (count_buc(invent, BUC_BLESSED))  ilets[iletct++] = 'B'; 1140. 	   if (count_buc(invent, BUC_UNCURSED)) ilets[iletct++] = 'U'; 1141. 	   if (count_buc(invent, BUC_CURSED))   ilets[iletct++] = 'C'; 1142. 	   if (count_buc(invent, BUC_UNKNOWN))  ilets[iletct++] = 'X'; 1143. 	   if (invent) ilets[iletct++] = 'a'; 1144. 	} else if (takeoff && invent) { 1145. 	   ilets[iletct++] = ' '; 1146. 	} 1147. 	ilets[iletct++] = 'i'; 1148. 	if (!combo) 1149. 	   ilets[iletct++] = 'm';	/* allow menu presentation on request */ 1150. 	ilets[iletct] = '\0'; 1151. 1152. 	for  { 1153. 	   Sprintf(qbuf,"What kinds of thing do you want to %s? [%s]",  1154. 		    word, ilets); 1155. 	   getlin(qbuf, buf); 1156. 	   if (buf[0] == '\033') return(0); 1157. 	   if (index(buf, 'i')) { 1158. 		if (display_inventory((char *)0, TRUE) == '\033') return 0; 1159. 	   } else 1160. 		break; 1161. 	} 1162.  1163. 	ip = buf; 1164. 	olets[oletct = 0] = '\0'; 1165. 	while ((sym = *ip++) != '\0') { 1166. 	   if (sym == ' ') continue; 1167. 	   oc_of_sym = def_char_to_objclass(sym); 1168. 	   if (takeoff && !(uwep && oc_of_sym == uwep->oclass) &&  1169. 		    (oc_of_sym != MAXOCLASSES)) { 1170. 		if (!index(removeables, oc_of_sym)) { 1171. 		   pline("Not applicable."); 1172. 		   return 0; 1173. 		} else if (oc_of_sym == ARMOR_CLASS && !wearing_armor) { 1174. 		   You("are not wearing any armor."); 1175. 		   return 0; 1176. 		} else if (oc_of_sym == WEAPON_CLASS && !uwep && !uswapwep && !uquiver) { 1177. 		   You("are not wielding anything."); 1178. 		   return 0; 1179. 		} else if (oc_of_sym == RING_CLASS && !uright && !uleft) { 1180. 		   You("are not wearing rings."); 1181. 		   return 0; 1182. 		} else if (oc_of_sym == AMULET_CLASS && !uamul) { 1183. 		   You("are not wearing an amulet."); 1184. 		   return 0; 1185. 		} else if (oc_of_sym == TOOL_CLASS && !ublindf) { 1186. 		   You("are not wearing a blindfold."); 1187. 		   return 0; 1188. 		} 1189. 	    }  1190.  1191. 	    if (oc_of_sym == GOLD_CLASS && !combo) { 1192. #ifndef GOLDOBJ 1193. 		if (allowgold == 1) 1194. 		   (*fn)(mkgoldobj(u.ugold)); 1195. 		else if (!u.ugold) 1196. 		   You("have no gold."); 1197. 		allowgold = 2; 1198. #else 1199. 		flags.botl = 1; 1200. #endif 1201. 	   } else if (sym == 'a') { 1202. 		allflag = TRUE; 1203. 	   } else if (sym == 'A') { 1204. 		/* same as the default */ ; 1205. 	   } else if (sym == 'u') { 1206. 		add_valid_menu_class('u'); 1207. 		ckfn = ckunpaid; 1208. 	   } else if (sym == 'B') { 1209. 	   	add_valid_menu_class('B'); 1210. 	   	ckfn = ckvalidcat; 1211. 	   } else if (sym == 'U') { 1212. 	   	add_valid_menu_class('U'); 1213. 	   	ckfn = ckvalidcat; 1214. 	   } else if (sym == 'C') { 1215. 	   	add_valid_menu_class('C'); 1216. 		ckfn = ckvalidcat; 1217. 	   } else if (sym == 'X') { 1218. 	   	add_valid_menu_class('X'); 1219. 		ckfn = ckvalidcat; 1220. 	   } else if (sym == 'm') { 1221. 		m_seen = TRUE; 1222. 	   } else if (oc_of_sym == MAXOCLASSES) { 1223. 		You("don't have any %c's.", sym); 1224. 	   } else if (oc_of_sym != VENOM_CLASS) {	/* suppress venom */ 1225. 		if (!index(olets, oc_of_sym)) { 1226. 		   add_valid_menu_class(oc_of_sym); 1227. 		   olets[oletct++] = oc_of_sym; 1228. 		   olets[oletct] = 0; 1229. 		} 1230. 	    }  1231. 	}  1232.  1233. 	if (m_seen) 1234. 	   return (allflag || (!oletct && ckfn != ckunpaid)) ? -2 : -3; 1235. 	else if (flags.menu_style != MENU_TRADITIONAL && combo && !allflag) 1236. 	   return 0; 1237. #ifndef GOLDOBJ 1238. 	else if (allowgold == 2 && !oletct) 1239. 	   return 1;	/* you dropped gold (or at least tried to) */ 1240. 	else { 1241. #else 1242. 	else /*!!!! if (allowgold == 2 && !oletct) 1243. 	   !!!! return 1;	 you dropped gold (or at least tried to) 1244.            !!!! test gold dropping 1245. 	else*/ { 1246. #endif 1247. 	   int cnt = askchain(&invent, olets, allflag, fn, ckfn, mx, word); 1248. 	   /*  1249. 	     * askchain has already finished the job in this case 1250. 	    * so set a special flag to convey that back to the caller 1251. 	    * so that it won't continue processing. 1252. 	    * Fix for bug C331-1 reported by Irina Rempt-Drijfhout. 1253. 	    */  1254. 	    if (combo && allflag && resultflags) 1255. 		*resultflags |= ALL_FINISHED; 1256. 	   return cnt; 1257. 	} 1258. }  1259.  1260. /*  1261.  * Walk through the chain starting at objchn and ask for all objects 1262. * with olet in olets (if nonNULL) and satisfying ckfn (if nonnull) 1263. * whether the action in question (i.e., fn) has to be performed. 1264. * If allflag then no questions are asked. Max gives the max nr of 1265. * objects to be treated. Return the number of objects treated. 1266. */  1267. int 1268. askchain(objchn, olets, allflag, fn, ckfn, mx, word) 1269. struct obj **objchn; 1270. register int allflag, mx; 1271. register const char *olets, *word;	/* olets is an Obj Class char array */ 1272. register int FDECL((*fn),(OBJ_P)), FDECL((*ckfn),(OBJ_P)); 1273. { 1274. 	register struct obj *otmp, *otmp2; 1275. 	register char sym, ilet; 1276. 	register int cnt = 0, dud = 0, tmp; 1277. 	boolean takeoff, nodot, ident, ininv; 1278. 	char qbuf[QBUFSZ]; 1279. 1280. 	takeoff = taking_off(word); 1281. 	ident = !strcmp(word, "identify"); 1282. 	nodot = (!strcmp(word, "nodot") || !strcmp(word, "drop") || 1283. 		 ident || takeoff); 1284. 	ininv = (*objchn == invent); 1285. 	/* Changed so the askchain is interrogated in the order specified. 1286. 	 * For example, if a person specifies =/ then first all rings will be 1287. * asked about followed by all wands -dgk 1288. 	 */ 1289. nextclass: 1290. 	ilet = 'a'-1; 1291. 	if (*objchn && (*objchn)->oclass == GOLD_CLASS) 1292. 		ilet--;		/* extra iteration */ 1293. 	for (otmp = *objchn; otmp; otmp = otmp2) { 1294. 		if(ilet == 'z') ilet = 'A'; else ilet++; 1295. 		otmp2 = otmp->nobj; 1296. 		if (olets && *olets && otmp->oclass != *olets) continue; 1297. 		if (takeoff && !is_worn(otmp)) continue; 1298. 		if (ident && !not_fully_identified(otmp)) continue; 1299. 		if (ckfn && !(*ckfn)(otmp)) continue; 1300. 		if (!allflag) { 1301. 			Strcpy(qbuf, !ininv ? doname(otmp) : 1302. 				xprname(otmp, (char *)0, ilet, !nodot, 0L, 0L)); 1303. 			Strcat(qbuf, "?"); 1304. 			sym = (takeoff || ident || otmp->quan < 2L) ? 1305. 				nyaq(qbuf) : nyNaq(qbuf); 1306. 		} 1307. 		else	sym = 'y'; 1308. 1309. 		if (sym == '#') { 1310. 		 /* Number was entered; split the object unless it corresponds 1311. 		   to 'none' or 'all'. 2 special cases: cursed loadstones and 1312. 		   welded weapons (eg, multiple daggers) will remain as merged 1313. 		   unit; done to avoid splitting an object that won't be  1314. droppable (even if we're picking up rather than dropping). 1315. 		 */  1316. 		    if (!yn_number) 1317. 			sym = 'n'; 1318. 		   else { 1319. 			sym = 'y'; 1320. 			if (yn_number < otmp->quan && !welded(otmp) && 1321. 			    (!otmp->cursed || otmp->otyp != LOADSTONE)) { 1322. 			   otmp = splitobj(otmp, yn_number); 1323. 			} 1324. 		    }  1325. 		}  1326. 		switch(sym){ 1327. 		case 'a': 1328. 			allflag = 1; 1329. 		case 'y': 1330. 			tmp = (*fn)(otmp); 1331. 			if(tmp < 0) goto ret; 1332. 			cnt += tmp; 1333. 			if(--mx == 0) goto ret; 1334. 		case 'n': 1335. 			if(nodot) dud++; 1336. 		default: 1337. 			break; 1338. 		case 'q': 1339. 			/* special case for seffects */ 1340. 			if (ident) cnt = -1; 1341. 			goto ret; 1342. 		} 1343. 	}  1344. 	if (olets && *olets && *++olets) 1345. 		goto nextclass; 1346. 	if(!takeoff && (dud || cnt)) pline("That was all."); 1347. 	else if(!dud && !cnt) pline("No applicable objects."); 1348. ret: 1349. 	return(cnt); 1350. } 1351.  1352.  1353. /*  1354.  *	Object identification routines: 1355. */  1356.  1357. /* make an object actually be identified; no display updating */ 1358. void 1359. fully_identify_obj(otmp) 1360. struct obj *otmp; 1361. { 1362.     makeknown(otmp->otyp); 1363.    if (otmp->oartifact) discover_artifact((xchar)otmp->oartifact); 1364.    otmp->known = otmp->dknown = otmp->bknown = otmp->rknown = 1; 1365.    if (otmp->otyp == EGG && otmp->corpsenm != NON_PM) 1366. 	learn_egg_type(otmp->corpsenm); 1367. } 1368.  1369. /* ggetobj callback routine; identify an object and give immediate feedback */ 1370. int 1371. identify(otmp) 1372. struct obj *otmp; 1373. { 1374.     fully_identify_obj(otmp); 1375.    prinv((char *)0, otmp, 0L); 1376.    return 1; 1377. } 1378.  1379. /* menu of unidentified objects; select and identify up to id_limit of them */ 1380. STATIC_OVL void 1381. menu_identify(id_limit) 1382. int id_limit; 1383. { 1384.     menu_item *pick_list; 1385.    int n, i, first = 1; 1386.    char buf[BUFSZ]; 1387.    /* assumptions:  id_limit > 0 and at least one unID'd item is present */ 1388. 1389.     while (id_limit) { 1390. 	Sprintf(buf, "What would you like to identify %s?", 1391. 		first ? "first" : "next"); 1392. 	n = query_objlist(buf, invent, SIGNAL_NOMENU|USE_INVLET|INVORDER_SORT, 1393. 		&pick_list, PICK_ANY, not_fully_identified); 1394. 1395. 	if (n > 0) { 1396. 	   if (n > id_limit) n = id_limit; 1397. 	   for (i = 0; i < n; i++, id_limit--) 1398. 		(void) identify(pick_list[i].item.a_obj); 1399. 	   free((genericptr_t) pick_list); 1400. 	   mark_synch; /* Before we loop to pop open another menu */ 1401. 	} else { 1402. 	   if (n < 0) pline("That was all."); 1403. 	   id_limit = 0; /* Stop now */ 1404. 	} 1405. 	first = 0; 1406.    }  1407. }  1408.  1409. /* dialog with user to identify a given number of items; 0 means all */ 1410. void 1411. identify_pack(id_limit) 1412. int id_limit; 1413. { 1414.     struct obj *obj, *the_obj; 1415.    int n, unid_cnt; 1416. 1417.     unid_cnt = 0; 1418.    the_obj = 0;		/* if unid_cnt ends up 1, this will be it */ 1419.    for (obj = invent; obj; obj = obj->nobj) 1420. 	if (not_fully_identified(obj)) ++unid_cnt, the_obj = obj; 1421. 1422.     if (!unid_cnt) { 1423. 	You("have already identified all of your possessions."); 1424.    } else if (!id_limit) { 1425. 	/* identify everything */ 1426. 	if (unid_cnt == 1) { 1427. 	   (void) identify(the_obj); 1428. 	} else { 1429. 1430. 	    /* TODO:  use fully_identify_obj and cornline/menu/whatever here */ 1431. 	   for (obj = invent; obj; obj = obj->nobj) 1432. 		if (not_fully_identified(obj)) (void) identify(obj); 1433. 1434. 	}  1435.     } else { 1436. 	/* identify up to `id_limit' items */ 1437. 	n = 0; 1438. 	if (flags.menu_style == MENU_TRADITIONAL) 1439. 	   do { 1440. 		n = ggetobj("identify", identify, id_limit, FALSE, (unsigned *)0); 1441. 		if (n < 0) break; /* quit or no eligible items */ 1442. 	   } while ((id_limit -= n) > 0); 1443. 	if (n == 0 || n < -1) 1444. 	   menu_identify(id_limit); 1445.    }  1446.     update_inventory; 1447. } 1448.  1449. #endif /* OVLB */ 1450. #ifdef OVL2 1451. 1452. STATIC_OVL char 1453. obj_to_let(obj)	/* should of course only be called for things in invent */ 1454. register struct obj *obj; 1455. { 1456. #ifndef GOLDOBJ 1457. 	if (obj->oclass == GOLD_CLASS) 1458. 		return GOLD_SYM; 1459. #endif 1460. 	if (!flags.invlet_constant) { 1461. 		obj->invlet = NOINVSYM; 1462. 		reassign; 1463. 	} 1464. 	return obj->invlet; 1465. } 1466.  1467. /*  1468.  * Print the indicated quantity of the given object. If quan == 0L then use 1469. * the current quantity. 1470. */  1471. void 1472. prinv(prefix, obj, quan) 1473. const char *prefix; 1474. register struct obj *obj; 1475. long quan; 1476. { 1477. 	if (!prefix) prefix = ""; 1478. 	pline("%s%s%s", 1479. 	      prefix, *prefix ? " " : "",  1480. 	      xprname(obj, (char *)0, obj_to_let(obj), TRUE, 0L, quan)); 1481. } 1482.  1483. #endif /* OVL2 */ 1484. #ifdef OVL1 1485. 1486. char * 1487. xprname(obj, txt, let, dot, cost, quan) 1488. struct obj *obj; 1489. const char *txt;	/* text to print instead of obj */ 1490. char let;		/* inventory letter */ 1491. boolean dot;		/* append period; (dot && cost => Iu) */ 1492. long cost;		/* cost (for inventory of unpaid or expended items) */ 1493. long quan;		/* if non-0, print this quantity, not obj->quan */ 1494. { 1495. #ifdef LINT	/* handle static char li[BUFSZ]; */ 1496.    char li[BUFSZ]; 1497. #else 1498.    static char li[BUFSZ]; 1499. #endif 1500.    boolean use_invlet = flags.invlet_constant && let != CONTAINED_SYM; 1501.    long savequan = 0; 1502. 1503.     if (quan && obj) { 1504. 	savequan = obj->quan; 1505. 	obj->quan = quan; 1506.    }  1507.  1508.     /*  1509.      * If let is: 1510.     *	*  Then obj == null and we are printing a total amount. 1511.     *	>  Then the object is contained and doesn't have an inventory letter. 1512.     */  1513.     if (cost != 0 || let == '*') { 1514. 	/* if dot is true, we're doing Iu, otherwise Ix */ 1515. 	Sprintf(li, "%c - %-45s %6ld %s", 1516. 		(dot && use_invlet ? obj->invlet : let), 1517. 		(txt ? txt : doname(obj)), cost, currency(cost)); 1518. #ifndef GOLDOBJ 1519.    } else if (obj && obj->oclass == GOLD_CLASS) { 1520. 	Sprintf(li, "%ld gold piece%s%s", obj->quan, plur(obj->quan), 1521. 		(dot ? "." : "")); 1522. #endif 1523.    } else { 1524. 	/* ordinary inventory display or pickup message */ 1525. 	Sprintf(li, "%c - %s%s", 1526. 		(use_invlet ? obj->invlet : let), 1527. 		(txt ? txt : doname(obj)), (dot ? "." : "")); 1528.     }  1529.     if (savequan) obj->quan = savequan; 1530. 1531.     return li; 1532. } 1533.  1534. #endif /* OVL1 */ 1535. #ifdef OVLB 1536. 1537. /* the 'i' command */ 1538. int 1539. ddoinv 1540. { 1541. 	(void) display_inventory((char *)0, FALSE); 1542. 	return 0; 1543. } 1544.  1545. /*  1546.  * find_unpaid 1547. *  1548.  * Scan the given list of objects. If last_found is NULL, return the first 1549. * unpaid object found. If last_found is not NULL, then skip over unpaid 1550. * objects until last_found is reached, then set last_found to NULL so the 1551. * next unpaid object is returned. This routine recursively follows 1552. * containers. 1553. */  1554. STATIC_OVL struct obj * 1555. find_unpaid(list, last_found) 1556.    struct obj *list, **last_found; 1557. { 1558.     struct obj *obj; 1559. 1560.     while (list) { 1561. 	if (list->unpaid) { 1562. 	   if (*last_found) { 1563. 		/* still looking for previous unpaid object */ 1564. 		if (list == *last_found) 1565. 		   *last_found = (struct obj *) 0; 1566. 	   } else 1567. 		return (*last_found = list); 1568. 	} 1569. 	if (Has_contents(list)) { 1570. 	   if ((obj = find_unpaid(list->cobj, last_found)) != 0) 1571. 		return obj; 1572. 	} 1573. 	list = list->nobj; 1574.    }  1575.     return (struct obj *) 0; 1576. } 1577.  1578. /*  1579.  * Internal function used by display_inventory and getobj that can display 1580. * inventory and return a count as well as a letter. If out_cnt is not null, 1581. * any count returned from the menu selection is placed here. 1582. */  1583. static char 1584. display_pickinv(lets, want_reply, out_cnt) 1585. register const char *lets; 1586. boolean want_reply; 1587. long* out_cnt; 1588. { 1589. 	struct obj *otmp; 1590. 	char ilet, ret; 1591. 	char *invlet = flags.inv_order; 1592. 	int n, classcount; 1593. 	winid win;				/* windows being used */ 1594. 	static winid local_win = WIN_ERR;	/* window for partial menus */ 1595. 	anything any; 1596. 	menu_item *selected; 1597. 1598. 	/* overriden by global flag */ 1599. 	if (flags.perm_invent) { 1600. 	   win = (lets && *lets) ? local_win : WIN_INVEN; 1601. 	   /* create the first time used */ 1602. 	   if (win == WIN_ERR) 1603. 		win = local_win = create_nhwindow(NHW_MENU); 1604. 	} else 1605. 	   win = WIN_INVEN; 1606. 1607. 	/*  1608. 	Exit early if no inventory -- but keep going if we are doing 1609. 	a permanent inventory update. We need to keep going so the 1610. 	permanent inventory window updates itself to remove the last 1611. 	item(s) dropped. One down side: the addition of the exception 1612. 	for permanent inventory window updates _can_ pop the window 1613. 	up when it's not displayed -- even if it's empty -- because we 1614. don't know at this level if its up or not. This may not be 1615. an issue if empty checks are done before hand and the call 1616. 	to here is short circuited away. 1617. 	*/ 1618. 	if (!invent && !(flags.perm_invent && !lets && !want_reply)) { 1619. #ifndef GOLDOBJ 1620. 	   pline("Not carrying anything%s.", u.ugold ? " except gold" : ""); 1621. #else 1622. 	   pline("Not carrying anything."); 1623. #endif 1624. 	   return 0; 1625. 	} 1626.  1627. 	/* oxymoron? temporarily assign permanent inventory letters */ 1628. 	if (!flags.invlet_constant) reassign; 1629. 1630. 	if (lets && strlen(lets) == 1) { 1631. 	   /* when only one item of interest, use pline instead of menus; 1632. 	      we actually use a fake message-line menu in order to allow 1633. 	      the user to perform selection at the --More-- prompt for tty */ 1634. 	   ret = '\0'; 1635. 	   for (otmp = invent; otmp; otmp = otmp->nobj) { 1636. 		if (otmp->invlet == lets[0]) { 1637. 		   ret = message_menu(lets[0],  1638. 			  want_reply ? PICK_ONE : PICK_NONE,  1639. 			  xprname(otmp, (char *)0, lets[0], TRUE, 0L, 0L)); 1640. 		   break; 1641. 		} 1642. 	    }  1643. 	    return ret; 1644. 	} 1645.  1646. 	start_menu(win); 1647. nextclass: 1648. 	classcount = 0; 1649. 	any.a_void = 0;		/* set all bits to zero */ 1650. 	for(otmp = invent; otmp; otmp = otmp->nobj) { 1651. 		ilet = otmp->invlet; 1652. 		if(!lets || !*lets || index(lets, ilet)) { 1653. 			if (!flags.sortpack || otmp->oclass == *invlet) { 1654. 			   if (flags.sortpack && !classcount) { 1655. 				any.a_void = 0;		/* zero */ 1656. 				add_menu(win, NO_GLYPH, &any, 0, 0, ATR_INVERSE, 1657. 				    let_to_name(*invlet, FALSE), MENU_UNSELECTED); 1658. 				classcount++; 1659. 			   }  1660. 			    any.a_char = ilet; 1661. 			   add_menu(win, obj_to_glyph(otmp),  1662. 					&any, ilet, 0, ATR_NONE, doname(otmp),  1663. 					MENU_UNSELECTED); 1664. 			} 1665. 		}  1666. 	}  1667. 	if (flags.sortpack) { 1668. 		if (*++invlet) goto nextclass; 1669. #ifdef WIZARD 1670. 		if (--invlet != venom_inv) { 1671. 			invlet = venom_inv; 1672. 			goto nextclass; 1673. 		} 1674. #endif 1675. 	} 1676. 	end_menu(win, (char *) 0); 1677. 1678. 	n = select_menu(win, want_reply ? PICK_ONE : PICK_NONE, &selected); 1679. 	if (n > 0) { 1680. 	   ret = selected[0].item.a_char; 1681. 	   if (out_cnt) *out_cnt = selected[0].count; 1682. 	   free((genericptr_t)selected); 1683. 	} else 1684. 	   ret = !n ? '\0' : '\033';	/* cancelled */ 1685. 1686. 	return ret; 1687. } 1688.  1689. /*  1690.  * If lets == NULL or "", list all objects in the inventory. Otherwise, 1691. * list all objects with object classes that match the order in lets. 1692. *  1693.  * Returns the letter identifier of a selected item, or 0 if nothing 1694. * was selected. 1695. */  1696. char 1697. display_inventory(lets, want_reply) 1698. register const char *lets; 1699. boolean want_reply; 1700. { 1701. 	return display_pickinv(lets, want_reply, (long *)0); 1702. } 1703.  1704. /*  1705.  * Returns the number of unpaid items within the given list. This includes 1706. * contained objects. 1707. */  1708. int 1709. count_unpaid(list) 1710.    struct obj *list; 1711. { 1712.     int count = 0; 1713. 1714.     while (list) { 1715. 	if (list->unpaid) count++; 1716. 	if (Has_contents(list)) 1717. 	   count += count_unpaid(list->cobj); 1718. 	list = list->nobj; 1719.    }  1720.     return count; 1721. } 1722.  1723. /*  1724.  * Returns the number of items with b/u/c/unknown within the given list. 1725. * This does NOT include contained objects. 1726. */  1727. int 1728. count_buc(list, type) 1729.    struct obj *list; 1730.    int type; 1731. { 1732.     int count = 0; 1733. 1734.     while (list) { 1735. 	switch(type) { 1736. 	   case BUC_BLESSED: 1737. 		if (list->oclass != GOLD_CLASS && list->bknown && list->blessed) 1738. 		   count++; 1739. 		break; 1740. 	   case BUC_CURSED: 1741. 		if (list->oclass != GOLD_CLASS && list->bknown && list->cursed) 1742. 		   count++; 1743. 		break; 1744. 	   case BUC_UNCURSED: 1745. 		if (list->oclass != GOLD_CLASS && 1746. 			list->bknown && !list->blessed && !list->cursed) 1747. 		   count++; 1748. 		break; 1749. 	   case BUC_UNKNOWN: 1750. 		if (list->oclass != GOLD_CLASS && !list->bknown) 1751. 		   count++; 1752. 		break; 1753. 	   default: 1754. 		impossible("need count of curse status %d?", type); 1755. 		return 0; 1756. 	} 1757. 	list = list->nobj; 1758.    }  1759.     return count; 1760. } 1761.  1762. STATIC_OVL void 1763. dounpaid 1764. { 1765.     winid win; 1766.    struct obj *otmp, *marker; 1767.    register char ilet; 1768.    char *invlet = flags.inv_order; 1769.    int classcount, count, num_so_far; 1770.    int save_unpaid = 0;	/* lint init */ 1771.    long cost, totcost; 1772. 1773.     count = count_unpaid(invent); 1774. 1775.     if (count == 1) { 1776. 	marker = (struct obj *) 0; 1777. 	otmp = find_unpaid(invent, &marker); 1778. 1779. 	/* see if the unpaid item is in the top level inventory */ 1780. 	for (marker = invent; marker; marker = marker->nobj) 1781. 	   if (marker == otmp) break; 1782. 1783. 	pline("%s", xprname(otmp, distant_name(otmp, doname), 1784. 			   marker ? otmp->invlet : CONTAINED_SYM, 1785. 			   TRUE, unpaid_cost(otmp), 0L)); 1786. 	return; 1787.    }  1788.  1789.     win = create_nhwindow(NHW_MENU); 1790.    cost = totcost = 0; 1791.    num_so_far = 0;	/* count of # printed so far */ 1792.    if (!flags.invlet_constant) reassign; 1793. 1794.     do { 1795. 	classcount = 0; 1796. 	for (otmp = invent; otmp; otmp = otmp->nobj) { 1797. 	   ilet = otmp->invlet; 1798. 	   if (otmp->unpaid) { 1799. 		if (!flags.sortpack || otmp->oclass == *invlet) { 1800. 		   if (flags.sortpack && !classcount) { 1801. 			putstr(win, 0, let_to_name(*invlet, TRUE)); 1802. 			classcount++; 1803. 		   }  1804.  1805. 		    totcost += cost = unpaid_cost(otmp); 1806. 		   /* suppress "(unpaid)" suffix */ 1807. 		   save_unpaid = otmp->unpaid; 1808. 		   otmp->unpaid = 0; 1809. 		   putstr(win, 0, xprname(otmp, distant_name(otmp, doname), 1810. 					  ilet, TRUE, cost, 0L)); 1811. 		   otmp->unpaid = save_unpaid; 1812. 		   num_so_far++; 1813. 		} 1814. 	    }  1815. 	}  1816.     } while (flags.sortpack && (*++invlet)); 1817. 1818.     if (count > num_so_far) { 1819. 	/* something unpaid is contained */ 1820. 	if (flags.sortpack) 1821. 	   putstr(win, 0, let_to_name(CONTAINED_SYM, TRUE)); 1822. 	/* 1823. 	 * Search through the container objects in the inventory for 1824. 	 * unpaid items. The top level inventory items have already 1825. 	 * been listed. 1826. 	 */ 1827. 	for (otmp = invent; otmp; otmp = otmp->nobj) { 1828. 	   if (Has_contents(otmp)) { 1829. 		marker = (struct obj *) 0;	/* haven't found any */ 1830. 		while (find_unpaid(otmp->cobj, &marker)) { 1831. 		   totcost += cost = unpaid_cost(marker); 1832. 		   save_unpaid = marker->unpaid; 1833. 		   marker->unpaid = 0;    /* suppress "(unpaid)" suffix */ 1834. 		   putstr(win, 0,  1835. 			   xprname(marker, distant_name(marker, doname), 1836. 				  CONTAINED_SYM, TRUE, cost, 0L)); 1837. 		   marker->unpaid = save_unpaid; 1838. 		} 1839. 	    }  1840. 	}  1841.     }  1842.  1843.     putstr(win, 0, ""); 1844.    putstr(win, 0, xprname((struct obj *)0, "Total:", '*', FALSE, totcost, 0L)); 1845.    display_nhwindow(win, FALSE); 1846.    destroy_nhwindow(win); 1847. } 1848.  1849.  1850. /* query objlist callback: return TRUE if obj type matches "this_type" */ 1851. static int this_type; 1852. 1853. STATIC_OVL boolean 1854. this_type_only(obj) 1855.    struct obj *obj; 1856. { 1857.     return (obj->oclass == this_type); 1858. } 1859.  1860. /* the 'I' command */ 1861. int 1862. dotypeinv 1863. { 1864. 	char c = '\0'; 1865. 	int n, i = 0; 1866. 	char *extra_types, types[BUFSZ]; 1867. 	int class_count, oclass, unpaid_count; 1868. 	boolean billx = *u.ushops && doinvbill(0); 1869. 	menu_item *pick_list; 1870. 	boolean traditional = TRUE; 1871. 	const char *prompt = "What type of object do you want an inventory of?"; 1872. 1873. #ifndef GOLDOBJ 1874. 	if (!invent && !u.ugold && !billx) { 1875. #else 1876. 	if (!invent && !billx) { 1877. #endif 1878. 	   You("aren't carrying anything."); 1879. 	   return 0; 1880. 	} 1881. 	unpaid_count = count_unpaid(invent); 1882. 	if (flags.menu_style != MENU_TRADITIONAL) { 1883. 	   if (flags.menu_style == MENU_FULL ||  1884. 				flags.menu_style == MENU_PARTIAL) { 1885. 		traditional = FALSE; 1886. 		i = UNPAID_TYPES; 1887. 		if (billx) i |= BILLED_TYPES; 1888. 		n = query_category(prompt, invent, i, &pick_list, PICK_ONE); 1889. 		if (!n) return 0; 1890. 		this_type = c = pick_list[0].item.a_int; 1891. 		free((genericptr_t) pick_list); 1892. 	   }  1893. 	}  1894. 	if (traditional) { 1895. 	   /* collect a list of classes of objects carried, for use as a prompt */ 1896. 	   types[0] = 0; 1897. 	   class_count = collect_obj_classes(types, invent,  1898. 					      FALSE,  1899. #ifndef GOLDOBJ  1900. 					      (u.ugold != 0),  1901. #endif  1902. 					      (boolean FDECL((*),(OBJ_P))) 0); 1903. 	   if (unpaid_count) { 1904. 		Strcat(types, "u"); 1905. 		class_count++; 1906. 	   }  1907. 	    if (billx) { 1908. 		Strcat(types, "x"); 1909. 		class_count++; 1910. 	   }  1911. 	    /* add everything not already included; user won't see these */ 1912. 	   extra_types = eos(types); 1913. 	   *extra_types++ = '\033'; 1914. 	   if (!unpaid_count) *extra_types++ = 'u'; 1915. 	   if (!billx) *extra_types++ = 'x'; 1916. 	   *extra_types = '\0';	/* for index */ 1917. 	   for (i = 0; i < MAXOCLASSES; i++) 1918. 		if (!index(types, def_oc_syms[i])) { 1919. 		   *extra_types++ = def_oc_syms[i]; 1920. 		   *extra_types = '\0'; 1921. 		} 1922.  1923. 	    if(class_count > 1) { 1924. 		c = yn_function(prompt, types, '\0'); 1925. #ifdef REDO 1926. 		savech(c); 1927. #endif 1928. 		if(c == '\0') { 1929. 			clear_nhwindow(WIN_MESSAGE); 1930. 			return 0; 1931. 		} 1932. 	    } else { 1933. 		/* only one thing to itemize */ 1934. 		if (unpaid_count) 1935. 		   c = 'u'; 1936. 		else if (billx) 1937. 		   c = 'x'; 1938. 		else 1939. 		   c = types[0]; 1940. 	   }  1941. 	}  1942. 	if (c == 'x') { 1943. 	   if (billx) 1944. 		(void) doinvbill(1); 1945. 	   else 1946. 		pline("No used-up objects on your shopping bill."); 1947. 	   return 0; 1948. 	} 1949. 	if (c == 'u') { 1950. 	   if (unpaid_count) 1951. 		dounpaid; 1952. 	   else 1953. 		You("are not carrying any unpaid objects."); 1954. 	   return 0; 1955. 	} 1956. 	if (traditional) { 1957. 	   oclass = def_char_to_objclass(c); /* change to object class */ 1958. 	   if (oclass == GOLD_CLASS) { 1959. 		return doprgold; 1960. 	   } else if (index(types, c) > index(types, '\033')) { 1961. 		You("have no such objects."); 1962. 		return 0; 1963. 	   }  1964. 	    this_type = oclass; 1965. 	} 1966. 	if (query_objlist((char *) 0, invent, 1967. 		   (flags.invlet_constant ? USE_INVLET : 0)|INVORDER_SORT, 1968. 		   &pick_list, PICK_NONE, this_type_only) > 0) 1969. 	   free((genericptr_t)pick_list); 1970. 	return 0; 1971. } 1972.  1973. /* return a string describing the dungeon feature at  if there 1974.   is one worth mentioning at that location; otherwise null */ 1975. const char * 1976. dfeature_at(x, y, buf) 1977. int x, y; 1978. char *buf; 1979. { 1980. 	struct rm *lev = &levl[x][y]; 1981. 	int ltyp = lev->typ, cmap = -1; 1982. 	const char *dfeature = 0; 1983. 	static char altbuf[BUFSZ]; 1984. 1985. 	if (IS_DOOR(ltyp)) { 1986. 	   switch (lev->doormask) { 1987. 	   case D_NODOOR:	cmap = S_ndoor; break;	/* "doorway" */ 1988. 	   case D_ISOPEN:	cmap = S_vodoor; break;	/* "open door" */ 1989. 	   case D_BROKEN:	dfeature = "broken door"; break; 1990. 	   default:	cmap = S_vcdoor; break;	/* "closed door" */ 1991. 	   }  1992. 	    /* override door description for open drawbridge */ 1993. 	   if (is_drawbridge_wall(x, y) >= 0) 1994. 		dfeature = "open drawbridge portcullis", cmap = -1; 1995. 	} else if (IS_FOUNTAIN(ltyp)) 1996. 	   cmap = S_fountain;				/* "fountain" */ 1997. 	else if (IS_THRONE(ltyp)) 1998. 	   cmap = S_throne;				/* "opulent throne" */ 1999. 	else if (is_lava(x,y)) 2000. 	   cmap = S_lava;				/* "molten lava" */ 2001. 	else if (is_ice(x,y)) 2002. 	   cmap = S_ice;				/* "ice" */ 2003. 	else if (is_pool(x,y)) 2004. 	   dfeature = "pool of water"; 2005. #ifdef SINKS 2006. 	else if (IS_SINK(ltyp)) 2007. 	   cmap = S_sink;				/* "sink" */ 2008. #endif 2009. 	else if (IS_ALTAR(ltyp)) { 2010. 	   Sprintf(altbuf, "altar to %s (%s)", a_gname,  2011. 		    align_str(Amask2align(lev->altarmask & ~AM_SHRINE))); 2012. 	   dfeature = altbuf; 2013. 	} else if ((x == xupstair && y == yupstair) || 2014. 		 (x == sstairs.sx && y == sstairs.sy && sstairs.up)) 2015. 	   cmap = S_upstair;				/* "staircase up" */ 2016. 	else if ((x == xdnstair && y == ydnstair) || 2017. 		 (x == sstairs.sx && y == sstairs.sy && !sstairs.up)) 2018. 	   cmap = S_dnstair;				/* "staircase down" */ 2019. 	else if (x == xupladder && y == yupladder) 2020. 	   cmap = S_upladder;				/* "ladder up" */ 2021. 	else if (x == xdnladder && y == ydnladder) 2022. 	   cmap = S_dnladder;				/* "ladder down" */ 2023. 	else if (ltyp == DRAWBRIDGE_DOWN) 2024. 	   cmap = S_vodbridge;			/* "lowered drawbridge" */ 2025. 	else if (ltyp == DBWALL) 2026. 	   cmap = S_vcdbridge;			/* "raised drawbridge" */ 2027. 	else if (IS_GRAVE(ltyp)) 2028. 	   cmap = S_grave;				/* "grave" */ 2029. 	else if (ltyp == TREE) 2030. 	   cmap = S_tree;				/* "tree" */ 2031. 	else if (ltyp == IRONBARS) 2032. 	   dfeature = "set of iron bars"; 2033. 2034. 	if (cmap >= 0) dfeature = defsyms[cmap].explanation; 2035. 	if (dfeature) Strcpy(buf, dfeature); 2036. 	return dfeature; 2037. } 2038.  2039. /* look at what is here; if there are many objects (5 or more), 2040.   don't show them unless obj_cnt is 0 */ 2041. int 2042. look_here(obj_cnt, picked_some) 2043. int obj_cnt;	/* obj_cnt > 0 implies that autopickup is in progess */ 2044. boolean picked_some; 2045. { 2046. 	struct obj *otmp; 2047. 	struct trap *trap; 2048. 	const char *verb = Blind ? "feel" : "see"; 2049. 	const char *dfeature = (char *)0; 2050. 	char fbuf[BUFSZ], fbuf2[BUFSZ]; 2051. 	winid tmpwin; 2052. 	boolean skip_objects = (obj_cnt >= 5); 2053. 2054. 	if (u.uswallow && u.ustuck) { 2055. 	   struct monst *mtmp = u.ustuck; 2056. 	   Sprintf(fbuf, "Contents of %s %s",  2057. 		s_suffix(mon_nam(mtmp)), mbodypart(mtmp, STOMACH)); 2058. 	   /* Skip "Contents of " by using fbuf index 12 */ 2059. 	   You("%s to %s what is lying in %s.",  2060. 		Blind ? "try" : "look around", verb, &fbuf[12]); 2061. 	   otmp = mtmp->minvent; 2062. 	   if (otmp) { 2063. 		for (otmp; otmp = otmp->nobj) { 2064. 			/* If swallower is an animal, it should have become stone but... */ 2065. 			if (otmp->otyp == CORPSE) feel_cockatrice(otmp, FALSE); 2066. 		} 2067. 		if (Blind) Strcpy(fbuf, "You feel"); 2068. 		Strcat(fbuf,":"); 2069. 	   	(void) display_minventory(mtmp, MINV_ALL, fbuf); 2070. 	   } else { 2071. 		You("%s no objects here.", verb); 2072. 	   }  2073. 	    return(!!Blind); 2074. 	} 2075. 	if (!skip_objects && (trap = t_at(u.ux,u.uy)) && trap->tseen) 2076. 		There("is %s here.", 2077. 			an(defsyms[trap_to_defsym(trap->ttyp)].explanation)); 2078. 2079. 	otmp = level.objects[u.ux][u.uy]; 2080. 	dfeature = dfeature_at(u.ux, u.uy, fbuf2); 2081. 	if (dfeature && !strcmp(dfeature, "pool of water") && Underwater) 2082. 		dfeature = 0; 2083. 2084. 	if (Blind) { 2085. 		boolean drift = Is_airlevel(&u.uz) || Is_waterlevel(&u.uz); 2086. 		You("try to feel what is %s%s.", 2087. 		    drift ? "floating here" : "lying here on the ",  2088. 		    drift ?	""	    : surface(u.ux, u.uy)); 2089. 		if (dfeature && !drift && !strcmp(dfeature, surface(u.ux,u.uy))) 2090. 			dfeature = 0;		/* ice already identifed */ 2091. 		if (!can_reach_floor) { 2092. 			pline("But you can't reach it!"); 2093. 			return(0); 2094. 		} 2095. 	}  2096.  2097. 	if (dfeature) 2098. 		Sprintf(fbuf, "There is %s here.", an(dfeature)); 2099. 2100. 	if (!otmp || is_lava(u.ux,u.uy) || (is_pool(u.ux,u.uy) && !Underwater)) { 2101. 		if (dfeature) pline(fbuf); 2102. 		read_engr_at(u.ux, u.uy); /* Eric Backus */ 2103. 		if (!skip_objects && (Blind || !dfeature)) 2104. 		   You("%s no objects here.", verb); 2105. 		return(!!Blind); 2106. 	} 2107. 	/* we know there is something here */ 2108. 2109. 	if (skip_objects) { 2110. 	   if (dfeature) pline(fbuf); 2111. 	   read_engr_at(u.ux, u.uy); /* Eric Backus */ 2112. 	   There("are %s%s objects here.",  2113. 		  (obj_cnt <= 10) ? "several" : "many",  2114. 		  picked_some ? " more" : ""); 2115. 	} else if (!otmp->nexthere) { 2116. 	   /* only one object */ 2117. 	   if (dfeature) pline(fbuf); 2118. 	   read_engr_at(u.ux, u.uy); /* Eric Backus */ 2119. #ifdef INVISIBLE_OBJECTS 2120. 	   if (otmp->oinvis && !See_invisible) verb = "feel"; 2121. #endif 2122. 	   You("%s here %s.", verb, doname(otmp)); 2123. 	   if (otmp->otyp == CORPSE) feel_cockatrice(otmp, FALSE); 2124. 	} else { 2125. 	   display_nhwindow(WIN_MESSAGE, FALSE); 2126. 	   tmpwin = create_nhwindow(NHW_MENU); 2127. 	   if(dfeature) { 2128. 		putstr(tmpwin, 0, fbuf); 2129. 		putstr(tmpwin, 0, ""); 2130. 	   }  2131. 	    putstr(tmpwin, 0, "Things that are here:"); 2132. 	   for (otmp; otmp = otmp->nexthere) { 2133. 		putstr(tmpwin, 0, doname(otmp)); 2134. 		if (otmp->otyp == CORPSE) feel_cockatrice(otmp, FALSE); 2135. 	   }  2136. 	    display_nhwindow(tmpwin, TRUE); 2137. 	   destroy_nhwindow(tmpwin); 2138. 	   read_engr_at(u.ux, u.uy); /* Eric Backus */ 2139. 	} 2140. 	return(!!Blind); 2141. } 2142.  2143. /* explicilty look at what is here, including all objects */ 2144. int 2145. dolook 2146. { 2147. 	return look_here(0, FALSE); 2148. } 2149.  2150. void 2151. feel_cockatrice(otmp, force_touch) 2152. struct obj *otmp; 2153. boolean force_touch; 2154. { 2155. 	char kbuf[BUFSZ]; 2156. 2157. 	if ((Blind || force_touch) && !uarmg && !Stone_resistance &&  2158. 		(otmp->otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm]))) { 2159. 	   if(poly_when_stoned(youmonst.data)) 2160. 			You("touched the %s corpse with your bare %s.", 2161. 				mons[otmp->corpsenm].mname, makeplural(body_part(HAND))); 2162. 	   else 2163. 			pline("Touching the %s corpse is a fatal mistake...", 2164. 				mons[otmp->corpsenm].mname); 2165. 		Sprintf(kbuf, "%s corpse", an(mons[otmp->corpsenm].mname)); 2166. 		instapetrify(kbuf); 2167. 	} 2168. }  2169.  2170. #endif /* OVLB */ 2171. #ifdef OVL1 2172. 2173. void 2174. stackobj(obj) 2175. struct obj *obj; 2176. { 2177. 	struct obj *otmp; 2178. 2179. 	for(otmp = level.objects[obj->ox][obj->oy]; otmp; otmp = otmp->nexthere) 2180. 		if(otmp != obj && merged(&obj,&otmp)) 2181. 			break; 2182. 	return; 2183. } 2184.  2185. STATIC_OVL boolean 2186. mergable(otmp, obj)	/* returns TRUE if obj & otmp can be merged */ 2187. 	register struct obj *otmp, *obj; 2188. { 2189. #ifndef GOLDOBJ 2190. 	if (obj->otyp != otmp->otyp || obj->unpaid != otmp->unpaid || 2191. #else  2192. 	if (obj->otyp != otmp->otyp) return FALSE;  2193.         2194.         /* Coins of the same kind will always merge. */  2195.         if (obj->oclass == GOLD_CLASS) return TRUE;  2196.  2197.         if (obj->unpaid != otmp->unpaid || 2198. #endif 2199. 	   obj->spe != otmp->spe || obj->dknown != otmp->dknown || 2200. 	   (obj->bknown != otmp->bknown && !Role_if(PM_PRIEST)) || 2201. 	   obj->cursed != otmp->cursed || obj->blessed != otmp->blessed || 2202. 	   obj->no_charge != otmp->no_charge || 2203. 	   obj->obroken != otmp->obroken || 2204. 	   obj->otrapped != otmp->otrapped || 2205. 	   obj->lamplit != otmp->lamplit || 2206. #ifdef INVISIBLE_OBJECTS 2207. 		obj->oinvis != otmp->oinvis || 2208. #endif 2209. 	   obj->greased != otmp->greased || 2210. 	   obj->oeroded != otmp->oeroded || 2211. 	   obj->oeroded2 != otmp->oeroded2 || 2212. 	   obj->bypass != otmp->bypass)  2213. 	    return(FALSE);  2214.  2215. 	if ((obj->oclass==WEAPON_CLASS || obj->oclass==ARMOR_CLASS) && 2216. 	   (obj->oerodeproof!=otmp->oerodeproof || obj->rknown!=otmp->rknown))  2217. 	    return FALSE;  2218.  2219. 	if (obj->oclass == FOOD_CLASS && (obj->oeaten != otmp->oeaten ||  2220. 					  obj->orotten != otmp->orotten))  2221. 	    return(FALSE);  2222.  2223. 	if (obj->otyp == CORPSE || obj->otyp == EGG || obj->otyp == TIN) {  2224. 		if (obj->corpsenm != otmp->corpsenm)  2225. 				return FALSE;  2226. 	}  2227.  2228. 	/* hatching eggs don't merge; ditto for revivable corpses */  2229. 	if ((obj->otyp == EGG && (obj->timed || otmp->timed)) || 2230. 	   (obj->otyp == CORPSE && otmp->corpsenm >= LOW_PM &&  2231. 		is_reviver(&mons[otmp->corpsenm])))  2232. 	    return FALSE;  2233.  2234. 	/* allow candle merging only if their ages are close */  2235. 	/* see begin_burn for a reference for the magic "25" */  2236. 	if (Is_candle(obj) && obj->age/25 != otmp->age/25)  2237. 	    return(FALSE);  2238.  2239. 	/* burning potions of oil never merge */  2240. 	if (obj->otyp == POT_OIL && obj->lamplit)  2241. 	    return FALSE;  2242.  2243. 	/* don't merge surcharged item with base-cost item */  2244. 	if (obj->unpaid && !same_price(obj, otmp))  2245. 	    return FALSE;  2246.  2247. 	/* if they have names, make sure they're the same */  2248. 	if ( (obj->onamelth != otmp->onamelth &&  2249. 		((obj->onamelth && otmp->onamelth) || obj->otyp == CORPSE)  2250. 	     ) || 2251. 	   (obj->onamelth && otmp->onamelth &&  2252. 		    strncmp(ONAME(obj), ONAME(otmp), (int)obj->onamelth)))  2253. 		return FALSE;  2254.  2255. 	/* for the moment, any additional information is incompatible */  2256. 	if (obj->oxlth || otmp->oxlth) return FALSE;  2257.  2258. 	if(obj->oartifact != otmp->oartifact) return FALSE;  2259.  2260. 	if(obj->known == otmp->known || 2261. 		!objects[otmp->otyp].oc_uses_known) { 2262. 		return((boolean)(objects[obj->otyp].oc_merge));  2263. 	} else return(FALSE);  2264. }  2265.  2266. int  2267. doprgold  2268. {  2269. 	/* the messages used to refer to "carrying gold", but that didn't  2270. 	   take containers into account */  2271. #ifndef GOLDOBJ  2272. 	if(!u.ugold)  2273. 	    Your("wallet is empty.");  2274. 	else  2275. 	    Your("wallet contains %ld gold piece%s.", u.ugold, plur(u.ugold));  2276. #else  2277.         long umoney = money_cnt(invent);  2278. 	if(!umoney)  2279. 	    Your("wallet is empty.");  2280. 	else  2281. 	    Your("wallet contains %ld %s.", umoney, currency(umoney));  2282. #endif  2283. 	shopper_financial_report;  2284. 	return 0;  2285. }  2286.  2287. #endif /* OVL1 */  2288. #ifdef OVLB  2289.  2290. int  2291. doprwep  2292. {  2293.     if (!uwep) {  2294. 	You("are empty %s.", body_part(HANDED)); 2295.    } else { 2296. 	prinv((char *)0, uwep, 0L); 2297. 	if (u.twoweap) prinv((char *)0, uswapwep, 0L); 2298.    }  2299.     return 0; 2300. } 2301.  2302. int 2303. doprarm 2304. { 2305. 	if(!wearing_armor) 2306. 		You("are not wearing any armor."); 2307. 	else { 2308. #ifdef TOURIST 2309. 		char lets[8]; 2310. #else 2311. 		char lets[7]; 2312. #endif 2313. 		register int ct = 0; 2314. 2315. #ifdef TOURIST 2316. 		if(uarmu) lets[ct++] = obj_to_let(uarmu); 2317. #endif 2318. 		if(uarm) lets[ct++] = obj_to_let(uarm); 2319. 		if(uarmc) lets[ct++] = obj_to_let(uarmc); 2320. 		if(uarmh) lets[ct++] = obj_to_let(uarmh); 2321. 		if(uarms) lets[ct++] = obj_to_let(uarms); 2322. 		if(uarmg) lets[ct++] = obj_to_let(uarmg); 2323. 		if(uarmf) lets[ct++] = obj_to_let(uarmf); 2324. 		lets[ct] = 0; 2325. 		(void) display_inventory(lets, FALSE); 2326. 	} 2327. 	return 0; 2328. } 2329.  2330. int 2331. doprring 2332. { 2333. 	if(!uleft && !uright) 2334. 		You("are not wearing any rings."); 2335. 	else { 2336. 		char lets[3]; 2337. 		register int ct = 0; 2338. 2339. 		if(uleft) lets[ct++] = obj_to_let(uleft); 2340. 		if(uright) lets[ct++] = obj_to_let(uright); 2341. 		lets[ct] = 0; 2342. 		(void) display_inventory(lets, FALSE); 2343. 	} 2344. 	return 0; 2345. } 2346.  2347. int 2348. dopramulet 2349. { 2350. 	if (!uamul) 2351. 		You("are not wearing an amulet."); 2352. 	else 2353. 		prinv((char *)0, uamul, 0L); 2354. 	return 0; 2355. } 2356.  2357. STATIC_OVL boolean 2358. tool_in_use(obj) 2359. struct obj *obj; 2360. { 2361. 	if ((obj->owornmask & (W_TOOL  2362. #ifdef STEED  2363. 			| W_SADDLE  2364. #endif  2365. 			)) != 0L) return TRUE; 2366. 	if (obj->oclass != TOOL_CLASS) return FALSE; 2367. 	return (boolean)(obj == uwep || obj->lamplit || 2368. 				(obj->otyp == LEASH && obj->leashmon)); 2369. } 2370.  2371. int 2372. doprtool 2373. { 2374. 	struct obj *otmp; 2375. 	int ct = 0; 2376. 	char lets[52+1]; 2377. 2378. 	for (otmp = invent; otmp; otmp = otmp->nobj) 2379. 	   if (tool_in_use(otmp)) 2380. 		lets[ct++] = obj_to_let(otmp); 2381. 	lets[ct] = '\0'; 2382. 	if (!ct) You("are not using any tools."); 2383. 	else (void) display_inventory(lets, FALSE); 2384. 	return 0; 2385. } 2386.  2387. /* '*' command; combines the ')' + '[' + '=' + '"' + '(' commands;  2388.    show inventory of all currently wielded, worn, or used objects */  2389. int  2390. doprinuse  2391. {  2392. 	struct obj *otmp;  2393. 	int ct = 0;  2394. 	char lets[52+1];  2395.  2396. 	for (otmp = invent; otmp; otmp = otmp->nobj)  2397. 	    if (is_worn(otmp) || tool_in_use(otmp))  2398. 		lets[ct++] = obj_to_let(otmp);  2399. 	lets[ct] = '\0';  2400. 	if (!ct) You("are not wearing or wielding anything.");  2401. 	else (void) display_inventory(lets, FALSE);  2402. 	return 0;  2403. }  2404.  2405. /*  2406.  * uses up an object that's on the floor, charging for it as necessary  2407.  */  2408. void  2409. useupf(obj, numused)  2410. register struct obj *obj;  2411. long numused;  2412. {  2413. 	register struct obj *otmp;  2414.  2415. 	/* burn_floor_paper keeps an object pointer that it tries to  2416. * useupf multiple times, so obj must survive if plural */ 2417. 	if (obj->quan > numused) 2418. 		otmp = splitobj(obj, numused); 2419. 	else 2420. 		otmp = obj; 2421. 	if(costly_spot(otmp->ox, otmp->oy)) { 2422. 	   if(index(u.urooms, *in_rooms(otmp->ox, otmp->oy, 0))) 2423. 	       addtobill(otmp, FALSE, FALSE, FALSE); 2424. 	   else (void)stolen_value(otmp, otmp->ox, otmp->oy, FALSE, FALSE); 2425. 	} 2426. 	delobj(otmp); 2427. } 2428.  2429. #endif /* OVLB */ 2430. 2431.  2432. #ifdef OVL1 2433. 2434. /*  2435.  * Conversion from a class to a string for printing. 2436. * This must match the object class order. 2437. */  2438. STATIC_VAR NEARDATA const char *names[] = { 0, 2439. 	"Illegal objects", "Weapons", "Armor", "Rings", "Amulets", 2440. 	"Tools", "Comestibles", "Potions", "Scrolls", "Spellbooks", 2441. 	"Wands", "Coins", "Gems", "Boulders/Statues", "Iron balls", 2442. 	"Chains", "Venoms" 2443. }; 2444.  2445. static NEARDATA const char oth_symbols[] = { 2446. 	CONTAINED_SYM, 2447. 	'\0' 2448. };  2449.  2450. static NEARDATA const char *oth_names[] = { 2451. 	"Bagged/Boxed items" 2452. }; 2453.  2454. static NEARDATA char *invbuf = (char *)0; 2455. static NEARDATA unsigned invbufsiz = 0; 2456. 2457. char * 2458. let_to_name(let,unpaid) 2459. char let; 2460. boolean unpaid; 2461. { 2462. 	const char *class_name; 2463. 	const char *pos; 2464. 	int oclass = (let >= 1 && let < MAXOCLASSES) ? let : 0; 2465. 	unsigned len; 2466. 2467. 	if (oclass) 2468. 	   class_name = names[oclass]; 2469. 	else if ((pos = index(oth_symbols, let)) != 0) 2470. 	   class_name = oth_names[pos - oth_symbols]; 2471. 	else 2472. 	   class_name = names[0]; 2473. 2474. 	len = strlen(class_name) + (unpaid ? sizeof "unpaid_" : sizeof ""); 2475. 	if (len > invbufsiz) { 2476. 	   if (invbuf) free((genericptr_t)invbuf); 2477. 	   invbufsiz = len + 10; /* add slop to reduce incremental realloc */ 2478. 	   invbuf = (char *) alloc(invbufsiz); 2479. 	} 2480. 	if (unpaid) 2481. 	   Strcat(strcpy(invbuf, "Unpaid "), class_name); 2482. 	else 2483. 	   Strcpy(invbuf, class_name); 2484. 	return invbuf; 2485. } 2486.  2487. void 2488. free_invbuf 2489. { 2490. 	if (invbuf) free((genericptr_t)invbuf),  invbuf = (char *)0; 2491. 	invbufsiz = 0; 2492. } 2493.  2494. #endif /* OVL1 */ 2495. #ifdef OVLB 2496. 2497. void 2498. reassign 2499. { 2500. 	register int i;  2501. register struct obj *obj; 2502. 2503. 	for(obj = invent, i = 0; obj; obj = obj->nobj, i++) 2504. 		obj->invlet = (i < 26) ? ('a'+i) : ('A'+i-26); 2505. 	lastinvnr = i; 2506. } 2507.  2508. #endif /* OVLB */ 2509. #ifdef OVL1 2510. 2511. int 2512. doorganize	/* inventory organizer by Del Lamb */ 2513. { 2514. 	struct obj *obj, *otmp; 2515. 	register int ix, cur; 2516. 	register char let; 2517. 	char alphabet[52+1], buf[52+1]; 2518. 	char qbuf[QBUFSZ]; 2519. 	char allowall[2]; 2520. 	const char *adj_type; 2521. 2522. 	if (!flags.invlet_constant) reassign; 2523. 	/* get a pointer to the object the user wants to organize */ 2524. 	allowall[0] = ALL_CLASSES; allowall[1] = '\0'; 2525. 	if (!(obj = getobj(allowall,"adjust"))) return(0); 2526. 2527. 	/* initialize the list with all upper and lower case letters */ 2528. 	for (let = 'a', ix = 0; let <= 'z';) alphabet[ix++] = let++; 2529. 	for (let = 'A', ix = 26; let <= 'Z';) alphabet[ix++] = let++; 2530. 	alphabet[52] = 0; 2531. 2532. 	/* blank out all the letters currently in use in the inventory */ 2533. 	/* except those that will be merged with the selected object  */ 2534. 	for (otmp = invent; otmp; otmp = otmp->nobj) 2535. 		if (otmp != obj && !mergable(otmp,obj)) { 2536. 			if (otmp->invlet <= 'Z') 2537. 				alphabet[(otmp->invlet) - 'A' + 26] = ' '; 2538. 			else	alphabet[(otmp->invlet) - 'a']	   = ' '; 2539. 		} 2540.  2541. 	/* compact the list by removing all the blanks */ 2542. 	for (ix = cur = 0; ix <= 52; ix++) 2543. 		if (alphabet[ix] != ' ') buf[cur++] = alphabet[ix]; 2544. 2545. 	/* and by dashing runs of letters */ 2546. 	if(cur > 5) compactify(buf); 2547. 2548. 	/* get new letter to use as inventory letter */ 2549. 	for { 2550. 		Sprintf(qbuf, "Adjust letter to what [%s]?",buf); 2551. 		let = yn_function(qbuf, (char *)0, '\0'); 2552. 		if(index(quitchars,let)) { 2553. 			pline(Never_mind); 2554. 			return(0); 2555. 		} 2556. 		if (let == '@' || !letter(let)) 2557. 			pline("Select an inventory slot letter."); 2558. 		else 2559. 			break; 2560. 	} 2561.  2562. 	/* change the inventory and print the resulting item */ 2563. 	adj_type = "Moving:"; 2564. 2565. 	/*  2566. 	 * don't use freeinv/addinv to avoid double-touching artifacts, 2567. 	 * dousing lamps, losing luck, cursing loadstone, etc. 2568. 	 */ 2569. 	extract_nobj(obj, &invent); 2570. 2571. 	for (otmp = invent; otmp;) 2572. 		if (merged(&otmp,&obj)) { 2573. 			adj_type = "Merging:"; 2574. 			obj = otmp; 2575. 			otmp = otmp->nobj; 2576. 			extract_nobj(obj, &invent); 2577. 		} else { 2578. 			if (otmp->invlet == let) { 2579. 				adj_type = "Swapping:"; 2580. 				otmp->invlet = obj->invlet; 2581. 			} 2582. 			otmp = otmp->nobj; 2583. 		} 2584.  2585. 	/* inline addinv (assuming flags.invlet_constant and !merged) */ 2586. 	obj->invlet = let; 2587. 	obj->nobj = invent; /* insert at beginning */ 2588. 	obj->where = OBJ_INVENT; 2589. 	invent = obj; 2590. 	reorder_invent; 2591. 2592. 	prinv(adj_type, obj, 0L); 2593. 	update_inventory; 2594. 	return(0); 2595. } 2596.  2597. /* common to display_minventory and display_cinventory */ 2598. STATIC_OVL void 2599. invdisp_nothing(hdr, txt) 2600. const char *hdr, *txt; 2601. { 2602. 	winid win; 2603. 	anything any; 2604. 	menu_item *selected; 2605. 2606. 	any.a_void = 0; 2607. 	win = create_nhwindow(NHW_MENU); 2608. 	start_menu(win); 2609. 	add_menu(win, NO_GLYPH, &any, 0, 0, ATR_INVERSE, hdr, MENU_UNSELECTED); 2610. 	add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, "", MENU_UNSELECTED); 2611. 	add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, txt, MENU_UNSELECTED); 2612. 	end_menu(win, (char *)0); 2613. 	if (select_menu(win, PICK_NONE, &selected) > 0) 2614. 	   free((genericptr_t)selected); 2615. 	destroy_nhwindow(win); 2616. 	return; 2617. } 2618.  2619. /* query_objlist callback: return things that could possibly be worn/wielded */ 2620. STATIC_OVL boolean 2621. worn_wield_only(obj) 2622. struct obj *obj; 2623. { 2624.     return (obj->oclass == WEAPON_CLASS  2625. 		|| obj->oclass == ARMOR_CLASS  2626. 		|| obj->oclass == AMULET_CLASS  2627. 		|| obj->oclass == RING_CLASS  2628. 		|| obj->oclass == TOOL_CLASS); 2629. } 2630.  2631. /*  2632.  * Display a monster's inventory. 2633. * Returns a pointer to the object from the monster's inventory selected 2634. * or NULL if nothing was selected. 2635. *  2636.  * By default, only worn and wielded items are displayed. The caller 2637. * can pick one. Modifier flags are: 2638. *  2639.  *	MINV_NOLET	- nothing selectable 2640. *	MINV_ALL	- display all inventory 2641. */  2642. struct obj * 2643. display_minventory(mon, dflags, title) 2644. register struct monst *mon; 2645. int dflags; 2646. char *title; 2647. { 2648. 	struct obj *ret; 2649. #ifndef GOLDOBJ 2650. 	struct obj m_gold; 2651. #endif 2652. 	char tmp[QBUFSZ]; 2653. 	int n; 2654. menu_item *selected = 0; 2655. #ifndef GOLDOBJ 2656. 	int do_all = (dflags & MINV_ALL) != 0, 2657. 	   do_gold = (do_all && mon->mgold); 2658. #else 2659. 	int do_all = (dflags & MINV_ALL) != 0; 2660. #endif 2661. 2662. 	Sprintf(tmp,"%s %s:", s_suffix(noit_Monnam(mon)),  2663. 		do_all ? "possessions" : "armament"); 2664. 2665. #ifndef GOLDOBJ 2666. 	if (do_all ? (mon->minvent || mon->mgold) 2667. #else  2668. 	if (do_all ? (mon->minvent != 0) 2669. #endif 2670. 		  : (mon->misc_worn_check || MON_WEP(mon))) {  2671. 	    /* Fool the 'weapon in hand' routine into  2672. 	     * displaying 'weapon in claw', etc. properly.  2673. 	     */  2674. 	    youmonst.data = mon->data;  2675.  2676. #ifndef GOLDOBJ  2677. 	    if (do_gold) {  2678. 		/*  2679. 		 * Make temporary gold object and insert at the head of  2680. 		 * the mon's inventory.  We can get away with using a  2681. 		 * stack variable object because monsters don't carry  2682. 		 * gold in their inventory, so it won't merge.  2683. 		 */  2684. 		m_gold = zeroobj;  2685. 		m_gold.otyp = GOLD_PIECE;  m_gold.oclass = GOLD_CLASS;  2686. 		m_gold.quan = mon->mgold;  m_gold.dknown = 1;  2687. 		m_gold.where = OBJ_FREE;  2688. 		/* we had better not merge and free this object... */  2689. 		if (add_to_minv(mon, &m_gold))  2690. 		    panic("display_minventory: static object freed."); 2691. 	   }  2692.  2693. #endif 2694. 	   n = query_objlist(title ? title : tmp, mon->minvent, INVORDER_SORT, &selected,  2695. 			(dflags & MINV_NOLET) ? PICK_NONE : PICK_ONE,  2696. 			do_all ? allow_all : worn_wield_only); 2697. 2698. #ifndef GOLDOBJ 2699. 	   if (do_gold) obj_extract_self(&m_gold); 2700. #endif 2701. 2702. 	    set_uasmon; 2703. 	} else { 2704. 	   invdisp_nothing(title ? title : tmp, "(none)"); 2705. 	   n = 0; 2706. 	} 2707.  2708. 	if (n > 0) { 2709. 	   ret = selected[0].item.a_obj; 2710. 	   free((genericptr_t)selected); 2711. #ifndef GOLDOBJ 2712. 	   /*  2713. 	     * Unfortunately, we can't return a pointer to our temporary 2714. 	    * gold object. We'll have to work out a scheme where this 2715. 	    * can happen. Maybe even put gold in the inventory list... 2716. */ 2717. 	    if (ret == &m_gold) ret = (struct obj *) 0; 2718. #endif 2719. 	} else 2720. 	   ret = (struct obj *) 0; 2721. 	return ret; 2722. } 2723.  2724. /*  2725.  * Display the contents of a container in inventory style. 2726. * Currently, this is only used for statues, via wand of probing. 2727. */  2728. struct obj * 2729. display_cinventory(obj) 2730. register struct obj *obj; 2731. { 2732. 	struct obj *ret; 2733. 	char tmp[QBUFSZ]; 2734. 	int n; 2735. menu_item *selected = 0; 2736. 2737. 	Sprintf(tmp,"Contents of %s:", doname(obj)); 2738. 2739. 	if (obj->cobj) { 2740. 	   n = query_objlist(tmp, obj->cobj, INVORDER_SORT, &selected,  2741. 			    PICK_NONE, allow_all); 2742. 	} else { 2743. 	   invdisp_nothing(tmp, "(empty)"); 2744. 	   n = 0; 2745. 	} 2746. 	if (n > 0) { 2747. 	   ret = selected[0].item.a_obj; 2748. 	   free((genericptr_t)selected); 2749. 	} else 2750. 	   ret = (struct obj *) 0; 2751. 	return ret; 2752. } 2753.  2754. /* query objlist callback: return TRUE if obj is at given location */ 2755. static coord only; 2756. 2757. STATIC_OVL boolean 2758. only_here(obj) 2759.    struct obj *obj; 2760. { 2761.     return (obj->ox == only.x && obj->oy == only.y); 2762. } 2763.  2764. /*  2765.  * Display a list of buried items in inventory style. Return a non-zero 2766. * value if there were items at that spot. 2767. *  2768.  * Currently, this is only used with a wand of probing zapped downwards. 2769. */  2770. int 2771. display_binventory(x, y, as_if_seen) 2772. int x, y; 2773. boolean as_if_seen; 2774. { 2775. 	struct obj *obj; 2776. 	menu_item *selected = 0; 2777. 	int n; 2778. 2779. 	/* count # of objects here */ 2780. 	for (n = 0, obj = level.buriedobjlist; obj; obj = obj->nobj) 2781. 	   if (obj->ox == x && obj->oy == y) { 2782. 		if (as_if_seen) obj->dknown = 1; 2783. 		n++; 2784. 	   }  2785.  2786. 	if (n) { 2787. 	   only.x = x;  2788. only.y = y; 2789. if (query_objlist("Things that are buried here:", 2790. 			     level.buriedobjlist, INVORDER_SORT, 2791. 			     &selected, PICK_NONE, only_here) > 0) 2792. 		free((genericptr_t)selected); 2793. 	   only.x = only.y = 0; 2794. 	} 2795. 	return n;  2796. } 2797.  2798. #endif /* OVL1 */ 2799. 2800. /*invent.c*/