Source:NetHack 3.4.3/src/shk.c

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

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

Top of file[edit]

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

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1. #include "hack.h"
  2. #include "eshk.h"
  3.  
  4. /*#define DEBUG*/
  5.  
  6. #define PAY_SOME    2
  7. #define PAY_BUY     1
  8. #define PAY_CANT    0	/* too poor */
  9. #define PAY_SKIP  (-1)
  10. #define PAY_BROKE (-2)
  11.  
  12. #ifdef KOPS
  13. STATIC_DCL void FDECL(makekops, (coord *));
  14. STATIC_DCL void FDECL(call_kops, (struct monst *,BOOLEAN_P));
  15. # ifdef OVLB
  16. STATIC_DCL void FDECL(kops_gone, (BOOLEAN_P));
  17. # endif /* OVLB */
  18. #endif /* KOPS */
  19.  
  20. #define IS_SHOP(x)	(rooms[x].rtype >= SHOPBASE)
  21.  
  22. extern const struct shclass shtypes[];	/* defined in shknam.c */
  23. extern struct obj *thrownobj;		/* defined in dothrow.c */
  24.  
  25. STATIC_VAR NEARDATA long int followmsg;	/* last time of follow message */
  26.  
  27. STATIC_DCL void FDECL(setpaid, (struct monst *));
  28. STATIC_DCL long FDECL(addupbill, (struct monst *));
  29. STATIC_DCL void FDECL(pacify_shk, (struct monst *));
  30. STATIC_DCL struct bill_x *FDECL(onbill, (struct obj *, struct monst *, BOOLEAN_P));
  31. STATIC_DCL struct monst *FDECL(next_shkp, (struct monst *, BOOLEAN_P));
  32. STATIC_DCL long FDECL(shop_debt, (struct eshk *));
  33. STATIC_DCL char *FDECL(shk_owns, (char *,struct obj *));
  34. STATIC_DCL char *FDECL(mon_owns, (char *,struct obj *));
  35. STATIC_DCL void FDECL(clear_unpaid,(struct obj *));
  36. STATIC_DCL long FDECL(check_credit, (long, struct monst *));
  37. STATIC_DCL void FDECL(pay, (long, struct monst *));
  38. STATIC_DCL long FDECL(get_cost, (struct obj *, struct monst *));
  39. STATIC_DCL long FDECL(set_cost, (struct obj *, struct monst *));
  40. STATIC_DCL const char *FDECL(shk_embellish, (struct obj *, long));
  41. STATIC_DCL long FDECL(cost_per_charge, (struct monst *,struct obj *,BOOLEAN_P));
  42. STATIC_DCL long FDECL(cheapest_item, (struct monst *));
  43. STATIC_DCL int FDECL(dopayobj, (struct monst *, struct bill_x *,
  44. 			    struct obj **, int, BOOLEAN_P));
  45. STATIC_DCL long FDECL(stolen_container, (struct obj *, struct monst *, long,
  46. 				     BOOLEAN_P));
  47. STATIC_DCL long FDECL(getprice, (struct obj *,BOOLEAN_P));
  48. STATIC_DCL void FDECL(shk_names_obj,
  49. 		 (struct monst *,struct obj *,const char *,long,const char *));
  50. STATIC_DCL struct obj *FDECL(bp_to_obj, (struct bill_x *));
  51. STATIC_DCL boolean FDECL(inherits, (struct monst *,int,int));
  52. STATIC_DCL void FDECL(set_repo_loc, (struct eshk *));
  53. STATIC_DCL boolean NDECL(angry_shk_exists);
  54. STATIC_DCL void FDECL(rile_shk, (struct monst *));
  55. STATIC_DCL void FDECL(rouse_shk, (struct monst *,BOOLEAN_P));
  56. STATIC_DCL void FDECL(remove_damage, (struct monst *, BOOLEAN_P));
  57. STATIC_DCL void FDECL(sub_one_frombill, (struct obj *, struct monst *));
  58. STATIC_DCL void FDECL(add_one_tobill, (struct obj *, BOOLEAN_P));
  59. STATIC_DCL void FDECL(dropped_container, (struct obj *, struct monst *,
  60. 				      BOOLEAN_P));
  61. STATIC_DCL void FDECL(add_to_billobjs, (struct obj *));
  62. STATIC_DCL void FDECL(bill_box_content, (struct obj *, BOOLEAN_P, BOOLEAN_P,
  63. 				     struct monst *));
  64. #ifdef OVL1
  65. static boolean FDECL(rob_shop, (struct monst *));
  66. #endif

money2mon[edit]

  1. #ifdef OVLB
  2. /*
  3. 	invariants: obj->unpaid iff onbill(obj) [unless bp->useup]
  4. 		obj->quan <= bp->bquan
  5. */
  6.  
  7.  
  8. #ifdef GOLDOBJ
  9. /*
  10. Transfer money from inventory to monster when paying
  11. shopkeepers, priests, oracle, succubus, & other demons.
  12. Simple with only gold coins.
  13. This routine will handle money changing when multiple
  14. coin types is implemented, only appropriate
  15. monsters will pay change.  (Peaceful shopkeepers, priests
  16. & the oracle try to maintain goodwill while selling
  17. their wares or services.  Angry monsters and all demons
  18. will keep anything they get their hands on.
  19. Returns the amount actually paid, so we can know
  20. if the monster kept the change.
  21. */
  22. long
  23. money2mon(mon, amount)
  24. struct monst *mon;
  25. long amount;
  26. {
  27. struct obj *ygold = findgold(invent);
  28.  
  29. if (amount <= 0) {
  30. 	impossible("%s payment in money2mon!", amount ? "negative" : "zero");
  31. 	return 0L;
  32. }
  33. if (!ygold || ygold->quan < amount) {
  34. 	impossible("Paying without %s money?", ygold ? "enough" : "");
  35. 	return 0L;
  36. }
  37.  
  38. if (ygold->quan > amount)
  39. 	ygold = splitobj(ygold, amount);
  40. else if (ygold->owornmask)
  41. 	remove_worn_item(ygold, FALSE);		/* quiver */
  42. freeinv(ygold);
  43. add_to_minv(mon, ygold);
  44. flags.botl = 1;
  45. return amount;
  46. }

money2u[edit]

  1. /*
  2. Transfer money from monster to inventory.
  3. Used when the shopkeeper pay for items, and when
  4. the priest gives you money for an ale.
  5. */
  6. void
  7. money2u(mon, amount)
  8. struct monst *mon;
  9. long amount;
  10. {
  11. struct obj *mongold = findgold(mon->minvent);
  12.  
  13. if (amount <= 0) {
  14. 	impossible("%s payment in money2u!", amount ? "negative" : "zero");
  15. 	return;
  16. }
  17. if (!mongold || mongold->quan < amount) {
  18. 	impossible("%s paying without %s money?", a_monnam(mon),
  19. 		   mongold ? "enough" : "");
  20. 	return;
  21. }
  22.  
  23. if (mongold->quan > amount) mongold = splitobj(mongold, amount);
  24. obj_extract_self(mongold);
  25.  
  26. if (!merge_choice(invent, mongold) && inv_cnt() >= 52) {
  27. 	You("have no room for the money!");
  28. 	dropy(mongold);
  29. } else {
  30. 	addinv(mongold);
  31. 	flags.botl = 1;
  32. }
  33. }
  34.  
  35. #endif /* GOLDOBJ */

next_shkp[edit]

  1. STATIC_OVL struct monst *
  2. next_shkp(shkp, withbill)
  3. register struct monst *shkp;
  4. register boolean withbill;
  5. {
  6. 	for (; shkp; shkp = shkp->nmon) {
  7. 	    if (DEADMONSTER(shkp)) continue;
  8. 	    if (shkp->isshk && (ESHK(shkp)->billct || !withbill)) break;
  9. 	}
  10.  
  11. 	if (shkp) {
  12. 	    if (NOTANGRY(shkp)) {
  13. 		if (ESHK(shkp)->surcharge) pacify_shk(shkp);
  14. 	    } else {
  15. 		if (!ESHK(shkp)->surcharge) rile_shk(shkp);
  16. 	    }
  17. 	}
  18. 	return(shkp);
  19. }

shkname[edit]

  1. char *
  2. shkname(mtmp)				/* called in do_name.c */
  3. register struct monst *mtmp;
  4. {
  5. 	return(ESHK(mtmp)->shknam);
  6. }

shkgone[edit]

  1. void
  2. shkgone(mtmp)				/* called in mon.c */
  3. struct monst *mtmp;
  4. {
  5. 	struct eshk *eshk = ESHK(mtmp);
  6. 	struct mkroom *sroom = &rooms[eshk->shoproom - ROOMOFFSET];
  7. 	struct obj *otmp;
  8. 	char *p;
  9. 	int sx, sy;
  10.  
  11. 	/* [BUG: some of this should be done on the shop level */
  12. 	/*       even when the shk dies on a different level.] */
  13. 	if (on_level(&eshk->shoplevel, &u.uz)) {
  14. 	    remove_damage(mtmp, TRUE);
  15. 	    sroom->resident = (struct monst *)0;
  16. 	    if (!search_special(ANY_SHOP))
  17. 		level.flags.has_shop = 0;
  18.  
  19. 	    /* items on shop floor revert to ordinary objects */
  20. 	    for (sx = sroom->lx; sx <= sroom->hx; sx++)
  21. 	      for (sy = sroom->ly; sy <= sroom->hy; sy++)
  22. 		for (otmp = level.objects[sx][sy]; otmp; otmp = otmp->nexthere)
  23. 		    otmp->no_charge = 0;
  24.  
  25. 	    /* Make sure bill is set only when the
  26. 	       dead shk is the resident shk. */
  27. 	    if ((p = index(u.ushops, eshk->shoproom)) != 0) {
  28. 		setpaid(mtmp);
  29. 		eshk->bill_p = (struct bill_x *)0;
  30. 		/* remove eshk->shoproom from u.ushops */
  31. 		do { *p = *(p + 1); } while (*++p);
  32. 	    }
  33. 	}
  34. }

set_residency[edit]

  1. void
  2. set_residency(shkp, zero_out)
  3. register struct monst *shkp;
  4. register boolean zero_out;
  5. {
  6. 	if (on_level(&(ESHK(shkp)->shoplevel), &u.uz))
  7. 	    rooms[ESHK(shkp)->shoproom - ROOMOFFSET].resident =
  8. 		(zero_out)? (struct monst *)0 : shkp;
  9. }

replshk[edit]

  1. void
  2. replshk(mtmp,mtmp2)
  3. register struct monst *mtmp, *mtmp2;
  4. {
  5. 	rooms[ESHK(mtmp2)->shoproom - ROOMOFFSET].resident = mtmp2;
  6. 	if (inhishop(mtmp) && *u.ushops == ESHK(mtmp)->shoproom) {
  7. 		ESHK(mtmp2)->bill_p = &(ESHK(mtmp2)->bill[0]);
  8. 	}
  9. }

restshk[edit]

  1. /* do shopkeeper specific structure munging -dlc */
  2. void
  3. restshk(shkp, ghostly)
  4. struct monst *shkp;
  5. boolean ghostly;
  6. {
  7. if (u.uz.dlevel) {
  8. 	struct eshk *eshkp = ESHK(shkp);
  9.  
  10. 	if (eshkp->bill_p != (struct bill_x *) -1000)
  11. 	    eshkp->bill_p = &eshkp->bill[0];
  12. 	/* shoplevel can change as dungeons move around */
  13. 	/* savebones guarantees that non-homed shk's will be gone */
  14. 	if (ghostly) {
  15. 	    assign_level(&eshkp->shoplevel, &u.uz);
  16. 	    if (ANGRY(shkp) && strncmpi(eshkp->customer, plname, PL_NSIZ))
  17. 		pacify_shk(shkp);
  18. 	}
  19. }
  20. }
  21.  
  22. #endif /* OVLB */

clear_unpaid[edit]

  1. #ifdef OVL3
  2.  
  3. /* Clear the unpaid bit on all of the objects in the list. */
  4. STATIC_OVL void
  5. clear_unpaid(list)
  6. register struct obj *list;
  7. {
  8. while (list) {
  9. 	if (Has_contents(list)) clear_unpaid(list->cobj);
  10. 	list->unpaid = 0;
  11. 	list = list->nobj;
  12. }
  13. }
  14. #endif /*OVL3*/

setpaid[edit]

  1. #ifdef OVLB
  2.  
  3. /* either you paid or left the shop or the shopkeeper died */
  4. STATIC_OVL void
  5. setpaid(shkp)
  6. register struct monst *shkp;
  7. {
  8. 	register struct obj *obj;
  9. 	register struct monst *mtmp;
  10.  
  11. 	/* FIXME: object handling should be limited to
  12. 	   items which are on this particular shk's bill */
  13.  
  14. 	clear_unpaid(invent);
  15. 	clear_unpaid(fobj);
  16. 	clear_unpaid(level.buriedobjlist);
  17. 	if (thrownobj) thrownobj->unpaid = 0;
  18. 	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  19. 		clear_unpaid(mtmp->minvent);
  20. 	for(mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon)
  21. 		clear_unpaid(mtmp->minvent);
  22.  
  23. 	while ((obj = billobjs) != 0) {
  24. 		obj_extract_self(obj);
  25. 		dealloc_obj(obj);
  26. 	}
  27. 	if(shkp) {
  28. 		ESHK(shkp)->billct = 0;
  29. 		ESHK(shkp)->credit = 0L;
  30. 		ESHK(shkp)->debit = 0L;
  31. 		ESHK(shkp)->loan = 0L;
  32. 	}
  33. }

addupbill[edit]

  1. STATIC_OVL long
  2. addupbill(shkp)
  3. register struct monst *shkp;
  4. {
  5. 	register int ct = ESHK(shkp)->billct;
  6. 	register struct bill_x *bp = ESHK(shkp)->bill_p;
  7. 	register long total = 0L;
  8.  
  9. 	while(ct--){
  10. 		total += bp->price * bp->bquan;
  11. 		bp++;
  12. 	}
  13. 	return(total);
  14. }
  15.  
  16. #endif /* OVLB */

call_kops[edit]

  1. #ifdef OVL1
  2.  
  3. #ifdef KOPS
  4. STATIC_OVL void
  5. call_kops(shkp, nearshop)
  6. register struct monst *shkp;
  7. register boolean nearshop;
  8. {
  9. 	/* Keystone Kops srt@ucla */
  10. 	register boolean nokops;
  11.  
  12. 	if(!shkp) return;
  13.  
  14. 	if (flags.soundok)
  15. 	    pline("An alarm sounds!");
  16.  
  17. 	nokops = ((mvitals[PM_KEYSTONE_KOP].mvflags & G_GONE) &&
  18. 		  (mvitals[PM_KOP_SERGEANT].mvflags & G_GONE) &&
  19. 		  (mvitals[PM_KOP_LIEUTENANT].mvflags & G_GONE) &&
  20. 		  (mvitals[PM_KOP_KAPTAIN].mvflags & G_GONE));
  21.  
  22. 	if(!angry_guards(!flags.soundok) && nokops) {
  23. 	    if(flags.verbose && flags.soundok)
  24. 		pline("But no one seems to respond to it.");
  25. 	    return;
  26. 	}
  27.  
  28. 	if(nokops) return;
  29.  
  30. 	{
  31. 	    coord mm;
  32.  
  33. 	    if (nearshop) {
  34. 		/* Create swarm around you, if you merely "stepped out" */
  35. 		if (flags.verbose)
  36. 		    pline_The("Keystone Kops appear!");
  37. 		mm.x = u.ux;
  38. 		mm.y = u.uy;
  39. 		makekops(&mm);
  40. 		return;
  41. 	    }
  42. 	    if (flags.verbose)
  43. 		 pline_The("Keystone Kops are after you!");
  44. 	    /* Create swarm near down staircase (hinders return to level) */
  45. 	    mm.x = xdnstair;
  46. 	    mm.y = ydnstair;
  47. 	    makekops(&mm);
  48. 	    /* Create swarm near shopkeeper (hinders return to shop) */
  49. 	    mm.x = shkp->mx;
  50. 	    mm.y = shkp->my;
  51. 	    makekops(&mm);
  52. 	}
  53. }
  54. #endif	/* KOPS */

inside_shop[edit]

  1. /* x,y is strictly inside shop */
  2. char
  3. inside_shop(x, y)
  4. register xchar x, y;
  5. {
  6. 	register char rno;
  7.  
  8. 	rno = levl[x][y].roomno;
  9. 	if ((rno < ROOMOFFSET) || levl[x][y].edge || !IS_SHOP(rno-ROOMOFFSET))
  10. 	    return(NO_ROOM);
  11. 	else
  12. 	    return(rno);
  13. }

u_left_shop[edit]

  1. void
  2. u_left_shop(leavestring, newlev)
  3. char *leavestring;
  4. boolean newlev;
  5. {
  6. 	struct monst *shkp;
  7. 	struct eshk *eshkp;
  8.  
  9. 	/*
  10. 	 * IF player
  11. 	 * ((didn't leave outright) AND
  12. 	 *  ((he is now strictly-inside the shop) OR
  13. 	 *   (he wasn't strictly-inside last turn anyway)))
  14. 	 * THEN (there's nothing to do, so just return)
  15. 	 */
  16. 	if(!*leavestring &&
  17. 	   (!levl[u.ux][u.uy].edge || levl[u.ux0][u.uy0].edge))
  18. 	    return;
  19.  
  20. 	shkp = shop_keeper(*u.ushops0);
  21. 	if (!shkp || !inhishop(shkp))
  22. 	    return;	/* shk died, teleported, changed levels... */
  23.  
  24. 	eshkp = ESHK(shkp);
  25. 	if (!eshkp->billct && !eshkp->debit)	/* bill is settled */
  26. 	    return;
  27.  
  28. 	if (!*leavestring && shkp->mcanmove && !shkp->msleeping) {
  29. 	    /*
  30. 	     * Player just stepped onto shop-boundary (known from above logic).
  31. 	     * Try to intimidate him into paying his bill
  32. 	     */
  33. 	    verbalize(NOTANGRY(shkp) ?
  34. 		      "%s!  Please pay before leaving." :
  35. 		      "%s!  Don't you leave without paying!",
  36. 		      plname);
  37. 	    return;
  38. 	}
  39.  
  40. 	if (rob_shop(shkp)) {
  41. #ifdef KOPS
  42. 	    call_kops(shkp, (!newlev && levl[u.ux0][u.uy0].edge));
  43. #else
  44. 	    (void) angry_guards(FALSE);
  45. #endif
  46. 	}
  47. }

remote_burglary[edit]

  1. /* robbery from outside the shop via telekinesis or grappling hook */
  2. void
  3. remote_burglary(x, y)
  4. xchar x, y;
  5. {
  6. 	struct monst *shkp;
  7. 	struct eshk *eshkp;
  8.  
  9. 	shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
  10. 	if (!shkp || !inhishop(shkp))
  11. 	    return;	/* shk died, teleported, changed levels... */
  12.  
  13. 	eshkp = ESHK(shkp);
  14. 	if (!eshkp->billct && !eshkp->debit)	/* bill is settled */
  15. 	    return;
  16.  
  17. 	if (rob_shop(shkp)) {
  18. #ifdef KOPS
  19. 	    /*[might want to set 2nd arg based on distance from shop doorway]*/
  20. 	    call_kops(shkp, FALSE);
  21. #else
  22. 	    (void) angry_guards(FALSE);
  23. #endif
  24. 	}
  25. }

rob_shop[edit]

  1. /* shop merchandise has been taken; pay for it with any credit available;  
  2. return false if the debt is fully covered by credit, true otherwise */
  3. static boolean
  4. rob_shop(shkp)
  5. struct monst *shkp;
  6. {
  7. 	struct eshk *eshkp;
  8. 	long total;
  9.  
  10. 	eshkp = ESHK(shkp);
  11. 	rouse_shk(shkp, TRUE);
  12. 	total = (addupbill(shkp) + eshkp->debit);
  13. 	if (eshkp->credit >= total) {
  14. 	    Your("credit of %ld %s is used to cover your shopping bill.",
  15. 		 eshkp->credit, currency(eshkp->credit));
  16. 	    total = 0L;		/* credit gets cleared by setpaid() */
  17. 	} else {
  18. 	    You("escaped the shop without paying!");
  19. 	    total -= eshkp->credit;
  20. 	}
  21. 	setpaid(shkp);
  22. 	if (!total) return FALSE;
  23.  
  24. 	/* by this point, we know an actual robbery has taken place */
  25. 	eshkp->robbed += total;
  26. 	You("stole %ld %s worth of merchandise.",
  27. 	    total, currency(total));
  28. 	if (!Role_if(PM_ROGUE))	/* stealing is unlawful */
  29. 	    adjalign(-sgn(u.ualign.type));
  30.  
  31. 	hot_pursuit(shkp);
  32. 	return TRUE;
  33. }

u_entered_shop[edit]

  1. void
  2. u_entered_shop(enterstring)
  3. register char *enterstring;
  4. {
  5.  
  6. 	register int rt;
  7. 	register struct monst *shkp;
  8. 	register struct eshk *eshkp;
  9. 	static const char no_shk[] = "This shop appears to be deserted.";
  10. 	static char empty_shops[5];
  11.  
  12. 	if(!*enterstring)
  13. 		return;
  14.  
  15. 	if(!(shkp = shop_keeper(*enterstring))) {
  16. 	    if (!index(empty_shops, *enterstring) &&
  17. 		in_rooms(u.ux, u.uy, SHOPBASE) !=
  18. 				  in_rooms(u.ux0, u.uy0, SHOPBASE))
  19. 		pline(no_shk);
  20. 	    Strcpy(empty_shops, u.ushops);
  21. 	    u.ushops[0] = '\0';
  22. 	    return;
  23. 	}
  24.  
  25. 	eshkp = ESHK(shkp);
  26.  
  27. 	if (!inhishop(shkp)) {
  28. 	    /* dump core when referenced */
  29. 	    eshkp->bill_p = (struct bill_x *) -1000;
  30. 	    if (!index(empty_shops, *enterstring))
  31. 		pline(no_shk);
  32. 	    Strcpy(empty_shops, u.ushops);
  33. 	    u.ushops[0] = '\0';
  34. 	    return;
  35. 	}
  36.  
  37. 	eshkp->bill_p = &(eshkp->bill[0]);
  38.  
  39. 	if ((!eshkp->visitct || *eshkp->customer) &&
  40. 	    strncmpi(eshkp->customer, plname, PL_NSIZ)) {
  41. 	    /* You seem to be new here */
  42. 	    eshkp->visitct = 0;
  43. 	    eshkp->following = 0;
  44. 	    (void) strncpy(eshkp->customer,plname,PL_NSIZ);
  45. 	    pacify_shk(shkp);
  46. 	}
  47.  
  48. 	if (shkp->msleeping || !shkp->mcanmove || eshkp->following)
  49. 	    return;	/* no dialog */
  50.  
  51. 	if (Invis) {
  52. 	    pline("%s senses your presence.", shkname(shkp));
  53. 	    verbalize("Invisible customers are not welcome!");
  54. 	    return;
  55. 	}
  56.  
  57. 	rt = rooms[*enterstring - ROOMOFFSET].rtype;
  58.  
  59. 	if (ANGRY(shkp)) {
  60. 	    verbalize("So, %s, you dare return to %s %s?!",
  61. 		      plname,
  62. 		      s_suffix(shkname(shkp)),
  63. 		      shtypes[rt - SHOPBASE].name);
  64. 	} else if (eshkp->robbed) {
  65. 	    pline("%s mutters imprecations against shoplifters.", shkname(shkp));
  66. 	} else {
  67. 	    verbalize("%s, %s!  Welcome%s to %s %s!",
  68. 		      Hello(shkp), plname,
  69. 		      eshkp->visitct++ ? " again" : "",
  70. 		      s_suffix(shkname(shkp)),
  71. 		      shtypes[rt - SHOPBASE].name);
  72. 	}
  73. 	/* can't do anything about blocking if teleported in */
  74. 	if (!inside_shop(u.ux, u.uy)) {
  75. 	    boolean should_block;
  76. 	    int cnt;
  77. 	    const char *tool;
  78. 	    struct obj *pick = carrying(PICK_AXE),
  79. 		       *mattock = carrying(DWARVISH_MATTOCK);
  80.  
  81. 	    if (pick || mattock) {
  82. 		cnt = 1;	/* so far */
  83. 		if (pick && mattock) {	/* carrying both types */
  84. 		    tool = "digging tool";
  85. 		    cnt = 2;	/* `more than 1' is all that matters */
  86. 		} else if (pick) {
  87. 		    tool = "pick-axe";
  88. 		    /* hack: `pick' already points somewhere into inventory */
  89. 		    while ((pick = pick->nobj) != 0)
  90. 			if (pick->otyp == PICK_AXE) ++cnt;
  91. 		} else {	/* assert(mattock != 0) */
  92. 		    tool = "mattock";
  93. 		    while ((mattock = mattock->nobj) != 0)
  94. 			if (mattock->otyp == DWARVISH_MATTOCK) ++cnt;
  95. 		    /* [ALI] Shopkeeper identifies mattock(s) */
  96. 		    if (!Blind) makeknown(DWARVISH_MATTOCK);
  97. 		}
  98. 		verbalize(NOTANGRY(shkp) ?
  99. 			  "Will you please leave your %s%s outside?" :
  100. 			  "Leave the %s%s outside.",
  101. 			  tool, plur(cnt));
  102. 		should_block = TRUE;
  103. #ifdef STEED
  104. 	    } else if (u.usteed) {
  105. 		verbalize(NOTANGRY(shkp) ?
  106. 			  "Will you please leave %s outside?" :
  107. 			  "Leave %s outside.", y_monnam(u.usteed));
  108. 		should_block = TRUE;
  109. #endif
  110. 	    } else {
  111. 		should_block = (Fast && (sobj_at(PICK_AXE, u.ux, u.uy) ||
  112. 				      sobj_at(DWARVISH_MATTOCK, u.ux, u.uy)));
  113. 	    }
  114. 	    if (should_block) (void) dochug(shkp);  /* shk gets extra move */
  115. 	}
  116. 	return;
  117. }

same_price[edit]

  1. /*
  2. Decide whether two unpaid items are mergable; caller is responsible for
  3. making sure they're unpaid and the same type of object; we check the price
  4. quoted by the shopkeeper and also that they both belong to the same shk.
  5. */
  6. boolean
  7. same_price(obj1, obj2)
  8. struct obj *obj1, *obj2;
  9. {
  10. 	register struct monst *shkp1, *shkp2;
  11. 	register struct bill_x *bp1 = 0, *bp2 = 0;
  12. 	register boolean are_mergable = FALSE;
  13.  
  14. 	/* look up the first object by finding shk whose bill it's on */
  15. 	for (shkp1 = next_shkp(fmon, TRUE); shkp1;
  16. 		shkp1 = next_shkp(shkp1->nmon, TRUE))
  17. 	    if ((bp1 = onbill(obj1, shkp1, TRUE)) != 0) break;
  18. 	/* second object is probably owned by same shk; if not, look harder */
  19. 	if (shkp1 && (bp2 = onbill(obj2, shkp1, TRUE)) != 0) {
  20. 	    shkp2 = shkp1;
  21. 	} else {
  22. 	    for (shkp2 = next_shkp(fmon, TRUE); shkp2;
  23. 		    shkp2 = next_shkp(shkp2->nmon, TRUE))
  24. 		if ((bp2 = onbill(obj2, shkp2, TRUE)) != 0) break;
  25. 	}
  26.  
  27. 	if (!bp1 || !bp2) impossible("same_price: object wasn't on any bill!");
  28. 	else are_mergable = (shkp1 == shkp2 && bp1->price == bp2->price);
  29. 	return are_mergable;
  30. }

shop_debt[edit]

  1. /*
  2. * Figure out how much is owed to a given shopkeeper.
  3. * At present, we ignore any amount robbed from the shop, to avoid
  4. * turning the `$' command into a way to discover that the current
  5. * level is bones data which has a shk on the warpath.
  6. */
  7. STATIC_OVL long
  8. shop_debt(eshkp)
  9. struct eshk *eshkp;
  10. {
  11. 	struct bill_x *bp;
  12. 	int ct;
  13. 	long debt = eshkp->debit;
  14.  
  15. 	for (bp = eshkp->bill_p, ct = eshkp->billct; ct > 0; bp++, ct--)
  16. 	    debt += bp->price * bp->bquan;
  17. 	return debt;
  18. }

shopper_financial_report[edit]

  1. /* called in response to the `$' command */
  2. void
  3. shopper_financial_report()
  4. {
  5. 	struct monst *shkp, *this_shkp = shop_keeper(inside_shop(u.ux, u.uy));
  6. 	struct eshk *eshkp;
  7. 	long amt;
  8. 	int pass;
  9.  
  10. 	if (this_shkp &&
  11. 	    !(ESHK(this_shkp)->credit || shop_debt(ESHK(this_shkp)))) {
  12. 	    You("have no credit or debt in here.");
  13. 	    this_shkp = 0;	/* skip first pass */
  14. 	}
  15.  
  16. 	/* pass 0: report for the shop we're currently in, if any;
  17. 	   pass 1: report for all other shops on this level. */
  18. 	for (pass = this_shkp ? 0 : 1; pass <= 1; pass++)
  19. 	    for (shkp = next_shkp(fmon, FALSE);
  20. 		    shkp; shkp = next_shkp(shkp->nmon, FALSE)) {
  21. 		if ((shkp != this_shkp) ^ pass) continue;
  22. 		eshkp = ESHK(shkp);
  23. 		if ((amt = eshkp->credit) != 0)
  24. 		    You("have %ld %s credit at %s %s.",
  25. 			amt, currency(amt), s_suffix(shkname(shkp)),
  26. 			shtypes[eshkp->shoptype - SHOPBASE].name);
  27. 		else if (shkp == this_shkp)
  28. 		    You("have no credit in here.");
  29. 		if ((amt = shop_debt(eshkp)) != 0)
  30. 		    You("owe %s %ld %s.",
  31. 			shkname(shkp), amt, currency(amt));
  32. 		else if (shkp == this_shkp)
  33. 		    You("don't owe any money here.");
  34. 	    }
  35. }
  36.  
  37. #endif /* OVL1 */

inhishop[edit]

  1. #ifdef OVLB
  2.  
  3. int
  4. inhishop(mtmp)
  5. register struct monst *mtmp;
  6. {
  7. 	return(index(in_rooms(mtmp->mx, mtmp->my, SHOPBASE),
  8. 		     ESHK(mtmp)->shoproom) &&
  9. 		on_level(&(ESHK(mtmp)->shoplevel), &u.uz));
  10. }

shop_keeper[edit]

  1. struct monst *
  2. shop_keeper(rmno)
  3. register char rmno;
  4. {
  5. 	struct monst *shkp = rmno >= ROOMOFFSET ?
  6. 				rooms[rmno - ROOMOFFSET].resident : 0;
  7.  
  8. 	if (shkp) {
  9. 	    if (NOTANGRY(shkp)) {
  10. 		if (ESHK(shkp)->surcharge) pacify_shk(shkp);
  11. 	    } else {
  12. 		if (!ESHK(shkp)->surcharge) rile_shk(shkp);
  13. 	    }
  14. 	}
  15. 	return shkp;
  16. }

tended_shop[edit]

  1. boolean
  2. tended_shop(sroom)
  3. register struct mkroom *sroom;
  4. {
  5. 	register struct monst *mtmp = sroom->resident;
  6.  
  7. 	if (!mtmp)
  8. 		return(FALSE);
  9. 	else
  10. 		return((boolean)(inhishop(mtmp)));
  11. }

onbill[edit]

  1. STATIC_OVL struct bill_x *
  2. onbill(obj, shkp, silent)
  3. register struct obj *obj;
  4. register struct monst *shkp;
  5. register boolean silent;
  6. {
  7. 	if (shkp) {
  8. 		register struct bill_x *bp = ESHK(shkp)->bill_p;
  9. 		register int ct = ESHK(shkp)->billct;
  10.  
  11. 		while (--ct >= 0)
  12. 		    if (bp->bo_id == obj->o_id) {
  13. 			if (!obj->unpaid) pline("onbill: paid obj on bill?");
  14. 			return bp;
  15. 		    } else bp++;
  16. 	}
  17. 	if(obj->unpaid & !silent) pline("onbill: unpaid obj not on bill?");
  18. 	return (struct bill_x *)0;
  19. }

delete_contents[edit]

  1. /* Delete the contents of the given object. */
  2. void
  3. delete_contents(obj)
  4. register struct obj *obj;
  5. {
  6. 	register struct obj *curr;
  7.  
  8. 	while ((curr = obj->cobj) != 0) {
  9. 	    obj_extract_self(curr);
  10. 	    obfree(curr, (struct obj *)0);
  11. 	}
  12. }

obfree[edit]

  1. /* called with two args on merge */
  2. void
  3. obfree(obj, merge)
  4. register struct obj *obj, *merge;
  5. {
  6. 	register struct bill_x *bp;
  7. 	register struct bill_x *bpm;
  8. 	register struct monst *shkp;
  9.  
  10. 	if (obj->otyp == LEASH && obj->leashmon) o_unleash(obj);
  11. 	if (obj->oclass == FOOD_CLASS) food_disappears(obj);
  12. 	if (obj->oclass == SPBOOK_CLASS) book_disappears(obj);
  13. 	if (Has_contents(obj)) delete_contents(obj);
  14.  
  15. 	shkp = 0;
  16. 	if (obj->unpaid) {
  17. 	    /* look for a shopkeeper who owns this object */
  18. 	    for (shkp = next_shkp(fmon, TRUE); shkp;
  19. 		    shkp = next_shkp(shkp->nmon, TRUE))
  20. 		if (onbill(obj, shkp, TRUE)) break;
  21. 	}
  22. 	/* sanity check, more or less */
  23. 	if (!shkp) shkp = shop_keeper(*u.ushops);
  24. 		/*
  25. 		 * Note:  `shkp = shop_keeper(*u.ushops)' used to be
  26. 		 *	  unconditional.  But obfree() is used all over
  27. 		 *	  the place, so making its behavior be dependent
  28. 		 *	  upon player location doesn't make much sense.
  29. 		 */
  30.  
  31. 	if ((bp = onbill(obj, shkp, FALSE)) != 0) {
  32. 		if(!merge){
  33. 			bp->useup = 1;
  34. 			obj->unpaid = 0;	/* only for doinvbill */
  35. 			add_to_billobjs(obj);
  36. 			return;
  37. 		}
  38. 		bpm = onbill(merge, shkp, FALSE);
  39. 		if(!bpm){
  40. 			/* this used to be a rename */
  41. 			impossible("obfree: not on bill??");
  42. 			return;
  43. 		} else {
  44. 			/* this was a merger */
  45. 			bpm->bquan += bp->bquan;
  46. 			ESHK(shkp)->billct--;
  47. #ifdef DUMB
  48. 			{
  49. 			/* DRS/NS 2.2.6 messes up -- Peter Kendell */
  50. 				int indx = ESHK(shkp)->billct;
  51. 				*bp = ESHK(shkp)->bill_p[indx];
  52. 			}
  53. #else
  54. 			*bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct];
  55. #endif
  56. 		}
  57. 	}
  58. 	dealloc_obj(obj);
  59. }
  60. #endif /* OVLB */

check_credit[edit]

  1. #ifdef OVL3
  2.  
  3. STATIC_OVL long
  4. check_credit(tmp, shkp)
  5. long tmp;
  6. register struct monst *shkp;
  7. {
  8. 	long credit = ESHK(shkp)->credit;
  9.  
  10. 	if(credit == 0L) return(tmp);
  11. 	if(credit >= tmp) {
  12. 		pline_The("price is deducted from your credit.");
  13. 		ESHK(shkp)->credit -=tmp;
  14. 		tmp = 0L;
  15. 	} else {
  16. 		pline_The("price is partially covered by your credit.");
  17. 		ESHK(shkp)->credit = 0L;
  18. 		tmp -= credit;
  19. 	}
  20. 	return(tmp);
  21. }

pay[edit]

  1. STATIC_OVL void
  2. pay(tmp,shkp)
  3. long tmp;
  4. register struct monst *shkp;
  5. {
  6. 	long robbed = ESHK(shkp)->robbed;
  7. 	long balance = ((tmp <= 0L) ? tmp : check_credit(tmp, shkp));
  8.  
  9. #ifndef GOLDOBJ
  10. 	u.ugold -= balance;
  11. 	shkp->mgold += balance;
  12. #else
  13. 	if (balance > 0) money2mon(shkp, balance);
  14. 	else if (balance < 0) money2u(shkp, -balance);
  15. #endif
  16. 	flags.botl = 1;
  17. 	if(robbed) {
  18. 		robbed -= tmp;
  19. 		if(robbed < 0) robbed = 0L;
  20. 		ESHK(shkp)->robbed = robbed;
  21. 	}
  22. }
  23. #endif /*OVL3*/

home_shk[edit]

  1. #ifdef OVLB
  2.  
  3. /* return shkp to home position */
  4. void
  5. home_shk(shkp, killkops)
  6. register struct monst *shkp;
  7. register boolean killkops;
  8. {
  9. 	register xchar x = ESHK(shkp)->shk.x, y = ESHK(shkp)->shk.y;
  10.  
  11. 	(void) mnearto(shkp, x, y, TRUE);
  12. 	level.flags.has_shop = 1;
  13. 	if (killkops) {
  14. #ifdef KOPS
  15. 		kops_gone(TRUE);
  16. #else
  17. 		You_feel("vaguely apprehensive.");
  18. #endif
  19. 		pacify_guards();
  20. 	}
  21. 	after_shk_move(shkp);
  22. }

angry_shk_exists[edit]

  1. STATIC_OVL boolean
  2. angry_shk_exists()
  3. {
  4. 	register struct monst *shkp;
  5.  
  6. 	for (shkp = next_shkp(fmon, FALSE);
  7. 		shkp; shkp = next_shkp(shkp->nmon, FALSE))
  8. 	    if (ANGRY(shkp)) return(TRUE);
  9. 	return(FALSE);
  10. }

pacify_shk[edit]

  1. /* remove previously applied surcharge from all billed items */
  2. STATIC_OVL void
  3. pacify_shk(shkp)
  4. register struct monst *shkp;
  5. {
  6. 	NOTANGRY(shkp) = TRUE;	/* make peaceful */
  7. 	if (ESHK(shkp)->surcharge) {
  8. 		register struct bill_x *bp = ESHK(shkp)->bill_p;
  9. 		register int ct = ESHK(shkp)->billct;
  10.  
  11. 		ESHK(shkp)->surcharge = FALSE;
  12. 		while (ct-- > 0) {
  13. 			register long reduction = (bp->price + 3L) / 4L;
  14. 			bp->price -= reduction;		/* undo 33% increase */
  15. 			bp++;
  16. 		}
  17. 	}
  18. }

rile_shk[edit]

  1. /* add aggravation surcharge to all billed items */
  2. STATIC_OVL void
  3. rile_shk(shkp)
  4. register struct monst *shkp;
  5. {
  6. 	NOTANGRY(shkp) = FALSE;	/* make angry */
  7. 	if (!ESHK(shkp)->surcharge) {
  8. 		register struct bill_x *bp = ESHK(shkp)->bill_p;
  9. 		register int ct = ESHK(shkp)->billct;
  10.  
  11. 		ESHK(shkp)->surcharge = TRUE;
  12. 		while (ct-- > 0) {
  13. 			register long surcharge = (bp->price + 2L) / 3L;
  14. 			bp->price += surcharge;
  15. 			bp++;
  16. 		}
  17. 	}
  18. }

rouse_shk[edit]

  1. /* wakeup and/or unparalyze shopkeeper */
  2. STATIC_OVL void
  3. rouse_shk(shkp, verbosely)
  4. struct monst *shkp;
  5. boolean verbosely;
  6. {
  7. 	if (!shkp->mcanmove || shkp->msleeping) {
  8. 	    /* greed induced recovery... */
  9. 	    if (verbosely && canspotmon(shkp))
  10. 		pline("%s %s.", Monnam(shkp),
  11. 		      shkp->msleeping ? "wakes up" : "can move again");
  12. 	    shkp->msleeping = 0;
  13. 	    shkp->mfrozen = 0;
  14. 	    shkp->mcanmove = 1;
  15. 	}
  16. }

make_happy_shk[edit]

  1. void
  2. make_happy_shk(shkp, silentkops)
  3. register struct monst *shkp;
  4. register boolean silentkops;
  5. {
  6. 	boolean wasmad = ANGRY(shkp);
  7. 	struct eshk *eshkp = ESHK(shkp);
  8.  
  9. 	pacify_shk(shkp);
  10. 	eshkp->following = 0;
  11. 	eshkp->robbed = 0L;
  12. 	if (!Role_if(PM_ROGUE))
  13. 		adjalign(sgn(u.ualign.type));
  14. 	if(!inhishop(shkp)) {
  15. 		char shk_nam[BUFSZ];
  16. 		boolean vanished = canseemon(shkp);
  17.  
  18. 		Strcpy(shk_nam, mon_nam(shkp));
  19. 		if (on_level(&eshkp->shoplevel, &u.uz)) {
  20. 			home_shk(shkp, FALSE);
  21. 			/* didn't disappear if shk can still be seen */
  22. 			if (canseemon(shkp)) vanished = FALSE;
  23. 		} else {
  24. 			/* if sensed, does disappear regardless whether seen */
  25. 			if (sensemon(shkp)) vanished = TRUE;
  26. 			/* can't act as porter for the Amulet, even if shk
  27. 			   happens to be going farther down rather than up */
  28. 			mdrop_special_objs(shkp);
  29. 			/* arrive near shop's door */
  30. 			migrate_to_level(shkp, ledger_no(&eshkp->shoplevel),
  31. 					 MIGR_APPROX_XY, &eshkp->shd);
  32. 		}
  33. 		if (vanished)
  34. 		    pline("Satisfied, %s suddenly disappears!", shk_nam);
  35. 	} else if(wasmad)
  36. 		pline("%s calms down.", Monnam(shkp));
  37.  
  38. 	if(!angry_shk_exists()) {
  39. #ifdef KOPS
  40. 		kops_gone(silentkops);
  41. #endif
  42. 		pacify_guards();
  43. 	}
  44. }

hot_pursuit[edit]

  1. void
  2. hot_pursuit(shkp)
  3. register struct monst *shkp;
  4. {
  5. 	if(!shkp->isshk) return;
  6.  
  7. 	rile_shk(shkp);
  8. 	(void) strncpy(ESHK(shkp)->customer, plname, PL_NSIZ);
  9. 	ESHK(shkp)->following = 1;
  10. }

make_angry_shk[edit]

  1. /* used when the shkp is teleported or falls (ox == 0) out of his shop,
  2. * or when the player is not on a costly_spot and he
  3. * damages something inside the shop.  these conditions
  4. * must be checked by the calling function.
  5. */
  6. void
  7. make_angry_shk(shkp, ox, oy)
  8. register struct monst *shkp;
  9. register xchar ox,oy;
  10. {
  11. 	xchar sx, sy;
  12. 	struct eshk *eshkp = ESHK(shkp);
  13.  
  14. 	/* all pending shop transactions are now "past due" */
  15. 	if (eshkp->billct || eshkp->debit || eshkp->loan || eshkp->credit) {
  16. 	    eshkp->robbed += (addupbill(shkp) + eshkp->debit + eshkp->loan);
  17. 	    eshkp->robbed -= eshkp->credit;
  18. 	    if (eshkp->robbed < 0L) eshkp->robbed = 0L;
  19. 	    /* billct, debit, loan, and credit will be cleared by setpaid */
  20. 	    setpaid(shkp);
  21. 	}
  22.  
  23. 	/* If you just used a wand of teleportation to send the shk away, you
  24. 	   might not be able to see her any more.  Monnam would yield "it",
  25. 	   which makes this message look pretty silly, so temporarily restore
  26. 	   her original location during the call to Monnam. */
  27. 	sx = shkp->mx,  sy = shkp->my;
  28. 	if (isok(ox, oy) && cansee(ox, oy) && !cansee(sx, sy))
  29. 		shkp->mx = ox,  shkp->my = oy;
  30. 	pline("%s %s!", Monnam(shkp),
  31. 	      !ANGRY(shkp) ? "gets angry" : "is furious");
  32. 	shkp->mx = sx,  shkp->my = sy;
  33. 	hot_pursuit(shkp);
  34. }
  1. STATIC_VAR const char no_money[] = "Moreover, you%s have no money.";
  2. STATIC_VAR const char not_enough_money[] =
  3. 			    "Besides, you don't have enough to interest %s.";
  4.  
  5. #else
  6. STATIC_VAR const char no_money[];
  7. STATIC_VAR const char not_enough_money[];
  8. #endif /*OVLB*/
  9.  
  10. #ifdef OVL3

cheapest_item[edit]

  1. STATIC_OVL long
  2. cheapest_item(shkp)   /* delivers the cheapest item on the list */
  3. register struct monst *shkp;
  4. {
  5. 	register int ct = ESHK(shkp)->billct;
  6. 	register struct bill_x *bp = ESHK(shkp)->bill_p;
  7. 	register long gmin = (bp->price * bp->bquan);
  8.  
  9. 	while(ct--){
  10. 		if(bp->price * bp->bquan < gmin)
  11. 			gmin = bp->price * bp->bquan;
  12. 		bp++;
  13. 	}
  14. 	return(gmin);
  15. }
  16. #endif /*OVL3*/

dopay[edit]

  1. #ifdef OVL0
  2.  
  3. int
  4. dopay()
  5. {
  6. 	register struct eshk *eshkp;
  7. 	register struct monst *shkp;
  8. 	struct monst *nxtm, *resident;
  9. 	long ltmp;
  10. #ifdef GOLDOBJ
  11. 	long umoney;
  12. #endif
  13. 	int pass, tmp, sk = 0, seensk = 0;
  14. 	boolean paid = FALSE, stashed_gold = (hidden_gold() > 0L);
  15.  
  16. 	multi = 0;
  17.  
  18. 	/* find how many shk's there are, how many are in */
  19. 	/* sight, and are you in a shop room with one.    */
  20. 	nxtm = resident = 0;
  21. 	for (shkp = next_shkp(fmon, FALSE);
  22. 		shkp; shkp = next_shkp(shkp->nmon, FALSE)) {
  23. 	    sk++;
  24. 	    if (ANGRY(shkp) && distu(shkp->mx, shkp->my) <= 2) nxtm = shkp;
  25. 	    if (canspotmon(shkp)) seensk++;
  26. 	    if (inhishop(shkp) && (*u.ushops == ESHK(shkp)->shoproom))
  27. 		resident = shkp;
  28. 	}
  29.  
  30. 	if (nxtm) {			/* Player should always appease an */
  31. 	     shkp = nxtm;		/* irate shk standing next to them. */
  32. 	     goto proceed;
  33. 	}
  34.  
  35. 	if ((!sk && (!Blind || Blind_telepat)) || (!Blind && !seensk)) {
  36. There("appears to be no shopkeeper here to receive your payment.");
  37. 		return(0);
  38. 	}
  39.  
  40. 	if(!seensk) {
  41. 		You_cant("see...");
  42. 		return(0);
  43. 	}
  44.  
  45. 	/* the usual case.  allow paying at a distance when */
  46. 	/* inside a tended shop.  should we change that?    */
  47. 	if(sk == 1 && resident) {
  48. 		shkp = resident;
  49. 		goto proceed;
  50. 	}
  51.  
  52. 	if (seensk == 1) {
  53. 		for (shkp = next_shkp(fmon, FALSE);
  54. 			shkp; shkp = next_shkp(shkp->nmon, FALSE))
  55. 		    if (canspotmon(shkp)) break;
  56. 		if (shkp != resident && distu(shkp->mx, shkp->my) > 2) {
  57. 		    pline("%s is not near enough to receive your payment.",
  58. 					     Monnam(shkp));
  59. 		    return(0);
  60. 		}
  61. 	} else {
  62. 		struct monst *mtmp;
  63. 		coord cc;
  64. 		int cx, cy;
  65.  
  66. 		pline("Pay whom?");
  67. 		cc.x = u.ux;
  68. 		cc.y = u.uy;
  69. 		if (getpos(&cc, TRUE, "the creature you want to pay") < 0)
  70. 		    return 0;	/* player pressed ESC */
  71. 		cx = cc.x;
  72. 		cy = cc.y;
  73. 		if(cx < 0) {
  74. 		     pline("Try again...");
  75. 		     return(0);
  76. 		}
  77. 		if(u.ux == cx && u.uy == cy) {
  78. 		     You("are generous to yourself.");
  79. 		     return(0);
  80. 		}
  81. 		mtmp = m_at(cx, cy);
  82. 		if(!mtmp) {
  83. 		     There("is no one there to receive your payment.");
  84. 		     return(0);
  85. 		}
  86. 		if(!mtmp->isshk) {
  87. 		     pline("%s is not interested in your payment.",
  88. 				    Monnam(mtmp));
  89. 		     return(0);
  90. 		}
  91. 		if (mtmp != resident && distu(mtmp->mx, mtmp->my) > 2) {
  92. 		     pline("%s is too far to receive your payment.",
  93. 				    Monnam(mtmp));
  94. 		     return(0);
  95. 		}
  96. 		shkp = mtmp;
  97. 	}
  98.  
  99. 	if(!shkp) {
  100. #ifdef DEBUG
  101. 		pline("dopay: null shkp.");
  102. #endif
  103. 		return(0);
  104. 	}
  105. proceed:
  106. 	eshkp = ESHK(shkp);
  107. 	ltmp = eshkp->robbed;
  108.  
  109. 	/* wake sleeping shk when someone who owes money offers payment */
  110. 	if (ltmp || eshkp->billct || eshkp->debit) 
  111. 	    rouse_shk(shkp, TRUE);
  112.  
  113. 	if (!shkp->mcanmove || shkp->msleeping) { /* still asleep/paralyzed */
  114. 		pline("%s %s.", Monnam(shkp),
  115. 		      rn2(2) ? "seems to be napping" : "doesn't respond");
  116. 		return 0;
  117. 	}
  118.  
  119. 	if(shkp != resident && NOTANGRY(shkp)) {
  120. #ifdef GOLDOBJ
  121. umoney = money_cnt(invent);
  122. #endif
  123. 		if(!ltmp)
  124. 		    You("do not owe %s anything.", mon_nam(shkp));
  125. #ifndef GOLDOBJ
  126. 		else if(!u.ugold) {
  127. #else
  128. 		else if(!umoney) {
  129. #endif
  130. 		    You("%shave no money.", stashed_gold ? "seem to " : "");
  131. 		    if(stashed_gold)
  132. 			pline("But you have some gold stashed away.");
  133. 		} else {
  134. #ifndef GOLDOBJ
  135. 		    long ugold = u.ugold;
  136. 		    if(ugold > ltmp) {
  137. #else
  138. 		    if(umoney > ltmp) {
  139. #endif
  140. 			You("give %s the %ld gold piece%s %s asked for.",
  141. 			    mon_nam(shkp), ltmp, plur(ltmp), mhe(shkp));
  142. 			pay(ltmp, shkp);
  143. 		    } else {
  144. 			You("give %s all your%s gold.", mon_nam(shkp),
  145. 					stashed_gold ? " openly kept" : "");
  146. #ifndef GOLDOBJ
  147. 			pay(u.ugold, shkp);
  148. #else
  149. 			pay(umoney, shkp);
  150. #endif
  151. 			if (stashed_gold) pline("But you have hidden gold!");
  152. 		    }
  153. #ifndef GOLDOBJ
  154. 		    if((ugold < ltmp/2L) || (ugold < ltmp && stashed_gold))
  155. #else
  156. 		    if((umoney < ltmp/2L) || (umoney < ltmp && stashed_gold))
  157. #endif
  158. 			pline("Unfortunately, %s doesn't look satisfied.",
  159. 			      mhe(shkp));
  160. 		    else
  161. 			make_happy_shk(shkp, FALSE);
  162. 		}
  163. 		return(1);
  164. 	}
  165.  
  166. 	/* ltmp is still eshkp->robbed here */
  167. 	if (!eshkp->billct && !eshkp->debit) {
  168. #ifdef GOLDOBJ
  169. umoney = money_cnt(invent);
  170. #endif
  171. 		if(!ltmp && NOTANGRY(shkp)) {
  172. 		    You("do not owe %s anything.", mon_nam(shkp));
  173. #ifndef GOLDOBJ
  174. 		    if (!u.ugold)
  175. #else
  176. 		    if (!umoney)
  177. #endif
  178. 			pline(no_money, stashed_gold ? " seem to" : "");
  179. 		} else if(ltmp) {
  180. 		    pline("%s is after blood, not money!", Monnam(shkp));
  181. #ifndef GOLDOBJ
  182. 		    if(u.ugold < ltmp/2L ||
  183. 				(u.ugold < ltmp && stashed_gold)) {
  184. 			if (!u.ugold)
  185. #else
  186. 		    if(umoney < ltmp/2L ||
  187. 				(umoney < ltmp && stashed_gold)) {
  188. 			if (!umoney)
  189. #endif
  190. 			    pline(no_money, stashed_gold ? " seem to" : "");
  191. 			else pline(not_enough_money, mhim(shkp));
  192. 			return(1);
  193. 		    }
  194. 		    pline("But since %s shop has been robbed recently,",
  195. 			  mhis(shkp));
  196. 		    pline("you %scompensate %s for %s losses.",
  197. #ifndef GOLDOBJ
  198. 			  (u.ugold < ltmp) ? 
  199. #else
  200. 			  (umoney < ltmp) ? 
  201. #endif
  202. 			  "partially " : "",
  203. 			  mon_nam(shkp), mhis(shkp));
  204. #ifndef GOLDOBJ
  205. 		    pay(u.ugold < ltmp ? u.ugold : ltmp, shkp);
  206. #else
  207. 		    pay(umoney < ltmp ? umoney : ltmp, shkp);
  208. #endif
  209. 		    make_happy_shk(shkp, FALSE);
  210. 		} else {
  211. 		    /* shopkeeper is angry, but has not been robbed --
  212. 		     * door broken, attacked, etc. */
  213. 		    pline("%s is after your hide, not your money!",
  214. 			  Monnam(shkp));
  215. #ifndef GOLDOBJ
  216. 		    if(u.ugold < 1000L) {
  217. 			if (!u.ugold)
  218. #else
  219. 		    if(umoney < 1000L) {
  220. 			if (!umoney)
  221. #endif
  222. 			    pline(no_money, stashed_gold ? " seem to" : "");
  223. 			else pline(not_enough_money, mhim(shkp));
  224. 			return(1);
  225. 		    }
  226. 		    You("try to appease %s by giving %s 1000 gold pieces.",
  227. 			x_monnam(shkp, ARTICLE_THE, "angry", 0, FALSE),
  228. 			mhim(shkp));
  229. 		    pay(1000L,shkp);
  230. 		    if (strncmp(eshkp->customer, plname, PL_NSIZ) || rn2(3))
  231. 			make_happy_shk(shkp, FALSE);
  232. 		    else
  233. 			pline("But %s is as angry as ever.", mon_nam(shkp));
  234. 		}
  235. 		return(1);
  236. 	}
  237. 	if(shkp != resident) {
  238. 		impossible("dopay: not to shopkeeper?");
  239. 		if(resident) setpaid(resident);
  240. 		return(0);
  241. 	}        
  242. 	/* pay debt, if any, first */
  243. 	if(eshkp->debit) {
  244. 		long dtmp = eshkp->debit;
  245. 		long loan = eshkp->loan;
  246. 		char sbuf[BUFSZ];
  247. #ifdef GOLDOBJ
  248. umoney = money_cnt(invent);
  249. #endif
  250. 		Sprintf(sbuf, "You owe %s %ld %s ",
  251. 					   shkname(shkp), dtmp, currency(dtmp));
  252. 		if(loan) {
  253. 		    if(loan == dtmp)
  254. 			Strcat(sbuf, "you picked up in the store.");
  255. 		    else Strcat(sbuf,
  256. 			   "for gold picked up and the use of merchandise.");
  257. 		} else Strcat(sbuf, "for the use of merchandise.");
  258. 		pline(sbuf);
  259. #ifndef GOLDOBJ
  260. 		if (u.ugold + eshkp->credit < dtmp) {
  261. #else
  262. 		if (umoney + eshkp->credit < dtmp) {
  263. #endif
  264. 		    pline("But you don't%s have enough gold%s.",
  265. 			stashed_gold ? " seem to" : "",
  266. 			eshkp->credit ? " or credit" : "");
  267. 		    return(1);
  268. 		} else {
  269. 		    if (eshkp->credit >= dtmp) {
  270. 			eshkp->credit -= dtmp;
  271. 			eshkp->debit = 0L;
  272. 			eshkp->loan = 0L;
  273. 			Your("debt is covered by your credit.");
  274. 		    } else if (!eshkp->credit) {
  275. #ifndef GOLDOBJ
  276. 			u.ugold -= dtmp;
  277. 			shkp->mgold += dtmp;
  278. #else
  279. money2mon(shkp, dtmp);
  280. #endif
  281. 			eshkp->debit = 0L;
  282. 			eshkp->loan = 0L;
  283. 			You("pay that debt.");
  284. 			flags.botl = 1;
  285. 		    } else {
  286. 			dtmp -= eshkp->credit;
  287. 			eshkp->credit = 0L;
  288. #ifndef GOLDOBJ
  289. 			u.ugold -= dtmp;
  290. 			shkp->mgold += dtmp;
  291. #else
  292. money2mon(shkp, dtmp);
  293. #endif
  294. 			eshkp->debit = 0L;
  295. 			eshkp->loan = 0L;
  296. 			pline("That debt is partially offset by your credit.");
  297. 			You("pay the remainder.");
  298. 			flags.botl = 1;
  299. 		    }
  300. 		    paid = TRUE;
  301. 		}
  302. 	}
  303. 	/* now check items on bill */
  304. 	if (eshkp->billct) {
  305. 	    register boolean itemize;
  306. #ifndef GOLDOBJ
  307. 	    if (!u.ugold && !eshkp->credit) {
  308. #else
  309. umoney = money_cnt(invent);
  310. 	    if (!umoney && !eshkp->credit) {
  311. #endif
  312. 		You("%shave no money or credit%s.",
  313. 				    stashed_gold ? "seem to " : "",
  314. 				    paid ? " left" : "");
  315. 		return(0);
  316. 	    }
  317. #ifndef GOLDOBJ
  318. 	    if ((u.ugold + eshkp->credit) < cheapest_item(shkp)) {
  319. #else
  320. 	    if ((umoney + eshkp->credit) < cheapest_item(shkp)) {
  321. #endif
  322. 		You("don't have enough money to buy%s the item%s you picked.",
  323. 		    eshkp->billct > 1 ? " any of" : "", plur(eshkp->billct));
  324. 		if(stashed_gold)
  325. 		    pline("Maybe you have some gold stashed away?");
  326. 		return(0);
  327. 	    }
  328.  
  329. 	    /* this isn't quite right; it itemizes without asking if the
  330. 	     * single item on the bill is partly used up and partly unpaid */
  331. 	    itemize = (eshkp->billct > 1 ? yn("Itemized billing?") == 'y' : 1);
  332.  
  333. 	    for (pass = 0; pass <= 1; pass++) {
  334. 		tmp = 0;
  335. 		while (tmp < eshkp->billct) {
  336. 		    struct obj *otmp;
  337. 		    register struct bill_x *bp = &(eshkp->bill_p[tmp]);
  338.  
  339. 		    /* find the object on one of the lists */
  340. 		    if ((otmp = bp_to_obj(bp)) != 0) {
  341. 			/* if completely used up, object quantity is stale;
  342. 			   restoring it to its original value here avoids
  343. 			   making the partly-used-up code more complicated */
  344. 			if (bp->useup) otmp->quan = bp->bquan;
  345. 		    } else {
  346. 			impossible("Shopkeeper administration out of order.");
  347. 			setpaid(shkp);	/* be nice to the player */
  348. 			return 1;
  349. 		    }
  350. 		    if (pass == bp->useup && otmp->quan == bp->bquan) {
  351. 			/* pay for used-up items on first pass and others
  352. 			 * on second, so player will be stuck in the store
  353. 			 * less often; things which are partly used up
  354. 			 * are processed on both passes */
  355. 			tmp++;
  356. 		    } else {
  357. 			switch (dopayobj(shkp, bp, &otmp, pass, itemize)) {
  358. 			  case PAY_CANT:
  359. 				return 1;	/*break*/
  360. 			  case PAY_BROKE:
  361. 				paid = TRUE;
  362. 				goto thanks;	/*break*/
  363. 			  case PAY_SKIP:
  364. 				tmp++;
  365. 				continue;	/*break*/
  366. 			  case PAY_SOME:
  367. 				paid = TRUE;
  368. 				if (itemize) bot();
  369. 				continue;	/*break*/
  370. 			  case PAY_BUY:
  371. 				paid = TRUE;
  372. 				break;
  373. 			}
  374. 			if (itemize) bot();
  375. 			*bp = eshkp->bill_p[--eshkp->billct];
  376. 		    }
  377. 		}
  378. 	    }
  379. 	thanks:
  380. 	    if (!itemize)
  381. 	        update_inventory(); /* Done in dopayobj() if itemize. */
  382. 	}
  383. 	if(!ANGRY(shkp) && paid)
  384. 	    verbalize("Thank you for shopping in %s %s!",
  385. 		s_suffix(shkname(shkp)),
  386. 		shtypes[eshkp->shoptype - SHOPBASE].name);
  387. 	return(1);
  388. }
  389. #endif /*OVL0*/

dopayobj[edit]

  1. #ifdef OVL3
  2.  
  3. /* return 2 if used-up portion paid */
  4. /*	  1 if paid successfully    */
  5. /*	  0 if not enough money     */
  6. /*	 -1 if skip this object     */
  7. /*	 -2 if no money/credit left */
  8. STATIC_OVL int
  9. dopayobj(shkp, bp, obj_p, which, itemize)
  10. register struct monst *shkp;
  11. register struct bill_x *bp;
  12. struct obj **obj_p;
  13. int	which;		/* 0 => used-up item, 1 => other (unpaid or lost) */
  14. boolean itemize;
  15. {
  16. 	register struct obj *obj = *obj_p;
  17. 	long ltmp, quan, save_quan;
  18. #ifdef GOLDOBJ
  19. 	long umoney = money_cnt(invent);
  20. #endif
  21. 	int buy;
  22. 	boolean stashed_gold = (hidden_gold() > 0L),
  23. 		consumed = (which == 0);
  24.  
  25. 	if(!obj->unpaid && !bp->useup){
  26. 		impossible("Paid object on bill??");
  27. 		return PAY_BUY;
  28. 	}
  29. #ifndef GOLDOBJ
  30. 	if(itemize && u.ugold + ESHK(shkp)->credit == 0L){
  31. #else
  32. 	if(itemize && umoney + ESHK(shkp)->credit == 0L){
  33. #endif
  34. 		You("%shave no money or credit left.",
  35. 			     stashed_gold ? "seem to " : "");
  36. 		return PAY_BROKE;
  37. 	}
  38. 	/* we may need to temporarily adjust the object, if part of the
  39. 	   original quantity has been used up but part remains unpaid  */
  40. 	save_quan = obj->quan;
  41. 	if (consumed) {
  42. 	    /* either completely used up (simple), or split needed */
  43. 	    quan = bp->bquan;
  44. 	    if (quan > obj->quan)	/* difference is amount used up */
  45. 		quan -= obj->quan;
  46. 	} else {
  47. 	    /* dealing with ordinary unpaid item */
  48. 	    quan = obj->quan;
  49. 	}
  50. 	obj->quan = quan;	/* to be used by doname() */
  51. 	obj->unpaid = 0;	/* ditto */
  52. 	ltmp = bp->price * quan;
  53. 	buy = PAY_BUY;		/* flag; if changed then return early */
  54.  
  55. 	if (itemize) {
  56. 	    char qbuf[BUFSZ];
  57. 	    Sprintf(qbuf,"%s for %ld %s.  Pay?", quan == 1L ?
  58. 		    Doname2(obj) : doname(obj), ltmp, currency(ltmp));
  59. 	    if (yn(qbuf) == 'n') {
  60. 		buy = PAY_SKIP;		/* don't want to buy */
  61. 	    } else if (quan < bp->bquan && !consumed) { /* partly used goods */
  62. 		obj->quan = bp->bquan - save_quan;	/* used up amount */
  63. 		verbalize("%s for the other %s before buying %s.",
  64. 			  ANGRY(shkp) ? "Pay" : "Please pay", xname(obj),
  65. 			  save_quan > 1L ? "these" : "this one");
  66. 		buy = PAY_SKIP;		/* shk won't sell */
  67. 	    }
  68. 	}
  69. #ifndef GOLDOBJ
  70. 	if (buy == PAY_BUY && u.ugold + ESHK(shkp)->credit < ltmp) {
  71. #else
  72. 	if (buy == PAY_BUY && umoney + ESHK(shkp)->credit < ltmp) {
  73. #endif
  74. 	    You("don't%s have gold%s enough to pay for %s.",
  75. 		stashed_gold ? " seem to" : "",
  76. 		(ESHK(shkp)->credit > 0L) ? " or credit" : "",
  77. 		doname(obj));
  78. 	    buy = itemize ? PAY_SKIP : PAY_CANT;
  79. 	}
  80.  
  81. 	if (buy != PAY_BUY) {
  82. 	    /* restore unpaid object to original state */
  83. 	    obj->quan = save_quan;
  84. 	    obj->unpaid = 1;
  85. 	    return buy;
  86. 	}
  87.  
  88. 	pay(ltmp, shkp);
  89. 	shk_names_obj(shkp, obj, consumed ?
  90. 			"paid for %s at a cost of %ld gold piece%s.%s" :
  91. 			"bought %s for %ld gold piece%s.%s", ltmp, "");
  92. 	obj->quan = save_quan;		/* restore original count */
  93. 	/* quan => amount just bought, save_quan => remaining unpaid count */
  94. 	if (consumed) {
  95. 	    if (quan != bp->bquan) {
  96. 		/* eliminate used-up portion; remainder is still unpaid */
  97. 		bp->bquan = obj->quan;
  98. 		obj->unpaid = 1;
  99. 		bp->useup = 0;
  100. 		buy = PAY_SOME;
  101. 	    } else {	/* completely used-up, so get rid of it */
  102. 		obj_extract_self(obj);
  103. 	     /* assert( obj == *obj_p ); */
  104. 		dealloc_obj(obj);
  105. 		*obj_p = 0;	/* destroy pointer to freed object */
  106. 	    }
  107. 	} else if (itemize)
  108. 	    update_inventory();	/* Done just once in dopay() if !itemize. */
  109. 	return buy;
  110. }
  111. #endif /*OVL3*/

paybill[edit]

  1. #ifdef OVLB
  2.  
  3. static coord repo_location;	/* repossession context */
  4.  
  5. /* routine called after dying (or quitting) */
  6. boolean
  7. paybill(croaked)
  8. int croaked;	/* -1: escaped dungeon; 0: quit; 1: died */
  9. {
  10. 	register struct monst *mtmp, *mtmp2, *resident= (struct monst *)0;
  11. 	register boolean taken = FALSE;
  12. 	register int numsk = 0;
  13.  
  14. 	/* if we escaped from the dungeon, shopkeepers can't reach us;
  15. 	   shops don't occur on level 1, but this could happen if hero
  16. 	   level teleports out of the dungeon and manages not to die */
  17. 	if (croaked < 0) return FALSE;
  18.  
  19. 	/* this is where inventory will end up if any shk takes it */
  20. 	repo_location.x = repo_location.y = 0;
  21.  
  22. 	/* give shopkeeper first crack */
  23. 	if ((mtmp = shop_keeper(*u.ushops)) && inhishop(mtmp)) {
  24. 	    numsk++;
  25. 	    resident = mtmp;
  26. 	    taken = inherits(resident, numsk, croaked);
  27. 	}
  28. 	for (mtmp = next_shkp(fmon, FALSE);
  29. 		mtmp; mtmp = next_shkp(mtmp2, FALSE)) {
  30. 	    mtmp2 = mtmp->nmon;
  31. 	    if (mtmp != resident) {
  32. 		/* for bones: we don't want a shopless shk around */
  33. 		if(!on_level(&(ESHK(mtmp)->shoplevel), &u.uz))
  34. 			mongone(mtmp);
  35. 		else {
  36. 		    numsk++;
  37. 		    taken |= inherits(mtmp, numsk, croaked);
  38. 		}
  39. 	    }
  40. 	}
  41. 	if(numsk == 0) return(FALSE);
  42. 	return(taken);
  43. }

inherits[edit]

  1. STATIC_OVL boolean
  2. inherits(shkp, numsk, croaked)
  3. struct monst *shkp;
  4. int numsk;
  5. int croaked;
  6. {
  7. 	long loss = 0L;
  8. #ifdef GOLDOBJ
  9. 	long umoney;
  10. #endif
  11. 	struct eshk *eshkp = ESHK(shkp);
  12. 	boolean take = FALSE, taken = FALSE;
  13. 	int roomno = *u.ushops;
  14. 	char takes[BUFSZ];
  15.  
  16. 	/* the simplifying principle is that first-come */
  17. 	/* already took everything you had.		*/
  18. 	if (numsk > 1) {
  19. 	    if (cansee(shkp->mx, shkp->my && croaked))
  20. 		pline("%s %slooks at your corpse%s and %s.",
  21. 		      Monnam(shkp),
  22. 		      (!shkp->mcanmove || shkp->msleeping) ? "wakes up, " : "",
  23. 		      !rn2(2) ? (shkp->female ? ", shakes her head," :
  24. 			   ", shakes his head,") : "",
  25. 		      !inhishop(shkp) ? "disappears" : "sighs");
  26. 	    rouse_shk(shkp, FALSE);	/* wake shk for bones */    
  27. 	    taken = (roomno == eshkp->shoproom);
  28. 	    goto skip;
  29. 	}
  30.  
  31. 	/* get one case out of the way: you die in the shop, the */
  32. 	/* shopkeeper is peaceful, nothing stolen, nothing owed. */
  33. 	if(roomno == eshkp->shoproom && inhishop(shkp) &&
  34. 	    !eshkp->billct && !eshkp->robbed && !eshkp->debit &&
  35. 	     NOTANGRY(shkp) && !eshkp->following) {
  36. 		if (invent)
  37. 			pline("%s gratefully inherits all your possessions.",
  38. 				shkname(shkp));
  39. 		set_repo_loc(eshkp);
  40. 		goto clear;
  41. 	}
  42.  
  43. 	if (eshkp->billct || eshkp->debit || eshkp->robbed) {
  44. 		if (roomno == eshkp->shoproom && inhishop(shkp))
  45. 		    loss = addupbill(shkp) + eshkp->debit;
  46. 		if (loss < eshkp->robbed) loss = eshkp->robbed;
  47. 		take = TRUE;
  48. 	}
  49.  
  50. 	if (eshkp->following || ANGRY(shkp) || take) {
  51. #ifndef GOLDOBJ
  52. 		if (!invent && !u.ugold) goto skip;
  53. #else
  54. 		if (!invent) goto skip;
  55. umoney = money_cnt(invent);
  56. #endif
  57. 		takes[0] = '\0';
  58. 		if (!shkp->mcanmove || shkp->msleeping)
  59. 			Strcat(takes, "wakes up and ");
  60. 		if (distu(shkp->mx, shkp->my) > 2)
  61. 			Strcat(takes, "comes and ");
  62. 		Strcat(takes, "takes");
  63.  
  64. #ifndef GOLDOBJ
  65. 		if (loss > u.ugold || !loss || roomno == eshkp->shoproom) {
  66. 			eshkp->robbed -= u.ugold;
  67. 			if (eshkp->robbed < 0L) eshkp->robbed = 0L;
  68. 			shkp->mgold += u.ugold;
  69. 			u.ugold = 0L;
  70. #else
  71. 		if (loss > umoney || !loss || roomno == eshkp->shoproom) {
  72. 			eshkp->robbed -= umoney;
  73. 			if (eshkp->robbed < 0L) eshkp->robbed = 0L;
  74. if (umoney > 0) money2mon(shkp, umoney);
  75. #endif
  76. 			flags.botl = 1;
  77. 			pline("%s %s all your possessions.",
  78. 			      shkname(shkp), takes);
  79. 			taken = TRUE;
  80. 			/* where to put player's invent (after disclosure) */
  81. 			set_repo_loc(eshkp);
  82. 		} else {
  83. #ifndef GOLDOBJ
  84. 			shkp->mgold += loss;
  85. 			u.ugold -= loss;
  86. #else
  87. money2mon(shkp, loss);
  88. #endif
  89. 			flags.botl = 1;
  90. 			pline("%s %s the %ld %s %sowed %s.",
  91. 			      Monnam(shkp), takes,
  92. 			      loss, currency(loss),
  93. 			      strncmp(eshkp->customer, plname, PL_NSIZ) ?
  94. 					"" : "you ",
  95. 			      shkp->female ? "her" : "him");
  96. 			/* shopkeeper has now been paid in full */
  97. 			pacify_shk(shkp);
  98. 			eshkp->following = 0;
  99. 			eshkp->robbed = 0L;
  100. 		}
  101. skip:
  102. 		/* in case we create bones */
  103. 		rouse_shk(shkp, FALSE);	/* wake up */
  104. 		if (!inhishop(shkp))
  105. 			home_shk(shkp, FALSE);
  106. 	}
  107. clear:
  108. 	setpaid(shkp);
  109. 	return(taken);
  110. }

set_repo_loc[edit]

  1. STATIC_OVL void
  2. set_repo_loc(eshkp)
  3. struct eshk *eshkp;
  4. {
  5. 	register xchar ox, oy;
  6.  
  7. 	/* if you're not in this shk's shop room, or if you're in its doorway
  8. 	    or entry spot, then your gear gets dumped all the way inside */
  9. 	if (*u.ushops != eshkp->shoproom ||
  10. 		IS_DOOR(levl[u.ux][u.uy].typ) ||
  11. 		(u.ux == eshkp->shk.x && u.uy == eshkp->shk.y)) {
  12. 	    /* shk.x,shk.y is the position immediately in
  13. 	     * front of the door -- move in one more space
  14. 	     */
  15. 	    ox = eshkp->shk.x;
  16. 	    oy = eshkp->shk.y;
  17. 	    ox += sgn(ox - eshkp->shd.x);
  18. 	    oy += sgn(oy - eshkp->shd.y);
  19. 	} else {		/* already inside this shk's shop */
  20. 	    ox = u.ux;
  21. 	    oy = u.uy;
  22. 	}
  23. 	/* finish_paybill will deposit invent here */
  24. 	repo_location.x = ox;
  25. 	repo_location.y = oy;
  26. }

finish_paybill[edit]

  1. /* called at game exit, after inventory disclosure but before making bones */
  2. void
  3. finish_paybill()
  4. {
  5. 	register struct obj *otmp;
  6. 	int ox = repo_location.x,
  7. 	    oy = repo_location.y;
  8.  
  9. #if 0		/* don't bother */
  10. 	if (ox == 0 && oy == 0) impossible("finish_paybill: no location");
  11. #endif
  12. 	/* normally done by savebones(), but that's too late in this case */
  13. 	unleash_all();
  14. 	/* transfer all of the character's inventory to the shop floor */
  15. 	while ((otmp = invent) != 0) {
  16. 	    otmp->owornmask = 0L;	/* perhaps we should call setnotworn? */
  17. 	    otmp->lamplit = 0;		/* avoid "goes out" msg from freeinv */
  18. 	    if (rn2(5)) curse(otmp);	/* normal bones treatment for invent */
  19. 	    obj_extract_self(otmp);
  20. 	    place_object(otmp, ox, oy);
  21. 	}
  22. }

bp_to_obj[edit]

  1. /* find obj on one of the lists */
  2. STATIC_OVL struct obj *
  3. bp_to_obj(bp)
  4. register struct bill_x *bp;
  5. {
  6. 	register struct obj *obj;
  7. 	register unsigned int id = bp->bo_id;
  8.  
  9. 	if(bp->useup)
  10. 		obj = o_on(id, billobjs);
  11. 	else
  12. 		obj = find_oid(id);
  13. 	return obj;
  14. }

find_oid[edit]

  1. /*
  2. * Look for o_id on all lists but billobj.  Return obj or NULL if not found.
  3. * Its OK for restore_timers() to call this function, there should not
  4. * be any timeouts on the billobjs chain.
  5. */
  6. struct obj *
  7. find_oid(id)
  8. unsigned id;
  9. {
  10. 	struct obj *obj;
  11. 	struct monst *mon, *mmtmp[3];
  12. 	int i;
  13.  
  14. 	/* first check various obj lists directly */
  15. 	if ((obj = o_on(id, invent)) != 0) return obj;
  16. 	if ((obj = o_on(id, fobj)) != 0) return obj;
  17. 	if ((obj = o_on(id, level.buriedobjlist)) != 0) return obj;
  18. 	if ((obj = o_on(id, migrating_objs)) != 0) return obj;
  19.  
  20. 	/* not found yet; check inventory for members of various monst lists */
  21. 	mmtmp[0] = fmon;
  22. 	mmtmp[1] = migrating_mons;
  23. 	mmtmp[2] = mydogs;		/* for use during level changes */
  24. 	for (i = 0; i < 3; i++)
  25. 	    for (mon = mmtmp[i]; mon; mon = mon->nmon)
  26. 		if ((obj = o_on(id, mon->minvent)) != 0) return obj;
  27.  
  28. 	/* not found at all */
  29. 	return (struct obj *)0;
  30. }
  31. #endif /*OVLB*/

get_cost[edit]

  1. #ifdef OVL3
  2.  
  3. /* calculate the value that the shk will charge for [one of] an object */
  4. STATIC_OVL long
  5. get_cost(obj, shkp)
  6. register struct obj *obj;
  7. register struct monst *shkp;	/* if angry, impose a surcharge */
  8. {
  9. 	register long tmp = getprice(obj, FALSE);
  10.  
  11. 	if (!tmp) tmp = 5L;
  12. 	/* shopkeeper may notice if the player isn't very knowledgeable -
  13. 	   especially when gem prices are concerned */
  14. 	if (!obj->dknown || !objects[obj->otyp].oc_name_known) {
  15. 		if (obj->oclass == GEM_CLASS &&
  16. 			objects[obj->otyp].oc_material == GLASS) {
  17. 		    int i;
  18. 		    /* get a value that's 'random' from game to game, but the
  19. 		       same within the same game */
  20. 		    boolean pseudorand =
  21. 			(((int)u.ubirthday % obj->otyp) >= obj->otyp/2);
  22.  
  23. 		    /* all gems are priced high - real or not */
  24. 		    switch(obj->otyp - LAST_GEM) {
  25. 			case 1: /* white */
  26. 			    i = pseudorand ? DIAMOND : OPAL;
  27. 			    break;
  28. 			case 2: /* blue */
  29. 			    i = pseudorand ? SAPPHIRE : AQUAMARINE;
  30. 			    break;
  31. 			case 3: /* red */
  32. 			    i = pseudorand ? RUBY : JASPER;
  33. 			    break;
  34. 			case 4: /* yellowish brown */
  35. 			    i = pseudorand ? AMBER : TOPAZ;
  36. 			    break;
  37. 			case 5: /* orange */
  38. 			    i = pseudorand ? JACINTH : AGATE;
  39. 			    break;
  40. 			case 6: /* yellow */
  41. 			    i = pseudorand ? CITRINE : CHRYSOBERYL;
  42. 			    break;
  43. 			case 7: /* black */
  44. 			    i = pseudorand ? BLACK_OPAL : JET;
  45. 			    break;
  46. 			case 8: /* green */
  47. 			    i = pseudorand ? EMERALD : JADE;
  48. 			    break;
  49. 			case 9: /* violet */
  50. 			    i = pseudorand ? AMETHYST : FLUORITE;
  51. 			    break;
  52. 			default: impossible("bad glass gem %d?", obj->otyp);
  53. 			    i = STRANGE_OBJECT;
  54. 			    break;
  55. 		    }
  56. 		    tmp = (long) objects[i].oc_cost;
  57. 		} else if (!(obj->o_id % 4)) /* arbitrarily impose surcharge */
  58. 		    tmp += tmp / 3L;
  59. 	}
  60. #ifdef TOURIST
  61. 	if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV/2))
  62. 	    || (uarmu && !uarm && !uarmc))	/* touristy shirt visible */
  63. 		tmp += tmp / 3L;
  64. 	else
  65. #endif
  66. 	if (uarmh && uarmh->otyp == DUNCE_CAP)
  67. 		tmp += tmp / 3L;
  68.  
  69. 	if (ACURR(A_CHA) > 18)		tmp /= 2L;
  70. 	else if (ACURR(A_CHA) > 17)	tmp -= tmp / 3L;
  71. 	else if (ACURR(A_CHA) > 15)	tmp -= tmp / 4L;
  72. 	else if (ACURR(A_CHA) < 6)	tmp *= 2L;
  73. 	else if (ACURR(A_CHA) < 8)	tmp += tmp / 2L;
  74. 	else if (ACURR(A_CHA) < 11)	tmp += tmp / 3L;
  75. 	if (tmp <= 0L) tmp = 1L;
  76. 	else if (obj->oartifact) tmp *= 4L;
  77. 	/* anger surcharge should match rile_shk's */
  78. 	if (shkp && ESHK(shkp)->surcharge) tmp += (tmp + 2L) / 3L;
  79. 	return tmp;
  80. }
  81. #endif /*OVL3*/

contained_cost[edit]

  1. #ifdef OVLB
  2.  
  3. /* returns the price of a container's content.  the price
  4. * of the "top" container is added in the calling functions.
  5. * a different price quoted for selling as vs. buying.
  6. */
  7. long
  8. contained_cost(obj, shkp, price, usell, unpaid_only)
  9. register struct obj *obj;
  10. register struct monst *shkp;
  11. long price;
  12. register boolean usell;
  13. register boolean unpaid_only;
  14. {
  15. 	register struct obj *otmp;
  16.  
  17. 	/* the price of contained objects */
  18. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
  19. 	    if (otmp->oclass == COIN_CLASS) continue;
  20. 	    /* the "top" container is evaluated by caller */
  21. 	    if (usell) {
  22. 		if (saleable(shkp, otmp) &&
  23. 			!otmp->unpaid && otmp->oclass != BALL_CLASS &&
  24. 			!(otmp->oclass == FOOD_CLASS && otmp->oeaten) &&
  25. 			!(Is_candle(otmp) && otmp->age <
  26. 				20L * (long)objects[otmp->otyp].oc_cost))
  27. 		    price += set_cost(otmp, shkp);
  28. 	    } else if (!otmp->no_charge &&
  29. 		      (!unpaid_only || (unpaid_only && otmp->unpaid))) {
  30. 		    price += get_cost(otmp, shkp) * otmp->quan;
  31. 	    }
  32.  
  33. 	    if (Has_contents(otmp))
  34. 		    price += contained_cost(otmp, shkp, price, usell, unpaid_only);
  35. 	}
  36.  
  37. 	return(price);
  38. }

contained_gold[edit]

  1. long
  2. contained_gold(obj)
  3. register struct obj *obj;
  4. {
  5. 	register struct obj *otmp;
  6. 	register long value = 0L;
  7.  
  8. 	/* accumulate contained gold */
  9. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj)
  10. 	    if (otmp->oclass == COIN_CLASS)
  11. 		value += otmp->quan;
  12. 	    else if (Has_contents(otmp))
  13. 		value += contained_gold(otmp);
  14.  
  15. 	return(value);
  16. }

dropped_container[edit]

  1. STATIC_OVL void
  2. dropped_container(obj, shkp, sale)
  3. register struct obj *obj;
  4. register struct monst *shkp;
  5. register boolean sale;
  6. {
  7. 	register struct obj *otmp;
  8.  
  9. 	/* the "top" container is treated in the calling fn */
  10. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
  11. 	    if (otmp->oclass == COIN_CLASS) continue;
  12.  
  13. 	    if (!otmp->unpaid && !(sale && saleable(shkp, otmp)))
  14. 		otmp->no_charge = 1;
  15.  
  16. 	    if (Has_contents(otmp))
  17. 		dropped_container(otmp, shkp, sale);
  18. 	}
  19. }

picked_container[edit]

  1. void
  2. picked_container(obj)
  3. register struct obj *obj;
  4. {
  5. 	register struct obj *otmp;
  6.  
  7. 	/* the "top" container is treated in the calling fn */
  8. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
  9. 	    if (otmp->oclass == COIN_CLASS) continue;
  10.  
  11. 	    if (otmp->no_charge)
  12. 		otmp->no_charge = 0;
  13.  
  14. 	    if (Has_contents(otmp))
  15. 		picked_container(otmp);
  16. 	}
  17. }
  18. #endif /*OVLB*/

set_cost[edit]

  1. #ifdef OVL3
  2.  
  3. /* calculate how much the shk will pay when buying [all of] an object */
  4. STATIC_OVL long
  5. set_cost(obj, shkp)
  6. register struct obj *obj;
  7. register struct monst *shkp;
  8. {
  9. 	long tmp = getprice(obj, TRUE) * obj->quan;
  10.  
  11. #ifdef TOURIST
  12. 	if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV/2))
  13. 	    || (uarmu && !uarm && !uarmc))	/* touristy shirt visible */
  14. 		tmp /= 3L;
  15. 	else
  16. #endif
  17. 	if (uarmh && uarmh->otyp == DUNCE_CAP)
  18. 		tmp /= 3L;
  19. 	else
  20. 		tmp /= 2L;
  21.  
  22. 	/* shopkeeper may notice if the player isn't very knowledgeable -
  23. 	   especially when gem prices are concerned */
  24. 	if (!obj->dknown || !objects[obj->otyp].oc_name_known) {
  25. 		if (obj->oclass == GEM_CLASS) {
  26. 			/* different shop keepers give different prices */
  27. 			if (objects[obj->otyp].oc_material == GEMSTONE ||
  28. 			    objects[obj->otyp].oc_material == GLASS) {
  29. 				tmp = (obj->otyp % (6 - shkp->m_id % 3));
  30. 				tmp = (tmp + 3) * obj->quan;
  31. 			}
  32. 		} else if (tmp > 1L && !rn2(4))
  33. 			tmp -= tmp / 4L;
  34. 	}
  35. 	return tmp;
  36. }
  37.  
  38. #endif /*OVL3*/

unpaid_cost[edit]

  1. #ifdef OVLB
  2.  
  3. /* called from doinv(invent.c) for inventory of unpaid objects */
  4. long
  5. unpaid_cost(unp_obj)
  6. register struct obj *unp_obj;	/* known to be unpaid */
  7. {
  8. 	register struct bill_x *bp = (struct bill_x *)0;
  9. 	register struct monst *shkp;
  10.  
  11. 	for(shkp = next_shkp(fmon, TRUE); shkp;
  12. 					shkp = next_shkp(shkp->nmon, TRUE))
  13. 	    if ((bp = onbill(unp_obj, shkp, TRUE)) != 0) break;
  14.  
  15. 	/* onbill() gave no message if unexpected problem occurred */
  16. 	if(!bp) impossible("unpaid_cost: object wasn't on any bill!");
  17.  
  18. 	return bp ? unp_obj->quan * bp->price : 0L;
  19. }

add_one_tobill[edit]

  1. STATIC_OVL void
  2. add_one_tobill(obj, dummy)
  3. register struct obj *obj;
  4. register boolean dummy;
  5. {
  6. 	register struct monst *shkp;
  7. 	register struct bill_x *bp;
  8. 	register int bct;
  9. 	register char roomno = *u.ushops;
  10.  
  11. 	if (!roomno) return;
  12. 	if (!(shkp = shop_keeper(roomno))) return;
  13. 	if (!inhishop(shkp)) return;
  14.  
  15. 	if (onbill(obj, shkp, FALSE) || /* perhaps thrown away earlier */
  16. 		    (obj->oclass == FOOD_CLASS && obj->oeaten))
  17. 		return;
  18.  
  19. 	if (ESHK(shkp)->billct == BILLSZ) {
  20. 		You("got that for free!");
  21. 		return;
  22. 	}
  23.  
  24. 	/* To recognize objects the shopkeeper is not interested in. -dgk
  25. 	 */
  26. 	if (obj->no_charge) {
  27. 		obj->no_charge = 0;
  28. 		return;
  29. 	}
  30.  
  31. 	bct = ESHK(shkp)->billct;
  32. 	bp = &(ESHK(shkp)->bill_p[bct]);
  33. 	bp->bo_id = obj->o_id;
  34. 	bp->bquan = obj->quan;
  35. 	if(dummy) {		  /* a dummy object must be inserted into  */
  36. 	    bp->useup = 1;	  /* the billobjs chain here.  crucial for */
  37. 	    add_to_billobjs(obj); /* eating floorfood in shop.  see eat.c  */
  38. 	} else	bp->useup = 0;
  39. 	bp->price = get_cost(obj, shkp);
  40. 	ESHK(shkp)->billct++;
  41. 	obj->unpaid = 1;
  42. }

add_to_billobjs[edit]

  1. STATIC_OVL void
  2. add_to_billobjs(obj)
  3. struct obj *obj;
  4. {
  5. if (obj->where != OBJ_FREE)
  6. 	panic("add_to_billobjs: obj not free");
  7. if (obj->timed)
  8. 	obj_stop_timers(obj);
  9.  
  10. obj->nobj = billobjs;
  11. billobjs = obj;
  12. obj->where = OBJ_ONBILL;
  13. }

bill_box_content[edit]

  1. /* recursive billing of objects within containers. */
  2. STATIC_OVL void
  3. bill_box_content(obj, ininv, dummy, shkp)
  4. register struct obj *obj;
  5. register boolean ininv, dummy;
  6. register struct monst *shkp;
  7. {
  8. 	register struct obj *otmp;
  9.  
  10. 	for (otmp = obj->cobj; otmp; otmp = otmp->nobj) {
  11. 		if (otmp->oclass == COIN_CLASS) continue;
  12.  
  13. 		/* the "top" box is added in addtobill() */
  14. 		if (!otmp->no_charge)
  15. 		    add_one_tobill(otmp, dummy);
  16. 		if (Has_contents(otmp))
  17. 		    bill_box_content(otmp, ininv, dummy, shkp);
  18. 	}
  19.  
  20. }

shk_names_obj[edit]

  1. /* shopkeeper tells you what you bought or sold, sometimes partly IDing it */
  2. STATIC_OVL void
  3. shk_names_obj(shkp, obj, fmt, amt, arg)
  4. struct monst *shkp;
  5. struct obj *obj;
  6. const char *fmt;	/* "%s %ld %s %s", doname(obj), amt, plur(amt), arg */
  7. long amt;
  8. const char *arg;
  9. {
  10. 	char *obj_name, fmtbuf[BUFSZ];
  11. 	boolean was_unknown = !obj->dknown;
  12.  
  13. 	obj->dknown = TRUE;
  14. 	/* Use real name for ordinary weapons/armor, and spell-less
  15. 	 * scrolls/books (that is, blank and mail), but only if the
  16. 	 * object is within the shk's area of interest/expertise.
  17. 	 */
  18. 	if (!objects[obj->otyp].oc_magic && saleable(shkp, obj) &&
  19. 	    (obj->oclass == WEAPON_CLASS || obj->oclass == ARMOR_CLASS ||
  20. 	     obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS ||
  21. 	     obj->otyp == MIRROR)) {
  22. 	    was_unknown |= !objects[obj->otyp].oc_name_known;
  23. 	    makeknown(obj->otyp);
  24. 	}
  25. 	obj_name = doname(obj);
  26. 	/* Use an alternate message when extra information is being provided */
  27. 	if (was_unknown) {
  28. 	    Sprintf(fmtbuf, "%%s; you %s", fmt);
  29. 	    obj_name[0] = highc(obj_name[0]);
  30. 	    pline(fmtbuf, obj_name, (obj->quan > 1) ? "them" : "it",
  31. 		  amt, plur(amt), arg);
  32. 	} else {
  33. 	    You(fmt, obj_name, amt, plur(amt), arg);
  34. 	}
  35. }

addtobill[edit]

  1. void
  2. addtobill(obj, ininv, dummy, silent)
  3. register struct obj *obj;
  4. register boolean ininv, dummy, silent;
  5. {
  6. 	register struct monst *shkp;
  7. 	register char roomno = *u.ushops;
  8. 	long ltmp = 0L, cltmp = 0L, gltmp = 0L;
  9. 	register boolean container = Has_contents(obj);
  10.  
  11. 	if(!*u.ushops) return;
  12.  
  13. 	if(!(shkp = shop_keeper(roomno))) return;
  14.  
  15. 	if(!inhishop(shkp)) return;
  16.  
  17. 	if(/* perhaps we threw it away earlier */
  18. 		 onbill(obj, shkp, FALSE) ||
  19. 		 (obj->oclass == FOOD_CLASS && obj->oeaten)
  20. 	      ) return;
  21.  
  22. 	if(ESHK(shkp)->billct == BILLSZ) {
  23. 		You("got that for free!");
  24. 		return;
  25. 	}
  26.  
  27. 	if(obj->oclass == COIN_CLASS) {
  28. 		costly_gold(obj->ox, obj->oy, obj->quan);
  29. 		return;
  30. 	}
  31.  
  32. 	if(!obj->no_charge)
  33. 	    ltmp = get_cost(obj, shkp);
  34.  
  35. 	if (obj->no_charge && !container) {
  36. 		obj->no_charge = 0;
  37. 		return;
  38. 	}
  39.  
  40. 	if(container) {
  41. 	    if(obj->cobj == (struct obj *)0) {
  42. 		if(obj->no_charge) {
  43. 		    obj->no_charge = 0;
  44. 		    return;
  45. 		} else {
  46. 		    add_one_tobill(obj, dummy);
  47. 		    goto speak;
  48. 		}
  49. 	    } else {
  50. 		cltmp += contained_cost(obj, shkp, cltmp, FALSE, FALSE);
  51. 		gltmp += contained_gold(obj);
  52. 	    }
  53.  
  54. 	    if(ltmp) add_one_tobill(obj, dummy);
  55. 	    if(cltmp) bill_box_content(obj, ininv, dummy, shkp);
  56. 	    picked_container(obj); /* reset contained obj->no_charge */
  57.  
  58. 	    ltmp += cltmp;
  59.  
  60. 	    if(gltmp) {
  61. 		costly_gold(obj->ox, obj->oy, gltmp);
  62. 		if(!ltmp) return;
  63. 	    }
  64.  
  65. 	    if(obj->no_charge)
  66. 		obj->no_charge = 0;
  67.  
  68. 	} else /* i.e., !container */
  69. 	    add_one_tobill(obj, dummy);
  70. speak:
  71. 	if (shkp->mcanmove && !shkp->msleeping && !silent) {
  72. 	    char buf[BUFSZ];
  73.  
  74. 	    if(!ltmp) {
  75. 		pline("%s has no interest in %s.", Monnam(shkp),
  76. 					     the(xname(obj)));
  77. 		return;
  78. 	    }
  79. 	    Strcpy(buf, "\"For you, ");
  80. 	    if (ANGRY(shkp)) Strcat(buf, "scum ");
  81. 	    else {
  82. 		static const char *honored[5] = {
  83. 		  "good", "honored", "most gracious", "esteemed",
  84. 		  "most renowned and sacred"
  85. 		};
  86. 		Strcat(buf, honored[rn2(4) + u.uevent.udemigod]);
  87. 		if (!is_human(youmonst.data)) Strcat(buf, " creature");
  88. 		else
  89. 		    Strcat(buf, (flags.female) ? " lady" : " sir");
  90. 	    }
  91. 	    if(ininv) {
  92. 		long quan = obj->quan;
  93. 		obj->quan = 1L; /* fool xname() into giving singular */
  94. 		pline("%s; only %ld %s %s.\"", buf, ltmp,
  95. 			(quan > 1L) ? "per" : "for this", xname(obj));
  96. 		obj->quan = quan;
  97. 	    } else
  98. 		pline("%s will cost you %ld %s%s.",
  99. 			The(xname(obj)), ltmp, currency(ltmp),
  100. 			(obj->quan > 1L) ? " each" : "");
  101. 	} else if(!silent) {
  102. 	    if(ltmp) pline_The("list price of %s is %ld %s%s.",
  103. 				   the(xname(obj)), ltmp, currency(ltmp),
  104. 				   (obj->quan > 1L) ? " each" : "");
  105. 	    else pline("%s does not notice.", Monnam(shkp));
  106. 	}
  107. }

splitbill[edit]

  1. void
  2. splitbill(obj, otmp)
  3. register struct obj *obj, *otmp;
  4. {
  5. 	/* otmp has been split off from obj */
  6. 	register struct bill_x *bp;
  7. 	register long tmp;
  8. 	register struct monst *shkp = shop_keeper(*u.ushops);
  9.  
  10. 	if(!shkp || !inhishop(shkp)) {
  11. 		impossible("splitbill: no resident shopkeeper??");
  12. 		return;
  13. 	}
  14. 	bp = onbill(obj, shkp, FALSE);
  15. 	if(!bp) {
  16. 		impossible("splitbill: not on bill?");
  17. 		return;
  18. 	}
  19. 	if(bp->bquan < otmp->quan) {
  20. 		impossible("Negative quantity on bill??");
  21. 	}
  22. 	if(bp->bquan == otmp->quan) {
  23. 		impossible("Zero quantity on bill??");
  24. 	}
  25. 	bp->bquan -= otmp->quan;
  26.  
  27. 	if(ESHK(shkp)->billct == BILLSZ) otmp->unpaid = 0;
  28. 	else {
  29. 		tmp = bp->price;
  30. 		bp = &(ESHK(shkp)->bill_p[ESHK(shkp)->billct]);
  31. 		bp->bo_id = otmp->o_id;
  32. 		bp->bquan = otmp->quan;
  33. 		bp->useup = 0;
  34. 		bp->price = tmp;
  35. 		ESHK(shkp)->billct++;
  36. 	}
  37. }

sub_one_frombill[edit]

  1. STATIC_OVL void
  2. sub_one_frombill(obj, shkp)
  3. register struct obj *obj;
  4. register struct monst *shkp;
  5. {
  6. 	register struct bill_x *bp;
  7.  
  8. 	if((bp = onbill(obj, shkp, FALSE)) != 0) {
  9. 		register struct obj *otmp;
  10.  
  11. 		obj->unpaid = 0;
  12. 		if(bp->bquan > obj->quan){
  13. 			otmp = newobj(0);
  14. 			*otmp = *obj;
  15. 			bp->bo_id = otmp->o_id = flags.ident++;
  16. 			otmp->where = OBJ_FREE;
  17. 			otmp->quan = (bp->bquan -= obj->quan);
  18. 			otmp->owt = 0;	/* superfluous */
  19. 			otmp->onamelth = 0;
  20. 			otmp->oxlth = 0;
  21. 			otmp->oattached = OATTACHED_NOTHING;
  22. 			bp->useup = 1;
  23. 			add_to_billobjs(otmp);
  24. 			return;
  25. 		}
  26. 		ESHK(shkp)->billct--;
  27. #ifdef DUMB
  28. 		{
  29. 		/* DRS/NS 2.2.6 messes up -- Peter Kendell */
  30. 			int indx = ESHK(shkp)->billct;
  31. 			*bp = ESHK(shkp)->bill_p[indx];
  32. 		}
  33. #else
  34. 		*bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct];
  35. #endif
  36. 		return;
  37. 	} else if (obj->unpaid) {
  38. 		impossible("sub_one_frombill: unpaid object not on bill");
  39. 		obj->unpaid = 0;
  40. 	}
  41. }

subfrombill[edit]

  1. /* recursive check of unpaid objects within nested containers. */
  2. void
  3. subfrombill(obj, shkp)
  4. register struct obj *obj;
  5. register struct monst *shkp;
  6. {
  7. 	register struct obj *otmp;
  8.  
  9. 	sub_one_frombill(obj, shkp);
  10.  
  11. 	if (Has_contents(obj))
  12. 	    for(otmp = obj->cobj; otmp; otmp = otmp->nobj) {
  13. 		if(otmp->oclass == COIN_CLASS) continue;
  14.  
  15. 		if (Has_contents(otmp))
  16. 		    subfrombill(otmp, shkp);
  17. 		else
  18. 		    sub_one_frombill(otmp, shkp);
  19. 	    }
  20. }
  21.  
  22. #endif /*OVLB*/

stolen_container[edit]

  1. #ifdef OVL3
  2.  
  3. STATIC_OVL long
  4. stolen_container(obj, shkp, price, ininv)
  5. register struct obj *obj;
  6. register struct monst *shkp;
  7. long price;
  8. register boolean ininv;
  9. {
  10. 	register struct obj *otmp;
  11.  
  12. 	if(ininv && obj->unpaid)
  13. 	    price += get_cost(obj, shkp);
  14. 	else {
  15. 	    if(!obj->no_charge)
  16. 		price += get_cost(obj, shkp);
  17. 	    obj->no_charge = 0;
  18. 	}
  19.  
  20. 	/* the price of contained objects, if any */
  21. 	for(otmp = obj->cobj; otmp; otmp = otmp->nobj) {
  22.  
  23. 	    if(otmp->oclass == COIN_CLASS) continue;
  24.  
  25. 	    if (!Has_contents(otmp)) {
  26. 		if(ininv) {
  27. 		    if(otmp->unpaid)
  28. 			price += otmp->quan * get_cost(otmp, shkp);
  29. 		} else {
  30. 		    if(!otmp->no_charge) {
  31. 			if(otmp->oclass != FOOD_CLASS || !otmp->oeaten)
  32. 			    price += otmp->quan * get_cost(otmp, shkp);
  33. 		    }
  34. 		    otmp->no_charge = 0;
  35. 		}
  36. 	    } else
  37. 		price += stolen_container(otmp, shkp, price, ininv);
  38. 	}
  39.  
  40. 	return(price);
  41. }
  42. #endif /*OVL3*/

stolen_value[edit]

  1. #ifdef OVLB
  2.  
  3. long
  4. stolen_value(obj, x, y, peaceful, silent)
  5. register struct obj *obj;
  6. register xchar x, y;
  7. register boolean peaceful, silent;
  8. {
  9. 	register long value = 0L, gvalue = 0L;
  10. 	register struct monst *shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
  11.  
  12. 	if (!shkp || !inhishop(shkp))
  13. 	    return (0L);
  14.  
  15. 	if(obj->oclass == COIN_CLASS) {
  16. 	    gvalue += obj->quan;
  17. 	} else if (Has_contents(obj)) {
  18. 	    register boolean ininv = !!count_unpaid(obj->cobj);
  19.  
  20. 	    value += stolen_container(obj, shkp, value, ininv);
  21. 	    if(!ininv) gvalue += contained_gold(obj);
  22. 	} else if (!obj->no_charge && saleable(shkp, obj)) {
  23. 	    value += get_cost(obj, shkp);
  24. 	}
  25.  
  26. 	if(gvalue + value == 0L) return(0L);
  27.  
  28. 	value += gvalue;
  29.  
  30. 	if(peaceful) {
  31. 	    boolean credit_use = !!ESHK(shkp)->credit;
  32. 	    value = check_credit(value, shkp);
  33. 	    /* 'peaceful' affects general treatment, but doesn't affect
  34. 	     * the fact that other code expects that all charges after the
  35. 	     * shopkeeper is angry are included in robbed, not debit */
  36. 	    if (ANGRY(shkp))
  37. 		ESHK(shkp)->robbed += value;
  38. 	    else 
  39. 		ESHK(shkp)->debit += value;
  40.  
  41. 	    if(!silent) {
  42. 		const char *still = "";
  43.  
  44. 		if (credit_use) {
  45. 		    if (ESHK(shkp)->credit) {
  46. 			You("have %ld %s credit remaining.",
  47. 				 ESHK(shkp)->credit, currency(ESHK(shkp)->credit));
  48. 			return value;
  49. 		    } else if (!value) {
  50. 			You("have no credit remaining.");
  51. 			return 0;
  52. 		    }
  53. 		    still = "still ";
  54. 		}
  55. 		if(obj->oclass == COIN_CLASS)
  56. 		    You("%sowe %s %ld %s!", still,
  57. 			mon_nam(shkp), value, currency(value));
  58. 		else
  59. 		    You("%sowe %s %ld %s for %s!", still,
  60. 			mon_nam(shkp), value, currency(value),
  61. 			obj->quan > 1L ? "them" : "it");
  62. 	    }
  63. 	} else {
  64. 	    ESHK(shkp)->robbed += value;
  65.  
  66. 	    if(!silent) {
  67. 		if(cansee(shkp->mx, shkp->my)) {
  68. 		    Norep("%s booms: \"%s, you are a thief!\"",
  69. 				Monnam(shkp), plname);
  70. 		} else  Norep("You hear a scream, \"Thief!\"");
  71. 	    }
  72. 	    hot_pursuit(shkp);
  73. 	    (void) angry_guards(FALSE);
  74. 	}
  75. 	return(value);
  76. }

sellobj_state[edit]

  1. /* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */
  2. static char sell_response = 'a';
  3. static int sell_how = SELL_NORMAL;
  4. /* can't just use sell_response='y' for auto_credit because the 'a' response
  5. shouldn't carry over from ordinary selling to credit selling */
  6. static boolean auto_credit = FALSE;
  7.  
  8. void
  9. sellobj_state(deliberate)
  10. int deliberate;
  11. {
  12. 	/* If we're deliberately dropping something, there's no automatic
  13. 	   response to the shopkeeper's "want to sell" query; however, if we
  14. 	   accidentally drop anything, the shk will buy it/them without asking.
  15. 	   This retains the old pre-query risk that slippery fingers while in
  16. 	   shops entailed:  you drop it, you've lost it.
  17. 	 */
  18. 	sell_response = (deliberate != SELL_NORMAL) ? '\0' : 'a';
  19. 	sell_how = deliberate;
  20. 	auto_credit = FALSE;
  21. }

sellobj[edit]

  1. void
  2. sellobj(obj, x, y)
  3. register struct obj *obj;
  4. xchar x, y;
  5. {
  6. 	register struct monst *shkp;
  7. 	register struct eshk *eshkp;
  8. 	long ltmp = 0L, cltmp = 0L, gltmp = 0L, offer;
  9. 	boolean saleitem, cgold = FALSE, container = Has_contents(obj);
  10. 	boolean isgold = (obj->oclass == COIN_CLASS);
  11. 	boolean only_partially_your_contents = FALSE;
  12.  
  13. 	if(!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) ||
  14. 	   !inhishop(shkp)) return;
  15. 	if(!costly_spot(x, y))	return;
  16. 	if(!*u.ushops) return;
  17.  
  18. 	if(obj->unpaid && !container && !isgold) {
  19. 	    sub_one_frombill(obj, shkp);
  20. 	    return;
  21. 	}
  22. 	if(container) {
  23. 		/* find the price of content before subfrombill */
  24. 		cltmp += contained_cost(obj, shkp, cltmp, TRUE, FALSE);
  25. 		/* find the value of contained gold */
  26. 		gltmp += contained_gold(obj);
  27. 		cgold = (gltmp > 0L);
  28. 	}
  29.  
  30. 	saleitem = saleable(shkp, obj);
  31. 	if(!isgold && !obj->unpaid && saleitem)
  32. 	    ltmp = set_cost(obj, shkp);
  33.  
  34. 	offer = ltmp + cltmp;
  35.  
  36. 	/* get one case out of the way: nothing to sell, and no gold */
  37. 	if(!isgold &&
  38. 	   ((offer + gltmp) == 0L || sell_how == SELL_DONTSELL)) {
  39. 		register boolean unpaid = (obj->unpaid ||
  40. 				  (container && count_unpaid(obj->cobj)));
  41.  
  42. 		if(container) {
  43. 			dropped_container(obj, shkp, FALSE);
  44. 			if(!obj->unpaid && !saleitem)
  45. 			    obj->no_charge = 1;
  46. 			if(obj->unpaid || count_unpaid(obj->cobj))
  47. 			    subfrombill(obj, shkp);
  48. 		} else obj->no_charge = 1;
  49.  
  50. 		if(!unpaid && (sell_how != SELL_DONTSELL))
  51. 		    pline("%s seems uninterested.", Monnam(shkp));
  52. 		return;
  53. 	}
  54.  
  55. 	/* you dropped something of your own - probably want to sell it */
  56. 	rouse_shk(shkp, TRUE);	/* wake up sleeping or paralyzed shk */
  57. 	eshkp = ESHK(shkp);
  58.  
  59. 	if (ANGRY(shkp)) { /* they become shop-objects, no pay */
  60. 		pline("Thank you, scum!");
  61. 		subfrombill(obj, shkp);
  62. 		return;
  63. 	}
  64.  
  65. 	if(eshkp->robbed) {  /* shkp is not angry? */
  66. 		if(isgold) offer = obj->quan;
  67. 		else if(cgold) offer += cgold;
  68. 		if((eshkp->robbed -= offer < 0L))
  69. 			eshkp->robbed = 0L;
  70. 		if(offer) verbalize(
  71. "Thank you for your contribution to restock this recently plundered shop.");
  72. 		subfrombill(obj, shkp);
  73. 		return;
  74. 	}
  75.  
  76. 	if(isgold || cgold) {
  77. 		if(!cgold) gltmp = obj->quan;
  78.  
  79. 		if(eshkp->debit >= gltmp) {
  80. 		    if(eshkp->loan) { /* you carry shop's gold */
  81. 			 if(eshkp->loan >= gltmp)
  82. 			     eshkp->loan -= gltmp;
  83. 			 else eshkp->loan = 0L;
  84. 		    }
  85. 		    eshkp->debit -= gltmp;
  86. 		    Your("debt is %spaid off.",
  87. 				eshkp->debit ? "partially " : "");
  88. 		} else {
  89. 		    long delta = gltmp - eshkp->debit;
  90.  
  91. 		    eshkp->credit += delta;
  92. 		    if(eshkp->debit) {
  93. 			eshkp->debit = 0L;
  94. 			eshkp->loan = 0L;
  95. 			Your("debt is paid off.");
  96. 		    }
  97. 		    pline("%ld %s %s added to your credit.",
  98. 				delta, currency(delta), delta > 1L ? "are" : "is");
  99. 		}
  100. 		if(offer) goto move_on;
  101. 		else {
  102. 		    if(!isgold) {
  103. 			if (container)
  104. 			    dropped_container(obj, shkp, FALSE);
  105. 			if (!obj->unpaid && !saleitem) obj->no_charge = 1;
  106. 			subfrombill(obj, shkp);
  107. 		    }
  108. 		    return;
  109. 		}
  110. 	}
  111. move_on:
  112. 	if((!saleitem && !(container && cltmp > 0L))
  113. 	   || eshkp->billct == BILLSZ
  114. 	   || obj->oclass == BALL_CLASS
  115. 	   || obj->oclass == CHAIN_CLASS || offer == 0L
  116. 	   || (obj->oclass == FOOD_CLASS && obj->oeaten)
  117. 	   || (Is_candle(obj) &&
  118. 		   obj->age < 20L * (long)objects[obj->otyp].oc_cost)) {
  119. 		pline("%s seems uninterested%s.", Monnam(shkp),
  120. 			cgold ? " in the rest" : "");
  121. 		if (container)
  122. 		    dropped_container(obj, shkp, FALSE);
  123. 		obj->no_charge = 1;
  124. 		return;
  125. 	}
  126.  
  127. #ifndef GOLDOBJ
  128. 	if(!shkp->mgold) {
  129. #else
  130. 	if(!money_cnt(shkp->minvent)) {
  131. #endif
  132. 		char c, qbuf[BUFSZ];
  133. 		long tmpcr = ((offer * 9L) / 10L) + (offer <= 1L);
  134.  
  135. 		if (sell_how == SELL_NORMAL || auto_credit) {
  136. 		    c = sell_response = 'y';
  137. 		} else if (sell_response != 'n') {
  138. 		    pline("%s cannot pay you at present.", Monnam(shkp));
  139. 		    Sprintf(qbuf,
  140. 			    "Will you accept %ld %s in credit for %s?",
  141. 			    tmpcr, currency(tmpcr), doname(obj));
  142. 		    /* won't accept 'a' response here */
  143. 		    /* KLY - 3/2000 yes, we will, it's a damn nuisance
  144. to have to constantly hit 'y' to sell for credit */
  145. 		    c = ynaq(qbuf);
  146. 		    if (c == 'a') {
  147. 			c = 'y';
  148. 			auto_credit = TRUE;
  149. 		    }
  150. 		} else		/* previously specified "quit" */
  151. 		    c = 'n';
  152.  
  153. 		if (c == 'y') {
  154. 		    shk_names_obj(shkp, obj, (sell_how != SELL_NORMAL) ?
  155. 			    "traded %s for %ld zorkmid%s in %scredit." :
  156. 			"relinquish %s and acquire %ld zorkmid%s in %scredit.",
  157. 			    tmpcr,
  158. 			    (eshkp->credit > 0L) ? "additional " : "");
  159. 		    eshkp->credit += tmpcr;
  160. 		    subfrombill(obj, shkp);
  161. 		} else {
  162. 		    if (c == 'q') sell_response = 'n';
  163. 		    if (container)
  164. 			dropped_container(obj, shkp, FALSE);
  165. 		    if (!obj->unpaid) obj->no_charge = 1;
  166. 		    subfrombill(obj, shkp);
  167. 		}
  168. 	} else {
  169. 		char qbuf[BUFSZ];
  170. #ifndef GOLDOBJ
  171. 		boolean short_funds = (offer > shkp->mgold);
  172. 		if (short_funds) offer = shkp->mgold;
  173. #else
  174. long shkmoney = money_cnt(shkp->minvent);
  175. 		boolean short_funds = (offer > shkmoney);
  176. 		if (short_funds) offer = shkmoney;
  177. #endif
  178. 		if (!sell_response) {
  179. 		    only_partially_your_contents =
  180. 			(contained_cost(obj, shkp, 0L, FALSE, FALSE) !=
  181. 			 contained_cost(obj, shkp, 0L, FALSE, TRUE));
  182. 		    Sprintf(qbuf,
  183. 			 "%s offers%s %ld gold piece%s for%s %s %s.  Sell %s?",
  184. 			    Monnam(shkp), short_funds ? " only" : "",
  185. 			    offer, plur(offer),
  186. 			    (!ltmp && cltmp && only_partially_your_contents) ?
  187. 			     " your items in" : (!ltmp && cltmp) ? " the contents of" : "",
  188. 			    obj->unpaid ? "the" : "your", cxname(obj),
  189. 			    (obj->quan == 1L &&
  190. 			    !(!ltmp && cltmp && only_partially_your_contents)) ?
  191. 			    "it" : "them");
  192. 		} else  qbuf[0] = '\0';		/* just to pacify lint */
  193.  
  194. 		switch (sell_response ? sell_response : ynaq(qbuf)) {
  195. 		 case 'q':  sell_response = 'n';
  196. 		 case 'n':  if (container)
  197. 				dropped_container(obj, shkp, FALSE);
  198. 			    if (!obj->unpaid) obj->no_charge = 1;
  199. 			    subfrombill(obj, shkp);
  200. 			    break;
  201. 		 case 'a':  sell_response = 'y';
  202. 		 case 'y':  if (container)
  203. 				dropped_container(obj, shkp, TRUE);
  204. 			    if (!obj->unpaid && !saleitem) obj->no_charge = 1;
  205. 			    subfrombill(obj, shkp);
  206. 			    pay(-offer, shkp);
  207. 			    shk_names_obj(shkp, obj, (sell_how != SELL_NORMAL) ?
  208. 				    (!ltmp && cltmp && only_partially_your_contents) ?
  209. 			    	    "sold some items inside %s for %ld gold pieces%s.%s" :
  210. 				    "sold %s for %ld gold piece%s.%s" :
  211. 	       "relinquish %s and receive %ld gold piece%s in compensation.%s",
  212. 				    offer, "");
  213. 			    break;
  214. 		 default:   impossible("invalid sell response");
  215. 		}
  216. 	}
  217. }

doinvbill[edit]

  1. int
  2. doinvbill(mode)
  3. int mode;		/* 0: deliver count 1: paged */
  4. {
  5. #ifdef	__SASC
  6. 	void sasc_bug(struct obj *, unsigned);
  7. #endif
  8. 	struct monst *shkp;
  9. 	struct eshk *eshkp;
  10. 	struct bill_x *bp, *end_bp;
  11. 	struct obj *obj;
  12. 	long totused;
  13. 	char *buf_p;
  14. 	winid datawin;
  15.  
  16. 	shkp = shop_keeper(*u.ushops);
  17. 	if (!shkp || !inhishop(shkp)) {
  18. 	    if (mode != 0) impossible("doinvbill: no shopkeeper?");
  19. 	    return 0;
  20. 	}
  21. 	eshkp = ESHK(shkp);
  22.  
  23. 	if (mode == 0) {
  24. 	    /* count expended items, so that the `I' command can decide
  25. 	       whether to include 'x' in its prompt string */
  26. 	    int cnt = !eshkp->debit ? 0 : 1;
  27.  
  28. 	    for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct];
  29. 		    bp < end_bp; bp++)
  30. 		if (bp->useup ||
  31. 			((obj = bp_to_obj(bp)) != 0 && obj->quan < bp->bquan))
  32. 		    cnt++;
  33. 	    return cnt;
  34. 	}
  35.  
  36. 	datawin = create_nhwindow(NHW_MENU);
  37. 	putstr(datawin, 0, "Unpaid articles already used up:");
  38. 	putstr(datawin, 0, "");
  39.  
  40. 	totused = 0L;
  41. 	for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct];
  42. 		bp < end_bp; bp++) {
  43. 	    obj = bp_to_obj(bp);
  44. 	    if(!obj) {
  45. 		impossible("Bad shopkeeper administration.");
  46. 		goto quit;
  47. 	    }
  48. 	    if(bp->useup || bp->bquan > obj->quan) {
  49. 		long oquan, uquan, thisused;
  50. 		unsigned save_unpaid;
  51.  
  52. 		save_unpaid = obj->unpaid;
  53. 		oquan = obj->quan;
  54. 		uquan = (bp->useup ? bp->bquan : bp->bquan - oquan);
  55. 		thisused = bp->price * uquan;
  56. 		totused += thisused;
  57. 		obj->unpaid = 0;		/* ditto */
  58. 		/* Why 'x'?  To match `I x', more or less. */
  59. 		buf_p = xprname(obj, (char *)0, 'x', FALSE, thisused, uquan);
  60. #ifdef __SASC
  61. 				/* SAS/C 6.2 can't cope for some reason */
  62. 		sasc_bug(obj,save_unpaid);
  63. #else
  64. 		obj->unpaid = save_unpaid;
  65. #endif
  66. 		putstr(datawin, 0, buf_p);
  67. 	    }
  68. 	}
  69. 	if (eshkp->debit) {
  70. 	    /* additional shop debt which has no itemization available */
  71. 	    if (totused) putstr(datawin, 0, "");
  72. 	    totused += eshkp->debit;
  73. 	    buf_p = xprname((struct obj *)0,
  74. 			    "usage charges and/or other fees",
  75. 			    GOLD_SYM, FALSE, eshkp->debit, 0L);
  76. 	    putstr(datawin, 0, buf_p);
  77. 	}
  78. 	buf_p = xprname((struct obj *)0, "Total:", '*', FALSE, totused, 0L);
  79. 	putstr(datawin, 0, "");
  80. 	putstr(datawin, 0, buf_p);
  81. 	display_nhwindow(datawin, FALSE);
  82. quit:
  83. 	destroy_nhwindow(datawin);
  84. 	return(0);
  85. }

getprice[edit]

  1. #define HUNGRY	2
  2.  
  3. STATIC_OVL long
  4. getprice(obj, shk_buying)
  5. register struct obj *obj;
  6. boolean shk_buying;
  7. {
  8. 	register long tmp = (long) objects[obj->otyp].oc_cost;
  9.  
  10. 	if (obj->oartifact) {
  11. 	    tmp = arti_cost(obj);
  12. 	    if (shk_buying) tmp /= 4;
  13. 	}
  14. 	switch(obj->oclass) {
  15. 	case FOOD_CLASS:
  16. 		/* simpler hunger check, (2-4)*cost */
  17. 		if (u.uhs >= HUNGRY && !shk_buying) tmp *= (long) u.uhs;
  18. 		if (obj->oeaten) tmp = 0L;
  19. 		break;
  20. 	case WAND_CLASS:
  21. 		if (obj->spe == -1) tmp = 0L;
  22. 		break;
  23. 	case POTION_CLASS:
  24. 		if (obj->otyp == POT_WATER && !obj->blessed && !obj->cursed)
  25. 			tmp = 0L;
  26. 		break;
  27. 	case ARMOR_CLASS:
  28. 	case WEAPON_CLASS:
  29. 		if (obj->spe > 0) tmp += 10L * (long) obj->spe;
  30. 		break;
  31. 	case TOOL_CLASS:
  32. 		if (Is_candle(obj) &&
  33. 			obj->age < 20L * (long)objects[obj->otyp].oc_cost)
  34. 		    tmp /= 2L;
  35. 		break;
  36. 	}
  37. 	return tmp;
  38. }

shkcatch[edit]

  1. /* shk catches thrown pick-axe */
  2. struct monst *
  3. shkcatch(obj, x, y)
  4. register struct obj *obj;
  5. register xchar x, y;
  6. {
  7. 	register struct monst *shkp;
  8.  
  9. 	if (!(shkp = shop_keeper(inside_shop(x, y))) ||
  10. 	    !inhishop(shkp)) return(0);
  11.  
  12. 	if (shkp->mcanmove && !shkp->msleeping &&
  13. 	    (*u.ushops != ESHK(shkp)->shoproom || !inside_shop(u.ux, u.uy)) &&
  14. 	    dist2(shkp->mx, shkp->my, x, y) < 3 &&
  15. 	    /* if it is the shk's pos, you hit and anger him */
  16. 	    (shkp->mx != x || shkp->my != y)) {
  17. 		if (mnearto(shkp, x, y, TRUE))
  18. 		    verbalize("Out of my way, scum!");
  19. 		if (cansee(x, y)) {
  20. 		    pline("%s nimbly%s catches %s.",
  21. 			  Monnam(shkp),
  22. 			  (x == shkp->mx && y == shkp->my) ? "" : " reaches over and",
  23. 			  the(xname(obj)));
  24. 		    if (!canspotmon(shkp))
  25. 			map_invisible(x, y);
  26. 		    delay_output();
  27. 		    mark_synch();
  28. 		}
  29. 		subfrombill(obj, shkp);
  30. 		(void) mpickobj(shkp, obj);
  31. 		return shkp;
  32. 	}
  33. 	return (struct monst *)0;
  34. }

add_damage[edit]

  1. void
  2. add_damage(x, y, cost)
  3. register xchar x, y;
  4. long cost;
  5. {
  6. 	struct damage *tmp_dam;
  7. 	char *shops;
  8.  
  9. 	if (IS_DOOR(levl[x][y].typ)) {
  10. 	    struct monst *mtmp;
  11.  
  12. 	    /* Don't schedule for repair unless it's a real shop entrance */
  13. 	    for (shops = in_rooms(x, y, SHOPBASE); *shops; shops++)
  14. 		if ((mtmp = shop_keeper(*shops)) != 0 &&
  15. 			x == ESHK(mtmp)->shd.x && y == ESHK(mtmp)->shd.y)
  16. 		    break;
  17. 	    if (!*shops) return;
  18. 	}
  19. 	for (tmp_dam = level.damagelist; tmp_dam; tmp_dam = tmp_dam->next)
  20. 	    if (tmp_dam->place.x == x && tmp_dam->place.y == y) {
  21. 		tmp_dam->cost += cost;
  22. 		return;
  23. 	    }
  24. 	tmp_dam = (struct damage *)alloc((unsigned)sizeof(struct damage));
  25. 	tmp_dam->when = monstermoves;
  26. 	tmp_dam->place.x = x;
  27. 	tmp_dam->place.y = y;
  28. 	tmp_dam->cost = cost;
  29. 	tmp_dam->typ = levl[x][y].typ;
  30. 	tmp_dam->next = level.damagelist;
  31. 	level.damagelist = tmp_dam;
  32. 	/* If player saw damage, display as a wall forever */
  33. 	if (cansee(x, y))
  34. 	    levl[x][y].seenv = SVALL;
  35. }
  36.  
  37. #endif /*OVLB*/

remove_damage[edit]

  1. #ifdef OVL0
  2.  
  3. /*
  4. * Do something about damage. Either (!croaked) try to repair it, or
  5. * (croaked) just discard damage structs for non-shared locations, since
  6. * they'll never get repaired. Assume that shared locations will get
  7. * repaired eventually by the other shopkeeper(s). This might be an erroneous
  8. * assumption (they might all be dead too), but we have no reasonable way of
  9. * telling that.
  10. */
  11. STATIC_OVL
  12. void
  13. remove_damage(shkp, croaked)
  14. register struct monst *shkp;
  15. register boolean croaked;
  16. {
  17. 	register struct damage *tmp_dam, *tmp2_dam;
  18. 	register boolean did_repair = FALSE, saw_door = FALSE;
  19. 	register boolean saw_floor = FALSE, stop_picking = FALSE;
  20. 	register boolean saw_untrap = FALSE;
  21. 	uchar saw_walls = 0;
  22.  
  23. 	tmp_dam = level.damagelist;
  24. 	tmp2_dam = 0;
  25. 	while (tmp_dam) {
  26. 	    register xchar x = tmp_dam->place.x, y = tmp_dam->place.y;
  27. 	    char shops[5];
  28. 	    int disposition;
  29.  
  30. 	    disposition = 0;
  31. 	    Strcpy(shops, in_rooms(x, y, SHOPBASE));
  32. 	    if (index(shops, ESHK(shkp)->shoproom)) {
  33. 		if (croaked)
  34. 		    disposition = (shops[1])? 0 : 1;
  35. 		else if (stop_picking)
  36. 		    disposition = repair_damage(shkp, tmp_dam, FALSE);
  37. 		else {
  38. 		    /* Defer the stop_occupation() until after repair msgs */
  39. 		    if (closed_door(x, y))
  40. 			stop_picking = picking_at(x, y);
  41. 		    disposition = repair_damage(shkp, tmp_dam, FALSE);
  42. 		    if (!disposition)
  43. 			stop_picking = FALSE;
  44. 		}
  45. 	    }
  46.  
  47. 	    if (!disposition) {
  48. 		tmp2_dam = tmp_dam;
  49. 		tmp_dam = tmp_dam->next;
  50. 		continue;
  51. 	    }
  52.  
  53. 	    if (disposition > 1) {
  54. 		did_repair = TRUE;
  55. 		if (cansee(x, y)) {
  56. 		    if (IS_WALL(levl[x][y].typ))
  57. 			saw_walls++;
  58. 		    else if (IS_DOOR(levl[x][y].typ))
  59. 			saw_door = TRUE;
  60. 		    else if (disposition == 3)		/* untrapped */
  61. 			saw_untrap = TRUE;
  62. 		    else
  63. 			saw_floor = TRUE;
  64. 		}
  65. 	    }
  66.  
  67. 	    tmp_dam = tmp_dam->next;
  68. 	    if (!tmp2_dam) {
  69. 		free((genericptr_t)level.damagelist);
  70. 		level.damagelist = tmp_dam;
  71. 	    } else {
  72. 		free((genericptr_t)tmp2_dam->next);
  73. 		tmp2_dam->next = tmp_dam;
  74. 	    }
  75. 	}
  76. 	if (!did_repair)
  77. 	    return;
  78. 	if (saw_walls) {
  79. 	    pline("Suddenly, %s section%s of wall close%s up!",
  80. 		  (saw_walls == 1) ? "a" : (saw_walls <= 3) ?
  81. 						  "some" : "several",
  82. 		  (saw_walls == 1) ? "" : "s", (saw_walls == 1) ? "s" : "");
  83. 	    if (saw_door)
  84. 		pline_The("shop door reappears!");
  85. 	    if (saw_floor)
  86. 		pline_The("floor is repaired!");
  87. 	} else {
  88. 	    if (saw_door)
  89. 		pline("Suddenly, the shop door reappears!");
  90. 	    else if (saw_floor)
  91. 		pline("Suddenly, the floor damage is gone!");
  92. 	    else if (saw_untrap)
  93. 	        pline("Suddenly, the trap is removed from the floor!");
  94. 	    else if (inside_shop(u.ux, u.uy) == ESHK(shkp)->shoproom)
  95. 		You_feel("more claustrophobic than before.");
  96. 	    else if (flags.soundok && !rn2(10))
  97. 		Norep("The dungeon acoustics noticeably change.");
  98. 	}
  99. 	if (stop_picking)
  100. 		stop_occupation();
  101. }

repair_damage[edit]

  1. /*
  2. * 0: repair postponed, 1: silent repair (no messages), 2: normal repair
  3. * 3: untrap
  4. */
  5. int
  6. repair_damage(shkp, tmp_dam, catchup)
  7. register struct monst *shkp;
  8. register struct damage *tmp_dam;
  9. boolean catchup;	/* restoring a level */
  10. {
  11. 	register xchar x, y, i;
  12. 	xchar litter[9];
  13. 	register struct monst *mtmp;
  14. 	register struct obj *otmp;
  15. 	register struct trap *ttmp;
  16.  
  17. 	if ((monstermoves - tmp_dam->when) < REPAIR_DELAY)
  18. 	    return(0);
  19. 	if (shkp->msleeping || !shkp->mcanmove || ESHK(shkp)->following)
  20. 	    return(0);
  21. 	x = tmp_dam->place.x;
  22. 	y = tmp_dam->place.y;
  23. 	if (!IS_ROOM(tmp_dam->typ)) {
  24. 	    if (x == u.ux && y == u.uy)
  25. 		if (!Passes_walls)
  26. 		    return(0);
  27. 	    if (x == shkp->mx && y == shkp->my)
  28. 		return(0);
  29. 	    if ((mtmp = m_at(x, y)) && (!passes_walls(mtmp->data)))
  30. 		return(0);
  31. 	}
  32. 	if ((ttmp = t_at(x, y)) != 0) {
  33. 	    if (x == u.ux && y == u.uy)
  34. 		if (!Passes_walls)
  35. 		    return(0);
  36. 	    if (ttmp->ttyp == LANDMINE || ttmp->ttyp == BEAR_TRAP) {
  37. 		/* convert to an object */
  38. 		otmp = mksobj((ttmp->ttyp == LANDMINE) ? LAND_MINE :
  39. 				BEARTRAP, TRUE, FALSE);
  40. 		otmp->quan= 1;
  41. 		otmp->owt = weight(otmp);
  42. 		(void) mpickobj(shkp, otmp);
  43. 	    }
  44. 	    deltrap(ttmp);
  45. 	    if(IS_DOOR(tmp_dam->typ)) {
  46. 		levl[x][y].doormask = D_CLOSED; /* arbitrary */
  47. 		block_point(x, y);
  48. 	    } else if (IS_WALL(tmp_dam->typ)) {
  49. 		levl[x][y].typ = tmp_dam->typ;
  50. 		block_point(x, y);
  51. 	    }
  52. 	    newsym(x, y);
  53. 	    return(3);
  54. 	}
  55. 	if (IS_ROOM(tmp_dam->typ)) {
  56. 	    /* No messages, because player already filled trap door */
  57. 	    return(1);
  58. 	}
  59. 	if ((tmp_dam->typ == levl[x][y].typ) &&
  60. 	    (!IS_DOOR(tmp_dam->typ) || (levl[x][y].doormask > D_BROKEN)))
  61. 	    /* No messages if player already replaced shop door */
  62. 	    return(1);
  63. 	levl[x][y].typ = tmp_dam->typ;
  64. 	(void) memset((genericptr_t)litter, 0, sizeof(litter));
  65. 	if ((otmp = level.objects[x][y]) != 0) {
  66. 	    /* Scatter objects haphazardly into the shop */
  67. #define NEED_UPDATE 1
  68. #define OPEN	    2
  69. #define INSHOP	    4
  70. #define horiz(i) ((i%3)-1)
  71. #define vert(i)  ((i/3)-1)
  72. 	    for (i = 0; i < 9; i++) {
  73. 		if ((i == 4) || (!ZAP_POS(levl[x+horiz(i)][y+vert(i)].typ)))
  74. 		    continue;
  75. 		litter[i] = OPEN;
  76. 		if (inside_shop(x+horiz(i),
  77. 				y+vert(i)) == ESHK(shkp)->shoproom)
  78. 		    litter[i] |= INSHOP;
  79. 	    }
  80. 	    if (Punished && !u.uswallow &&
  81. 				((uchain->ox == x && uchain->oy == y) ||
  82. 				 (uball->ox == x && uball->oy == y))) {
  83. 		/*
  84. 		 * Either the ball or chain is in the repair location.
  85. 		 *
  86. 		 * Take the easy way out and put ball&chain under hero.
  87. 		 */
  88. 		verbalize("Get your junk out of my wall!");
  89. 		unplacebc();	/* pick 'em up */
  90. 		placebc();	/* put 'em down */
  91. 	    }
  92. 	    while ((otmp = level.objects[x][y]) != 0)
  93. 		/* Don't mess w/ boulders -- just merge into wall */
  94. 		if ((otmp->otyp == BOULDER) || (otmp->otyp == ROCK)) {
  95. 		    obj_extract_self(otmp);
  96. 		    obfree(otmp, (struct obj *)0);
  97. 		} else {
  98. 		    while (!(litter[i = rn2(9)] & INSHOP));
  99. 			remove_object(otmp);
  100. 			place_object(otmp, x+horiz(i), y+vert(i));
  101. 			litter[i] |= NEED_UPDATE;
  102. 		}
  103. 	}
  104. 	if (catchup) return 1;	/* repair occurred while off level */
  105.  
  106. 	block_point(x, y);
  107. 	if(IS_DOOR(tmp_dam->typ)) {
  108. 	    levl[x][y].doormask = D_CLOSED; /* arbitrary */
  109. 	    newsym(x, y);
  110. 	} else {
  111. 	    /* don't set doormask  - it is (hopefully) the same as it was */
  112. 	    /* if not, perhaps save it with the damage array...  */
  113.  
  114. 	    if (IS_WALL(tmp_dam->typ) && cansee(x, y)) {
  115. 	    /* Player sees actual repair process, so they KNOW it's a wall */
  116. 		levl[x][y].seenv = SVALL;
  117. 		newsym(x, y);
  118. 	    }
  119. 	    /* Mark this wall as "repaired".  There currently is no code */
  120. 	    /* to do anything about repaired walls, so don't do it.	 */
  121. 	}
  122. 	for (i = 0; i < 9; i++)
  123. 	    if (litter[i] & NEED_UPDATE)
  124. 		newsym(x+horiz(i), y+vert(i));
  125. 	return(2);
  126. #undef NEED_UPDATE
  127. #undef OPEN
  128. #undef INSHOP
  129. #undef vert
  130. #undef horiz
  131. }
  132. #endif /*OVL0*/

shk_move[edit]

  1. #ifdef OVL3
  2. /*
  3. * shk_move: return 1: moved  0: didn't  -1: let m_move do it  -2: died
  4. */
  5. int
  6. shk_move(shkp)
  7. register struct monst *shkp;
  8. {
  9. 	register xchar gx,gy,omx,omy;
  10. 	register int udist;
  11. 	register schar appr;
  12. 	register struct eshk *eshkp = ESHK(shkp);
  13. 	int z;
  14. 	boolean uondoor = FALSE, satdoor, avoid = FALSE, badinv;
  15.  
  16. 	omx = shkp->mx;
  17. 	omy = shkp->my;
  18.  
  19. 	if (inhishop(shkp))
  20. 	    remove_damage(shkp, FALSE);
  21.  
  22. 	if((udist = distu(omx,omy)) < 3 &&
  23. 	   (shkp->data != &mons[PM_GRID_BUG] || (omx==u.ux || omy==u.uy))) {
  24. 		if(ANGRY(shkp) ||
  25. 		   (Conflict && !resist(shkp, RING_CLASS, 0, 0))) {
  26. 			if(Displaced)
  27. 			  Your("displaced image doesn't fool %s!",
  28. 				mon_nam(shkp));
  29. 			(void) mattacku(shkp);
  30. 			return(0);
  31. 		}
  32. 		if(eshkp->following) {
  33. 			if(strncmp(eshkp->customer, plname, PL_NSIZ)) {
  34. 			    verbalize("%s, %s!  I was looking for %s.",
  35. 				    Hello(shkp), plname, eshkp->customer);
  36. 				    eshkp->following = 0;
  37. 			    return(0);
  38. 			}
  39. 			if(moves > followmsg+4) {
  40. 			    verbalize("%s, %s!  Didn't you forget to pay?",
  41. 				    Hello(shkp), plname);
  42. 			    followmsg = moves;
  43. 			    if (!rn2(9)) {
  44. 			      pline("%s doesn't like customers who don't pay.",
  45. 				    Monnam(shkp));
  46. 				rile_shk(shkp);
  47. 			    }
  48. 			}
  49. 			if(udist < 2)
  50. 			    return(0);
  51. 		}
  52. 	}
  53.  
  54. 	appr = 1;
  55. 	gx = eshkp->shk.x;
  56. 	gy = eshkp->shk.y;
  57. 	satdoor = (gx == omx && gy == omy);
  58. 	if(eshkp->following || ((z = holetime()) >= 0 && z*z <= udist)){
  59. 		/* [This distance check used to apply regardless of
  60. 		    whether the shk was following, but that resulted in
  61. 		    m_move() sometimes taking the shk out of the shop if
  62. 		    the player had fenced him in with boulders or traps.
  63. 		    Such voluntary abandonment left unpaid objects in
  64. 		    invent, triggering billing impossibilities on the
  65. 		    next level once the character fell through the hole.] */
  66. 		if (udist > 4 && eshkp->following)
  67. 		    return(-1);	/* leave it to m_move */
  68. 		gx = u.ux;
  69. 		gy = u.uy;
  70. 	} else if(ANGRY(shkp)) {
  71. 		/* Move towards the hero if the shopkeeper can see him. */
  72. 		if(shkp->mcansee && m_canseeu(shkp)) {
  73. 			gx = u.ux;
  74. 			gy = u.uy;
  75. 		}
  76. 		avoid = FALSE;
  77. 	} else {
  78. #define	GDIST(x,y)	(dist2(x,y,gx,gy))
  79. 		if (Invis
  80. #ifdef STEED
  81. 			|| u.usteed
  82. #endif
  83. 			) {
  84. 		    avoid = FALSE;
  85. 		} else {
  86. 		    uondoor = (u.ux == eshkp->shd.x && u.uy == eshkp->shd.y);
  87. 		    if(uondoor) {
  88. 			badinv = (carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK) ||
  89. 				  (Fast && (sobj_at(PICK_AXE, u.ux, u.uy) ||
  90. 				  sobj_at(DWARVISH_MATTOCK, u.ux, u.uy))));
  91. 			if(satdoor && badinv)
  92. 			    return(0);
  93. 			avoid = !badinv;
  94. 		    } else {
  95. 			avoid = (*u.ushops && distu(gx,gy) > 8);
  96. 			badinv = FALSE;
  97. 		    }
  98.  
  99. 		    if(((!eshkp->robbed && !eshkp->billct && !eshkp->debit)
  100. 			|| avoid) && GDIST(omx,omy) < 3) {
  101. 			if (!badinv && !onlineu(omx,omy))
  102. 			    return(0);
  103. 			if(satdoor)
  104. 			    appr = gx = gy = 0;
  105. 		    }
  106. 		}
  107. 	}
  108.  
  109. 	z = move_special(shkp,inhishop(shkp),appr,uondoor,avoid,omx,omy,gx,gy);
  110. 	if (z > 0) after_shk_move(shkp);
  111.  
  112. 	return z;
  113. }

after_shk_move[edit]

  1. /* called after shopkeeper moves, in case the move causes re-entry into shop */
  2. void
  3. after_shk_move(shkp)
  4. struct monst *shkp;
  5. {
  6. 	struct eshk *eshkp = ESHK(shkp);
  7.  
  8. 	if (eshkp->bill_p == (struct bill_x *) -1000 && inhishop(shkp)) {
  9. 	    /* reset bill_p, need to re-calc player's occupancy too */
  10. 	    eshkp->bill_p = &eshkp->bill[0];
  11. 	    check_special_room(FALSE);
  12. 	}
  13. }
  14.  
  15. #endif /*OVL3*/

is_fshk[edit]

levl_follower (mondata.c)

  1. #ifdef OVLB
  2.  
  3. /* for use in levl_follower (mondata.c) */
  4. boolean
  5. is_fshk(mtmp)
  6. register struct monst *mtmp;
  7. {
  8. 	return((boolean)(mtmp->isshk && ESHK(mtmp)->following));
  9. }

shopdig[edit]

  1. /* You are digging in the shop. */
  2. void
  3. shopdig(fall)
  4. register int fall;
  5. {
  6. register struct monst *shkp = shop_keeper(*u.ushops);
  7. int lang;
  8. const char *grabs = "grabs";
  9.  
  10. if(!shkp) return;
  11.  
  12. /* 0 == can't speak, 1 == makes animal noises, 2 == speaks */
  13. lang = 0;
  14. if (shkp->msleeping || !shkp->mcanmove || is_silent(shkp->data))
  15. 	;	/* lang stays 0 */
  16. else if (shkp->data->msound <= MS_ANIMAL)
  17. 	lang = 1;
  18. else if (shkp->data->msound >= MS_HUMANOID)
  19. 	lang = 2;
  20.  
  21. if(!inhishop(shkp)) {
  22. 	if (Role_if(PM_KNIGHT)) {
  23. 	    You_feel("like a common thief.");
  24. 	    adjalign(-sgn(u.ualign.type));
  25. 	}
  26. 	return;
  27. }
  28.  
  29. if(!fall) {
  30. 	if (lang == 2) {
  31. 	    if(u.utraptype == TT_PIT)
  32. 		verbalize(
  33. 			"Be careful, %s, or you might fall through the floor.",
  34. 			flags.female ? "madam" : "sir");
  35. 	    else
  36. 		verbalize("%s, do not damage the floor here!",
  37. 			flags.female ? "Madam" : "Sir");
  38. 	}
  39. 	if (Role_if(PM_KNIGHT)) {
  40. 	    You_feel("like a common thief.");
  41. 	    adjalign(-sgn(u.ualign.type));
  42. 	}
  43. } else if(!um_dist(shkp->mx, shkp->my, 5) &&
  44. 		!shkp->msleeping && shkp->mcanmove &&
  45. 		(ESHK(shkp)->billct || ESHK(shkp)->debit)) {
  46. 	    register struct obj *obj, *obj2;
  47. 	    if (nolimbs(shkp->data)) {
  48. 		grabs = "knocks off";
  49. #if 0
  50. 	       /* This is what should happen, but for balance
  51. 	        * reasons, it isn't currently.
  52. 	        */
  53. 		if (lang == 2)
  54. 		    pline("%s curses %s inability to grab your backpack!",
  55. 			  shkname(shkp), mhim(shkp));
  56. 		rile_shk(shkp);
  57. 		return;
  58. #endif
  59. 	    }
  60. 	    if (distu(shkp->mx, shkp->my) > 2) {
  61. 		mnexto(shkp);
  62. 		/* for some reason the shopkeeper can't come next to you */
  63. 		if (distu(shkp->mx, shkp->my) > 2) {
  64. 		    if (lang == 2)
  65. 			pline("%s curses you in anger and frustration!",
  66. 			      shkname(shkp));
  67. 		    rile_shk(shkp);
  68. 		    return;
  69. 		} else
  70. 		    pline("%s %s, and %s your backpack!",
  71. 			  shkname(shkp),
  72. 			  makeplural(locomotion(shkp->data,"leap")), grabs);
  73. 	    } else
  74. 		pline("%s %s your backpack!", shkname(shkp), grabs);
  75.  
  76. 	    for(obj = invent; obj; obj = obj2) {
  77. 		obj2 = obj->nobj;
  78. 		if ((obj->owornmask & ~(W_SWAPWEP|W_QUIVER)) != 0 ||
  79. 			(obj == uswapwep && u.twoweap) ||
  80. 			(obj->otyp == LEASH && obj->leashmon)) continue;
  81. 		if (obj == current_wand) continue;
  82. 		setnotworn(obj);
  83. 		freeinv(obj);
  84. 		subfrombill(obj, shkp);
  85. 		(void) add_to_minv(shkp, obj);	/* may free obj */
  86. 	    }
  87. }
  88. }

makekops[edit]

  1. #ifdef KOPS
  2. STATIC_OVL void
  3. makekops(mm)
  4. coord *mm;
  5. {
  6. 	static const short k_mndx[4] = {
  7. 	    PM_KEYSTONE_KOP, PM_KOP_SERGEANT, PM_KOP_LIEUTENANT, PM_KOP_KAPTAIN
  8. 	};
  9. 	int k_cnt[4], cnt, mndx, k;
  10.  
  11. 	k_cnt[0] = cnt = abs(depth(&u.uz)) + rnd(5);
  12. 	k_cnt[1] = (cnt / 3) + 1;	/* at least one sarge */
  13. 	k_cnt[2] = (cnt / 6);		/* maybe a lieutenant */
  14. 	k_cnt[3] = (cnt / 9);		/* and maybe a kaptain */
  15.  
  16. 	for (k = 0; k < 4; k++) {
  17. 	    if ((cnt = k_cnt[k]) == 0) break;
  18. 	    mndx = k_mndx[k];
  19. 	    if (mvitals[mndx].mvflags & G_GONE) continue;
  20.  
  21. 	    while (cnt--)
  22. 		if (enexto(mm, mm->x, mm->y, &mons[mndx]))
  23. 		    (void) makemon(&mons[mndx], mm->x, mm->y, NO_MM_FLAGS);
  24. 	}
  25. }
  26. #endif	/* KOPS */

pay_for_damage[edit]

  1. void
  2. pay_for_damage(dmgstr, cant_mollify)
  3. const char *dmgstr;
  4. boolean cant_mollify;
  5. {
  6. 	register struct monst *shkp = (struct monst *)0;
  7. 	char shops_affected[5];
  8. 	register boolean uinshp = (*u.ushops != '\0');
  9. 	char qbuf[80];
  10. 	register xchar x, y;
  11. 	boolean dugwall = !strcmp(dmgstr, "dig into") ||	/* wand */
  12. 			  !strcmp(dmgstr, "damage");		/* pick-axe */
  13. 	struct damage *tmp_dam, *appear_here = 0;
  14. 	/* any number >= (80*80)+(24*24) would do, actually */
  15. 	long cost_of_damage = 0L;
  16. 	unsigned int nearest_shk = 7000, nearest_damage = 7000;
  17. 	int picks = 0;
  18.  
  19. 	for (tmp_dam = level.damagelist;
  20. 	     (tmp_dam && (tmp_dam->when == monstermoves));
  21. 	     tmp_dam = tmp_dam->next) {
  22. 	    char *shp;
  23.  
  24. 	    if (!tmp_dam->cost)
  25. 		continue;
  26. 	    cost_of_damage += tmp_dam->cost;
  27. 	    Strcpy(shops_affected,
  28. 		   in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE));
  29. 	    for (shp = shops_affected; *shp; shp++) {
  30. 		struct monst *tmp_shk;
  31. 		unsigned int shk_distance;
  32.  
  33. 		if (!(tmp_shk = shop_keeper(*shp)))
  34. 		    continue;
  35. 		if (tmp_shk == shkp) {
  36. 		    unsigned int damage_distance =
  37. 				   distu(tmp_dam->place.x, tmp_dam->place.y);
  38.  
  39. 		    if (damage_distance < nearest_damage) {
  40. 			nearest_damage = damage_distance;
  41. 			appear_here = tmp_dam;
  42. 		    }
  43. 		    continue;
  44. 		}
  45. 		if (!inhishop(tmp_shk))
  46. 		    continue;
  47. 		shk_distance = distu(tmp_shk->mx, tmp_shk->my);
  48. 		if (shk_distance > nearest_shk)
  49. 		    continue;
  50. 		if ((shk_distance == nearest_shk) && picks) {
  51. 		    if (rn2(++picks))
  52. 			continue;
  53. 		} else
  54. 		    picks = 1;
  55. 		shkp = tmp_shk;
  56. 		nearest_shk = shk_distance;
  57. 		appear_here = tmp_dam;
  58. 		nearest_damage = distu(tmp_dam->place.x, tmp_dam->place.y);
  59. 	    }
  60. 	}
  61.  
  62. 	if (!cost_of_damage || !shkp)
  63. 	    return;
  64.  
  65. 	x = appear_here->place.x;
  66. 	y = appear_here->place.y;
  67.  
  68. 	/* not the best introduction to the shk... */
  69. 	(void) strncpy(ESHK(shkp)->customer,plname,PL_NSIZ);
  70.  
  71. 	/* if the shk is already on the war path, be sure it's all out */
  72. 	if(ANGRY(shkp) || ESHK(shkp)->following) {
  73. 		hot_pursuit(shkp);
  74. 		return;
  75. 	}
  76.  
  77. 	/* if the shk is not in their shop.. */
  78. 	if(!*in_rooms(shkp->mx,shkp->my,SHOPBASE)) {
  79. 		if(!cansee(shkp->mx, shkp->my))
  80. 			return;
  81. 		goto getcad;
  82. 	}
  83.  
  84. 	if(uinshp) {
  85. 		if(um_dist(shkp->mx, shkp->my, 1) &&
  86. 			!um_dist(shkp->mx, shkp->my, 3)) {
  87. 		    pline("%s leaps towards you!", shkname(shkp));
  88. 		    mnexto(shkp);
  89. 		}
  90. 		if(um_dist(shkp->mx, shkp->my, 1)) goto getcad;
  91. 	} else {
  92. 	    /*
  93. 	     * Make shkp show up at the door.  Effect:  If there is a monster
  94. 	     * in the doorway, have the hero hear the shopkeeper yell a bit,
  95. 	     * pause, then have the shopkeeper appear at the door, having
  96. 	     * yanked the hapless critter out of the way.
  97. 	     */
  98. 	    if (MON_AT(x, y)) {
  99. 		if(flags.soundok) {
  100. 		    You_hear("an angry voice:");
  101. 		    verbalize("Out of my way, scum!");
  102. 		    wait_synch();
  103. #if defined(UNIX) || defined(VMS)
  104. # if defined(SYSV) || defined(ULTRIX) || defined(VMS)
  105. 		    (void)
  106. # endif
  107. 			sleep(1);
  108. #endif
  109. 		}
  110. 	    }
  111. 	    (void) mnearto(shkp, x, y, TRUE);
  112. 	}
  113.  
  114. 	if((um_dist(x, y, 1) && !uinshp) || cant_mollify ||
  115. #ifndef GOLDOBJ
  116. 	   (u.ugold + ESHK(shkp)->credit) < cost_of_damage
  117. #else
  118. 	   (money_cnt(invent) + ESHK(shkp)->credit) < cost_of_damage
  119. #endif
  120. 				|| !rn2(50)) {
  121. 		if(um_dist(x, y, 1) && !uinshp) {
  122. 		    pline("%s shouts:", shkname(shkp));
  123. 		    verbalize("Who dared %s my %s?", dmgstr,
  124. 					 dugwall ? "shop" : "door");
  125. 		} else {
  126. getcad:
  127. 		    verbalize("How dare you %s my %s?", dmgstr,
  128. 					 dugwall ? "shop" : "door");
  129. 		}
  130. 		hot_pursuit(shkp);
  131. 		return;
  132. 	}
  133.  
  134. 	if (Invis) Your("invisibility does not fool %s!", shkname(shkp));
  135. 	Sprintf(qbuf,"\"Cad!  You did %ld %s worth of damage!\"  Pay? ",
  136. 		 cost_of_damage, currency(cost_of_damage));
  137. 	if(yn(qbuf) != 'n') {
  138. 		cost_of_damage = check_credit(cost_of_damage, shkp);
  139. #ifndef GOLDOBJ
  140. 		u.ugold -= cost_of_damage;
  141. 		shkp->mgold += cost_of_damage;
  142. #else
  143. money2mon(shkp, cost_of_damage);
  144. #endif
  145. 		flags.botl = 1;
  146. 		pline("Mollified, %s accepts your restitution.",
  147. 			shkname(shkp));
  148. 		/* move shk back to his home loc */
  149. 		home_shk(shkp, FALSE);
  150. 		pacify_shk(shkp);
  151. 	} else {
  152. 		verbalize("Oh, yes!  You'll pay!");
  153. 		hot_pursuit(shkp);
  154. 		adjalign(-sgn(u.ualign.type));
  155. 	}
  156. }
  157. #endif /*OVLB*/

costly_spot[edit]

  1. #ifdef OVL0
  2. /* called in dokick.c when we kick an object that might be in a store */
  3. boolean
  4. costly_spot(x, y)
  5. register xchar x, y;
  6. {
  7. 	register struct monst *shkp;
  8.  
  9. 	if (!level.flags.has_shop) return FALSE;
  10. 	shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
  11. 	if(!shkp || !inhishop(shkp)) return(FALSE);
  12.  
  13. 	return((boolean)(inside_shop(x, y) &&
  14. 		!(x == ESHK(shkp)->shk.x &&
  15. 			y == ESHK(shkp)->shk.y)));
  16. }
  17. #endif /*OVL0*/

shop_object[edit]

  1. #ifdef OVLB
  2.  
  3. /* called by dotalk(sounds.c) when #chatting; returns obj if location
  4. contains shop goods and shopkeeper is willing & able to speak */
  5. struct obj *
  6. shop_object(x, y)
  7. register xchar x, y;
  8. {
  9. register struct obj *otmp;
  10. register struct monst *shkp;
  11.  
  12. if(!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp))
  13. 	return(struct obj *)0;
  14.  
  15. for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
  16. 	if (otmp->oclass != COIN_CLASS)
  17. 	    break;
  18. /* note: otmp might have ->no_charge set, but that's ok */
  19. return (otmp && costly_spot(x, y) && NOTANGRY(shkp)
  20. 	    && shkp->mcanmove && !shkp->msleeping)
  21. 		? otmp : (struct obj *)0;
  22. }

price_quote[edit]

  1. /* give price quotes for all objects linked to this one (ie, on this spot) */
  2. void
  3. price_quote(first_obj)
  4. register struct obj *first_obj;
  5. {
  6. register struct obj *otmp;
  7. char buf[BUFSZ], price[40];
  8. long cost;
  9. int cnt = 0;
  10. winid tmpwin;
  11. struct monst *shkp = shop_keeper(inside_shop(u.ux, u.uy));
  12.  
  13. tmpwin = create_nhwindow(NHW_MENU);
  14. putstr(tmpwin, 0, "Fine goods for sale:");
  15. putstr(tmpwin, 0, "");
  16. for (otmp = first_obj; otmp; otmp = otmp->nexthere) {
  17. 	if (otmp->oclass == COIN_CLASS) continue;
  18. 	cost = (otmp->no_charge || otmp == uball || otmp == uchain) ? 0L :
  19. 		get_cost(otmp, (struct monst *)0);
  20. 	if (Has_contents(otmp))
  21. 	    cost += contained_cost(otmp, shkp, 0L, FALSE, FALSE);
  22. 	if (!cost) {
  23. 	    Strcpy(price, "no charge");
  24. 	} else {
  25. 	    Sprintf(price, "%ld %s%s", cost, currency(cost),
  26. 		    otmp->quan > 1L ? " each" : "");
  27. 	}
  28. 	Sprintf(buf, "%s, %s", doname(otmp), price);
  29. 	putstr(tmpwin, 0, buf),  cnt++;
  30. }
  31. if (cnt > 1) {
  32. 	display_nhwindow(tmpwin, TRUE);
  33. } else if (cnt == 1) {
  34. 	if (first_obj->no_charge || first_obj == uball || first_obj == uchain){
  35. 	    pline("%s!", buf);	/* buf still contains the string */
  36. 	} else {
  37. 	    /* print cost in slightly different format, so can't reuse buf */
  38. 	    cost = get_cost(first_obj, (struct monst *)0);
  39. 	    if (Has_contents(first_obj))
  40. 		cost += contained_cost(first_obj, shkp, 0L, FALSE, FALSE);
  41. 	    pline("%s, price %ld %s%s%s", doname(first_obj),
  42. 		cost, currency(cost), first_obj->quan > 1L ? " each" : "",
  43. 		shk_embellish(first_obj, cost));
  44. 	}
  45. }
  46. destroy_nhwindow(tmpwin);
  47. }
  48. #endif /*OVLB*/

shk_embellish[edit]

  1. #ifdef OVL3
  2.  
  3. STATIC_OVL const char *
  4. shk_embellish(itm, cost)
  5. register struct obj *itm;
  6. long cost;
  7. {
  8. if (!rn2(3)) {
  9. 	register int o, choice = rn2(5);
  10. 	if (choice == 0) choice = (cost < 100L ? 1 : cost < 500L ? 2 : 3);
  11. 	switch (choice) {
  12. 	    case 4:
  13. 		if (cost < 10L) break; else o = itm->oclass;
  14. 		if (o == FOOD_CLASS) return ", gourmets' delight!";
  15. 		if (objects[itm->otyp].oc_name_known
  16. 		    ? objects[itm->otyp].oc_magic
  17. 		    : (o == AMULET_CLASS || o == RING_CLASS   ||
  18. 		       o == WAND_CLASS   || o == POTION_CLASS ||
  19. 		       o == SCROLL_CLASS || o == SPBOOK_CLASS))
  20. 		    return ", painstakingly developed!";
  21. 		return ", superb craftsmanship!";
  22. 	    case 3: return ", finest quality.";
  23. 	    case 2: return ", an excellent choice.";
  24. 	    case 1: return ", a real bargain.";
  25. 	   default: break;
  26. 	}
  27. } else if (itm->oartifact) {
  28. 	return ", one of a kind!";
  29. }
  30. return ".";
  31. }
  32. #endif /*OVL3*/

shk_chat[edit]

  1. #ifdef OVLB
  2.  
  3. /* First 4 supplied by Ronen and Tamar, remainder by development team */
  4. const char *Izchak_speaks[]={
  5. "%s says: 'These shopping malls give me a headache.'",
  6. "%s says: 'Slow down.  Think clearly.'",
  7. "%s says: 'You need to take things one at a time.'",
  8. "%s says: 'I don't like poofy coffee... give me Columbian Supremo.'",
  9. "%s says that getting the devteam's agreement on anything is difficult.",
  10. "%s says that he has noticed those who serve their deity will prosper.",
  11. "%s says: 'Don't try to steal from me - I have friends in high places!'",
  12. "%s says: 'You may well need something from this shop in the future.'",
  13. "%s comments about the Valley of the Dead as being a gateway."
  14. };
  15.  
  16. void
  17. shk_chat(shkp)
  18. struct monst *shkp;
  19. {
  20. 	struct eshk *eshk;
  21. #ifdef GOLDOBJ
  22. 	long shkmoney;
  23. #endif
  24. 	if (!shkp->isshk) {
  25. 		/* The monster type is shopkeeper, but this monster is
  26. 		   not actually a shk, which could happen if someone
  27. 		   wishes for a shopkeeper statue and then animates it.
  28. 		   (Note: shkname() would be "" in a case like this.) */
  29. 		pline("%s asks whether you've seen any untended shops recently.",
  30. 		      Monnam(shkp));
  31. 		/* [Perhaps we ought to check whether this conversation
  32. 		   is taking place inside an untended shop, but a shopless
  33. 		   shk can probably be expected to be rather disoriented.] */
  34. 		return;
  35. 	}
  36.  
  37. 	eshk = ESHK(shkp);
  38. 	if (ANGRY(shkp))
  39. 		pline("%s mentions how much %s dislikes %s customers.",
  40. 			shkname(shkp), mhe(shkp),
  41. 			eshk->robbed ? "non-paying" : "rude");
  42. 	else if (eshk->following) {
  43. 		if (strncmp(eshk->customer, plname, PL_NSIZ)) {
  44. 		    verbalize("%s %s!  I was looking for %s.",
  45. 			    Hello(shkp), plname, eshk->customer);
  46. 		    eshk->following = 0;
  47. 		} else {
  48. 		    verbalize("%s %s!  Didn't you forget to pay?",
  49. 			      Hello(shkp), plname);
  50. 		}
  51. 	} else if (eshk->billct) {
  52. 		register long total = addupbill(shkp) + eshk->debit;
  53. 		pline("%s says that your bill comes to %ld %s.",
  54. 		      shkname(shkp), total, currency(total));
  55. 	} else if (eshk->debit)
  56. 		pline("%s reminds you that you owe %s %ld %s.",
  57. 		      shkname(shkp), mhim(shkp),
  58. 		      eshk->debit, currency(eshk->debit));
  59. 	else if (eshk->credit)
  60. 		pline("%s encourages you to use your %ld %s of credit.",
  61. 		      shkname(shkp), eshk->credit, currency(eshk->credit));
  62. 	else if (eshk->robbed)
  63. 		pline("%s complains about a recent robbery.", shkname(shkp));
  64. #ifndef GOLDOBJ
  65. 	else if (shkp->mgold < 50)
  66. #else
  67. 	else if ((shkmoney = money_cnt(shkp->minvent)) < 50)
  68. #endif
  69. 		pline("%s complains that business is bad.", shkname(shkp));
  70. #ifndef GOLDOBJ
  71. 	else if (shkp->mgold > 4000)
  72. #else
  73. 	else if (shkmoney > 4000)
  74. #endif
  75. 		pline("%s says that business is good.", shkname(shkp));
  76. 	else if (strcmp(shkname(shkp), "Izchak") == 0)
  77. 		pline(Izchak_speaks[rn2(SIZE(Izchak_speaks))],shkname(shkp));
  78. 	else
  79. 		pline("%s talks about the problem of shoplifters.",shkname(shkp));
  80. }

kops_gone[edit]

  1. #ifdef KOPS
  2. STATIC_OVL void
  3. kops_gone(silent)
  4. register boolean silent;
  5. {
  6. 	register int cnt = 0;
  7. 	register struct monst *mtmp, *mtmp2;
  8.  
  9. 	for (mtmp = fmon; mtmp; mtmp = mtmp2) {
  10. 	    mtmp2 = mtmp->nmon;
  11. 	    if (mtmp->data->mlet == S_KOP) {
  12. 		if (canspotmon(mtmp)) cnt++;
  13. 		mongone(mtmp);
  14. 	    }
  15. 	}
  16. 	if (cnt && !silent)
  17. 	    pline_The("Kop%s (disappointed) vanish%s into thin air.",
  18. 		      plur(cnt), cnt == 1 ? "es" : "");
  19. }
  20. #endif	/* KOPS */
  21.  
  22. #endif /*OVLB*/

cost_per_charge[edit]

  1. #ifdef OVL3
  2.  
  3. STATIC_OVL long
  4. cost_per_charge(shkp, otmp, altusage)
  5. struct monst *shkp;
  6. struct obj *otmp;
  7. boolean altusage; /* some items have an "alternate" use with different cost */
  8. {
  9. 	long tmp = 0L;
  10.  
  11. 	if(!shkp || !inhishop(shkp)) return(0L); /* insurance */
  12. 	tmp = get_cost(otmp, shkp);
  13.  
  14. 	/* The idea is to make the exhaustive use of */
  15. 	/* an unpaid item more expensive than buying */
  16. 	/* it outright.				     */
  17. 	if(otmp->otyp == MAGIC_LAMP) {			 /* 1 */
  18. 		/* normal use (ie, as light source) of a magic lamp never
  19. 		   degrades its value, but not charging anything would make
  20. 		   identifcation too easy; charge an amount comparable to
  21. 		   what is charged for an ordinary lamp (don't bother with
  22. 		   angry shk surchage) */
  23. 		if (!altusage) tmp = (long) objects[OIL_LAMP].oc_cost;
  24. 		else tmp += tmp / 3L;	/* djinni is being released */
  25. 	} else if(otmp->otyp == MAGIC_MARKER) {		 /* 70 - 100 */
  26. 		/* no way to determine in advance   */
  27. 		/* how many charges will be wasted. */
  28. 		/* so, arbitrarily, one half of the */
  29. 		/* price per use.		    */
  30. 		tmp /= 2L;
  31. 	} else if(otmp->otyp == BAG_OF_TRICKS ||	 /* 1 - 20 */
  32. 		  otmp->otyp == HORN_OF_PLENTY) {
  33. 		tmp /= 5L;
  34. 	} else if(otmp->otyp == CRYSTAL_BALL ||		 /* 1 - 5 */
  35. 		  otmp->otyp == OIL_LAMP ||		 /* 1 - 10 */
  36. 		  otmp->otyp == BRASS_LANTERN ||
  37. 		 (otmp->otyp >= MAGIC_FLUTE &&
  38. 		  otmp->otyp <= DRUM_OF_EARTHQUAKE) ||	 /* 5 - 9 */
  39. 		  otmp->oclass == WAND_CLASS) {		 /* 3 - 11 */
  40. 		if (otmp->spe > 1) tmp /= 4L;
  41. 	} else if (otmp->oclass == SPBOOK_CLASS) {
  42. 		tmp -= tmp / 5L;
  43. 	} else if (otmp->otyp == CAN_OF_GREASE ||
  44. 		   otmp->otyp == TINNING_KIT
  45. #ifdef TOURIST
  46. 		   || otmp->otyp == EXPENSIVE_CAMERA
  47. #endif
  48. 		   ) {
  49. 		tmp /= 10L;
  50. 	} else if (otmp->otyp == POT_OIL) {
  51. 		tmp /= 5L;
  52. 	}
  53. 	return(tmp);
  54. }
  55. #endif /*OVL3*/

check_unpaid_usage[edit]

  1. #ifdef OVLB
  2.  
  3. /* Charge the player for partial use of an unpaid object.
  4. *
  5. * Note that bill_dummy_object() should be used instead
  6. * when an object is completely used.
  7. */
  8. void
  9. check_unpaid_usage(otmp, altusage)
  10. struct obj *otmp;
  11. boolean altusage;
  12. {
  13. 	struct monst *shkp;
  14. 	const char *fmt, *arg1, *arg2;
  15. 	long tmp;
  16.  
  17. 	if (!otmp->unpaid || !*u.ushops ||
  18. 		(otmp->spe <= 0 && objects[otmp->otyp].oc_charged))
  19. 	    return;
  20. 	if (!(shkp = shop_keeper(*u.ushops)) || !inhishop(shkp))
  21. 	    return;
  22. 	if ((tmp = cost_per_charge(shkp, otmp, altusage)) == 0L)
  23. 	    return;
  24.  
  25. 	arg1 = arg2 = "";
  26. 	if (otmp->oclass == SPBOOK_CLASS) {
  27. 	    fmt = "%sYou owe%s %ld %s.";
  28. 	    arg1 = rn2(2) ? "This is no free library, cad!  " : "";
  29. 	    arg2 = ESHK(shkp)->debit > 0L ? " an additional" : "";
  30. 	} else if (otmp->otyp == POT_OIL) {
  31. 	    fmt = "%s%sThat will cost you %ld %s (Yendorian Fuel Tax).";
  32. 	} else {
  33. 	    fmt = "%s%sUsage fee, %ld %s.";
  34. 	    if (!rn2(3)) arg1 = "Hey!  ";
  35. 	    if (!rn2(3)) arg2 = "Ahem.  ";
  36. 	}
  37.  
  38. 	if (shkp->mcanmove || !shkp->msleeping)
  39. 	    verbalize(fmt, arg1, arg2, tmp, currency(tmp));
  40. 	ESHK(shkp)->debit += tmp;
  41. 	exercise(A_WIS, TRUE);		/* you just got info */
  42. }

check_unpaid[edit]

  1. /* for using charges of unpaid objects "used in the normal manner" */
  2. void
  3. check_unpaid(otmp)
  4. struct obj *otmp;
  5. {
  6. 	check_unpaid_usage(otmp, FALSE);		/* normal item use */
  7. }

costly_gold[edit]

  1. void
  2. costly_gold(x, y, amount)
  3. register xchar x, y;
  4. register long amount;
  5. {
  6. 	register long delta;
  7. 	register struct monst *shkp;
  8. 	register struct eshk *eshkp;
  9.  
  10. 	if(!costly_spot(x, y)) return;
  11. 	/* shkp now guaranteed to exist by costly_spot() */
  12. 	shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
  13.  
  14. 	eshkp = ESHK(shkp);
  15. 	if(eshkp->credit >= amount) {
  16. 	    if(eshkp->credit > amount)
  17. 		Your("credit is reduced by %ld %s.",
  18. 					amount, currency(amount));
  19. 	    else Your("credit is erased.");
  20. 	    eshkp->credit -= amount;
  21. 	} else {
  22. 	    delta = amount - eshkp->credit;
  23. 	    if(eshkp->credit)
  24. 		Your("credit is erased.");
  25. 	    if(eshkp->debit)
  26. 		Your("debt increases by %ld %s.",
  27. 					delta, currency(delta));
  28. 	    else You("owe %s %ld %s.",
  29. 				shkname(shkp), delta, currency(delta));
  30. 	    eshkp->debit += delta;
  31. 	    eshkp->loan += delta;
  32. 	    eshkp->credit = 0L;
  33. 	}
  34. }

block_door[edit]

  1. /* used in domove to block diagonal shop-exit */
  2. /* x,y should always be a door */
  3. boolean
  4. block_door(x,y)
  5. register xchar x, y;
  6. {
  7. 	register int roomno = *in_rooms(x, y, SHOPBASE);
  8. 	register struct monst *shkp;
  9.  
  10. 	if(roomno < 0 || !IS_SHOP(roomno)) return(FALSE);
  11. 	if(!IS_DOOR(levl[x][y].typ)) return(FALSE);
  12. 	if(roomno != *u.ushops) return(FALSE);
  13.  
  14. 	if(!(shkp = shop_keeper((char)roomno)) || !inhishop(shkp))
  15. 		return(FALSE);
  16.  
  17. 	if(shkp->mx == ESHK(shkp)->shk.x && shkp->my == ESHK(shkp)->shk.y
  18. 	    /* Actually, the shk should be made to block _any_
  19. 	     * door, including a door the player digs, if the
  20. 	     * shk is within a 'jumping' distance.
  21. 	     */
  22. 	    && ESHK(shkp)->shd.x == x && ESHK(shkp)->shd.y == y
  23. 	    && shkp->mcanmove && !shkp->msleeping
  24. 	    && (ESHK(shkp)->debit || ESHK(shkp)->billct ||
  25. 		ESHK(shkp)->robbed)) {
  26. 		pline("%s%s blocks your way!", shkname(shkp),
  27. 				Invis ? " senses your motion and" : "");
  28. 		return(TRUE);
  29. 	}
  30. 	return(FALSE);
  31. }

block_entry[edit]

  1. /* used in domove to block diagonal shop-entry */
  2. /* u.ux, u.uy should always be a door */
  3. boolean
  4. block_entry(x,y)
  5. register xchar x, y;
  6. {
  7. 	register xchar sx, sy;
  8. 	register int roomno;
  9. 	register struct monst *shkp;
  10.  
  11. 	if(!(IS_DOOR(levl[u.ux][u.uy].typ) &&
  12. 		levl[u.ux][u.uy].doormask == D_BROKEN)) return(FALSE);
  13.  
  14. 	roomno = *in_rooms(x, y, SHOPBASE);
  15. 	if(roomno < 0 || !IS_SHOP(roomno)) return(FALSE);
  16. 	if(!(shkp = shop_keeper((char)roomno)) || !inhishop(shkp))
  17. 		return(FALSE);
  18.  
  19. 	if(ESHK(shkp)->shd.x != u.ux || ESHK(shkp)->shd.y != u.uy)
  20. 		return(FALSE);
  21.  
  22. 	sx = ESHK(shkp)->shk.x;
  23. 	sy = ESHK(shkp)->shk.y;
  24.  
  25. 	if(shkp->mx == sx && shkp->my == sy
  26. 		&& shkp->mcanmove && !shkp->msleeping
  27. 		&& (x == sx-1 || x == sx+1 || y == sy-1 || y == sy+1)
  28. 		&& (Invis || carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK)
  29. #ifdef STEED
  30. 			|| u.usteed
  31. #endif
  32. 	  )) {
  33. 		pline("%s%s blocks your way!", shkname(shkp),
  34. 				Invis ? " senses your motion and" : "");
  35. 		return(TRUE);
  36. 	}
  37. 	return(FALSE);
  38. }
  39.  
  40. #endif /* OVLB */

shk_your[edit]

  1. #ifdef OVL2
  2.  
  3. char *
  4. shk_your(buf, obj)
  5. char *buf;
  6. struct obj *obj;
  7. {
  8. 	if (!shk_owns(buf, obj) && !mon_owns(buf, obj))
  9. 	    Strcpy(buf, carried(obj) ? "your" : "the");
  10. 	return buf;
  11. }

Shk_Your[edit]

  1. char *
  2. Shk_Your(buf, obj)
  3. char *buf;
  4. struct obj *obj;
  5. {
  6. 	(void) shk_your(buf, obj);
  7. 	*buf = highc(*buf);
  8. 	return buf;
  9. }

shk_owns[edit]

  1. STATIC_OVL char *
  2. shk_owns(buf, obj)
  3. char *buf;
  4. struct obj *obj;
  5. {
  6. 	struct monst *shkp;
  7. 	xchar x, y;
  8.  
  9. 	if (get_obj_location(obj, &x, &y, 0) &&
  10. 	    (obj->unpaid ||
  11. 	     (obj->where==OBJ_FLOOR && !obj->no_charge && costly_spot(x,y)))) {
  12. 	    shkp = shop_keeper(inside_shop(x, y));
  13. 	    return strcpy(buf, shkp ? s_suffix(shkname(shkp)) : "the");
  14. 	}
  15. 	return (char *)0;
  16. }

mon_owns[edit]

  1. STATIC_OVL char *
  2. mon_owns(buf, obj)
  3. char *buf;
  4. struct obj *obj;
  5. {
  6. 	if (obj->where == OBJ_MINVENT)
  7. 	    return strcpy(buf, s_suffix(mon_nam(obj->ocarry)));
  8. 	return (char *)0;
  9. }
  10.  
  11. #endif /* OVL2 */

sasc_bug[edit]

  1. #ifdef OVLB
  2.  
  3. #ifdef __SASC
  4. void
  5. sasc_bug(struct obj *op, unsigned x){
  6. 	op->unpaid=x;
  7. }
  8. #endif
  9.  
  10. #endif /* OVLB */
  11.  
  12. /*shk.c*/