Source:NetHack 3.2.0/shk.c

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

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

1.   /*	SCCS Id: @(#)shk.c	3.2	96/03/09	*/ 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 "eshk.h"  7. 8.   /*#define DEBUG*/ 9.    10.   #define PAY_SOME    2 11.  #define PAY_BUY     1 12.  #define PAY_CANT    0	/* too poor */ 13.  #define PAY_SKIP  (-1) 14.  #define PAY_BROKE (-2) 15.   16.   #ifdef KOPS 17.  STATIC_DCL void FDECL(makekops, (coord *)); 18.  STATIC_DCL void FDECL(call_kops, (struct monst *,BOOLEAN_P)); 19.  # ifdef OVLB 20.  STATIC_DCL void FDECL(kops_gone, (BOOLEAN_P)); 21.  # endif /* OVLB */ 22.  #endif /* KOPS */ 23.   24.   #define IS_SHOP(x)	(rooms[x].rtype >= SHOPBASE) 25.   26.   extern const struct shclass shtypes[];	/* defined in shknam.c */ 27.   28.   STATIC_VAR NEARDATA long int followmsg;	/* last time of follow message */ 29.   30.   STATIC_DCL void FDECL(setpaid, (struct monst *)); 31.  STATIC_DCL long FDECL(addupbill, (struct monst *)); 32.  STATIC_DCL void FDECL(pacify_shk, (struct monst *)); 33.  STATIC_DCL struct bill_x *FDECL(onbill, (struct obj *, struct monst *, BOOLEAN_P)); 34.  STATIC_DCL struct monst *FDECL(next_shkp, (struct monst *, BOOLEAN_P)); 35.  STATIC_DCL long FDECL(shop_debt, (struct eshk *)); 36.  STATIC_DCL char *FDECL(shk_owns, (char *,struct obj *)); 37.  STATIC_DCL char *FDECL(mon_owns, (char *,struct obj *)); 38.  STATIC_DCL void FDECL(clear_unpaid,(struct obj *)); 39.  STATIC_DCL long FDECL(check_credit, (long, struct monst *)); 40.  STATIC_DCL void FDECL(pay, (long, struct monst *)); 41.  STATIC_DCL long FDECL(get_cost, (struct obj *, struct monst *)); 42.  STATIC_DCL long FDECL(set_cost, (struct obj *, struct monst *)); 43.  STATIC_DCL const char *FDECL(shk_embellish, (struct obj *, long)); 44.  STATIC_DCL long FDECL(cost_per_charge, (struct monst *,struct obj *)); 45.  STATIC_DCL long FDECL(cheapest_item, (struct monst *)); 46.  STATIC_DCL int FDECL(dopayobj, (struct monst *, struct bill_x *, 47.  			    struct obj **, int, BOOLEAN_P)); 48.  STATIC_DCL long FDECL(stolen_container, (struct obj *, struct monst *, long, 49.  				     BOOLEAN_P)); 50.  STATIC_DCL long FDECL(getprice, (struct obj *,BOOLEAN_P)); 51.  STATIC_DCL void FDECL(shk_names_obj,  52.   		 (struct monst *,struct obj *,const char *,long,const char *)); 53.  STATIC_DCL struct obj *FDECL(bp_to_obj, (struct bill_x *)); 54.  STATIC_DCL boolean FDECL(inherits, (struct monst *, int, BOOLEAN_P)); 55.  STATIC_DCL void FDECL(set_repo_loc, (struct eshk *)); 56.  STATIC_DCL boolean NDECL(angry_shk_exists); 57.  STATIC_DCL void FDECL(rile_shk, (struct monst *)); 58.  STATIC_DCL void FDECL(remove_damage, (struct monst *, BOOLEAN_P)); 59.  STATIC_DCL void FDECL(sub_one_frombill, (struct obj *, struct monst *)); 60.  STATIC_DCL void FDECL(add_one_tobill, (struct obj *, BOOLEAN_P)); 61.  STATIC_DCL void FDECL(dropped_container, (struct obj *, struct monst *, 62.  				      BOOLEAN_P)); 63.  STATIC_DCL void FDECL(add_to_billobjs, (struct obj *)); 64.  STATIC_DCL void FDECL(bill_box_content, (struct obj *, BOOLEAN_P, BOOLEAN_P, 65.  				     struct monst *)); 66.   67.   #ifdef OVLB 68.  /*  69.   	invariants: obj->unpaid iff onbill(obj) [unless bp->useup] 70.  		obj->quan <= bp->bquan 71.   */  72.    73.   STATIC_OVL struct monst * 74.  next_shkp(shkp, withbill) 75.  register struct monst *shkp; 76.  register boolean withbill; 77.  {  78.   	for (shkp; shkp = shkp->nmon) 79.  	    if (shkp->isshk) 80.  		if (ESHK(shkp)->billct || !withbill) break; 81.   82.   	if (shkp) { 83.  	    if (NOTANGRY(shkp)) { 84.  		if (ESHK(shkp)->surcharge) pacify_shk(shkp); 85.  	    } else { 86.  		if (!ESHK(shkp)->surcharge) rile_shk(shkp); 87.  	    }  88.   	}  89.   	return(shkp); 90.  }  91.    92.   char * 93.  shkname(mtmp)				/* called in do_name.c */ 94.  register struct monst *mtmp; 95.  {  96.   	return(ESHK(mtmp)->shknam); 97.  }  98.    99.   void 100. shkgone(mtmp)				/* called in mon.c */ 101. register struct monst *mtmp; 102. {  103.  	register struct eshk *eshk = ESHK(mtmp); 104.  105.  	if(on_level(&(eshk->shoplevel), &u.uz)) { 106. 		remove_damage(mtmp, TRUE); 107. 		rooms[eshk->shoproom - ROOMOFFSET].resident 108. 						  = (struct monst *)0; 109. 		if(!search_special(ANY_SHOP)) 110. 		    level.flags.has_shop = 0; 111. 	}  112.  	/* make sure bill is set only when the 113. 	 * dead shk is the resident shk. */ 114.  	if(*u.ushops == eshk->shoproom) { 115. 	    setpaid(mtmp); 116. 	    /* dump core when referenced */ 117. 	    ESHK(mtmp)->bill_p = (struct bill_x *) -1000; 118. 	    u.ushops[0] = '\0'; 119. 	}  120.  }  121.   122.  void 123. set_residency(shkp, zero_out) 124. register struct monst *shkp; 125. register boolean zero_out; 126. {  127.  	if (on_level(&(ESHK(shkp)->shoplevel), &u.uz)) 128. 	    rooms[ESHK(shkp)->shoproom - ROOMOFFSET].resident = 129. 		(zero_out)? (struct monst *)0 : shkp; 130. }  131.   132.  void 133. replshk(mtmp,mtmp2) 134. register struct monst *mtmp, *mtmp2; 135. {  136.  	rooms[ESHK(mtmp2)->shoproom - ROOMOFFSET].resident = mtmp2; 137. 	if (inhishop(mtmp) && *u.ushops == ESHK(mtmp)->shoproom) { 138. 		ESHK(mtmp2)->bill_p = &(ESHK(mtmp2)->bill[0]); 139. 	}  140.  }  141.   142.  /* do shopkeeper specific structure munging -dlc */ 143. void 144. restshk(shkp, ghostly) 145. struct monst *shkp; 146. boolean ghostly; 147. {  148.      if (u.uz.dlevel) { 149. 	struct eshk *eshkp = ESHK(shkp); 150.  151.  	if (eshkp->bill_p != (struct bill_x *) -1000) 152. 	    eshkp->bill_p = &eshkp->bill[0]; 153. 	/* shoplevel can change as dungeons move around */ 154. 	/* savebones guarantees that non-homed shk's will be gone */ 155. 	if (ghostly) { 156. 	    assign_level(&eshkp->shoplevel, &u.uz); 157. 	    if (ANGRY(shkp) && strncmpi(eshkp->customer, plname, PL_NSIZ)) 158. 		pacify_shk(shkp); 159. 	}  160.      }  161.  }  162.   163.  #endif /* OVLB */ 164. #ifdef OVL3 165.  166.  /* Clear the unpaid bit on all of the objects in the list. */ 167.  STATIC_OVL void 168. clear_unpaid(list) 169. register struct obj *list; 170. {  171.      while (list) { 172. 	if (Has_contents(list)) clear_unpaid(list->cobj); 173. 	list->unpaid = 0; 174. 	list = list->nobj; 175.     }  176.  }  177.  #endif /*OVL3*/ 178. #ifdef OVLB 179.  180.  STATIC_OVL void 181. setpaid(shkp)	/* either you paid or left the shop or the shopkeeper died */ 182. register struct monst *shkp; 183. {  184.  	register struct obj *obj; 185. 	register struct monst *mtmp; 186.  187.  	clear_unpaid(invent); 188. 	clear_unpaid(fobj); 189. 	clear_unpaid(level.buriedobjlist); 190. 	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) 191. 		clear_unpaid(mtmp->minvent); 192. 	for(mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) 193. 		clear_unpaid(mtmp->minvent); 194.  195.  	while ((obj = billobjs) != 0) { 196. 		obj_extract_self(obj); 197. 		dealloc_obj(obj); 198. 	}  199.  	if(shkp) { 200. 		ESHK(shkp)->billct = 0; 201. 		ESHK(shkp)->credit = 0L; 202. 		ESHK(shkp)->debit = 0L; 203. 		ESHK(shkp)->loan = 0L; 204. 	}  205.  }  206.   207.  STATIC_OVL long 208. addupbill(shkp) 209. register struct monst *shkp; 210. {  211.  	register int ct = ESHK(shkp)->billct; 212. 	register struct bill_x *bp = ESHK(shkp)->bill_p; 213. 	register long total = 0L; 214.  215.  	while(ct--){ 216. 		total += bp->price * bp->bquan; 217. 		bp++; 218. 	}  219.  	return(total); 220. }  221.   222.  #endif /* OVLB */ 223. #ifdef OVL1 224.  225.  #ifdef KOPS 226. STATIC_OVL void 227. call_kops(shkp, nearshop) 228. register struct monst *shkp; 229. register boolean nearshop; 230. {  231.  	/* Keystone Kops srt@ucla */ 232. 	register boolean nokops; 233.  234.  	if(!shkp) return; 235.  236.  	if (flags.soundok) 237. 	    pline("An alarm sounds!"); 238.  239.  	nokops = ((mvitals[PM_KEYSTONE_KOP].mvflags & G_GONE) &&  240.  		  (mvitals[PM_KOP_SERGEANT].mvflags & G_GONE) &&  241.  		  (mvitals[PM_KOP_LIEUTENANT].mvflags & G_GONE) &&  242.  		  (mvitals[PM_KOP_KAPTAIN].mvflags & G_GONE)); 243.  244.  	if(!angry_guards(!flags.soundok) && nokops) { 245. 	    if(flags.verbose && flags.soundok) 246. 		pline("But no one seems to respond to it."); 247. 	    return; 248. 	}  249.   250.  	if(nokops) return; 251.  252.  	{  253.  	    coord mm; 254.  255.  	    if (nearshop) { 256. 		/* Create swarm around you, if you merely "stepped out" */ 257. 		if (flags.verbose) 258. 		    pline_The("Keystone Kops appear!"); 259. 		mm.x = u.ux; 260. 		mm.y = u.uy; 261. 		makekops(&mm); 262. 		return; 263. 	    }  264.  	    if (flags.verbose) 265. 		 pline_The("Keystone Kops are after you!"); 266. 	    /* Create swarm near down staircase (hinders return to level) */ 267. 	    mm.x = xdnstair; 268. 	    mm.y = ydnstair; 269. 	    makekops(&mm); 270. 	    /* Create swarm near shopkeeper (hinders return to shop) */ 271. 	    mm.x = shkp->mx; 272. 	    mm.y = shkp->my; 273. 	    makekops(&mm); 274. 	}  275.  }  276.  #endif	/* KOPS */ 277.  278.  /* x,y is strictly inside shop */ 279. char 280. inside_shop(x, y)  281. register xchar x, y; 282. { 283.  	register char rno; 284.  285.  	rno = levl[x][y].roomno; 286. 	if ((rno < ROOMOFFSET) || levl[x][y].edge || !IS_SHOP(rno-ROOMOFFSET)) 287. 	    return(NO_ROOM); 288. 	else 289. 	    return(rno); 290. }  291.   292.  void 293. u_left_shop(leavestring, newlev) 294. register char *leavestring; 295. register boolean newlev; 296. {  297.  	register struct monst *shkp; 298. 	register struct eshk *eshkp; 299. 	register long total; 300.  301.  	/*  302.  	 * IF player 303. 	 * ((didn't leave outright) AND  304.  	 *  ((he is now strictly-inside the shop) OR  305. *  (he wasn't strictly-inside last turn anyway))) 306. 	 * THEN (there's nothing to do, so just return) 307. 	 */  308.  	if(!*leavestring &&  309.  	   (!levl[u.ux][u.uy].edge || levl[u.ux0][u.uy0].edge)) 310. 	    return; 311.  312.  	shkp = shop_keeper(*u.ushops0); 313.  314.  	if(!shkp || !inhishop(shkp)) 315. 				/* shk died, teleported, changed levels... */ 316.  	    return; 317.  318.  	eshkp = ESHK(shkp); 319.  320.  	if(!eshkp->billct && !eshkp->debit)	/* bill is settled */ 321. 	    return; 322.  323.  	if (!*leavestring && shkp->mcanmove && !shkp->msleep) { 324. 	    /*  325.  	     * Player just stepped onto shop-boundary (known from above logic). 326. 	     * Try to intimidate him into paying his bill 327. 	     */  328.  	    verbalize(NOTANGRY(shkp) ?  329.  		      "%s!  Please pay before leaving." :  330.  		      "%s!  Don't you leave without paying!",  331.  		      plname); 332. 	    return; 333. 	}  334.  	total = (addupbill(shkp) + eshkp->debit); 335. 	if (eshkp->credit >= total) { 336. 	    Your("credit of %ld zorkmid%s is used to cover your shopping bill.",  337.  		 eshkp->credit, plur(eshkp->credit)); 338. 	    total = 0L;		/* credit gets cleared by setpaid */ 339. 	} else { 340. 	    You("escaped the shop without paying!"); 341. 	    total -= eshkp->credit; 342. 	}  343.  	setpaid(shkp); 344. 	if (!total) return; 345.  346.  	/* by this point, we know an actual robbery has taken place */ 347. 	eshkp->robbed += total; 348. 	You("stole %ld zorkmid%s worth of merchandise.",  349.  	    total, plur(total)); 350. 	if (!Role_is('R'))	/* stealing is unlawful */ 351. 	    adjalign(-sgn(u.ualign.type)); 352.  353.  	hot_pursuit(shkp); 354. #ifdef KOPS 355. 	call_kops(shkp, (!newlev && levl[u.ux0][u.uy0].edge)); 356. #else 357. 	(void) angry_guards(FALSE); 358. #endif 359. }  360.   361.  void 362. u_entered_shop(enterstring) 363. register char *enterstring; 364. {  365.   366.  	register int rt; 367. 	register struct monst *shkp; 368. 	register struct eshk *eshkp; 369. 	struct obj *pick; 370. 	static const char no_shk[] = "This shop appears to be deserted."; 371. 	static char empty_shops[5]; 372.  373.  	if(!*enterstring) 374. 		return; 375.  376.  	if(!(shkp = shop_keeper(*enterstring))) { 377. 	    if (!index(empty_shops, *enterstring) &&  378.  		in_rooms(u.ux, u.uy, SHOPBASE) !=  379.  				  in_rooms(u.ux0, u.uy0, SHOPBASE)) 380. 		pline(no_shk); 381. 	    Strcpy(empty_shops, u.ushops); 382. 	    u.ushops[0] = '\0'; 383. 	    return; 384. 	}  385.   386.  	eshkp = ESHK(shkp); 387.  388.  	if (!inhishop(shkp)) { 389. 	    /* dump core when referenced */ 390. 	    eshkp->bill_p = (struct bill_x *) -1000; 391. 	    if (!index(empty_shops, *enterstring)) 392. 		pline(no_shk); 393. 	    Strcpy(empty_shops, u.ushops); 394. 	    u.ushops[0] = '\0'; 395. 	    return; 396. 	}  397.   398.  	eshkp->bill_p = &(eshkp->bill[0]); 399.  400.  	if (!eshkp->visitct || strncmpi(eshkp->customer, plname, PL_NSIZ)) { 401. 	    /* You seem to be new here */ 402. 	    eshkp->visitct = 0; 403. 	    eshkp->following = 0; 404. 	    (void) strncpy(eshkp->customer,plname,PL_NSIZ); 405. 	    pacify_shk(shkp); 406. 	}  407.   408.  	if (shkp->msleep || !shkp->mcanmove || eshkp->following) /* no dialog */ 409. 	    return; 410.  411.  	if (Invis) { 412. 	    pline("%s senses your presence.", shkname(shkp)); 413. 	    verbalize("Invisible customers are not welcome!"); 414. 	    return; 415. 	}  416.   417.  	rt = rooms[*enterstring - ROOMOFFSET].rtype; 418.  419.  	if (ANGRY(shkp)) { 420. 	    verbalize("So, %s, you dare return to %s %s?!",  421.  		      plname,  422.  		      s_suffix(shkname(shkp)),  423.  		      shtypes[rt - SHOPBASE].name); 424. 	} else if (eshkp->robbed) { 425. 	    pline("%s mutters imprecations against shoplifters.", shkname(shkp)); 426. 	} else { 427. 	    verbalize("Hello, %s!  Welcome%s to %s %s!",  428.  		      plname,  429.  		      eshkp->visitct++ ? " again" : "",  430.  		      s_suffix(shkname(shkp)),  431.  		      shtypes[rt - SHOPBASE].name); 432. 	}  433.  	/* can't do anything about blocking if teleported in */ 434. 	if (!inside_shop(u.ux, u.uy)) { 435. 	    boolean should_block; 436.  437.  	    if ((pick = carrying(PICK_AXE)) != 0) { 438. 		int cnt = 1; 439. 		/* hack: `pick' already points somewhere into inventory */ 440. 		while ((pick = pick->nobj) != 0) 441. 		    if (pick->otyp == PICK_AXE) ++cnt; 442. 		verbalize(NOTANGRY(shkp) ?  443.  			  "Will you please leave your pick-axe%s outside?" :  444.  			  "Leave the pick-axe%s outside.",  445.  			  plur(cnt)); 446. 		should_block = TRUE; 447. 	    } else { 448. 		should_block = (Fast && sobj_at(PICK_AXE, u.ux, u.uy)); 449. 	    }  450.  	    if (should_block) (void) dochug(shkp);  /* shk gets extra move */ 451. 	}  452.  	return; 453. }  454.   455.  /*  456.     Decide whether two unpaid items are mergable; caller is responsible for 457.    making sure they're unpaid and the same type of object; we check the price 458.    quoted by the shopkeeper and also that they both belong to the same shk. 459.  */  460.  boolean same_price(obj1, obj2) 461. struct obj *obj1, *obj2; 462. {  463.  	register struct monst *shkp1, *shkp2; 464. 	register struct bill_x *bp1 = 0, *bp2 = 0; 465. 	register boolean are_mergable = FALSE; 466.  467.  	/* look up the first object by finding shk whose bill it's on */ 468. 	for (shkp1 = next_shkp(fmon, TRUE); shkp1;  469.  		shkp1 = next_shkp(shkp1, TRUE)) 470. 	    if ((bp1 = onbill(obj1, shkp1, TRUE)) != 0) break; 471. 	/* second object is probably owned by same shk; if not, look harder */ 472. 	if (shkp1 && (bp2 = onbill(obj2, shkp1, TRUE)) != 0) { 473. 	    shkp2 = shkp1; 474. 	} else { 475. 	    for (shkp2 = next_shkp(fmon, TRUE); shkp2;  476.  		    shkp2 = next_shkp(shkp2, TRUE)) 477. 		if ((bp2 = onbill(obj2, shkp2, TRUE)) != 0) break; 478. 	}  479.   480.  	if (!bp1 || !bp2) impossible("same_price: object wasn't on any bill!"); 481. 	else are_mergable = (shkp1 == shkp2 && bp1->price == bp2->price); 482. 	return are_mergable; 483. }  484.   485.  /*  486.   * Figure out how much is owed to a given shopkeeper. 487.  * At present, we ignore any amount robbed from the shop, to avoid 488.  * turning the `$' command into a way to discover that the current 489.  * level is bones data which has a shk on the warpath. 490.  */  491.  STATIC_OVL long 492. shop_debt(eshkp) 493. struct eshk *eshkp; 494. {  495.  	struct bill_x *bp; 496. 	int ct; 497. 	long debt = eshkp->debit; 498.  499.  	for (bp = eshkp->bill_p, ct = eshkp->billct; ct > 0; bp++, ct--) 500. 	    debt += bp->price * bp->bquan; 501. 	return debt; 502. }  503.   504.  /* called in response to the `$' command */ 505. void 506. shopper_financial_report 507. {  508.  	struct monst *shkp, *this_shkp = shop_keeper(inside_shop(u.ux, u.uy)); 509. 	struct eshk *eshkp; 510. 	long amt; 511. 	int pass; 512.  513.  	if (this_shkp &&  514.  	    !(ESHK(this_shkp)->credit || shop_debt(ESHK(this_shkp)))) { 515. 	    You("have no credit or debt in here."); 516. 	    this_shkp = 0;	/* skip first pass */ 517. 	}  518.   519.  	/* pass 0: report for the shop we're currently in, if any; 520. 	   pass 1: report for all other shops on this level. */ 521.  	for (pass = this_shkp ? 0 : 1; pass <= 1; pass++) 522. 	    for (shkp = next_shkp(fmon, FALSE);  523.  		    shkp; shkp = next_shkp(shkp->nmon, FALSE)) { 524. 		if ((shkp != this_shkp) ^ pass) continue; 525. 		eshkp = ESHK(shkp); 526. 		if ((amt = eshkp->credit) != 0) 527. 		    You("have %ld zorkmid%s credit at %s %s.",  528.  			amt, plur(amt), s_suffix(shkname(shkp)),  529.  			shtypes[eshkp->shoptype - SHOPBASE].name); 530. 		else if (shkp == this_shkp) 531. 		    You("have no credit in here."); 532. 		if ((amt = shop_debt(eshkp)) != 0) 533. 		    You("owe %s %ld zorkmid%s.",  534.  			shkname(shkp), amt, plur(amt)); 535. 		else if (shkp == this_shkp) 536. 		    You("don't owe any money here."); 537. 	    }  538.  }  539.   540.  #endif /* OVL1 */ 541. #ifdef OVLB 542.  543.  int 544. inhishop(mtmp) 545. register struct monst *mtmp; 546. {  547.  	return(index(in_rooms(mtmp->mx, mtmp->my, SHOPBASE), 548. 		     ESHK(mtmp)->shoproom) &&  549.  		on_level(&(ESHK(mtmp)->shoplevel), &u.uz)); 550. }  551.   552.  struct monst * 553. shop_keeper(rmno) 554. register char rmno; 555. {  556.  	struct monst *shkp = rmno >= ROOMOFFSET ? 557. 				rooms[rmno - ROOMOFFSET].resident : 0; 558.  559.  	if (shkp) { 560. 	    if (NOTANGRY(shkp)) { 561. 		if (ESHK(shkp)->surcharge) pacify_shk(shkp); 562. 	    } else { 563. 		if (!ESHK(shkp)->surcharge) rile_shk(shkp); 564. 	    }  565.  	}  566.  	return shkp; 567. }  568.   569.  boolean 570. tended_shop(sroom) 571. register struct mkroom *sroom; 572. {  573.  	register struct monst *mtmp = sroom->resident; 574.  575.  	if (!mtmp) 576. 		return(FALSE); 577. 	else 578. 		return((boolean)(inhishop(mtmp))); 579. }  580.   581.  STATIC_OVL struct bill_x * 582. onbill(obj, shkp, silent) 583. register struct obj *obj; 584. register struct monst *shkp; 585. register boolean silent; 586. {  587.  	if (shkp) { 588. 		register struct bill_x *bp = ESHK(shkp)->bill_p; 589. 		register int ct = ESHK(shkp)->billct; 590.  591.  		while (--ct >= 0) 592. 		    if (bp->bo_id == obj->o_id) { 593. 			if (!obj->unpaid) pline("onbill: paid obj on bill?"); 594. 			return bp; 595. 		    } else bp++; 596. 	}  597.  	if(obj->unpaid & !silent) pline("onbill: unpaid obj not on bill?"); 598. 	return (struct bill_x *)0; 599. }  600.   601.  /* Delete the contents of the given object. */ 602.  void 603. delete_contents(obj) 604. register struct obj *obj; 605. {  606.  	register struct obj *curr; 607.  608.  	while ((curr = obj->cobj) != 0) { 609. 	    obj_extract_self(curr); 610. 	    obfree(curr, (struct obj *)0); 611. 	}  612.  }  613.   614.  /* called with two args on merge */ 615. void 616. obfree(obj, merge) 617. register struct obj *obj, *merge; 618. {  619.  	register struct bill_x *bp; 620. 	register struct bill_x *bpm; 621. 	register struct monst *shkp; 622.  623.  	if(obj->oclass == FOOD_CLASS) food_disappears(obj); 624.  625.  	if (obj->cobj) delete_contents(obj); 626.  627.  	shkp = shop_keeper(*u.ushops); 628.  629.  	if ((bp = onbill(obj, shkp, FALSE)) != 0) { 630. 		if(!merge){ 631. 			bp->useup = 1; 632. 			obj->unpaid = 0;	/* only for doinvbill */ 633. 			add_to_billobjs(obj); 634. 			return; 635. 		}  636.  		bpm = onbill(merge, shkp, FALSE); 637. 		if(!bpm){ 638. 			/* this used to be a rename */ 639. 			impossible("obfree: not on bill??"); 640. 			return; 641. 		} else { 642. 			/* this was a merger */ 643. 			bpm->bquan += bp->bquan; 644. 			ESHK(shkp)->billct--; 645. #ifdef DUMB 646. 			{  647.  			/* DRS/NS 2.2.6 messes up -- Peter Kendell */ 648. 				int indx = ESHK(shkp)->billct; 649. 				*bp = ESHK(shkp)->bill_p[indx]; 650. 			}  651.  #else 652. 			*bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct]; 653. #endif 654. 		}  655.  	}  656.  	dealloc_obj(obj); 657. }  658.  #endif /* OVLB */ 659. #ifdef OVL3 660.  661.  STATIC_OVL long 662. check_credit(tmp, shkp) 663. long tmp; 664. register struct monst *shkp; 665. {  666.  	long credit = ESHK(shkp)->credit; 667.  668.  	if(credit == 0L) return(tmp); 669. 	if(credit >= tmp) { 670. 		pline_The("price is deducted from your credit."); 671. 		ESHK(shkp)->credit -=tmp; 672. 		tmp = 0L; 673. 	} else { 674. 		pline_The("price is partially covered by your credit."); 675. 		ESHK(shkp)->credit = 0L; 676. 		tmp -= credit; 677. 	}  678.  	return(tmp); 679. }  680.   681.  STATIC_OVL void 682. pay(tmp,shkp) 683. long tmp; 684. register struct monst *shkp; 685. {  686.  	long robbed = ESHK(shkp)->robbed; 687. 	long balance = ((tmp <= 0L) ? tmp : check_credit(tmp, shkp)); 688.  689.  	u.ugold -= balance; 690. 	shkp->mgold += balance; 691. 	flags.botl = 1; 692. 	if(robbed) { 693. 		robbed -= tmp; 694. 		if(robbed < 0) robbed = 0L; 695. 		ESHK(shkp)->robbed = robbed; 696. 	}  697.  }  698.  #endif /*OVL3*/ 699. #ifdef OVLB 700.  701.  /* return shkp to home position */ 702. void 703. home_shk(shkp, killkops) 704. register struct monst *shkp; 705. register boolean killkops; 706. {  707.  	register xchar x = ESHK(shkp)->shk.x, y = ESHK(shkp)->shk.y;  708. 709. 	(void) mnearto(shkp, x, y, TRUE); 710. 	level.flags.has_shop = 1; 711. 	if (killkops) { 712. #ifdef KOPS 713. 		kops_gone(TRUE); 714. #else 715. 		You_feel("vaguely apprehensive."); 716. #endif 717. 		pacify_guards; 718. 	}  719.  }  720.   721.  STATIC_OVL boolean 722. angry_shk_exists 723. {  724.  	register struct monst *shkp; 725.  726.  	for (shkp = next_shkp(fmon, FALSE);  727.  		shkp; shkp = next_shkp(shkp->nmon, FALSE)) 728. 	    if (ANGRY(shkp)) return(TRUE); 729. 	return(FALSE); 730. }  731.   732.  /* remove previously applied surcharge from all billed items */ 733. STATIC_OVL void 734. pacify_shk(shkp) 735. register struct monst *shkp; 736. {  737.  	NOTANGRY(shkp) = TRUE;	/* make peaceful */ 738. 	if (ESHK(shkp)->surcharge) { 739. 		register struct bill_x *bp = ESHK(shkp)->bill_p; 740. 		register int ct = ESHK(shkp)->billct; 741.  742.  		ESHK(shkp)->surcharge = FALSE; 743. 		while (ct-- > 0) { 744. 			register long reduction = (bp->price + 3L) / 4L; 745. 			bp->price -= reduction;		/* undo 33% increase */ 746. 			bp++; 747. 		}  748.  	}  749.  }  750.   751.  /* add aggravation surcharge to all billed items */ 752. STATIC_OVL void 753. rile_shk(shkp) 754. register struct monst *shkp; 755. {  756.  	NOTANGRY(shkp) = FALSE;	/* make angry */ 757. 	if (!ESHK(shkp)->surcharge) { 758. 		register struct bill_x *bp = ESHK(shkp)->bill_p; 759. 		register int ct = ESHK(shkp)->billct; 760.  761.  		ESHK(shkp)->surcharge = TRUE; 762. 		while (ct-- > 0) { 763. 			register long surcharge = (bp->price + 2L) / 3L; 764. 			bp->price += surcharge; 765. 			bp++; 766. 		}  767.  	}  768.  }  769.   770.  void 771. make_happy_shk(shkp, silentkops) 772. register struct monst *shkp; 773. register boolean silentkops; 774. {  775.  	boolean wasmad = ANGRY(shkp); 776. 	struct eshk *eshkp = ESHK(shkp); 777.  778.  	pacify_shk(shkp); 779. 	eshkp->following = 0; 780. 	eshkp->robbed = 0L; 781. 	if (!Role_is('R')) 782. 		adjalign(sgn(u.ualign.type)); 783. 	if(!inhishop(shkp)) { 784. 		char shk_nam[BUFSZ]; 785. 		boolean vanished = canseemon(shkp); 786.  787.  		Strcpy(shk_nam, mon_nam(shkp)); 788. 		if (on_level(&eshkp->shoplevel, &u.uz)) { 789. 			home_shk(shkp, FALSE); 790. 			/* didn't disappear if shk can still be seen */ 791. 			if (canseemon(shkp)) vanished = FALSE; 792. 		} else { 793. 			/* if sensed, does disappear regardless whether seen */ 794. 			if (sensemon(shkp)) vanished = TRUE; 795. 			/* arrive near shop's door */ 796. 			migrate_to_level(shkp, ledger_no(&eshkp->shoplevel),  797.  					 MIGR_APPROX_XY, &eshkp->shd); 798. 		}  799.  		if (vanished) 800. 		    pline("Satisfied, %s suddenly disappears!", shk_nam); 801. 	} else if(wasmad) 802. 		pline("%s calms down.", Monnam(shkp)); 803.  804.  	if(!angry_shk_exists) { 805. #ifdef KOPS 806. 		kops_gone(silentkops); 807. #endif 808. 		pacify_guards; 809. 	}  810.  }  811.   812.  void 813. hot_pursuit(shkp) 814. register struct monst *shkp; 815. {  816.  	if(!shkp->isshk) return; 817.  818.  	rile_shk(shkp); 819. 	ESHK(shkp)->following = 1; 820. }  821.   822.  /* used when the shkp is teleported out of his shop, 823.  * or when the player is not on a costly_spot and he  824. * damages something inside the shop. these conditions 825.  * must be checked by the calling function. 826.  */  827.  void 828. make_angry_shk(shkp, ox, oy) 829. register struct monst *shkp; 830. register xchar ox,oy; 831. {  832.  	xchar sx, sy; 833.  834.  	if(index(in_rooms(ox, oy, SHOPBASE), ESHK(shkp)->shoproom) &&  835.  	    !ANGRY(shkp)) { 836. 		ESHK(shkp)->robbed += (addupbill(shkp) +  837.  				       ESHK(shkp)->debit + ESHK(shkp)->loan); 838. 		ESHK(shkp)->robbed -= ESHK(shkp)->credit; 839. 		if(ESHK(shkp)->robbed < 0L) 840. 		    ESHK(shkp)->robbed = 0L; 841. 		ESHK(shkp)->credit = 0L; 842. 		setpaid(shkp); 843. 	}  844.  	/* If you just used a wand of teleportation to send the shk away, you 845. 	   might not be able to see her any more. Monnam would yield "it", 846. 	   which makes this message look pretty silly, so temporarily restore 847. 	   her original location during the call to Monnam. */ 848.  	sx = shkp->mx,  sy = shkp->my; 849. 	if (cansee(ox, oy) && !cansee(sx, sy)) 850. 		shkp->mx = ox,  shkp->my = oy; 851. 	pline("%s %s!", Monnam(shkp),  852.  	      !ANGRY(shkp) ? "gets angry" : "is furious"); 853. 	shkp->mx = sx,  shkp->my = sy; 854. 	hot_pursuit(shkp); 855. }  856.   857.  STATIC_VAR const char no_money[] = "Moreover, you%s have no money."; 858. STATIC_VAR const char not_enough_money[] = 859. 			    "Besides, you don't have enough to interest %s."; 860.  861.  #else 862. STATIC_VAR const char no_money[]; 863. STATIC_VAR const char not_enough_money[]; 864. #endif /*OVLB*/ 865.  866.  #ifdef OVL3 867.  868.  STATIC_OVL long 869. cheapest_item(shkp)   /* delivers the cheapest item on the list */ 870. register struct monst *shkp; 871. {  872.  	register int ct = ESHK(shkp)->billct; 873. 	register struct bill_x *bp = ESHK(shkp)->bill_p; 874. 	register long gmin = (bp->price * bp->bquan); 875.  876.  	while(ct--){ 877. 		if(bp->price * bp->bquan < gmin) 878. 			gmin = bp->price * bp->bquan; 879. 		bp++; 880. 	}  881.  	return(gmin); 882. }  883.  #endif /*OVL3*/ 884. #ifdef OVL0 885.  886.  int 887. dopay 888. {  889.  	register struct eshk *eshkp; 890. 	register struct monst *shkp; 891. 	struct monst *nxtm, *resident; 892. 	long ltmp; 893. 	int pass, tmp, shk_pronoun, sk = 0, seensk = 0; 894. 	boolean paid = FALSE, stashed_gold = (hidden_gold > 0L); 895.  896.  	multi = 0; 897.  898.  	/* find how many shk's there are, how many are in */ 899. 	/* sight, and are you in a shop room with one. */ 900.  	nxtm = resident = 0; 901. 	for (shkp = next_shkp(fmon, FALSE);  902.  		shkp; shkp = next_shkp(shkp->nmon, FALSE)) { 903. 	    sk++; 904. 	    if (ANGRY(shkp) && distu(shkp->mx, shkp->my) <= 2) nxtm = shkp; 905. 	    if (canspotmon(shkp)) seensk++; 906. 	    if (inhishop(shkp) && (*u.ushops == ESHK(shkp)->shoproom)) 907. 		resident = shkp; 908. 	}  909.   910.  	if (nxtm) {			/* Player should always appease an */ 911. 	     shkp = nxtm;		/* irate shk standing next to them. */ 912.  	     goto proceed; 913. 	}  914.   915.  	if ((!sk && (!Blind || Telepat)) || (!Blind && !seensk)) { 916.       pline("There appears to be no shopkeeper here to receive your payment."); 917. 		return(0); 918. 	}  919.   920.  	if(!seensk) { 921. 		You_cant("see..."); 922. 		return(0); 923. 	}  924.   925.  	/* the usual case. allow paying at a distance when */ 926. 	/* inside a tended shop. should we change that? */ 927.  	if(sk == 1 && resident) { 928. 		shkp = resident; 929. 		goto proceed; 930. 	}  931.   932.  	if (seensk == 1) { 933. 		for (shkp = next_shkp(fmon, FALSE);  934.  			shkp; shkp = next_shkp(shkp->nmon, FALSE)) 935. 		    if (canspotmon(shkp)) break; 936. 		if (shkp != resident && distu(shkp->mx, shkp->my) > 2) { 937. 		    pline("%s is not near enough to receive your payment.",  938.  					     Monnam(shkp)); 939. 		    return(0); 940. 		}  941.  	} else { 942. 		struct monst *mtmp; 943. 		coord cc; 944. 		int cx, cy; 945.  946.  		pline("Pay whom?"); 947. 		cc.x = u.ux; 948. 		cc.y = u.uy; 949. 		getpos(&cc, TRUE, "the creature you want to pay"); 950. 		cx = cc.x;  951. cy = cc.y; 952. if(cx == -10) return(0); /* player pressed esc */ 953. 		if(cx < 0) { 954. 		     pline("Try again..."); 955. 		     return(0); 956. 		}  957.  		if(u.ux == cx && u.uy == cy) { 958. 		     You("are generous to yourself."); 959. 		     return(0); 960. 		}  961.  		mtmp = m_at(cx, cy); 962. 		if(!mtmp) { 963. 		     pline("There is no one there to receive your payment."); 964. 		     return(0); 965. 		}  966.  		if(!mtmp->isshk) { 967. 		     pline("%s is not interested in your payment.",  968.  				    Monnam(mtmp)); 969. 		     return(0); 970. 		}  971.  		if (mtmp != resident && distu(mtmp->mx, mtmp->my) > 2) { 972. 		     pline("%s is too far to receive your payment.",  973.  				    Monnam(mtmp)); 974. 		     return(0); 975. 		}  976.  		shkp = mtmp; 977. 	}  978.   979.  	if(!shkp) { 980. #ifdef DEBUG 981. 		pline("dopay: null shkp."); 982. #endif 983. 		return(0); 984. 	}  985.  proceed: 986.  987.  	if (shkp->msleep || !shkp->mcanmove) { 988. 		pline("%s %s.", Monnam(shkp),  989.  		      rn2(2) ? "seems to be napping" : "doesn't respond"); 990. 		return 0; 991. 	}  992.  	eshkp = ESHK(shkp); 993. 	shk_pronoun = pronoun_gender(shkp); 994.  995.  	ltmp = eshkp->robbed; 996. 	if(shkp != resident && NOTANGRY(shkp)) { 997. 		if(!ltmp) 998. 		    You("do not owe %s anything.", mon_nam(shkp)); 999. 		else if(!u.ugold) { 1000. 		   You("%shave no money.", stashed_gold ? "seem to " : ""); 1001. 		   if(stashed_gold) 1002. 			pline("But you have some gold stashed away."); 1003. 		} else { 1004. 		   long ugold = u.ugold; 1005. 1006. 		    if(ugold > ltmp) { 1007. 			You("give %s the %ld gold piece%s %s asked for.", 1008. 			    mon_nam(shkp), ltmp, plur(ltmp), he[shk_pronoun]); 1009. 			pay(ltmp, shkp); 1010. 		   } else { 1011. 			You("give %s all your%s gold.", mon_nam(shkp), 1012. 					stashed_gold ? " openly kept" : ""); 1013. 			pay(u.ugold, shkp); 1014. 			if (stashed_gold) pline("But you have hidden gold!"); 1015. 		   }  1016. 		    if((ugold < ltmp/2L) || (ugold < ltmp && stashed_gold)) 1017. 			pline("Unfortunately, %s doesn't look satisfied.", 1018. 			      he[shk_pronoun]); 1019. 		   else 1020. 			make_happy_shk(shkp, FALSE); 1021. 		} 1022. 		return(1); 1023. 	} 1024.  1025. 	/* ltmp is still eshkp->robbed here */ 1026. 	if (!eshkp->billct && !eshkp->debit) { 1027. 		if(!ltmp && NOTANGRY(shkp)) { 1028. 		   You("do not owe %s anything.", mon_nam(shkp)); 1029. 		   if (!u.ugold) 1030. 			pline(no_money, stashed_gold ? " seem to" : ""); 1031. 		} else if(ltmp) { 1032. 		   pline("%s is after blood, not money!", Monnam(shkp)); 1033. 		   if(u.ugold < ltmp/2L ||  1034. 				(u.ugold < ltmp && stashed_gold)) { 1035. 			if (!u.ugold) 1036. 			   pline(no_money, stashed_gold ? " seem to" : ""); 1037. 			else pline(not_enough_money, him[shk_pronoun]); 1038. 			return(1); 1039. 		   }  1040. 		    pline("But since %s shop has been robbed recently,",  1041. 			  his[shk_pronoun]); 1042. 		   pline("you %scompensate %s for %s losses.",  1043. 			  (u.ugold < ltmp) ? "partially " : "",  1044. 			  mon_nam(shkp), his[shk_pronoun]); 1045. 		   pay(u.ugold < ltmp ? u.ugold : ltmp, shkp); 1046. 		   make_happy_shk(shkp, FALSE); 1047. 		} else { 1048. 		   /* shopkeeper is angry, but has not been robbed -- 1049. 		    * door broken, attacked, etc. */ 1050. 		   pline("%s is after your hide, not your money!",  1051. 			  Monnam(shkp)); 1052. 		   if(u.ugold < 1000L) { 1053. 			if (!u.ugold) 1054. 			   pline(no_money, stashed_gold ? " seem to" : ""); 1055. 			else pline(not_enough_money, him[shk_pronoun]); 1056. 			return(1); 1057. 		   }  1058. 		    You("try to appease %s by giving %s 1000 gold pieces.",  1059. 			x_monnam(shkp, 1, "angry", 0), him[shk_pronoun]); 1060. 		   pay(1000L,shkp); 1061. 		   if (strncmp(eshkp->customer, plname, PL_NSIZ) || rn2(3)) 1062. 			make_happy_shk(shkp, FALSE); 1063. 		   else 1064. 			pline("But %s is as angry as ever.", mon_nam(shkp)); 1065. 		} 1066. 		return(1); 1067. 	} 1068. 	if(shkp != resident) { 1069. 		impossible("dopay: not to shopkeeper?"); 1070. 		if(resident) setpaid(resident); 1071. 		return(0); 1072. 	} 1073. 	/* pay debt, if any, first */ 1074. 	if(eshkp->debit) { 1075. 		long dtmp = eshkp->debit; 1076. 		long loan = eshkp->loan; 1077. 		char sbuf[BUFSZ]; 1078. 1079. 		Sprintf(sbuf, "You owe %s %ld zorkmid%s ",  1080. 					   shkname(shkp), dtmp, plur(dtmp)); 1081. 		if(loan) { 1082. 		   if(loan == dtmp) 1083. 			Strcat(sbuf, "you picked up in the store."); 1084. 		   else Strcat(sbuf,  1085. 			   "for gold picked up and the use of merchandise."); 1086. 		} else Strcat(sbuf, "for the use of merchandise."); 1087. 		pline(sbuf); 1088. 		if (u.ugold + eshkp->credit < dtmp) { 1089. 		   pline("But you don't%s have enough gold%s.",  1090. 			stashed_gold ? " seem to" : "",  1091. 			eshkp->credit ? " or credit" : ""); 1092. 		   return(1); 1093. 		} else { 1094. 		   if (eshkp->credit >= dtmp) { 1095. 			eshkp->credit -= dtmp; 1096. 			eshkp->debit = 0L; 1097. 			eshkp->loan = 0L; 1098. 			Your("debt is covered by your credit."); 1099. 		   } else if (!eshkp->credit) { 1100. 			u.ugold -= dtmp; 1101. 			shkp->mgold += dtmp; 1102. 			eshkp->debit = 0L; 1103. 			eshkp->loan = 0L; 1104. 			You("pay that debt."); 1105. 			flags.botl = 1; 1106. 		   } else { 1107. 			dtmp -= eshkp->credit; 1108. 			eshkp->credit = 0L; 1109. 			u.ugold -= dtmp; 1110. 			shkp->mgold += dtmp; 1111. 			eshkp->debit = 0L; 1112. 			eshkp->loan = 0L; 1113. 			pline("That debt is partially offset by your credit."); 1114. 			You("pay the remainder."); 1115. 			flags.botl = 1; 1116. 		   }  1117. 		    paid = TRUE; 1118. 		} 1119. 	}  1120. 	/* now check items on bill */ 1121. 	if (eshkp->billct) { 1122. 	   register boolean itemize; 1123. 1124. 	    if (!u.ugold && !eshkp->credit) { 1125. 		You("%shave no money or credit%s.", 1126. 				    stashed_gold ? "seem to " : "",  1127. 				    paid ? " left" : ""); 1128. 		return(0); 1129. 	   }  1130. 	    if ((u.ugold + eshkp->credit) < cheapest_item(shkp)) { 1131. 		You("don't have enough money to buy%s the item%s you picked.", 1132. 		    eshkp->billct > 1 ? " any of" : "", plur(eshkp->billct)); 1133. 		if(stashed_gold) 1134. 		   pline("Maybe you have some gold stashed away?"); 1135. 		return(0); 1136. 	   }  1137.  1138. 	    /* this isn't quite right; it itemizes without asking if the 1139. 	    * single item on the bill is partly used up and partly unpaid */ 1140. 	   itemize = (eshkp->billct > 1 ? yn("Itemized billing?") == 'y' : 1); 1141. 1142. 	    for (pass = 0; pass <= 1; pass++) { 1143. 		tmp = 0; 1144. 		while (tmp < eshkp->billct) { 1145. 		   struct obj *otmp; 1146. 		   register struct bill_x *bp = &(eshkp->bill_p[tmp]); 1147. 1148. 		    /* find the object on one of the lists */ 1149. 		   if ((otmp = bp_to_obj(bp)) != 0) { 1150. 			/* if completely used up, object quantity is stale; 1151. 			  restoring it to its original value here avoids 1152. 			  making the partly-used-up code more complicated */ 1153. 			if (bp->useup) otmp->quan = bp->bquan; 1154. 		   } else { 1155. 			impossible("Shopkeeper administration out of order."); 1156. 			setpaid(shkp);	/* be nice to the player */ 1157. 			return 1; 1158. 		   }  1159. 		    if (pass == bp->useup && otmp->quan == bp->bquan) { 1160. 			/* pay for used-up items on first pass and others 1161. 			 * on second, so player will be stuck in the store 1162. 			 * less often; things which are partly used up 1163. * are processed on both passes */ 1164. 			tmp++; 1165. 		   } else { 1166. 			switch (dopayobj(shkp, bp, &otmp, pass, itemize)) { 1167. 			 case PAY_CANT: 1168. 				return 1;	/*break*/ 1169. 			 case PAY_BROKE: 1170. 				paid = TRUE; 1171. 				goto thanks;	/*break*/ 1172. 			 case PAY_SKIP: 1173. 				tmp++; 1174. 				continue;	/*break*/ 1175. 			 case PAY_SOME: 1176. 				paid = TRUE; 1177. 				if (itemize) bot; 1178. 				continue;	/*break*/ 1179. 			 case PAY_BUY: 1180. 				paid = TRUE; 1181. 				break; 1182. 			} 1183. 			if (itemize) bot; 1184. 			*bp = eshkp->bill_p[--eshkp->billct]; 1185. 		   }  1186. 		}  1187. 	    }  1188. 	}  1189. thanks: 1190. 	if(!ANGRY(shkp) && paid) 1191. 	   verbalize("Thank you for shopping in %s %s!",  1192. 		s_suffix(shkname(shkp)),  1193. 		shtypes[eshkp->shoptype - SHOPBASE].name); 1194. 	return(1); 1195. } 1196. #endif /*OVL0*/ 1197. #ifdef OVL3 1198. 1199. /* return 2 if used-up portion paid */ 1200. /*	 1 if paid successfully    */ 1201. /*	 0 if not enough money     */ 1202. /*	 -1 if skip this object    */ 1203. /*	 -2 if no money/credit left */ 1204. STATIC_OVL int 1205. dopayobj(shkp, bp, obj_p, which, itemize) 1206. register struct monst *shkp; 1207. register struct bill_x *bp; 1208. struct obj **obj_p; 1209. int	which;		/* 0 => used-up item, 1 => other (unpaid or lost) */ 1210. boolean itemize; 1211. { 1212. 	register struct obj *obj = *obj_p; 1213. 	long ltmp, quan, save_quan; 1214. 	int buy; 1215. 	boolean stashed_gold = (hidden_gold > 0L), 1216. 		consumed = (which == 0); 1217. 1218. 	if(!obj->unpaid && !bp->useup){ 1219. 		impossible("Paid object on bill??"); 1220. 		return PAY_BUY; 1221. 	} 1222. 	if(itemize && u.ugold + ESHK(shkp)->credit == 0L){ 1223. 		You("%shave no money or credit left.", 1224. 			     stashed_gold ? "seem to " : ""); 1225. 		return PAY_BROKE; 1226. 	} 1227. 	/* we may need to temporarily adjust the object, if part of the 1228. 	  original quantity has been used up but part remains unpaid  */ 1229. 	save_quan = obj->quan; 1230. 	if (consumed) { 1231. 	   /* either completely used up (simple), or split needed */ 1232. 	   quan = bp->bquan; 1233. 	   if (quan > obj->quan)	/* difference is amount used up */ 1234. 		quan -= obj->quan; 1235. 	} else { 1236. 	   /* dealing with ordinary unpaid item */ 1237. 	   quan = obj->quan; 1238. 	} 1239. 	obj->quan = quan;	/* to be used by doname */ 1240. 	obj->unpaid = 0;	/* ditto */ 1241. 	ltmp = bp->price * quan; 1242. 	buy = PAY_BUY;		/* flag; if changed then return early */ 1243. 1244. 	if (itemize) { 1245. 	   char qbuf[BUFSZ]; 1246. 	   Sprintf(qbuf,"%s for %ld zorkmid%s.  Pay?", quan == 1L ?  1247. 		    Doname2(obj) : doname(obj), ltmp, plur(ltmp)); 1248. 	   if (yn(qbuf) == 'n') { 1249. 		buy = PAY_SKIP;		/* don't want to buy */ 1250. 	   } else if (quan < bp->bquan && !consumed) { /* partly used goods */ 1251. 		obj->quan = bp->bquan - save_quan;	/* used up amount */ 1252. 		verbalize("%s for the other %s before buying %s.", 1253. 			  ANGRY(shkp) ? "Pay" : "Please pay", xname(obj),  1254. 			  save_quan > 1L ? "these" : "this one"); 1255. 		buy = PAY_SKIP;		/* shk won't sell */ 1256. 	   }  1257. 	}  1258. 	if (buy == PAY_BUY && u.ugold + ESHK(shkp)->credit < ltmp) { 1259. 	   You("don't%s have gold%s enough to pay for %s.",  1260. 		stashed_gold ? " seem to" : "",  1261. 		(ESHK(shkp)->credit > 0L) ? " or credit" : "",  1262. 		doname(obj)); 1263. 	   buy = itemize ? PAY_SKIP : PAY_CANT; 1264. 	} 1265.  1266. 	if (buy != PAY_BUY) { 1267. 	   /* restore unpaid object to original state */ 1268. 	   obj->quan = save_quan; 1269. 	   obj->unpaid = 1; 1270. 	   return buy; 1271. 	} 1272.  1273. 	pay(ltmp, shkp); 1274. 	shk_names_obj(shkp, obj, "bought %s for %ld gold piece%s.%s", ltmp, ""); 1275. 	obj->quan = save_quan;		/* restore original count */ 1276. 	/* quan => amount just bought, save_quan => remaining unpaid count */ 1277. 	if (consumed) { 1278. 	   if (quan != bp->bquan) { 1279. 		/* eliminate used-up portion; remainder is still unpaid */ 1280. 		bp->bquan = obj->quan; 1281. 		obj->unpaid = 1; 1282. 		bp->useup = 0; 1283. 		buy = PAY_SOME; 1284. 	   } else {	/* completely used-up, so get rid of it */ 1285. 		obj_extract_self(obj); 1286. 	    /* assert( obj == *obj_p ); */ 1287. 		dealloc_obj(obj); 1288. 		*obj_p = 0;	/* destroy pointer to freed object */ 1289. 	   }  1290. 	}  1291. 	return buy; 1292. } 1293. #endif /*OVL3*/ 1294. #ifdef OVLB 1295. 1296. static coord repo_location;	/* repossession context */ 1297. 1298. /* routine called after dying (or quitting) */ 1299. boolean 1300. paybill(croaked) 1301. register boolean croaked; 1302. { 1303. 	register struct monst *mtmp, *mtmp2, *resident= (struct monst *)0; 1304. 	register boolean taken = FALSE; 1305. 	register int numsk = 0; 1306. 1307. 	/* this is where inventory will end up if any shk takes it */ 1308. 	repo_location.x = repo_location.y = 0; 1309. 1310. 	/* give shopkeeper first crack */ 1311. 	if ((mtmp = shop_keeper(*u.ushops)) && inhishop(mtmp)) { 1312. 	   numsk++; 1313. 	   resident = mtmp; 1314. 	   taken = inherits(resident, numsk, croaked); 1315. 	} 1316. 	for (mtmp = next_shkp(fmon, FALSE);  1317. 		mtmp; mtmp = next_shkp(mtmp2, FALSE)) { 1318. 	   mtmp2 = mtmp->nmon; 1319. 	   if (mtmp != resident) { 1320. 		/* for bones: we don't want a shopless shk around */ 1321. 		if(!on_level(&(ESHK(mtmp)->shoplevel), &u.uz)) 1322. 			mongone(mtmp); 1323. 		else { 1324. 		   numsk++; 1325. 		   taken |= inherits(mtmp, numsk, croaked); 1326. 		} 1327. 	    }  1328. 	}  1329. 	if(numsk == 0) return(FALSE); 1330. 	return(taken); 1331. } 1332.  1333. STATIC_OVL boolean 1334. inherits(shkp, numsk, croaked) 1335. struct monst *shkp; 1336. int numsk; 1337. boolean croaked; 1338. { 1339. 	long loss = 0L; 1340. 	struct eshk *eshkp = ESHK(shkp); 1341. 	boolean take = FALSE, taken = FALSE; 1342. 	int roomno = *u.ushops; 1343. 1344. 	/* the simplifying principle is that first-come */ 1345. 	/* already took everything you had. */ 1346. 	if(numsk > 1) { 1347. 	   if(cansee(shkp->mx, shkp->my) && croaked) 1348. 		pline("%s %slooks at your corpse%s%s", Monnam(shkp), 1349. 		     (shkp->msleep || !shkp->mcanmove) ?  1350. 				   "wakes up, " : "",  1351. 		     !rn2(2) ? (shkp->female ? ", shakes her head," : 1352. 				 ", shakes his head,") : "", 1353. 		     !inhishop(shkp) ? " and disappears. " : " and sighs."); 1354. 	   taken = (roomno == eshkp->shoproom); 1355. 	   goto skip; 1356. 	} 1357.  1358. 	/* get one case out of the way: you die in the shop, the */ 1359. 	/* shopkeeper is peaceful, nothing stolen, nothing owed. */ 1360. 	if(roomno == eshkp->shoproom && inhishop(shkp) &&  1361. 	    !eshkp->billct && !eshkp->robbed && !eshkp->debit &&  1362. 	     NOTANGRY(shkp) && !eshkp->following) { 1363. 		if (invent) 1364. 			pline("%s gratefully inherits all your possessions.", 1365. 				shkname(shkp)); 1366. 		set_repo_loc(eshkp); 1367. 		goto clear; 1368. 	} 1369.  1370. 	if (eshkp->billct || eshkp->debit || eshkp->robbed) { 1371. 		register long total = 0L; 1372. 1373. 		if(roomno == eshkp->shoproom && inhishop(shkp)) 1374. 		   total = (addupbill(shkp) + eshkp->debit); 1375. 		loss = ((total >= eshkp->robbed) ? total : eshkp->robbed); 1376. 		take = TRUE; 1377. 	} 1378.  1379. 	if (eshkp->following || ANGRY(shkp) || take) { 1380. 		if(!invent && !u.ugold) goto skip; 1381. 1382. 		if ((loss > u.ugold) || !loss || roomno == eshkp->shoproom) { 1383. 			pline("%s %s%stakes all your possessions.", 1384. 				shkname(shkp),  1385. 				(shkp->msleep || !shkp->mcanmove) ?  1386. 				   "wakes up and " : "",  1387. 				(distu(shkp->mx, shkp->my) > 2) ?  1388. 				    "comes and " : ""); 1389. 			taken = TRUE; 1390. 			shkp->mgold += u.ugold; 1391. 			u.ugold = 0L; 1392. 			set_repo_loc(eshkp); 1393. 		} else { 1394. 			u.ugold -= loss; 1395. 			shkp->mgold += loss; 1396. 			pline("%s %sand takes %ld zorkmid%s %sowed %s.", 1397. 			      Monnam(shkp),  1398. 			      (shkp->msleep || !shkp->mcanmove) ?  1399. 					"wakes up " : "comes ",  1400. 			      loss, plur(loss),  1401. 			      strncmp(eshkp->customer, 1402. 					  plname, PL_NSIZ) ? "" : "you ",  1403. 			      shkp->female ? "her" : "him"); 1404. 		} 1405. skip: 1406. 		/* in case we create bones */ 1407. 		shkp->msleep = 0; 1408. 		if(!inhishop(shkp)) 1409. 			home_shk(shkp, FALSE); 1410. 	} 1411. clear: 1412. 	setpaid(shkp); 1413. 	return(taken); 1414. } 1415.  1416. STATIC_OVL void 1417. set_repo_loc(eshkp) 1418. struct eshk *eshkp; 1419. { 1420. 	register xchar ox, oy; 1421. 1422. 	/* if you're not in this shk's shop room, or if you're in its doorway 1423. 	   or entry spot, then your gear gets dumped all the way inside */ 1424. 	if (*u.ushops != eshkp->shoproom || 1425. 		IS_DOOR(levl[u.ux][u.uy].typ) ||  1426. 		(u.ux == eshkp->shk.x && u.uy == eshkp->shk.y)) { 1427. 	   /* shk.x,shk.y is the position immediately in  1428. * front of the door -- move in one more space 1429. 	    */  1430. 	    ox = eshkp->shk.x;  1431. oy = eshkp->shk.y; 1432. ox += sgn(ox - eshkp->shd.x); 1433. 	   oy += sgn(oy - eshkp->shd.y); 1434. 	} else {		/* already inside this shk's shop */ 1435. 	   ox = u.ux; 1436. 	   oy = u.uy; 1437. 	} 1438. 	/* finish_paybill will deposit invent here */ 1439. 	repo_location.x = ox; 1440. 	repo_location.y = oy; 1441. } 1442.  1443. /* called at game exit, after inventory disclosure but before making bones */ 1444. void finish_paybill 1445. { 1446. 	register struct obj *otmp; 1447. 	int ox = repo_location.x, 1448. oy = repo_location.y; 1449. 1450. #if 0		/* don't bother */ 1451. 	if (ox == 0 && oy == 0) impossible("finish_paybill: no location"); 1452. #endif 1453. 	/* transfer all of the character's inventory to the shop floor */ 1454. 	while ((otmp = invent) != 0) { 1455. 	   otmp->owornmask = 0L;	/* perhaps we should call setnotworn? */ 1456. 	    otmp->lamplit = 0;		/* avoid "goes out" msg from freeinv */ 1457. 	   if (rn2(5)) curse(otmp);	/* normal bones treatment for invent */ 1458. 	   obj_extract_self(otmp); 1459. 	   place_object(otmp, ox, oy); 1460. 	} 1461. }  1462.  1463. /* find obj on one of the lists */ 1464. STATIC_OVL struct obj * 1465. bp_to_obj(bp) 1466. register struct bill_x *bp; 1467. { 1468. 	register struct obj *obj; 1469. 	register unsigned int id = bp->bo_id; 1470. 1471. 	if(bp->useup) 1472. 		obj = o_on(id, billobjs); 1473. 	else 1474. 		obj = find_oid(id); 1475. 	return obj; 1476. } 1477.  1478. /*  1479.  * Look for o_id on all lists but billobj. Return obj or NULL if not found. 1480. * Its OK for restore_timers to call this function, there should not 1481. * be any timeouts on the billobjs chain. 1482. */  1483. struct obj * 1484. find_oid(id) 1485. unsigned id; 1486. { 1487. 	struct obj *obj; 1488. 	struct monst *mon, *mmtmp[3]; 1489. 	int i; 1490. 1491. 	/* first check various obj lists directly */ 1492. 	if ((obj = o_on(id, invent)) != 0) return obj; 1493. 	if ((obj = o_on(id, fobj)) != 0) return obj; 1494. 	if ((obj = o_on(id, level.buriedobjlist)) != 0) return obj; 1495. 	if ((obj = o_on(id, migrating_objs)) != 0) return obj; 1496. 1497. 	/* not found yet; check inventory for members of various monst lists */ 1498. 	mmtmp[0] = fmon; 1499. 	mmtmp[1] = migrating_mons; 1500. 	mmtmp[2] = mydogs;		/* for use during level changes */ 1501. 	for (i = 0; i < 3; i++) 1502. 	   for (mon = mmtmp[i]; mon; mon = mon->nmon) 1503. 		if ((obj = o_on(id, mon->minvent)) != 0) return obj; 1504. 1505. 	/* not found at all */ 1506. 	return (struct obj *)0; 1507. } 1508. #endif /*OVLB*/ 1509. #ifdef OVL3 1510. 1511. /* calculate the value that the shk will charge for [one of] an object */ 1512. STATIC_OVL long 1513. get_cost(obj, shkp) 1514. register struct obj *obj; 1515. register struct monst *shkp;	/* if angry, impose a surcharge */ 1516. { 1517. 	register long tmp = getprice(obj, FALSE); 1518. 1519. 	if (!tmp) tmp = 5L; 1520. 	/* shopkeeper may notice if the player isn't very knowledgeable - 1521. 	  especially when gem prices are concerned */ 1522. 	if (!obj->dknown || !objects[obj->otyp].oc_name_known) { 1523. 		if (obj->oclass == GEM_CLASS) { 1524. 			/* all gems are priced high - real or not */ 1525. 			if (objects[obj->otyp].oc_material == GLASS) { 1526. 			   int i = obj->otyp - LUCKSTONE + JADE + 1; 1527. 			   /* real gem's cost (worthless gems come  1528. 			       after jade but before luckstone) */ 1529. 			   tmp = (long) objects[i].oc_cost; 1530. 			} 1531. 		} else if (!(obj->o_id % 4)) /* arbitrarily impose surcharge */ 1532. 			tmp += tmp / 3L; 1533. 	} 1534. #ifdef TOURIST 1535. 	if ((Role_is('T') && u.ulevel < (MAXULEV/2)) 1536. 	    || (uarmu && !uarm && !uarmc))	/* touristy shirt visible */ 1537. 		tmp += tmp / 3L; 1538. 	else 1539. #endif 1540. 	if (uarmh && uarmh->otyp == DUNCE_CAP) 1541. 		tmp += tmp / 3L; 1542. 1543. 	if (ACURR(A_CHA) > 18)		tmp /= 2L; 1544. 	else if (ACURR(A_CHA) > 17)	tmp -= tmp / 3L; 1545. 	else if (ACURR(A_CHA) > 15)	tmp -= tmp / 4L; 1546. 	else if (ACURR(A_CHA) < 6)	tmp *= 2L; 1547. 	else if (ACURR(A_CHA) < 8)	tmp += tmp / 2L; 1548. 	else if (ACURR(A_CHA) < 11)	tmp += tmp / 3L; 1549. 	if (tmp <= 0L) tmp = 1L; 1550. 	else if (obj->oartifact) tmp *= 4L; 1551. 	/* anger surcharge should match rile_shk's */ 1552. 	if (shkp && ESHK(shkp)->surcharge) tmp += (tmp + 2L) / 3L; 1553. 	return tmp; 1554. } 1555. #endif /*OVL3*/ 1556. #ifdef OVLB 1557. 1558. /* returns the price of a container's content. the price 1559. * of the "top" container is added in the calling functions. 1560. * a different price quoted for selling as vs. buying. 1561. */  1562. long 1563. contained_cost(obj, shkp, price, usell) 1564. register struct obj *obj; 1565. register struct monst *shkp; 1566. long price; 1567. register boolean usell; 1568. { 1569. 	register struct obj *otmp; 1570. 1571. 	/* the price of contained objects */ 1572. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { 1573. 	   if (otmp->oclass == GOLD_CLASS) continue; 1574. 	   /* the "top" container is evaluated by caller */ 1575. 	   if (usell) { 1576. 		if (saleable(shkp, otmp) && 1577. 			!otmp->unpaid && otmp->oclass != BALL_CLASS &&  1578. 			!(otmp->oclass == FOOD_CLASS && otmp->oeaten) &&  1579. 			!(Is_candle(otmp) && otmp->age < 1580. 				20L * (long)objects[otmp->otyp].oc_cost)) 1581. 		   price += set_cost(otmp, shkp); 1582. 	   } else if (!otmp->no_charge) { 1583. 		   price += get_cost(otmp, shkp) * otmp->quan; 1584. 	   }  1585.  1586. 	    if (Has_contents(otmp)) 1587. 		   price += contained_cost(otmp, shkp, price, usell); 1588. 	} 1589.  1590. 	return(price); 1591. } 1592.  1593. long 1594. contained_gold(obj) 1595. register struct obj *obj; 1596. { 1597. 	register struct obj *otmp; 1598. 	register long value = 0L; 1599. 1600. 	/* accumulate contained gold */ 1601. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) 1602. 	   if (otmp->oclass == GOLD_CLASS) 1603. 		value += otmp->quan; 1604. 	   else if (Has_contents(otmp)) 1605. 		value += contained_gold(otmp); 1606. 1607. 	return(value); 1608. } 1609.  1610. STATIC_OVL void 1611. dropped_container(obj, shkp, sale) 1612. register struct obj *obj; 1613. register struct monst *shkp; 1614. register boolean sale; 1615. { 1616. 	register struct obj *otmp; 1617. 1618. 	/* the "top" container is treated in the calling fn */ 1619. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { 1620. 	   if (otmp->oclass == GOLD_CLASS) continue; 1621. 1622. 	    if (!otmp->unpaid && !(sale && saleable(shkp, otmp))) 1623. 		otmp->no_charge = 1; 1624. 1625. 	    if (Has_contents(otmp)) 1626. 		dropped_container(otmp, shkp, sale); 1627. 	} 1628. }  1629.  1630. void 1631. picked_container(obj) 1632. register struct obj *obj; 1633. { 1634. 	register struct obj *otmp; 1635. 1636. 	/* the "top" container is treated in the calling fn */ 1637. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { 1638. 	   if (otmp->oclass == GOLD_CLASS) continue; 1639. 1640. 	    if (otmp->no_charge) 1641. 		otmp->no_charge = 0; 1642. 1643. 	    if (Has_contents(otmp)) 1644. 		picked_container(otmp); 1645. 	} 1646. }  1647. #endif /*OVLB*/ 1648. #ifdef OVL3 1649. 1650. /* calculate how much the shk will pay when buying [all of] an object */ 1651. STATIC_OVL long 1652. set_cost(obj, shkp) 1653. register struct obj *obj; 1654. register struct monst *shkp; 1655. { 1656. 	long tmp = getprice(obj, TRUE) * obj->quan; 1657. 1658. #ifdef TOURIST 1659. 	if ((Role_is('T') && u.ulevel < (MAXULEV/2)) 1660. 	    || (uarmu && !uarm && !uarmc))	/* touristy shirt visible */ 1661. 		tmp /= 3L; 1662. 	else 1663. #endif 1664. 	if (uarmh && uarmh->otyp == DUNCE_CAP) 1665. 		tmp /= 3L; 1666. 	else 1667. 		tmp /= 2L; 1668. 1669. 	/* shopkeeper may notice if the player isn't very knowledgeable - 1670. 	  especially when gem prices are concerned */ 1671. 	if (!obj->dknown || !objects[obj->otyp].oc_name_known) { 1672. 		if (obj->oclass == GEM_CLASS) { 1673. 			/* different shop keepers give different prices */ 1674. 			if (objects[obj->otyp].oc_material == GEMSTONE || 1675. 			    objects[obj->otyp].oc_material == GLASS) { 1676. 				tmp = (obj->otyp % (6 - shkp->m_id % 3)); 1677. 				tmp = (tmp + 3) * obj->quan; 1678. 			} 1679. 		} else if (tmp > 1L && !rn2(4)) 1680. 			tmp -= tmp / 4L; 1681. 	} 1682. 	return tmp; 1683. } 1684.  1685. #endif /*OVL3*/ 1686. #ifdef OVLB 1687. 1688. /* called from doinv(invent.c) for inventory of unpaid objects */ 1689. long 1690. unpaid_cost(unp_obj) 1691. register struct obj *unp_obj;	/* known to be unpaid */ 1692. { 1693. 	register struct bill_x *bp = (struct bill_x *)0; 1694. 	register struct monst *shkp; 1695. 1696. 	for(shkp = next_shkp(fmon, TRUE); shkp;  1697. 					shkp = next_shkp(shkp->nmon, TRUE)) 1698. 	   if ((bp = onbill(unp_obj, shkp, TRUE)) != 0) break; 1699. 1700. 	/* onbill gave no message if unexpected problem occurred */ 1701. 	if(!bp) impossible("unpaid_cost: object wasn't on any bill!"); 1702. 1703. 	return bp ? unp_obj->quan * bp->price : 0L; 1704. } 1705.  1706. STATIC_OVL void 1707. add_one_tobill(obj, dummy) 1708. register struct obj *obj; 1709. register boolean dummy; 1710. { 1711. 	register struct monst *shkp; 1712. 	register struct bill_x *bp; 1713. 	register int bct; 1714. 	register char roomno = *u.ushops; 1715. 1716. 	if (!roomno) return; 1717. 	if (!(shkp = shop_keeper(roomno))) return; 1718. 	if (!inhishop(shkp)) return; 1719. 1720. 	if (onbill(obj, shkp, FALSE) || /* perhaps thrown away earlier */  1721. 		    (obj->oclass == FOOD_CLASS && obj->oeaten)) 1722. 		return; 1723. 1724. 	if (ESHK(shkp)->billct == BILLSZ) { 1725. 		You("got that for free!"); 1726. 		return; 1727. 	} 1728.  1729. 	/* To recognize objects the shopkeeper is not interested in. -dgk 1730. 	 */ 1731. 	if (obj->no_charge) { 1732. 		obj->no_charge = 0; 1733. 		return; 1734. 	} 1735.  1736. 	bct = ESHK(shkp)->billct; 1737. 	bp = &(ESHK(shkp)->bill_p[bct]); 1738. 	bp->bo_id = obj->o_id; 1739. 	bp->bquan = obj->quan; 1740. 	if(dummy) {		 /* a dummy object must be inserted into  */ 1741. 	   bp->useup = 1;	  /* the billobjs chain here. crucial for */ 1742. 	   add_to_billobjs(obj); /* eating floorfood in shop. see eat.c */ 1743. 	} else	bp->useup = 0; 1744. 	bp->price = get_cost(obj, shkp); 1745. 	ESHK(shkp)->billct++; 1746. 	obj->unpaid = 1; 1747. } 1748.  1749. STATIC_OVL void 1750. add_to_billobjs(obj) 1751.    struct obj *obj; 1752. { 1753.     if (obj->where != OBJ_FREE) 1754. 	panic("add_to_billobjs: obj not free"); 1755.    if (obj->timed) 1756. 	panic("add_to_billobjs: obj is timed"); 1757. 1758.     obj->nobj = billobjs; 1759.    billobjs = obj; 1760.    obj->where = OBJ_ONBILL; 1761. } 1762.  1763. /* recursive billing of objects within containers. */ 1764. STATIC_OVL void 1765. bill_box_content(obj, ininv, dummy, shkp) 1766. register struct obj *obj; 1767. register boolean ininv, dummy; 1768. register struct monst *shkp; 1769. { 1770. 	register struct obj *otmp; 1771. 1772. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { 1773. 		if (otmp->oclass == GOLD_CLASS) continue; 1774. 1775. 		/* the "top" box is added in addtobill */ 1776. 		if (!otmp->no_charge) 1777. 		   add_one_tobill(otmp, dummy); 1778. 		if (Has_contents(otmp)) 1779. 		   bill_box_content(otmp, ininv, dummy, shkp); 1780. 	} 1781.  1782. }  1783.  1784. /* shopkeeper tells you what you bought or sold, sometimes partly IDing it */ 1785. STATIC_OVL void 1786. shk_names_obj(shkp, obj, fmt, amt, arg) 1787. struct monst *shkp; 1788. struct obj *obj; 1789. const char *fmt;	/* "%s %ld %s %s", doname(obj), amt, plur(amt), arg */ 1790. long amt; 1791. const char *arg; 1792. { 1793. 	char *obj_name, fmtbuf[BUFSZ]; 1794. 	boolean was_unknown = !obj->dknown; 1795. 1796. 	obj->dknown = TRUE; 1797. 	/* Use real name for ordinary weapons/armor, and spell-less 1798. 	 * scrolls/books (that is, blank and mail), but only if the 1799. 	 * object is within the shk's area of interest/expertise. 1800. 	 */ 1801. 	if (!objects[obj->otyp].oc_magic && saleable(shkp, obj) &&  1802. 	    (obj->oclass == WEAPON_CLASS || obj->oclass == ARMOR_CLASS || 1803. 	    obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS || 1804. 	    obj->otyp == MIRROR)) { 1805. 	   was_unknown |= !objects[obj->otyp].oc_name_known; 1806. 	   makeknown(obj->otyp); 1807. 	} 1808. 	obj_name = doname(obj); 1809. 	/* Use an alternate message when extra information is being provided */ 1810. 	if (was_unknown) { 1811. 	   Sprintf(fmtbuf, "%%s; you %s", fmt); 1812. 	   obj_name[0] = highc(obj_name[0]); 1813. 	   pline(fmtbuf, obj_name, (obj->quan > 1) ? "them" : "it",  1814. 		  amt, plur(amt), arg); 1815. 	} else { 1816. 	   You(fmt, obj_name, amt, plur(amt), arg); 1817. 	} 1818. }  1819.  1820. void 1821. addtobill(obj, ininv, dummy, silent) 1822. register struct obj *obj; 1823. register boolean ininv, dummy, silent; 1824. { 1825. 	register struct monst *shkp; 1826. 	register char roomno = *u.ushops; 1827. 	long ltmp = 0L, cltmp = 0L, gltmp = 0L; 1828. 	register boolean container = Has_contents(obj); 1829. 1830. 	if(!*u.ushops) return; 1831. 1832. 	if(!(shkp = shop_keeper(roomno))) return; 1833. 1834. 	if(!inhishop(shkp)) return; 1835. 1836. 	if(/* perhaps we threw it away earlier */  1837. 		 onbill(obj, shkp, FALSE) ||  1838. 		 (obj->oclass == FOOD_CLASS && obj->oeaten)  1839. 	      ) return; 1840. 1841. 	if(ESHK(shkp)->billct == BILLSZ) { 1842. 		You("got that for free!"); 1843. 		return; 1844. 	} 1845.  1846. 	if(obj->oclass == GOLD_CLASS) { 1847. 		costly_gold(obj->ox, obj->oy, obj->quan); 1848. 		return; 1849. 	} 1850.  1851. 	if(!obj->no_charge) 1852. 	   ltmp = get_cost(obj, shkp); 1853. 1854. 	if (obj->no_charge && !container) { 1855. 		obj->no_charge = 0; 1856. 		return; 1857. 	} 1858.  1859. 	if(container) { 1860. 	   if(obj->cobj == (struct obj *)0) { 1861. 		if(obj->no_charge) { 1862. 		   obj->no_charge = 0; 1863. 		   return; 1864. 		} else { 1865. 		   add_one_tobill(obj, dummy); 1866. 		   goto speak; 1867. 		} 1868. 	    } else { 1869. 		cltmp += contained_cost(obj, shkp, cltmp, FALSE); 1870. 		gltmp += contained_gold(obj); 1871. 	   }  1872.  1873. 	    if(ltmp) add_one_tobill(obj, dummy); 1874. 	   if(cltmp) bill_box_content(obj, ininv, dummy, shkp); 1875. 	   picked_container(obj); /* reset contained obj->no_charge */ 1876. 1877. 	    ltmp += cltmp; 1878. 1879. 	    if(gltmp) { 1880. 		costly_gold(obj->ox, obj->oy, gltmp); 1881. 		if(!ltmp) return; 1882. 	   }  1883.  1884. 	    if(obj->no_charge) 1885. 		obj->no_charge = 0; 1886. 1887. 	} else /* i.e., !container */ 1888. 	   add_one_tobill(obj, dummy); 1889. speak: 1890. 	if (shkp->mcanmove && !shkp->msleep && !silent) { 1891. 	   char buf[BUFSZ]; 1892. 1893. 	    if(!ltmp) { 1894. 		pline("%s has no interest in %s.", Monnam(shkp), 1895. 					     the(xname(obj))); 1896. 		return; 1897. 	   }  1898. 	    Strcpy(buf, "\"For you, ");  1899. 	    if (ANGRY(shkp)) Strcat(buf, "scum ");  1900. 	    else {  1901. 		static const char *honored[5] = {  1902. 		  "good", "honored", "most gracious", "esteemed",  1903. 		  "most renowned and sacred"  1904. 		};  1905. 		Strcat(buf, honored[rn2(4) + u.uevent.udemigod]);  1906. 		if (!is_human(uasmon)) Strcat(buf, " creature");  1907. 		else  1908. 		    Strcat(buf, (flags.female) ? " lady" : " sir");  1909. 	    }  1910. 	    if(ininv) {  1911. 		long quan = obj->quan;  1912. 		obj->quan = 1L; /* fool xname into giving singular */  1913. 		pline("%s; only %ld %s %s.\"", buf, ltmp,  1914. 			(quan > 1L) ? "per" : "for this", xname(obj)); 1915. 		obj->quan = quan; 1916. 	   } else 1917. 		pline("%s will cost you %ld zorkmid%s%s.", 1918. 			The(xname(obj)), ltmp, plur(ltmp),  1919. 			(obj->quan > 1L) ? " each" : ""); 1920. 	} else if(!silent) { 1921. 	   if(ltmp) pline_The("list price of %s is %ld zorkmid%s%s.",  1922. 				   the(xname(obj)), ltmp, plur(ltmp),  1923. 				   (obj->quan > 1L) ? " each" : ""); 1924. 	   else pline("%s does not notice.", Monnam(shkp)); 1925. 	} 1926. }  1927.  1928. void 1929. splitbill(obj, otmp) 1930. register struct obj *obj, *otmp; 1931. { 1932. 	/* otmp has been split off from obj */ 1933. 	register struct bill_x *bp; 1934. 	register long tmp; 1935. 	register struct monst *shkp = shop_keeper(*u.ushops); 1936. 1937. 	if(!shkp || !inhishop(shkp)) { 1938. 		impossible("splitbill: no resident shopkeeper??"); 1939. 		return; 1940. 	} 1941. 	bp = onbill(obj, shkp, FALSE); 1942. 	if(!bp) { 1943. 		impossible("splitbill: not on bill?"); 1944. 		return; 1945. 	} 1946. 	if(bp->bquan < otmp->quan) { 1947. 		impossible("Negative quantity on bill??"); 1948. 	} 1949. 	if(bp->bquan == otmp->quan) { 1950. 		impossible("Zero quantity on bill??"); 1951. 	} 1952. 	bp->bquan -= otmp->quan; 1953. 1954. 	if(ESHK(shkp)->billct == BILLSZ) otmp->unpaid = 0; 1955. 	else { 1956. 		tmp = bp->price; 1957. 		bp = &(ESHK(shkp)->bill_p[ESHK(shkp)->billct]); 1958. 		bp->bo_id = otmp->o_id; 1959. 		bp->bquan = otmp->quan; 1960. 		bp->useup = 0; 1961. 		bp->price = tmp; 1962. 		ESHK(shkp)->billct++; 1963. 	} 1964. }  1965.  1966. STATIC_OVL void 1967. sub_one_frombill(obj, shkp) 1968. register struct obj *obj; 1969. register struct monst *shkp; 1970. { 1971. 	register struct bill_x *bp; 1972. 1973. 	if((bp = onbill(obj, shkp, FALSE)) != 0) { 1974. 		register struct obj *otmp; 1975. 1976. 		obj->unpaid = 0; 1977. 		if(bp->bquan > obj->quan){ 1978. 			otmp = newobj(0); 1979. 			*otmp = *obj; 1980. 			bp->bo_id = otmp->o_id = flags.ident++; 1981. 			otmp->where = OBJ_FREE; 1982. 			otmp->quan = (bp->bquan -= obj->quan); 1983. 			otmp->owt = 0;	/* superfluous */ 1984. 			otmp->onamelth = 0; 1985. 			bp->useup = 1; 1986. 			add_to_billobjs(otmp); 1987. 			return; 1988. 		} 1989. 		ESHK(shkp)->billct--; 1990. #ifdef DUMB 1991. 		{ 1992. 		/* DRS/NS 2.2.6 messes up -- Peter Kendell */ 1993. 			int indx = ESHK(shkp)->billct; 1994. 			*bp = ESHK(shkp)->bill_p[indx]; 1995. 		} 1996. #else 1997. 		*bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct]; 1998. #endif 1999. 		return; 2000. 	} else if (obj->unpaid) { 2001. 		impossible("sub_one_frombill: unpaid object not on bill"); 2002. 		obj->unpaid = 0; 2003. 	} 2004. }  2005.  2006. /* recursive check of unpaid objects within nested containers. */ 2007. void 2008. subfrombill(obj, shkp) 2009. register struct obj *obj; 2010. register struct monst *shkp; 2011. { 2012. 	register struct obj *otmp; 2013. 2014. 	sub_one_frombill(obj, shkp); 2015. 2016. 	if (Has_contents(obj)) 2017. 	   for(otmp = obj->cobj; otmp; otmp = otmp->nobj) { 2018. 		if(otmp->oclass == GOLD_CLASS) continue; 2019. 2020. 		if (Has_contents(otmp)) 2021. 		   subfrombill(otmp, shkp); 2022. 		else 2023. 		   sub_one_frombill(otmp, shkp); 2024. 	   }  2025. }  2026.  2027. #endif /*OVLB*/ 2028. #ifdef OVL3 2029. 2030. STATIC_OVL long 2031. stolen_container(obj, shkp, price, ininv) 2032. register struct obj *obj; 2033. register struct monst *shkp; 2034. long price; 2035. register boolean ininv; 2036. { 2037. 	register struct obj *otmp; 2038. 2039. 	if(ininv && obj->unpaid) 2040. 	   price += get_cost(obj, shkp); 2041. 	else { 2042. 	   if(!obj->no_charge) 2043. 		price += get_cost(obj, shkp); 2044. 	   obj->no_charge = 0; 2045. 	} 2046.  2047. 	/* the price of contained objects, if any */ 2048. 	for(otmp = obj->cobj; otmp; otmp = otmp->nobj) { 2049. 2050. 	    if(otmp->oclass == GOLD_CLASS) continue; 2051. 2052. 	    if (!Has_contents(otmp)) { 2053. 		if(ininv) { 2054. 		   if(otmp->unpaid) 2055. 			price += get_cost(otmp, shkp); 2056. 		} else { 2057. 		   if(!otmp->no_charge) { 2058. 			if(!(otmp->oclass == BALL_CLASS || 2059. 			   (otmp->oclass == FOOD_CLASS && otmp->oeaten) || 2060. 			   (Is_candle(otmp) && otmp->age <  2061. 				  20L * (long)objects[otmp->otyp].oc_cost))  2062. 			  ) price += get_cost(otmp, shkp); 2063. 		   }  2064. 		    otmp->no_charge = 0; 2065. 		} 2066. 	    } else 2067. 		price += stolen_container(otmp, shkp, price, ininv); 2068. 	} 2069.  2070. 	return(price); 2071. } 2072. #endif /*OVL3*/ 2073. #ifdef OVLB 2074. 2075. long 2076. stolen_value(obj, x, y, peaceful, silent) 2077. register struct obj *obj; 2078. register xchar x, y; 2079. register boolean peaceful, silent; 2080. { 2081. 	register long value = 0L, gvalue = 0L; 2082. 	register struct monst *shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); 2083. 2084. 	if (!shkp || !inhishop(shkp)) 2085. 	   return (0L); 2086. 2087. 	if(obj->oclass == GOLD_CLASS) { 2088. 	   gvalue += obj->quan; 2089. 	} else if (Has_contents(obj)) { 2090. 	   register boolean ininv = !!count_unpaid(obj->cobj); 2091. 2092. 	    value += stolen_container(obj, shkp, value, ininv); 2093. 	   if(!ininv) gvalue += contained_gold(obj); 2094. 	} else if (!obj->no_charge && saleable(shkp, obj)) { 2095. 	   value += get_cost(obj, shkp); 2096. 	} 2097.  2098. 	if(gvalue + value == 0L) return(0L); 2099. 2100. 	value += gvalue; 2101. 2102. 	if(peaceful) { 2103. 	   value = check_credit(value, shkp); 2104. 	   ESHK(shkp)->debit += value; 2105. 2106. 	    if(!silent) { 2107. 		if(obj->oclass == GOLD_CLASS) 2108. 		   You("owe %s %ld zorkmids!", mon_nam(shkp), value); 2109. 		else You("owe %s %ld zorkmids for %s!", 2110. 			mon_nam(shkp),  2111. 			value,  2112. 			obj->quan > 1L ? "them" : "it"); 2113. 	   }  2114. 	} else { 2115. 	   ESHK(shkp)->robbed += value; 2116. 2117. 	    if(!silent) { 2118. 		if(cansee(shkp->mx, shkp->my)) { 2119. 		   if(ESHK(shkp)->customer[0] == 0) 2120. 			(void) strncpy(ESHK(shkp)->customer,plname,PL_NSIZ); 2121. 		   Norep("%s booms: \"%s, you are a thief!\"",  2122. 				Monnam(shkp), plname); 2123. 		} else Norep("You hear a scream, \"Thief!\""); 2124. 	   }  2125. 	    hot_pursuit(shkp); 2126. 	   (void) angry_guards(FALSE); 2127. 	} 2128. 	return(value); 2129. } 2130.  2131. /* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */ 2132. static char sell_response = 'a'; 2133. static boolean sell_voluntarily = FALSE; 2134. 2135. void 2136. sellobj_state(deliberate)	/* called from dodrop(do.c) and doddrop */ 2137. boolean deliberate; 2138. { 2139. 	/* If we're deliberately dropping something, there's no automatic 2140. 	response to the shopkeeper's "want to sell" query; however, if we 2141. accidentally drop anything, the shk will buy it/them without asking. 2142. 	This retains the old pre-query risk that slippery fingers while in 2143. shops entailed: you drop it, you've lost it. 2144. 	 */ 2145. 	sell_response = deliberate ? '\0' : 'a'; 2146. 	sell_voluntarily = deliberate; 2147. } 2148.  2149. void 2150. sellobj(obj, x, y) 2151. register struct obj *obj; 2152. xchar x, y; 2153. { 2154. 	register struct monst *shkp; 2155. 	register struct eshk *eshkp; 2156. 	long ltmp = 0L, cltmp = 0L, gltmp = 0L, offer; 2157. 	boolean saleitem, cgold = FALSE, container = Has_contents(obj); 2158. 	boolean isgold = (obj->oclass == GOLD_CLASS); 2159. 2160. 	if(!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) ||  2161. 	   !inhishop(shkp)) return; 2162. 	if(!costly_spot(x, y))	return; 2163. 	if(!*u.ushops) return; 2164. 2165. 	if(obj->unpaid && !container && !isgold) { 2166. 	   sub_one_frombill(obj, shkp); 2167. 	   return; 2168. 	} 2169. 	if(container) { 2170. 		/* find the price of content before subfrombill */ 2171. 		cltmp += contained_cost(obj, shkp, cltmp, TRUE); 2172. 		/* find the value of contained gold */ 2173. 		gltmp += contained_gold(obj); 2174. 		cgold = (gltmp > 0L); 2175. 	} 2176.  2177. 	saleitem = saleable(shkp, obj); 2178. 	if(!isgold && !obj->unpaid && saleitem) 2179. 	   ltmp = set_cost(obj, shkp); 2180. 2181. 	offer = ltmp + cltmp; 2182. 2183. 	/* get one case out of the way: nothing to sell, and no gold */ 2184. 	if(!isgold && (offer + gltmp) == 0L) { 2185. 		register boolean unpaid = (obj->unpaid || 2186. 				  (container && count_unpaid(obj->cobj))); 2187. 2188. 		if(container) { 2189. 			dropped_container(obj, shkp, FALSE); 2190. 			if(!obj->unpaid && !saleitem) 2191. 			   obj->no_charge = 1; 2192. 			if(obj->unpaid || count_unpaid(obj->cobj)) 2193. 			   subfrombill(obj, shkp); 2194. 		} else obj->no_charge = 1; 2195. 2196. 		if(!unpaid) 2197. 		   pline("%s seems uninterested.", Monnam(shkp)); 2198. 		return; 2199. 	} 2200.  2201. 	/* you dropped something of your own - probably want to sell it */ 2202. 	if (shkp->msleep || !shkp->mcanmove) { 2203. 		if (container) 2204. 		   dropped_container(obj, shkp, TRUE); 2205. 		if (!obj->unpaid) 2206. 		   obj->no_charge = 1; 2207. 		if (!shkp->mcanmove) { 2208. 		   if(ANGRY(shkp) && !rn2(4)) 2209. 			pline("%s utters a curse.", Monnam(shkp)); 2210. 		   else pline("%s is indisposed.", Monnam(shkp)); 2211. 		} else if(!rn2(3)) { 2212. 		   pline("%s snores indifferently.", Monnam(shkp)); 2213. 		} 2214. 		subfrombill(obj, shkp); 2215. 		return; 2216. 	} 2217.  2218. 	eshkp = ESHK(shkp); 2219. 2220. 	if (ANGRY(shkp)) { /* they become shop-objects, no pay */ 2221. 		pline("Thank you, scum!"); 2222. 		subfrombill(obj, shkp); 2223. 		return; 2224. 	} 2225.  2226. 	if(eshkp->robbed) {  /* shkp is not angry? */ 2227. 		if(isgold) offer = obj->quan; 2228. 		else if(cgold) offer += cgold; 2229. 		if((eshkp->robbed -= offer < 0L)) 2230. 			eshkp->robbed = 0L; 2231. 		if(offer) verbalize( 2232.   "Thank you for your contribution to restock this recently plundered shop."); 2233. 		subfrombill(obj, shkp); 2234. 		return; 2235. 	} 2236.  2237. 	if(isgold || cgold) { 2238. 		if(!cgold) gltmp = obj->quan; 2239. 2240. 		if(eshkp->debit >= gltmp) { 2241. 		   if(eshkp->loan) { /* you carry shop's gold */ 2242. 			 if(eshkp->loan >= gltmp) 2243. 			    eshkp->loan -= gltmp; 2244. 			 else eshkp->loan = 0L; 2245. 		   }  2246. 		    eshkp->debit -= gltmp; 2247. 		   Your("debt is %spaid off.",  2248. 				eshkp->debit ? "partially " : ""); 2249. 		} else { 2250. 		   long delta = gltmp - eshkp->debit; 2251. 2252. 		    eshkp->credit += delta; 2253. 		   if(eshkp->debit) { 2254. 			eshkp->debit = 0L; 2255. 			eshkp->loan = 0L; 2256. 			Your("debt is paid off."); 2257. 		   }  2258. 		    pline("%ld zorkmid%s added to your credit.",  2259. 				delta, delta > 1L ? "s are" : " is"); 2260. 		} 2261. 		if(offer) goto move_on; 2262. 		else { 2263. 		   if(!isgold) { 2264. 			if (container) 2265. 			   dropped_container(obj, shkp, FALSE); 2266. 			if (!obj->unpaid && !saleitem) obj->no_charge = 1; 2267. 			subfrombill(obj, shkp); 2268. 		   }  2269. 		    return; 2270. 		} 2271. 	}  2272. move_on: 2273. 	if((!saleitem && !(container && cltmp > 0L)) 2274. 	   || eshkp->billct == BILLSZ  2275. 	   || obj->oclass == BALL_CLASS  2276. 	   || obj->oclass == CHAIN_CLASS || offer == 0L  2277. 	   || (obj->oclass == FOOD_CLASS && obj->oeaten)  2278. 	   || (Is_candle(obj) && 2279. 		  obj->age < 20L * (long)objects[obj->otyp].oc_cost)) { 2280. 		pline("%s seems not interested%s.", Monnam(shkp), 2281. 			cgold ? " in the rest" : ""); 2282. 		if (container) 2283. 		   dropped_container(obj, shkp, FALSE); 2284. 		obj->no_charge = 1; 2285. 		return; 2286. 	} 2287.  2288. 	if(!shkp->mgold) { 2289. 		char c, qbuf[BUFSZ]; 2290. 		long tmpcr = ((offer * 9L) / 10L) + (offer <= 1L); 2291. 2292. 		if (!sell_voluntarily) { 2293. 		   c = sell_response = 'y'; 2294. 		} else if (sell_response != 'n') { 2295. 		   pline("%s cannot pay you at present.", Monnam(shkp)); 2296. 		   Sprintf(qbuf,  2297. 			    "Will you accept %ld zorkmid%s in credit for %s?",  2298. 			    tmpcr, plur(tmpcr), doname(obj)); 2299. 		   /* won't accept 'a' response here */ 2300. 		   c = ynq(qbuf); 2301. 		} else		/* previously specified "quit" */ 2302. 		   c = 'n'; 2303. 2304. 		if (c == 'y') { 2305. 		   shk_names_obj(shkp, obj, sell_voluntarily ?  2306. 			    "traded %s for %ld zorkmid%s in %scredit." :  2307. 			"relinquish %s and acquire %ld zorkmid%s in %scredit.",  2308. 			    tmpcr,  2309. 			    (eshkp->credit > 0L) ? "additional " : ""); 2310. 		   eshkp->credit += tmpcr; 2311. 		   subfrombill(obj, shkp); 2312. 		} else { 2313. 		   if (c == 'q') sell_response = 'n'; 2314. 		   if (container) 2315. 			dropped_container(obj, shkp, FALSE); 2316. 		   if (!obj->unpaid) obj->no_charge = 1; 2317. 		   subfrombill(obj, shkp); 2318. 		} 2319. 	} else { 2320. 		char qbuf[BUFSZ]; 2321. 		boolean short_funds = (offer > shkp->mgold); 2322. 2323. 		if (short_funds) offer = shkp->mgold; 2324. 2325. 		if (!sell_response) { 2326. 		   Sprintf(qbuf,  2327. 			 "%s offers%s %ld gold piece%s for%s %s %s.  Sell %s?",  2328. 			    Monnam(shkp), short_funds ? " only" : "",  2329. 			    offer, plur(offer),  2330. 			    (!ltmp && cltmp) ? " the contents of" : "",  2331. 			    obj->unpaid ? "the" : "your", xname(obj),  2332. 			    (obj->quan == 1L) ? "it" : "them"); 2333. 		} else qbuf[0] = '\0';		/* just to pacify lint */ 2334. 2335. 		switch (sell_response ? sell_response : ynaq(qbuf)) { 2336. 		 case 'q': sell_response = 'n'; 2337. 		 case 'n': if (container) 2338. 				dropped_container(obj, shkp, FALSE); 2339. 			   if (!obj->unpaid) obj->no_charge = 1; 2340. 			   subfrombill(obj, shkp); 2341. 			   break; 2342. 		 case 'a': sell_response = 'y'; 2343. 		 case 'y': if (container) 2344. 				dropped_container(obj, shkp, TRUE); 2345. 			   if (!obj->unpaid && !saleitem) obj->no_charge = 1; 2346. 			   subfrombill(obj, shkp); 2347. 			   pay(-offer, shkp); 2348. 			   shk_names_obj(shkp, obj, sell_voluntarily ?  2349. 				    "sold %s for %ld gold piece%s.%s" :  2350. 	       "relinquish %s and receive %ld gold piece%s in compensation.%s",  2351. 				    offer, ""); 2352. 			   break; 2353. 		 default:  impossible("invalid sell response"); 2354. 		} 2355. 	}  2356. }  2357.  2358. int 2359. doinvbill(mode) 2360. int mode;		/* 0: deliver count 1: paged */ 2361. { 2362. #ifdef	__SASC 2363. 	void sasc_bug(struct obj *, unsigned); 2364. #endif 2365. 	struct monst *shkp; 2366. 	struct eshk *eshkp; 2367. 	struct bill_x *bp, *end_bp; 2368. 	struct obj *obj; 2369. 	long totused; 2370. 	char *buf_p; 2371. 	winid datawin; 2372. 2373. 	shkp = shop_keeper(*u.ushops); 2374. 	if (!shkp || !inhishop(shkp)) { 2375. 	   if (mode != 0) impossible("doinvbill: no shopkeeper?"); 2376. 	   return 0; 2377. 	} 2378. 	eshkp = ESHK(shkp); 2379. 2380. 	if (mode == 0) { 2381. 	   /* count expended items, so that the `I' command can decide 2382. 	      whether to include 'x' in its prompt string */ 2383. 	   int cnt = !eshkp->debit ? 0 : 1; 2384.  2385. 	    for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct];  2386. 		    bp < end_bp; bp++) 2387. 		if (bp->useup || 2388. 			((obj = bp_to_obj(bp)) != 0 && obj->quan < bp->bquan)) 2389. 		   cnt++; 2390. 	   return cnt; 2391. 	} 2392.  2393. 	datawin = create_nhwindow(NHW_MENU); 2394. 	putstr(datawin, 0, "Unpaid articles already used up:"); 2395. 	putstr(datawin, 0, ""); 2396. 2397. 	totused = 0L; 2398. 	for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct]; 2399. 		bp < end_bp; bp++) { 2400. 	   obj = bp_to_obj(bp); 2401. 	   if(!obj) { 2402. 		impossible("Bad shopkeeper administration."); 2403. 		goto quit; 2404. 	   }  2405. 	    if(bp->useup || bp->bquan > obj->quan) { 2406. 		long oquan, uquan, thisused; 2407. 		unsigned save_unpaid; 2408. 2409. 		save_unpaid = obj->unpaid; 2410. 		oquan = obj->quan; 2411. 		uquan = (bp->useup ? bp->bquan : bp->bquan - oquan); 2412. 		thisused = bp->price * uquan; 2413. 		totused += thisused; 2414. 		obj->quan = uquan;		/* cheat doname */ 2415. 		obj->unpaid = 0;		/* ditto */ 2416. 		/* Why 'x'? To match `I x', more or less. */ 2417. 		buf_p = xprname(obj, (char *)0, 'x', FALSE, thisused); 2418. 		obj->quan = oquan;		/* restore value */ 2419. #ifdef __SASC 2420. 				/* SAS/C 6.2 can't cope for some reason */ 2421. 		sasc_bug(obj,save_unpaid); 2422. #else 2423. 		obj->unpaid = save_unpaid; 2424. #endif 2425. 		putstr(datawin, 0, buf_p); 2426. 	   }  2427. 	}  2428. 	if (eshkp->debit) { 2429. 	   /* additional shop debt which has no itemization available */ 2430. 	   if (totused) putstr(datawin, 0, ""); 2431. 	   totused += eshkp->debit; 2432. 	   buf_p = xprname((struct obj *)0,  2433. 			    "usage charges and/or other fees",  2434. 			    GOLD_SYM, FALSE, eshkp->debit); 2435. 	   putstr(datawin, 0, buf_p); 2436. 	} 2437. 	buf_p = xprname((struct obj *)0, "Total:", '*', FALSE, totused); 2438. 	putstr(datawin, 0, ""); 2439. 	putstr(datawin, 0, buf_p); 2440. 	display_nhwindow(datawin, FALSE); 2441.    quit: 2442. 	destroy_nhwindow(datawin); 2443. 	return(0); 2444. } 2445.  2446. #define HUNGRY	2 2447. 2448. STATIC_OVL long 2449. getprice(obj, shk_buying) 2450. register struct obj *obj; 2451. boolean shk_buying; 2452. { 2453. 	register long tmp = (long) objects[obj->otyp].oc_cost; 2454. 2455. 	switch(obj->oclass) { 2456. 	case FOOD_CLASS: 2457. 		/* simpler hunger check, (2-4)*cost */ 2458. 		if (u.uhs >= HUNGRY && !shk_buying) tmp *= (long) u.uhs; 2459. 		if (obj->oeaten) tmp = 0L; 2460. 		break; 2461. 	case WAND_CLASS: 2462. 		if (obj->spe == -1) tmp = 0L; 2463. 		break; 2464. 	case POTION_CLASS: 2465. 		if (obj->otyp == POT_WATER && !obj->blessed && !obj->cursed) 2466. 			tmp = 0L; 2467. 		break; 2468. 	case ARMOR_CLASS: 2469. 	case WEAPON_CLASS: 2470. 		if (obj->spe > 0) tmp += 10L * (long) obj->spe; 2471. 		break; 2472. 	case TOOL_CLASS: 2473. 		if (Is_candle(obj) && 2474. 			obj->age < 20L * (long)objects[obj->otyp].oc_cost) 2475. 		   tmp /= 2L; 2476. 		break; 2477. 	} 2478. 	if (obj->oartifact) tmp *= 25L; 2479. 	return tmp; 2480. } 2481.  2482. /* shk catches thrown pick-axe */ 2483. int 2484. shkcatch(obj, x, y) 2485. register struct obj *obj; 2486. register xchar x, y; 2487. { 2488. 	register struct monst *shkp; 2489. 2490. 	if (!(shkp = shop_keeper(inside_shop(x, y))) ||  2491. 	    !inhishop(shkp)) return(0); 2492. 2493. 	if (shkp->mcanmove && !shkp->msleep &&  2494. 	    (*u.ushops != ESHK(shkp)->shoproom || !inside_shop(u.ux, u.uy)) &&  2495. 	    dist2(shkp->mx, shkp->my, x, y) < 3 &&  2496. 	    /* if it is the shk's pos, you hit and anger him */  2497. 	    (shkp->mx != x || shkp->my != y)) { 2498. 		if (mnearto(shkp, x, y, TRUE)) 2499. 		   verbalize("Out of my way, scum!"); 2500. 		if (cansee(x, y)) { 2501. 		   pline("%s nimbly catches %s.",  2502. 			  Monnam(shkp), the(xname(obj))); 2503. 		   delay_output; 2504. 		   mark_synch; 2505. 		} 2506. 		mpickobj(shkp, obj); 2507. 		subfrombill(obj, shkp); 2508. 		return(1); 2509. 	} 2510. 	return(0); 2511. } 2512.  2513. void 2514. add_damage(x, y, cost) 2515. register xchar x, y; 2516. long cost; 2517. { 2518. 	struct damage *tmp_dam; 2519. 	char *shops; 2520. 2521. 	if (IS_DOOR(levl[x][y].typ)) { 2522. 	   struct monst *mtmp; 2523. 2524. 	    /* Don't schedule for repair unless it's a real shop entrance */ 2525. 	   for (shops = in_rooms(x, y, SHOPBASE); *shops; shops++) 2526. 		if ((mtmp = shop_keeper(*shops)) != 0 && 2527. 			x == ESHK(mtmp)->shd.x && y == ESHK(mtmp)->shd.y)  2528. break; 2529. 	   if (!*shops) return; 2530. 	} 2531. 	for (tmp_dam = level.damagelist; tmp_dam; tmp_dam = tmp_dam->next) 2532. 	   if (tmp_dam->place.x == x && tmp_dam->place.y == y) { 2533. 		tmp_dam->cost += cost; 2534. 		return; 2535. 	   }  2536. 	tmp_dam = (struct damage *)alloc((unsigned)sizeof(struct damage)); 2537. 	tmp_dam->when = monstermoves; 2538. 	tmp_dam->place.x = x; 2539. tmp_dam->place.y = y; 2540. tmp_dam->cost = cost; 2541. 	tmp_dam->typ = levl[x][y].typ; 2542. 	tmp_dam->next = level.damagelist; 2543. 	level.damagelist = tmp_dam; 2544. 	/* If player saw damage, display as a wall forever */ 2545. 	if (cansee(x, y)) 2546. 	   levl[x][y].seenv = SVALL; 2547. } 2548.  2549. #endif /*OVLB*/ 2550. #ifdef OVL0 2551. 2552. /*  2553.  * Do something about damage. Either (!croaked) try to repair it, or 2554. * (croaked) just discard damage structs for non-shared locations, since 2555. * they'll never get repaired. Assume that shared locations will get 2556. * repaired eventually by the other shopkeeper(s). This might be an erroneous 2557. * assumption (they might all be dead too), but we have no reasonable way of  2558. * telling that. 2559. */  2560. STATIC_OVL 2561. void 2562. remove_damage(shkp, croaked) 2563. register struct monst *shkp; 2564. register boolean croaked; 2565. { 2566. 	register struct damage *tmp_dam, *tmp2_dam; 2567. 	register boolean did_repair = FALSE, saw_door = FALSE; 2568. 	register boolean saw_floor = FALSE, stop_picking = FALSE; 2569. 	uchar saw_walls = 0; 2570. 2571. 	tmp_dam = level.damagelist; 2572. 	tmp2_dam = 0; 2573. 	while (tmp_dam) { 2574. 	   register xchar x = tmp_dam->place.x, y = tmp_dam->place.y;  2575. char shops[5]; 2576. 	   int disposition; 2577. 2578. 	    disposition = 0; 2579. 	   Strcpy(shops, in_rooms(x, y, SHOPBASE)); 2580. 	   if (index(shops, ESHK(shkp)->shoproom)) { 2581. 		if (croaked) 2582. 		   disposition = (shops[1])? 0 : 1; 2583. 		else if (stop_picking) 2584. 		   disposition = repair_damage(shkp, tmp_dam, FALSE); 2585. 		else { 2586. 		   /* Defer the stop_occupation until after repair msgs */ 2587. 		   if (closed_door(x, y)) 2588. 			stop_picking = picking_at(x, y); 2589. 		   disposition = repair_damage(shkp, tmp_dam, FALSE); 2590. 		   if (!disposition) 2591. 			stop_picking = FALSE; 2592. 		} 2593. 	    }  2594.  2595. 	    if (!disposition) { 2596. 		tmp2_dam = tmp_dam; 2597. 		tmp_dam = tmp_dam->next; 2598. 		continue; 2599. 	   }  2600.  2601. 	    if (disposition > 1) { 2602. 		did_repair = TRUE; 2603. 		if (cansee(x, y)) { 2604. 		   if (IS_WALL(levl[x][y].typ)) 2605. 			saw_walls++; 2606. 		   else if (IS_DOOR(levl[x][y].typ)) 2607. 			saw_door = TRUE; 2608. 		   else 2609. 			saw_floor = TRUE; 2610. 		} 2611. 	    }  2612.  2613. 	    tmp_dam = tmp_dam->next; 2614. 	   if (!tmp2_dam) { 2615. 		free((genericptr_t)level.damagelist); 2616. 		level.damagelist = tmp_dam; 2617. 	   } else { 2618. 		free((genericptr_t)tmp2_dam->next); 2619. 		tmp2_dam->next = tmp_dam; 2620. 	   }  2621. 	}  2622. 	if (!did_repair) 2623. 	   return; 2624. 	if (saw_walls) { 2625. 	   pline("Suddenly, %s section%s of wall close%s up!",  2626. 		  (saw_walls == 1) ? "a" : (saw_walls <= 3) ?  2627. 						  "some" : "several",  2628. 		  (saw_walls == 1) ? "" : "s", (saw_walls == 1) ? "s" : ""); 2629. 	   if (saw_door) 2630. 		pline_The("shop door reappears!"); 2631. 	   if (saw_floor) 2632. 		pline_The("floor is repaired!"); 2633. 	} else { 2634. 	   if (saw_door) 2635. 		pline("Suddenly, the shop door reappears!"); 2636. 	   else if (saw_floor) 2637. 		pline("Suddenly, the floor damage is gone!"); 2638. 	   else if (inside_shop(u.ux, u.uy) == ESHK(shkp)->shoproom) 2639. 		You_feel("more claustrophobic than before."); 2640. 	   else if (flags.soundok && !rn2(10)) 2641. 		Norep("The dungeon acoustics noticeably change."); 2642. 	} 2643. 	if (stop_picking) 2644. 		stop_occupation; 2645. } 2646.  2647. /*  2648.  * 0: repair postponed, 1: silent repair (no messages), 2: normal repair 2649. */  2650. int 2651. repair_damage(shkp, tmp_dam, catchup) 2652. register struct monst *shkp; 2653. register struct damage *tmp_dam; 2654. boolean catchup;	/* restoring a level */ 2655. { 2656. 	register xchar x, y, i;  2657. xchar litter[9]; 2658. 	register struct monst *mtmp; 2659. 	register struct obj *otmp; 2660. 	register struct trap *ttmp; 2661. 2662. 	if ((monstermoves - tmp_dam->when) < REPAIR_DELAY) 2663. 	   return(0); 2664. 	if (shkp->msleep || !shkp->mcanmove || ESHK(shkp)->following) 2665. 	   return(0); 2666. 	x = tmp_dam->place.x; 2667. y = tmp_dam->place.y; 2668. if (!IS_ROOM(tmp_dam->typ)) { 2669. 	   if (x == u.ux && y == u.uy) 2670. 		if (!passes_walls(uasmon)) 2671. 		   return(0); 2672. 	   if (x == shkp->mx && y == shkp->my) 2673. 		return(0); 2674. 	   if ((mtmp = m_at(x, y)) && (!passes_walls(mtmp->data))) 2675. 		return(0); 2676. 	} 2677. 	if ((ttmp = t_at(x, y)) != 0) 2678. 	   deltrap(ttmp); 2679. 	if (IS_ROOM(tmp_dam->typ)) { 2680. 	   /* No messages if player already filled trapdoor */ 2681. 	   if (catchup || !ttmp) 2682. 		return(1); 2683. 	   newsym(x, y); 2684. 	   return(2); 2685. 	} 2686. 	if (!ttmp && (tmp_dam->typ == levl[x][y].typ) &&  2687. 	    (!IS_DOOR(tmp_dam->typ) || (levl[x][y].doormask > D_BROKEN))) 2688. 	   /* No messages if player already replaced shop door */ 2689. 	   return(1); 2690. 	levl[x][y].typ = tmp_dam->typ; 2691. 	(void) memset((genericptr_t)litter, 0, sizeof(litter)); 2692. 	if ((otmp = level.objects[x][y]) != 0) { 2693. 	   /* Scatter objects haphazardly into the shop */ 2694. #define NEED_UPDATE 1 2695. #define OPEN	   2 2696. #define INSHOP	   4 2697. #define horiz(i) ((i%3)-1) 2698. #define vert(i) ((i/3)-1) 2699. 	   for (i = 0; i < 9; i++) { 2700. 		if ((i == 4) || (!ZAP_POS(levl[x+horiz(i)][y+vert(i)].typ))) 2701. 		   continue; 2702. 		litter[i] = OPEN; 2703. 		if (inside_shop(x+horiz(i), 2704. 				y+vert(i)) == ESHK(shkp)->shoproom) 2705. 		   litter[i] |= INSHOP; 2706. 	   }  2707. 	    if (Punished && !u.uswallow &&  2708. 				((uchain->ox == x && uchain->oy == y) || 2709. 				 (uball->ox == x && uball->oy == y))) { 2710. 		/* 2711. 		 * Either the ball or chain is in the repair location. 2712. 		 * 2713. 		 * Take the easy way out and put ball&chain under hero. 2714. 		 */ 2715. 		verbalize("Get your junk out of my wall!"); 2716. 		unplacebc;	/* pick 'em up */ 2717. 		placebc;	/* put 'em down */ 2718. 	   }  2719. 	    while ((otmp = level.objects[x][y]) != 0) 2720. 		/* Don't mess w/ boulders -- just merge into wall */ 2721. 		if ((otmp->otyp == BOULDER) || (otmp->otyp == ROCK)) { 2722. 		   obj_extract_self(otmp); 2723. 		   obfree(otmp, (struct obj *)0); 2724. 		} else { 2725. 		   while (!(litter[i = rn2(9)] & INSHOP)); 2726. 			remove_object(otmp); 2727. 			place_object(otmp, x+horiz(i), y+vert(i)); 2728. 			litter[i] |= NEED_UPDATE; 2729. 		} 2730. 	}  2731. 	if (catchup) return 1;	/* repair occurred while off level */ 2732. 2733. 	block_point(x, y); 2734. 	if(IS_DOOR(tmp_dam->typ)) { 2735. 	   levl[x][y].doormask = D_CLOSED; /* arbitrary */ 2736. 	   newsym(x, y); 2737. 	} else { 2738. 	   /* don't set doormask  - it is (hopefully) the same as it was */ 2739. 	   /* if not, perhaps save it with the damage array... */ 2740.  2741. 	    if (IS_WALL(tmp_dam->typ) && cansee(x, y)) { 2742. 	   /* Player sees actual repair process, so they KNOW it's a wall */ 2743. 		levl[x][y].seenv = SVALL; 2744. 		newsym(x, y); 2745. 	   }  2746. 	    /* Mark this wall as "repaired". There currently is no code */ 2747. 	   /* to do anything about repaired walls, so don't do it. */ 2748. 	}  2749. 	for (i = 0; i < 9; i++) 2750. 	   if (litter[i] & NEED_UPDATE) 2751. 		newsym(x+horiz(i), y+vert(i)); 2752. 	return(2); 2753. #undef NEED_UPDATE 2754. #undef OPEN 2755. #undef INSHOP 2756. #undef vert 2757. #undef horiz 2758. } 2759. #endif /*OVL0*/ 2760. #ifdef OVL3 2761. /* 2762.  * shk_move: return 1: moved  0: didn't  -1: let m_move do it  -2: died 2763. */  2764. int 2765. shk_move(shkp) 2766. register struct monst *shkp; 2767. { 2768. 	register xchar gx,gy,omx,omy; 2769. 	register int udist; 2770. 	register schar appr; 2771. 	register struct eshk *eshkp = ESHK(shkp); 2772. 	int z; 2773. boolean uondoor = FALSE, satdoor, avoid = FALSE, badinv; 2774. 2775. 	omx = shkp->mx; 2776. 	omy = shkp->my; 2777. 2778. 	if (inhishop(shkp)) 2779. 	   remove_damage(shkp, FALSE); 2780. 2781. 	if((udist = distu(omx,omy)) < 3 &&  2782. 	   (shkp->data != &mons[PM_GRID_BUG] || (omx==u.ux || omy==u.uy))) { 2783. 		if(ANGRY(shkp) || 2784. 		   (Conflict && !resist(shkp, RING_CLASS, 0, 0))) { 2785. 			if(Displaced) 2786. 			 Your("displaced image doesn't fool %s!",  2787. 				mon_nam(shkp)); 2788. 			(void) mattacku(shkp); 2789. 			return(0); 2790. 		} 2791. 		if(eshkp->following) { 2792. 			if(strncmp(eshkp->customer, plname, PL_NSIZ)) { 2793. 			   verbalize("Hello, %s!  I was looking for %s.",  2794. 				    plname, eshkp->customer); 2795. 				   eshkp->following = 0; 2796. 			   return(0); 2797. 			} 2798. 			if(moves > followmsg+4) { 2799. 			   verbalize("Hello, %s!  Didn't you forget to pay?",  2800. 				    plname); 2801. 			   followmsg = moves; 2802. 			   if (!rn2(9)) { 2803. 			     pline("%s doesn't like customers who don't pay.",  2804. 				    Monnam(shkp)); 2805. 				rile_shk(shkp); 2806. 			   }  2807. 			}  2808. 			if(udist < 2) 2809. 			   return(0); 2810. 		} 2811. 	}  2812.  2813. 	appr = 1; 2814. 	gx = eshkp->shk.x; 2815. gy = eshkp->shk.y; 2816. satdoor = (gx == omx && gy == omy); 2817. 	if(eshkp->following || ((z = holetime) >= 0 && z*z <= udist)){ 2818. 		if(udist > 4) 2819. 		   return(-1);	/* leave it to m_move */ 2820. 		gx = u.ux; 2821. 		gy = u.uy; 2822. 	} else if(ANGRY(shkp)) { 2823. 		/* Move towards the hero if the shopkeeper can see him. */ 2824. 		if(shkp->mcansee && m_canseeu(shkp)) { 2825. 			gx = u.ux; 2826. 			gy = u.uy; 2827. 		} 2828. 		avoid = FALSE; 2829. 	} else { 2830. #define	GDIST(x,y)	(dist2(x,y,gx,gy)) 2831. 		if(Invis) { 2832. 		   avoid = FALSE; 2833. 		} else { 2834. 		   uondoor = (u.ux == eshkp->shd.x && u.uy == eshkp->shd.y); 2835. 		   if(uondoor) { 2836. 			badinv = (carrying(PICK_AXE) || 2837. 				  (Fast && sobj_at(PICK_AXE, u.ux, u.uy))); 2838. 			if(satdoor && badinv) 2839. 			   return(0); 2840. 			avoid = !badinv; 2841. 		   } else { 2842. 			avoid = (*u.ushops && distu(gx,gy) > 8); 2843. 			badinv = FALSE; 2844. 		   }  2845.  2846. 		    if(((!eshkp->robbed && !eshkp->billct && !eshkp->debit) 2847. 			|| avoid) && GDIST(omx,omy) < 3) { 2848. 			if (!badinv && !onlineu(omx,omy)) 2849. 			   return(0); 2850. 			if(satdoor) 2851. 			   appr = gx = gy = 0; 2852. 		   }  2853. 		}  2854. 	}  2855.  2856. 	return(move_special(shkp,inhishop(shkp), 2857. 			   appr,uondoor,avoid,omx,omy,gx,gy)); 2858. } 2859.  2860. #endif /*OVL3*/ 2861. #ifdef OVLB 2862. 2863. /* for use in levl_follower (mondata.c) */ 2864. boolean 2865. is_fshk(mtmp) 2866. register struct monst *mtmp; 2867. { 2868. 	return((boolean)(mtmp->isshk && ESHK(mtmp)->following)); 2869. } 2870.  2871. /* You are digging in the shop. */ 2872. void 2873. shopdig(fall) 2874. register int fall; 2875. { 2876.     register struct monst *shkp = shop_keeper(*u.ushops); 2877. 2878.     if(!shkp) return; 2879. 2880.     if(!inhishop(shkp)) { 2881. 	if (Role_is('K')) adjalign(-sgn(u.ualign.type)); 2882. 	return; 2883.    }  2884.  2885.     if(!fall) { 2886. 	if(u.utraptype == TT_PIT) 2887. 	   verbalize("Be careful, %s, or you might fall through the floor.",  2888. 		flags.female ? "madam" : "sir"); 2889. 	else 2890. 	   verbalize("%s, do not damage the floor here!",  2891. 			flags.female ? "Madam" : "Sir"); 2892. 	if (Role_is('K')) adjalign(-sgn(u.ualign.type)); 2893.    } else if(!um_dist(shkp->mx, shkp->my, 5) &&  2894. 		!shkp->msleep && shkp->mcanmove &&  2895. 		(ESHK(shkp)->billct || ESHK(shkp)->debit)) { 2896. 	   register struct obj *obj, *obj2; 2897. 2898. 	    if (distu(shkp->mx, shkp->my) > 2) { 2899. 		mnexto(shkp); 2900. 		/* for some reason the shopkeeper can't come next to you */ 2901. 		if (distu(shkp->mx, shkp->my) > 2) { 2902. 		   pline("%s curses you in anger and frustration!",  2903. 					shkname(shkp)); 2904. 		   rile_shk(shkp); 2905. 		   return; 2906. 		} else pline("%s leaps, and grabs your backpack!", 2907. 					shkname(shkp)); 2908. 	   } else pline("%s grabs your backpack!", shkname(shkp)); 2909. 2910. 	    for(obj = invent; obj; obj = obj2) { 2911. 		obj2 = obj->nobj; 2912. 		if(obj->owornmask) continue; 2913. 		if(obj->otyp == LEASH && obj->leashmon) continue; 2914. 		freeinv(obj); 2915. 		add_to_minv(shkp, obj); 2916. 		subfrombill(obj, shkp); 2917. 	   }  2918.     }  2919. }  2920.  2921. #ifdef KOPS 2922. STATIC_OVL void 2923. makekops(mm) 2924. coord *mm; 2925. { 2926. 	static const short k_mndx[4] = { 2927. 	   PM_KEYSTONE_KOP, PM_KOP_SERGEANT, PM_KOP_LIEUTENANT, PM_KOP_KAPTAIN 2928. 	}; 2929. 	int k_cnt[4], cnt, mndx, k;  2930. 2931. 	k_cnt[0] = cnt = abs(depth(&u.uz)) + rnd(5); 2932. 	k_cnt[1] = (cnt / 3) + 1;	/* at least one sarge */ 2933. 	k_cnt[2] = (cnt / 6);		/* maybe a lieutenant */ 2934. 	k_cnt[3] = (cnt / 9);		/* and maybe a kaptain */ 2935. 2936. 	for (k = 0; k < 4; k++) { 2937. 	   if ((cnt = k_cnt[k]) == 0) break; 2938. 	   mndx = k_mndx[k]; 2939. 	   if (mvitals[mndx].mvflags & G_GONE) continue; 2940. 2941. 	    while (cnt--) 2942. 		if (enexto(mm, mm->x, mm->y, &mons[mndx])) 2943. 		   (void) makemon(&mons[mndx], mm->x, mm->y); 2944. 	} 2945. }  2946. #endif	/* KOPS */ 2947. 2948. void 2949. pay_for_damage(dmgstr) 2950. const char *dmgstr; 2951. { 2952. 	register struct monst *shkp = (struct monst *)0; 2953. 	char shops_affected[5]; 2954. 	register boolean uinshp = (*u.ushops != '\0'); 2955. 	char qbuf[80]; 2956. 	register xchar x, y; 2957. boolean dugwall = !strcmp(dmgstr, "dig into") ||	/* wand */ 2958. 			 !strcmp(dmgstr, "damage");		/* pick-axe */ 2959. 	struct damage *tmp_dam, *appear_here = 0; 2960. 	/* any number >= (80*80)+(24*24) would do, actually */ 2961. 	long cost_of_damage = 0L; 2962. 	unsigned int nearest_shk = 7000, nearest_damage = 7000; 2963. 	int picks = 0; 2964. 2965. 	for (tmp_dam = level.damagelist;  2966. 	     (tmp_dam && (tmp_dam->when == monstermoves));  2967. 	     tmp_dam = tmp_dam->next) { 2968. 	   char *shp; 2969. 2970. 	    if (!tmp_dam->cost) 2971. 		continue; 2972. 	   cost_of_damage += tmp_dam->cost; 2973. 	   Strcpy(shops_affected,  2974. 		   in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE)); 2975. 	   for (shp = shops_affected; *shp; shp++) { 2976. 		struct monst *tmp_shk; 2977. 		unsigned int shk_distance; 2978. 2979. 		if (!(tmp_shk = shop_keeper(*shp))) 2980. 		   continue; 2981. 		if (tmp_shk == shkp) { 2982. 		   unsigned int damage_distance = 2983. 				  distu(tmp_dam->place.x, tmp_dam->place.y); 2984. 2985. 		    if (damage_distance < nearest_damage) { 2986. 			nearest_damage = damage_distance; 2987. 			appear_here = tmp_dam; 2988. 		   }  2989. 		    continue; 2990. 		} 2991. 		if (!inhishop(tmp_shk)) 2992. 		   continue; 2993. 		shk_distance = distu(tmp_shk->mx, tmp_shk->my); 2994. 		if (shk_distance > nearest_shk) 2995. 		   continue; 2996. 		if ((shk_distance == nearest_shk) && picks) { 2997. 		   if (rn2(++picks)) 2998. 			continue; 2999. 		} else 3000. 		   picks = 1; 3001. 		shkp = tmp_shk; 3002. 		nearest_shk = shk_distance; 3003. 		appear_here = tmp_dam; 3004. 		nearest_damage = distu(tmp_dam->place.x, tmp_dam->place.y); 3005. 	   }  3006. 	}  3007.  3008. 	if (!cost_of_damage || !shkp) 3009. 	   return; 3010. 3011. 	x = appear_here->place.x;  3012. y = appear_here->place.y; 3013. 3014. 	/* not the best introduction to the shk... */ 3015. 	(void) strncpy(ESHK(shkp)->customer,plname,PL_NSIZ); 3016. 3017. 	/* if the shk is already on the war path, be sure it's all out */ 3018. 	if(ANGRY(shkp) || ESHK(shkp)->following) { 3019. 		hot_pursuit(shkp); 3020. 		return; 3021. 	} 3022.  3023. 	/* if the shk is not in their shop.. */ 3024. 	if(!*in_rooms(shkp->mx,shkp->my,SHOPBASE)) { 3025. 		if(!cansee(shkp->mx, shkp->my)) 3026. 			return; 3027. 		goto getcad; 3028. 	} 3029.  3030. 	if(uinshp) { 3031. 		if(um_dist(shkp->mx, shkp->my, 1) && 3032. 			!um_dist(shkp->mx, shkp->my, 3)) { 3033. 		   pline("%s leaps towards you!", shkname(shkp)); 3034. 		   mnexto(shkp); 3035. 		} 3036. 		if(um_dist(shkp->mx, shkp->my, 1)) goto getcad; 3037. 	} else { 3038. 	   /*  3039. 	     * Make shkp show up at the door. Effect: If there is a monster 3040. 	    * in the doorway, have the hero hear the shopkeeper yell a bit, 3041. 	    * pause, then have the shopkeeper appear at the door, having 3042. 	    * yanked the hapless critter out of the way. 3043. 	    */  3044. 	    if (MON_AT(x, y)) { 3045. 		if(flags.soundok) { 3046. 		   You_hear("an angry voice:"); 3047. 		   verbalize("Out of my way, scum!"); 3048. 		   wait_synch; 3049. #if defined(UNIX) || defined(VMS) 3050. # if defined(SYSV) || defined(ULTRIX) || defined(VMS) 3051. 		   (void) 3052. # endif 3053. 			sleep(1); 3054. #endif 3055. 		} 3056. 	    }  3057. 	    (void) mnearto(shkp, x, y, TRUE); 3058. 	} 3059.  3060. 	if((um_dist(x, y, 1) && !uinshp) ||  3061. 			(u.ugold + ESHK(shkp)->credit) < cost_of_damage  3062. 				|| !rn2(50)) { 3063. 		if(um_dist(x, y, 1) && !uinshp) { 3064. 		   pline("%s shouts:", shkname(shkp)); 3065. 		   verbalize("Who dared %s my %s?", dmgstr,  3066. 					 dugwall ? "shop" : "door"); 3067. 		} else { 3068. getcad: 3069. 		   verbalize("How dare you %s my %s?", dmgstr,  3070. 					 dugwall ? "shop" : "door"); 3071. 		} 3072. 		hot_pursuit(shkp); 3073. 		return; 3074. 	} 3075.  3076. 	if(Invis) Your("invisibility does not fool %s!", shkname(shkp)); 3077. 	Sprintf(qbuf,"\"Cad! You did %ld zorkmids worth of damage!\"  Pay? ",  3078. 		 cost_of_damage); 3079. 	if(yn(qbuf) != 'n') { 3080. 		cost_of_damage = check_credit(cost_of_damage, shkp); 3081. 		u.ugold -= cost_of_damage; 3082. 		shkp->mgold += cost_of_damage; 3083. 		flags.botl = 1; 3084. 		pline("Mollified, %s accepts your restitution.", 3085. 			shkname(shkp)); 3086. 		/* move shk back to his home loc */ 3087. 		home_shk(shkp, FALSE); 3088. 		pacify_shk(shkp); 3089. 	} else { 3090. 		verbalize("Oh, yes! You'll pay!"); 3091. 		hot_pursuit(shkp); 3092. 		adjalign(-sgn(u.ualign.type)); 3093. 	} 3094. }  3095. #endif /*OVLB*/ 3096. #ifdef OVL0 3097. /* called in dokick.c when we kick an object that might be in a store */ 3098. boolean 3099. costly_spot(x, y) 3100. register xchar x, y; 3101. { 3102. 	register struct monst *shkp; 3103. 3104. 	if (!level.flags.has_shop) return FALSE; 3105. 	shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); 3106. 	if(!shkp || !inhishop(shkp)) return(FALSE); 3107. 3108. 	return((boolean)(inside_shop(x, y) && 3109. 		!(x == ESHK(shkp)->shk.x && 3110. 			y == ESHK(shkp)->shk.y))); 3111. } 3112. #endif /*OVL0*/ 3113. #ifdef OVLB 3114. 3115. /* called by dotalk(sounds.c) when #chatting; returns obj if location 3116.   contains shop goods and shopkeeper is willing & able to speak */ 3117. struct obj * 3118. shop_object(x, y) 3119. register xchar x, y; 3120. { 3121.     register struct obj *otmp; 3122.    register struct monst *shkp; 3123. 3124.     if(!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp)) 3125. 	return(struct obj *)0; 3126. 3127.     for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) 3128. 	if (otmp->oclass != GOLD_CLASS) 3129. 	   break; 3130.    /* note: otmp might have ->no_charge set, but that's ok */ 3131.    return (otmp && costly_spot(x, y) && NOTANGRY(shkp)  3132. 	    && shkp->mcanmove && !shkp->msleep) 3133. 		? otmp : (struct obj *)0; 3134. } 3135.  3136. /* give price quotes for all objects linked to this one (ie, on this spot) */ 3137. void 3138. price_quote(first_obj) 3139. register struct obj *first_obj; 3140. { 3141.     register struct obj *otmp; 3142.    char buf[BUFSZ], price[40]; 3143.    long cost; 3144.    int cnt = 0; 3145.    winid tmpwin; 3146.    struct monst *shkp = shop_keeper(inside_shop(u.ux, u.uy)); 3147. 3148.     tmpwin = create_nhwindow(NHW_MENU); 3149.    putstr(tmpwin, 0, "Fine goods for sale:"); 3150.    putstr(tmpwin, 0, ""); 3151.    for (otmp = first_obj; otmp; otmp = otmp->nexthere) { 3152. 	if (otmp->oclass == GOLD_CLASS) continue; 3153. 	cost = (otmp->no_charge || otmp == uball || otmp == uchain) ? 0L : 3154. 		get_cost(otmp, (struct monst *)0); 3155. 	if (Has_contents(otmp)) 3156. 	   cost += contained_cost(otmp, shkp, 0L, FALSE); 3157. 	if (!cost) { 3158. 	   Strcpy(price, "no charge"); 3159. 	} else { 3160. 	   Sprintf(price, "%ld zorkmid%s%s", cost, plur(cost),  3161. 		    otmp->quan > 1L ? " each" : ""); 3162. 	} 3163. 	Sprintf(buf, "%s, %s", doname(otmp), price); 3164. 	putstr(tmpwin, 0, buf), cnt++; 3165.    }  3166.     if (cnt > 1) { 3167. 	display_nhwindow(tmpwin, TRUE); 3168.    } else if (cnt == 1) { 3169. 	if (first_obj->no_charge || first_obj == uball || first_obj == uchain){ 3170. 	   pline("%s!", buf);	/* buf still contains the string */ 3171. 	} else { 3172. 	   /* print cost in slightly different format, so can't reuse buf */ 3173. 	   cost = get_cost(first_obj, (struct monst *)0); 3174. 	   if (Has_contents(first_obj)) 3175. 		cost += contained_cost(first_obj, shkp, 0L, FALSE); 3176. 	   pline("%s, price %ld zorkmid%s%s%s", doname(first_obj),  3177. 		cost, plur(cost), first_obj->quan > 1L ? " each" : "",  3178. 		shk_embellish(first_obj, cost)); 3179. 	} 3180.     }  3181.     destroy_nhwindow(tmpwin); 3182. } 3183. #endif /*OVLB*/ 3184. #ifdef OVL3 3185. 3186. STATIC_OVL const char * 3187. shk_embellish(itm, cost) 3188. register struct obj *itm; 3189. long cost; 3190. { 3191.     if (!rn2(3)) { 3192. 	register int o, choice = rn2(5); 3193. 	if (choice == 0) choice = (cost < 100L ? 1 : cost < 500L ? 2 : 3); 3194. 	switch (choice) { 3195. 	   case 4: 3196. 		if (cost < 10L) break; else o = itm->oclass; 3197. 		if (o == FOOD_CLASS) return ", gourmets' delight!"; 3198. 		if (objects[itm->otyp].oc_name_known 3199. 		    ? objects[itm->otyp].oc_magic  3200. 		    : (o == AMULET_CLASS || o == RING_CLASS   || 3201. 		      o == WAND_CLASS   || o == POTION_CLASS || 3202. 		      o == SCROLL_CLASS || o == SPBOOK_CLASS)) 3203. 		   return ", painstakingly developed!"; 3204. 		return ", superb craftsmanship!"; 3205. 	   case 3: return ", finest quality."; 3206. 	   case 2: return ", an excellent choice."; 3207. 	   case 1: return ", a real bargain."; 3208. 	  default: break; 3209. 	} 3210.     } else if (itm->oartifact) { 3211. 	return ", one of a kind!"; 3212.    }  3213.     return "."; 3214. } 3215. #endif /*OVL3*/ 3216. #ifdef OVLB 3217. 3218. /* First 4 supplied by Ronen and Tamar, remainder by development team */ 3219. const char *Izchak_speaks[]={ 3220.    "%s says: 'These shopping malls give me a headache.'", 3221.    "%s says: 'Slow down.  Think clearly.'", 3222.    "%s says: 'You need to take things one at a time.'", 3223.    "%s says: 'I don't like poofy coffee... give me Columbian Supremo.'", 3224.    "%s says that getting the devteam's agreement on anything is difficult.", 3225.    "%s says that he has noticed those who serve their deity will prosper.", 3226.    "%s says: 'Don't try to steal from me - I have friends in high places!'", 3227.    "%s says: 'You may well need something from this shop in the future.'", 3228.    "%s comments about the Valley of the Dead as being a gateway." 3229. }; 3230.  3231. void 3232. shk_chat(shkp) 3233. register struct monst *shkp; 3234. { 3235. 	register struct eshk *eshk = ESHK(shkp); 3236. 3237. 	if (ANGRY(shkp)) 3238. 		pline("%s mentions how much %s dislikes %s customers.", 3239. 			shkname(shkp), he[shkp->female],  3240. 			eshk->robbed ? "non-paying" : "rude"); 3241. 	else if (eshk->following) { 3242. 		if (strncmp(eshk->customer, plname, PL_NSIZ)) { 3243. 		   verbalize("Hello %s!  I was looking for %s.",  3244. 			    plname, eshk->customer); 3245. 		   eshk->following = 0; 3246. 		} else { 3247. 		   verbalize("Hello %s!  Didn't you forget to pay?", plname); 3248. 		} 3249. 	} else if (eshk->billct) { 3250. 		register long total = addupbill(shkp) + eshk->debit; 3251. 		pline("%s says that your bill comes to %ld zorkmid%s.", 3252. 		      shkname(shkp), total, plur(total)); 3253. 	} else if (eshk->debit) 3254. 		pline("%s reminds you that you owe %s %ld zorkmid%s.", 3255. 		      shkname(shkp), him[shkp->female],  3256. 		      eshk->debit, plur(eshk->debit)); 3257. 	else if (eshk->credit) 3258. 		pline("%s encourages you to use your %ld zorkmid%s of credit.", 3259. 		      shkname(shkp), eshk->credit, plur(eshk->credit)); 3260. 	else if (eshk->robbed) 3261. 		pline("%s complains about a recent robbery.", shkname(shkp)); 3262. 	else if (shkp->mgold < 50) 3263. 		pline("%s complains that business is bad.", shkname(shkp)); 3264. 	else if (shkp->mgold > 4000) 3265. 		pline("%s says that business is good.", shkname(shkp)); 3266. 	else if (strcmp(shkname(shkp), "Izchak") == 0) 3267. 		pline(Izchak_speaks[rn2(SIZE(Izchak_speaks))],shkname(shkp)); 3268. 	else 3269. 		pline("%s talks about the problem of shoplifters.",shkname(shkp)); 3270. } 3271.  3272. #ifdef KOPS 3273. STATIC_OVL void 3274. kops_gone(silent) 3275. register boolean silent; 3276. { 3277. 	register int cnt = 0; 3278. 	register struct monst *mtmp, *mtmp2; 3279. 3280. 	for (mtmp = fmon; mtmp; mtmp = mtmp2) { 3281. 	   mtmp2 = mtmp->nmon; 3282. 	   if (mtmp->data->mlet == S_KOP) { 3283. 		if (canspotmon(mtmp)) cnt++; 3284. 		mongone(mtmp); 3285. 	   }  3286. 	}  3287. 	if (cnt && !silent) 3288. 	   pline_The("Kop%s (disappointed) vanish%s into thin air.",  3289. 		      plur(cnt), cnt == 1 ? "es" : ""); 3290. } 3291. #endif	/* KOPS */ 3292. 3293. #endif /*OVLB*/ 3294. #ifdef OVL3 3295. 3296. STATIC_OVL long 3297. cost_per_charge(shkp, otmp) 3298. struct monst *shkp; 3299. struct obj *otmp; 3300. { 3301. 	long tmp = 0L; 3302. 3303. 	if(!shkp || !inhishop(shkp)) return(0L); /* insurance */ 3304. 	tmp = get_cost(otmp, shkp); 3305. 3306. 	/* The idea is to make the exhaustive use of */ 3307. 	/* an unpaid item more expensive than buying */ 3308. 	/* it outright. */ 3309. 	if(otmp->otyp == MAGIC_LAMP) {			 /* 1 */ 3310. 		tmp += tmp / 3L; 3311. 	} else if(otmp->otyp == MAGIC_MARKER) {		 /* 70 - 100 */ 3312. 		/* no way to determine in advance  */ 3313. 		/* how many charges will be wasted. */ 3314. 		/* so, arbitrarily, one half of the */ 3315. 		/* price per use. */ 3316. 		tmp /= 2L; 3317. 	} else if(otmp->otyp == BAG_OF_TRICKS ||	 /* 1 - 20 */ 3318. 		  otmp->otyp == HORN_OF_PLENTY) { 3319. 		tmp /= 5L; 3320. 	} else if(otmp->otyp == CRYSTAL_BALL ||		 /* 1 - 5 */ 3321. 		  otmp->otyp == OIL_LAMP ||		 /* 1 - 10 */  3322. 		  otmp->otyp == BRASS_LANTERN ||  3323. 		 (otmp->otyp >= MAGIC_FLUTE && 3324. 		 otmp->otyp <= DRUM_OF_EARTHQUAKE) ||	 /* 5 - 9 */  3325. 		  otmp->oclass == WAND_CLASS) {		 /* 3 - 11 */ 3326. 		   if (otmp->spe > 1) tmp /= 4L; 3327. 	} else if (otmp->oclass == SPBOOK_CLASS) { 3328. 		   tmp -= tmp / 5L; 3329. 	} else if (otmp->otyp == CAN_OF_GREASE) { 3330. 		   tmp /= 10L; 3331. 	} else if (otmp->otyp == POT_OIL) { 3332. 		   tmp /= 5L; 3333. 	} 3334. 	return(tmp); 3335. } 3336. #endif /*OVL3*/ 3337. #ifdef OVLB 3338. 3339. /* for using charges of unpaid objects */ 3340. void 3341. check_unpaid(otmp) 3342. register struct obj *otmp; 3343. { 3344. 	struct monst *shkp; 3345. 	const char *fmt, *arg1, *arg2; 3346. 	long tmp; 3347. 3348. 	if (!otmp->unpaid || !*u.ushops ||  3349. 		(otmp->spe <= 0 && objects[otmp->otyp].oc_charged)) 3350. 	   return; 3351. 	if (!(shkp = shop_keeper(*u.ushops)) || !inhishop(shkp) || 3352. 		(tmp = cost_per_charge(shkp, otmp)) == 0L) 3353. 	   return; 3354. 3355. 	arg1 = arg2 = ""; 3356. 	if (otmp->oclass == SPBOOK_CLASS) { 3357. 	   fmt = "%sYou owe%s %ld zorkmids."; 3358. 	   arg1 = rn2(2) ? "This is no free library, cad! " : ""; 3359. 	   arg2 = ESHK(shkp)->debit > 0L ? " an additional" : ""; 3360. 	} else if (otmp->otyp == POT_OIL) { 3361. 	   fmt = "%s%sThat will cost you %ld zorkmids (Yendorian Fuel Tax)."; 3362. 	} else { 3363. 	   fmt = "%s%sUsage fee, %ld zorkmids."; 3364. 	   if (!rn2(3)) arg1 = "Hey!  "; 3365. 	   if (!rn2(3)) arg2 = "Ahem.  "; 3366. 	} 3367.  3368. 	if (shkp->mcanmove || !shkp->msleep) 3369. 	   verbalize(fmt, arg1, arg2, tmp); 3370. 	ESHK(shkp)->debit += tmp; 3371. 	exercise(A_WIS, TRUE);		/* you just got info */ 3372. } 3373.  3374. void 3375. costly_gold(x, y, amount) 3376. register xchar x, y; 3377. register long amount; 3378. { 3379. 	register long delta; 3380. 	register struct monst *shkp; 3381. 	register struct eshk *eshkp; 3382. 3383. 	if(!costly_spot(x, y)) return; 3384. 	/* shkp now guaranteed to exist by costly_spot */ 3385. 	shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); 3386. 3387. 	eshkp = ESHK(shkp); 3388. 	if(eshkp->credit >= amount) { 3389. 	   if(eshkp->credit > amount) 3390. 		Your("credit is reduced by %ld zorkmid%s.", 3391. 					amount, plur(amount)); 3392. 	   else Your("credit is erased."); 3393. 	   eshkp->credit -= amount; 3394. 	} else { 3395. 	   delta = amount - eshkp->credit; 3396. 	   if(eshkp->credit) 3397. 		Your("credit is erased."); 3398. 	   if(eshkp->debit) 3399. 		Your("debt increases by %ld zorkmid%s.", 3400. 					delta, plur(delta)); 3401. 	   else You("owe %s %ld zorkmid%s.",  3402. 				shkname(shkp), delta, plur(delta)); 3403. 	   eshkp->debit += delta; 3404. 	   eshkp->loan += delta; 3405. 	   eshkp->credit = 0L; 3406. 	} 3407. }  3408.  3409. /* used in domove to block diagonal shop-exit */ 3410. /* x,y should always be a door */ 3411. boolean 3412. block_door(x,y) 3413. register xchar x, y; 3414. { 3415. 	register int roomno = *in_rooms(x, y, SHOPBASE); 3416. 	register struct monst *shkp; 3417. 3418. 	if(roomno < 0 || !IS_SHOP(roomno)) return(FALSE); 3419. 	if(!IS_DOOR(levl[x][y].typ)) return(FALSE); 3420. 	if(roomno != *u.ushops) return(FALSE); 3421. 3422. 	if(!(shkp = shop_keeper((char)roomno)) || !inhishop(shkp)) 3423. 		return(FALSE); 3424. 3425. 	if(shkp->mx == ESHK(shkp)->shk.x && shkp->my == ESHK(shkp)->shk.y  3426. 	    /* Actually, the shk should be made to block _any_  3427. 	     * door, including a door the player digs, if the  3428. 	     * shk is within a 'jumping' distance.  3429. 	     */  3430. 	    && ESHK(shkp)->shd.x == x && ESHK(shkp)->shd.y == y  3431. 	    && shkp->mcanmove && !shkp->msleep  3432. 	    && (ESHK(shkp)->debit || ESHK(shkp)->billct || 3433. 		ESHK(shkp)->robbed)) { 3434. 		pline("%s%s blocks your way!", shkname(shkp), 3435. 				Invis ? " senses your motion and" : ""); 3436. 		return(TRUE); 3437. 	} 3438. 	return(FALSE); 3439. } 3440.  3441. /* used in domove to block diagonal shop-entry */ 3442. /* u.ux, u.uy should always be a door */ 3443. boolean 3444. block_entry(x,y) 3445. register xchar x, y; 3446. { 3447. 	register xchar sx, sy; 3448. 	register int roomno; 3449. 	register struct monst *shkp; 3450. 3451. 	if(!(IS_DOOR(levl[u.ux][u.uy].typ) && 3452. 		levl[u.ux][u.uy].doormask == D_BROKEN)) return(FALSE); 3453. 3454. 	roomno = *in_rooms(x, y, SHOPBASE); 3455. 	if(roomno < 0 || !IS_SHOP(roomno)) return(FALSE); 3456. 	if(!(shkp = shop_keeper((char)roomno)) || !inhishop(shkp)) 3457. 		return(FALSE); 3458. 3459. 	if(ESHK(shkp)->shd.x != u.ux || ESHK(shkp)->shd.y != u.uy) 3460. 		return(FALSE); 3461. 3462. 	sx = ESHK(shkp)->shk.x;  3463. sy = ESHK(shkp)->shk.y; 3464. 3465. 	if(shkp->mx == sx && shkp->my == sy 3466. 		&& shkp->mcanmove && !shkp->msleep  3467. 		&& (x == sx-1 || x == sx+1 || y == sy-1 || y == sy+1)  3468. 		&& (Invis || carrying(PICK_AXE))  3469. 	  ) { 3470. 		pline("%s%s blocks your way!", shkname(shkp), 3471. 				Invis ? " senses your motion and" : ""); 3472. 		return(TRUE); 3473. 	} 3474. 	return(FALSE); 3475. } 3476.  3477. #endif /* OVLB */ 3478. #ifdef OVL2 3479. 3480. char * 3481. shk_your(buf, obj) 3482. char *buf; 3483. struct obj *obj; 3484. { 3485. 	if (!shk_owns(buf, obj) && !mon_owns(buf, obj)) 3486. 	   Strcpy(buf, obj->where == OBJ_INVENT ? "your" : "the"); 3487. 	return buf; 3488. } 3489.  3490. char * 3491. Shk_Your(buf, obj) 3492. char *buf; 3493. struct obj *obj; 3494. { 3495. 	(void) shk_your(buf, obj); 3496. 	*buf = highc(*buf); 3497. 	return buf; 3498. } 3499.  3500. STATIC_OVL char * 3501. shk_owns(buf, obj) 3502. char *buf; 3503. struct obj *obj; 3504. { 3505. 	struct monst *shkp; 3506. 	xchar x, y; 3507. 3508. 	if (get_obj_location(obj, &x, &y, 0) && 3509. 	    (obj->unpaid || 3510. 	    (obj->where==OBJ_FLOOR && !obj->no_charge && costly_spot(x,y)))) { 3511. 	   shkp = shop_keeper(inside_shop(x, y)); 3512. 	   return strcpy(buf, shkp ? s_suffix(shkname(shkp)) : "the"); 3513. 	} 3514. 	return (char *)0; 3515. } 3516.  3517. STATIC_OVL char * 3518. mon_owns(buf, obj) 3519. char *buf; 3520. struct obj *obj; 3521. { 3522. 	if (obj->where == OBJ_MINVENT) 3523. 	   return strcpy(buf, s_suffix(mon_nam(obj->ocarry))); 3524. 	return (char *)0; 3525. } 3526.  3527. #endif /* OVL2 */ 3528. #ifdef OVLB 3529. 3530. #ifdef __SASC 3531. void 3532. sasc_bug(struct obj *op, unsigned x){ 3533. 	op->unpaid=x; 3534. } 3535. #endif 3536. 3537. #endif /* OVLB */ 3538. 3539. /*shk.c*/