Source:SLASH'EM 0.0.7E7F2/shk.c
Jump to navigation
Jump to search
Below is the full text to shk.c from the source code of SLASH'EM 0.0.7E7F2. To link to a particular line, write [[Source:SLASH'EM 0.0.7E7F2/shk.c#line123]], for example.
Source code for vanilla NetHack is at Source code.
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. /* 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. */ 4. 5. #include "hack.h" 6. #include "eshk.h" 7. 8. /*#define DEBUG*/ 9. 10. #define PAY_SOME 2 11. #define PAY_BUY 1 12. #define PAY_CANT 0 /* too poor */ 13. #define PAY_SKIP (-1) 14. #define PAY_BROKE (-2) 15. 16. #ifdef KOPS 17. STATIC_DCL void FDECL(makekops, (coord *)); 18. STATIC_DCL void FDECL(call_kops, (struct monst *,BOOLEAN_P)); 19. # ifdef OVLB 20. STATIC_DCL void FDECL(kops_gone, (BOOLEAN_P)); 21. # endif /* OVLB */ 22. #endif /* KOPS */ 23. 24. #define IS_SHOP(x) (rooms[x].rtype >= SHOPBASE) 25. #define no_cheat ((ACURR(A_CHA) - rnl(3)) > 7) 26. 27. extern const struct shclass shtypes[]; /* defined in shknam.c */ 28. extern struct obj *thrownobj; /* defined in dothrow.c */ 29. 30. STATIC_VAR NEARDATA long int followmsg; /* last time of follow message */ 31. 32. STATIC_DCL void FDECL(setpaid, (struct monst *)); 33. STATIC_DCL long FDECL(addupbill, (struct monst *)); 34. STATIC_DCL void FDECL(pacify_shk, (struct monst *)); 35. STATIC_DCL struct bill_x *FDECL(onbill, (struct obj *, struct monst *, BOOLEAN_P)); 36. STATIC_DCL struct monst *FDECL(next_shkp, (struct monst *, BOOLEAN_P)); 37. STATIC_DCL long FDECL(shop_debt, (struct eshk *)); 38. STATIC_DCL char *FDECL(shk_owns, (char *,struct obj *)); 39. STATIC_DCL char *FDECL(mon_owns, (char *,struct obj *)); 40. STATIC_DCL void FDECL(clear_unpaid,(struct obj *)); 41. STATIC_DCL long FDECL(check_credit, (long, struct monst *)); 42. STATIC_DCL void FDECL(pay, (long, struct monst *)); 43. STATIC_DCL long FDECL(get_cost, (struct obj *, struct monst *)); 44. STATIC_DCL long FDECL(set_cost, (struct obj *, struct monst *)); 45. STATIC_DCL const char *FDECL(shk_embellish, (struct obj *, long)); 46. STATIC_DCL long FDECL(cost_per_charge, (struct monst *,struct obj *,BOOLEAN_P)); 47. STATIC_DCL long FDECL(cheapest_item, (struct monst *)); 48. STATIC_DCL int FDECL(dopayobj, (struct monst *, struct bill_x *, 49. struct obj **, int, BOOLEAN_P)); 50. STATIC_DCL long FDECL(stolen_container, (struct obj *, struct monst *, long, 51. BOOLEAN_P, BOOLEAN_P)); 52. STATIC_DCL long FDECL(getprice, (struct obj *,BOOLEAN_P)); 53. STATIC_DCL void FDECL(shk_names_obj, 54. (struct monst *,struct obj *,const char *,long,const char *)); 55. STATIC_DCL struct obj *FDECL(bp_to_obj, (struct bill_x *)); 56. STATIC_DCL boolean FDECL(inherits, (struct monst *,int,int)); 57. STATIC_DCL void FDECL(set_repo_loc, (struct eshk *)); 58. STATIC_DCL boolean NDECL(angry_shk_exists); 59. STATIC_DCL void FDECL(rile_shk, (struct monst *)); 60. STATIC_DCL void FDECL(rouse_shk, (struct monst *,BOOLEAN_P)); 61. STATIC_DCL void FDECL(remove_damage, (struct monst *, BOOLEAN_P)); 62. STATIC_DCL void FDECL(sub_one_frombill, (struct obj *, struct monst *)); 63. STATIC_DCL void FDECL(add_one_tobill, (struct obj *, BOOLEAN_P)); 64. STATIC_DCL void FDECL(dropped_container, (struct obj *, struct monst *, 65. BOOLEAN_P)); 66. STATIC_DCL void FDECL(add_to_billobjs, (struct obj *)); 67. STATIC_DCL void FDECL(bill_box_content, (struct obj *, BOOLEAN_P, BOOLEAN_P, 68. struct monst *)); 69. #ifdef OVL1 70. static boolean FDECL(rob_shop, (struct monst *)); 71. #endif 72. 73. #ifdef OTHER_SERVICES 74. #define NOBOUND (-1) /* No lower/upper limit to charge */ 75. static void NDECL(shk_other_services); 76. static void FDECL(shk_identify, (char *, struct monst *)); 77. static void FDECL(shk_uncurse, (char *, struct monst *)); 78. static void FDECL(shk_appraisal, (char *, struct monst *)); 79. static void FDECL(shk_weapon_works, (char *, struct monst *)); 80. static void FDECL(shk_armor_works, (char *, struct monst *)); 81. static void FDECL(shk_charge, (char *, struct monst *)); 82. static boolean FDECL(shk_obj_match, (struct obj *, struct monst *)); 83. /*static int FDECL(shk_class_match, (long class, struct monst *shkp));*/ 84. static boolean FDECL(shk_offer_price, (char *, long, struct monst *)); 85. static void FDECL(shk_smooth_charge, (int *, int, int)); 86. #endif 87. 88. #ifdef OVLB 89. /* 90. invariants: obj->unpaid iff onbill(obj) [unless bp->useup] 91. obj->quan <= bp->bquan 92. */ 93. 94. 95. #ifdef GOLDOBJ 96. /* 97. Transfer money from inventory to monster when paying 98. shopkeepers, priests, oracle, succubus, & other demons. 99. Simple with only gold coins. 100. This routine will handle money changing when multiple 101. coin types is implemented, only appropriate 102. monsters will pay change. (Peaceful shopkeepers, priests 103. & the oracle try to maintain goodwill while selling 104. their wares or services. Angry monsters and all demons 105. will keep anything they get their hands on. 106. Returns the amount actually paid, so we can know 107. if the monster kept the change. 108. */ 109. long 110. money2mon(mon, amount) 111. struct monst *mon; 112. long amount; 113. { 114. struct obj *ygold = findgold(invent); 115. 116. if (amount <= 0) { 117. impossible("%s payment in money2mon!", amount ? "negative" : "zero"); 118. return 0L; 119. } 120. if (!ygold || ygold->quan < amount) { 121. impossible("Paying without %s money?", ygold ? "enough" : ""); 122. return 0L; 123. } 124. 125. if (ygold->quan > amount) 126. ygold = splitobj(ygold, amount); 127. else if (ygold->owornmask) 128. remove_worn_item(ygold, FALSE); /* quiver */ 129. freeinv(ygold); 130. add_to_minv(mon, ygold); 131. flags.botl = 1; 132. return amount; 133. } 134. 135. 136. /* 137. Transfer money from monster to inventory. 138. Used when the shopkeeper pay for items, and when 139. the priest gives you money for an ale. 140. */ 141. void 142. money2u(mon, amount) 143. struct monst *mon; 144. long amount; 145. { 146. struct obj *mongold = findgold(mon->minvent); 147. 148. if (amount <= 0) { 149. impossible("%s payment in money2u!", amount ? "negative" : "zero"); 150. return; 151. } 152. if (!mongold || mongold->quan < amount) { 153. impossible("%s paying without %s money?", a_monnam(mon), 154. mongold ? "enough" : ""); 155. return; 156. } 157. 158. if (mongold->quan > amount) mongold = splitobj(mongold, amount); 159. obj_extract_self(mongold); 160. 161. if (!merge_choice(invent, mongold) && inv_cnt() >= 52) { 162. You("have no room for the money!"); 163. dropy(mongold); 164. } else { 165. addinv(mongold); 166. flags.botl = 1; 167. } 168. } 169. 170. #endif /* GOLDOBJ */ 171. 172. STATIC_OVL struct monst * 173. next_shkp(shkp, withbill) 174. register struct monst *shkp; 175. register boolean withbill; 176. { 177. for (; shkp; shkp = shkp->nmon) { 178. if (DEADMONSTER(shkp)) continue; 179. if (shkp->isshk && (ESHK(shkp)->billct || !withbill)) break; 180. } 181. 182. if (shkp) { 183. if (NOTANGRY(shkp)) { 184. if (ESHK(shkp)->surcharge) pacify_shk(shkp); 185. } else { 186. if (!ESHK(shkp)->surcharge) rile_shk(shkp); 187. } 188. } 189. return(shkp); 190. } 191. 192. char * 193. shkname(mtmp) /* called in do_name.c */ 194. register struct monst *mtmp; 195. { 196. return(ESHK(mtmp)->shknam); 197. } 198. 199. void 200. shkgone(mtmp) /* called in mon.c */ 201. struct monst *mtmp; 202. { 203. struct eshk *eshk = ESHK(mtmp); 204. struct mkroom *sroom = &rooms[eshk->shoproom - ROOMOFFSET]; 205. struct obj *otmp; 206. char *p; 207. int sx, sy; 208. 209. /* [BUG: some of this should be done on the shop level */ 210. /* even when the shk dies on a different level.] */ 211. if (on_level(&eshk->shoplevel, &u.uz)) { 212. remove_damage(mtmp, TRUE); 213. sroom->resident = (struct monst *)0; 214. if (!search_special(ANY_SHOP)) 215. level.flags.has_shop = 0; 216. 217. /* items on shop floor revert to ordinary objects */ 218. for (sx = sroom->lx; sx <= sroom->hx; sx++) 219. for (sy = sroom->ly; sy <= sroom->hy; sy++) 220. for (otmp = level.objects[sx][sy]; otmp; otmp = otmp->nexthere) 221. otmp->no_charge = 0; 222. 223. /* Make sure bill is set only when the 224. dead shk is the resident shk. */ 225. if ((p = index(u.ushops, eshk->shoproom)) != 0) { 226. setpaid(mtmp); 227. eshk->bill_p = (struct bill_x *)0; 228. /* remove eshk->shoproom from u.ushops */ 229. do { *p = *(p + 1); } while (*++p); 230. } 231. } 232. } 233. 234. void 235. set_residency(shkp, zero_out) 236. register struct monst *shkp; 237. register boolean zero_out; 238. { 239. if (on_level(&(ESHK(shkp)->shoplevel), &u.uz)) 240. rooms[ESHK(shkp)->shoproom - ROOMOFFSET].resident = 241. (zero_out)? (struct monst *)0 : shkp; 242. } 243. 244. void 245. replshk(mtmp,mtmp2) 246. register struct monst *mtmp, *mtmp2; 247. { 248. rooms[ESHK(mtmp2)->shoproom - ROOMOFFSET].resident = mtmp2; 249. if (inhishop(mtmp) && *u.ushops == ESHK(mtmp)->shoproom) { 250. ESHK(mtmp2)->bill_p = &(ESHK(mtmp2)->bill[0]); 251. } 252. } 253. 254. /* do shopkeeper specific structure munging -dlc */ 255. void 256. restshk(shkp, ghostly) 257. struct monst *shkp; 258. boolean ghostly; 259. { 260. if (u.uz.dlevel) { 261. struct eshk *eshkp = ESHK(shkp); 262. 263. if (eshkp->bill_p != (struct bill_x *) -1000) 264. eshkp->bill_p = &eshkp->bill[0]; 265. /* shoplevel can change as dungeons move around */ 266. /* savebones guarantees that non-homed shk's will be gone */ 267. if (ghostly) { 268. assign_level(&eshkp->shoplevel, &u.uz); 269. if (ANGRY(shkp) && strncmpi(eshkp->customer, plname, PL_NSIZ)) 270. pacify_shk(shkp); 271. } 272. } 273. } 274. 275. #endif /* OVLB */ 276. #ifdef OVL3 277. 278. /* Clear the unpaid bit on all of the objects in the list. */ 279. STATIC_OVL void 280. clear_unpaid(list) 281. register struct obj *list; 282. { 283. while (list) { 284. if (Has_contents(list)) clear_unpaid(list->cobj); 285. list->unpaid = 0; 286. list = list->nobj; 287. } 288. } 289. #endif /*OVL3*/ 290. #ifdef OVLB 291. 292. /* either you paid or left the shop or the shopkeeper died */ 293. STATIC_OVL void 294. setpaid(shkp) 295. register struct monst *shkp; 296. { 297. register struct obj *obj; 298. register struct monst *mtmp; 299. 300. /* FIXME: object handling should be limited to 301. items which are on this particular shk's bill */ 302. 303. clear_unpaid(invent); 304. clear_unpaid(fobj); 305. clear_unpaid(level.buriedobjlist); 306. if (thrownobj) thrownobj->unpaid = 0; 307. for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) 308. clear_unpaid(mtmp->minvent); 309. for(mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) 310. clear_unpaid(mtmp->minvent); 311. 312. while ((obj = billobjs) != 0) { 313. obj_extract_self(obj); 314. dealloc_obj(obj); 315. } 316. if(shkp) { 317. ESHK(shkp)->billct = 0; 318. ESHK(shkp)->credit = 0L; 319. ESHK(shkp)->debit = 0L; 320. ESHK(shkp)->loan = 0L; 321. } 322. } 323. 324. STATIC_OVL long 325. addupbill(shkp) 326. register struct monst *shkp; 327. { 328. register int ct = ESHK(shkp)->billct; 329. register struct bill_x *bp = ESHK(shkp)->bill_p; 330. register long total = 0L; 331. 332. while(ct--){ 333. total += bp->price * bp->bquan; 334. bp++; 335. } 336. return(total); 337. } 338. 339. #endif /* OVLB */ 340. #ifdef OVL1 341. 342. #ifdef KOPS 343. STATIC_OVL void 344. call_kops(shkp, nearshop) 345. register struct monst *shkp; 346. register boolean nearshop; 347. { 348. /* Keystone Kops srt@ucla */ 349. register boolean nokops; 350. char kopname[20]; 351. 352. Strcpy(kopname, "Keystone Kops"); 353. 354. if(!shkp) return; 355. 356. if (flags.soundok) 357. pline("An alarm sounds!"); 358. 359. nokops = ((mvitals[PM_KEYSTONE_KOP].mvflags & G_GONE) && 360. (mvitals[PM_KOP_SERGEANT].mvflags & G_GONE) && 361. (mvitals[PM_KOP_LIEUTENANT].mvflags & G_GONE) && 362. (mvitals[PM_KOP_KAPTAIN].mvflags & G_GONE)); 363. 364. #ifdef BLACKMARKET 365. if (Is_blackmarket(&u.uz)) { 366. nokops = ((mvitals[PM_SOLDIER].mvflags & G_GONE) && 367. (mvitals[PM_SERGEANT].mvflags & G_GONE) && 368. (mvitals[PM_LIEUTENANT].mvflags & G_GONE) && 369. (mvitals[PM_CAPTAIN].mvflags & G_GONE)); 370. 371. Strcpy(kopname, "guards"); 372. } 373. #endif /* defined(BLACKMARKET) */ 374. 375. if(!angry_guards(!flags.soundok) && nokops) { 376. if(flags.verbose && flags.soundok) 377. pline("But no one seems to respond to it."); 378. return; 379. } 380. 381. if(nokops) return; 382. 383. { 384. coord mm; 385. 386. if (nearshop) 387. #ifdef BLACKMARKET 388. if (!Is_blackmarket(&u.uz)) 389. #endif /* BLACKMARKET */ 390. { 391. /* Create swarm around you, if you merely "stepped out" */ 392. if (flags.verbose) 393. pline_The("%s appear!", kopname); 394. mm.x = u.ux; 395. mm.y = u.uy; 396. makekops(&mm); 397. return; 398. } 399. if (flags.verbose) 400. pline_The("%s are after you!", kopname); 401. /* Create swarm near down staircase (hinders return to level) */ 402. #ifdef BLACKMARKET 403. if (Is_blackmarket(&u.uz)) { 404. struct trap *trap = ftrap; 405. while (trap) { 406. if (trap->ttyp == MAGIC_PORTAL) { 407. mm.x = trap->tx; 408. mm.y = trap->ty; 409. } 410. trap = trap->ntrap; 411. } 412. } else { 413. mm.x = xdnstair; 414. mm.y = ydnstair; 415. } 416. #else /* BLACKMARKET */ 417. mm.x = xdnstair; 418. mm.y = ydnstair; 419. #endif /* BLACKMARKET */ 420. makekops(&mm); 421. /* Create swarm near shopkeeper (hinders return to shop) */ 422. mm.x = shkp->mx; 423. mm.y = shkp->my; 424. makekops(&mm); 425. } 426. } 427. #endif /* KOPS */ 428. 429. 430. #ifdef BLACKMARKET 431. void 432. blkmar_guards(shkp) 433. register struct monst *shkp; 434. { 435. register struct monst *mt; 436. register struct eshk *eshkp = ESHK(shkp); 437. boolean mesg_given = FALSE; /* Only give message if assistants peaceful */ 438. static boolean rlock = FALSE; /* Prevent recursive calls (via wakeup) */ 439. 440. if (rlock) return; 441. rlock = TRUE; 442. 443. /* wake up assistants */ 444. for (mt = fmon; mt; mt = mt->nmon) { 445. if (DEADMONSTER(mt)) continue; 446. /* non-tame named monsters are presumably 447. * black marketeer's assistants */ 448. if (!mt->mtame && NAME(mt) && *NAME(mt) && mt->mpeaceful && 449. mt != shkp && inside_shop(mt->mx, mt->my) == eshkp->shoproom) { 450. if (!mesg_given) { 451. pline("%s calls for %s assistants!", 452. noit_Monnam(shkp), mhis(shkp)); 453. mesg_given = TRUE; 454. } 455. wakeup(mt); 456. } 457. } 458. rlock = FALSE; 459. } 460. #endif /* BLACKMARKET */ 461. 462. 463. /* x,y is strictly inside shop */ 464. char 465. inside_shop(x, y) 466. register xchar x, y; 467. { 468. register char rno; 469. 470. rno = levl[x][y].roomno; 471. if ((rno < ROOMOFFSET) || levl[x][y].edge || !IS_SHOP(rno-ROOMOFFSET)) 472. return(NO_ROOM); 473. else 474. return(rno); 475. } 476. 477. void 478. u_left_shop(leavestring, newlev) 479. char *leavestring; 480. boolean newlev; 481. { 482. struct monst *shkp; 483. struct eshk *eshkp; 484. 485. /* 486. * IF player 487. * ((didn't leave outright) AND 488. * ((he is now strictly-inside the shop) OR 489. * (he wasn't strictly-inside last turn anyway))) 490. * THEN (there's nothing to do, so just return) 491. */ 492. if(!*leavestring && 493. (!levl[u.ux][u.uy].edge || levl[u.ux0][u.uy0].edge)) 494. return; 495. 496. shkp = shop_keeper(*u.ushops0); 497. if (!shkp || !inhishop(shkp)) 498. return; /* shk died, teleported, changed levels... */ 499. 500. eshkp = ESHK(shkp); 501. if (!eshkp->billct && !eshkp->debit) /* bill is settled */ 502. return; 503. 504. if (!*leavestring && shkp->mcanmove && !shkp->msleeping) { 505. /* 506. * Player just stepped onto shop-boundary (known from above logic). 507. * Try to intimidate him into paying his bill 508. */ 509. verbalize(NOTANGRY(shkp) ? 510. "%s! Please pay before leaving." : 511. "%s! Don't you leave without paying!", 512. plname); 513. return; 514. } 515. 516. if (rob_shop(shkp)) { 517. 518. #ifdef BLACKMARKET 519. if (Is_blackmarket(&u.uz)) 520. blkmar_guards(shkp); 521. #endif 522. 523. #ifdef KOPS 524. call_kops(shkp, (!newlev && levl[u.ux0][u.uy0].edge)); 525. #else 526. (void) angry_guards(FALSE); 527. #endif 528. } 529. } 530. 531. /* robbery from outside the shop via telekinesis or grappling hook */ 532. void 533. remote_burglary(x, y) 534. xchar x, y; 535. { 536. struct monst *shkp; 537. struct eshk *eshkp; 538. 539. shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); 540. if (!shkp || !inhishop(shkp)) 541. return; /* shk died, teleported, changed levels... */ 542. 543. eshkp = ESHK(shkp); 544. if (!eshkp->billct && !eshkp->debit) /* bill is settled */ 545. return; 546. 547. if (rob_shop(shkp)) { 548. 549. #ifdef BLACKMARKET 550. if (Is_blackmarket(&u.uz)) 551. blkmar_guards(shkp); 552. #endif 553. 554. #ifdef KOPS 555. /*[might want to set 2nd arg based on distance from shop doorway]*/ 556. call_kops(shkp, FALSE); 557. #else 558. (void) angry_guards(FALSE); 559. #endif 560. } 561. } 562. 563. /* shop merchandise has been taken; pay for it with any credit available; 564. return false if the debt is fully covered by credit, true otherwise */ 565. static boolean 566. rob_shop(shkp) 567. struct monst *shkp; 568. { 569. struct eshk *eshkp; 570. long total; 571. 572. eshkp = ESHK(shkp); 573. rouse_shk(shkp, TRUE); 574. total = (addupbill(shkp) + eshkp->debit); 575. if (eshkp->credit >= total) { 576. Your("credit of %ld %s is used to cover your shopping bill.", 577. eshkp->credit, currency(eshkp->credit)); 578. total = 0L; /* credit gets cleared by setpaid() */ 579. } else { 580. You("escaped the shop without paying!"); 581. total -= eshkp->credit; 582. } 583. setpaid(shkp); 584. if (!total) return FALSE; 585. 586. /* by this point, we know an actual robbery has taken place */ 587. eshkp->robbed += total; 588. You("stole %ld %s worth of merchandise.", 589. total, currency(total)); 590. if (!Role_if(PM_ROGUE)) { /* stealing is unlawful */ 591. adjalign(-sgn(u.ualign.type)); 592. You("feel like an evil rogue."); 593. } 594. 595. hot_pursuit(shkp); 596. return TRUE; 597. } 598. 599. void 600. u_entered_shop(enterstring) 601. register char *enterstring; 602. { 603. 604. register int rt; 605. register struct monst *shkp; 606. register struct eshk *eshkp; 607. static const char no_shk[] = "This shop appears to be deserted."; 608. static char empty_shops[5]; 609. 610. if(!*enterstring) 611. return; 612. 613. if(!(shkp = shop_keeper(*enterstring))) { 614. if (!index(empty_shops, *enterstring) && 615. in_rooms(u.ux, u.uy, SHOPBASE) != 616. in_rooms(u.ux0, u.uy0, SHOPBASE)) 617. pline(no_shk); 618. Strcpy(empty_shops, u.ushops); 619. u.ushops[0] = '\0'; 620. return; 621. } 622. 623. eshkp = ESHK(shkp); 624. 625. if (!inhishop(shkp)) { 626. /* dump core when referenced */ 627. eshkp->bill_p = (struct bill_x *) -1000; 628. if (!index(empty_shops, *enterstring)) 629. pline(no_shk); 630. Strcpy(empty_shops, u.ushops); 631. u.ushops[0] = '\0'; 632. return; 633. } 634. 635. eshkp->bill_p = &(eshkp->bill[0]); 636. 637. if ((!eshkp->visitct || *eshkp->customer) && 638. strncmpi(eshkp->customer, plname, PL_NSIZ)) { 639. /* You seem to be new here */ 640. eshkp->visitct = 0; 641. eshkp->following = 0; 642. (void) strncpy(eshkp->customer,plname,PL_NSIZ); 643. pacify_shk(shkp); 644. } 645. 646. if (shkp->msleeping || !shkp->mcanmove || eshkp->following) 647. return; /* no dialog */ 648. 649. if (Invis) { 650. pline("%s senses your presence.", shkname(shkp)); 651. #ifdef BLACKMARKET 652. if (!Is_blackmarket(&u.uz)) { 653. verbalize("Invisible customers are not welcome!"); 654. return; 655. } 656. #else /* BLACKMARKET */ 657. verbalize("Invisible customers are not welcome!"); 658. return; 659. #endif /* BLACKMARKET */ 660. } 661. 662. #ifdef BLACKMARKET 663. if (Is_blackmarket(&u.uz) && 664. u.umonnum>0 && mons[u.umonnum].mlet != S_HUMAN) { 665. verbalize("Non-human customers are not welcome!"); 666. return; 667. } 668. #endif /* BLACKMARKET */ 669. 670. rt = rooms[*enterstring - ROOMOFFSET].rtype; 671. 672. if (ANGRY(shkp)) { 673. verbalize("So, %s, you dare return to %s %s?!", 674. plname, 675. s_suffix(shkname(shkp)), 676. shtypes[rt - SHOPBASE].name); 677. } else if (eshkp->robbed) { 678. pline("%s mutters imprecations against shoplifters.", shkname(shkp)); 679. } else { 680. verbalize("%s, %s! Welcome%s to %s %s!", 681. Hello(shkp), plname, 682. eshkp->visitct++ ? " again" : "", 683. s_suffix(shkname(shkp)), 684. shtypes[rt - SHOPBASE].name); 685. } 686. /* can't do anything about blocking if teleported in */ 687. if (!inside_shop(u.ux, u.uy)) { 688. boolean should_block; 689. int cnt; 690. const char *tool; 691. struct obj *pick = carrying(PICK_AXE), 692. *mattock = carrying(DWARVISH_MATTOCK); 693. 694. if (pick || mattock) { 695. cnt = 1; 696. if (pick && mattock) { /* carrying both types */ 697. tool = "digging tool"; 698. cnt = 2; /* `more than 1' is all that matters */ 699. } else if (pick) { 700. tool = "pick-axe"; 701. /* hack: `pick' already points somewhere into inventory */ 702. while ((pick = pick->nobj) != 0) 703. if (pick->otyp == PICK_AXE) ++cnt; 704. } else { /* assert(mattock != 0) */ 705. tool = "mattock"; 706. while ((mattock = mattock->nobj) != 0) 707. if (mattock->otyp == DWARVISH_MATTOCK) ++cnt; 708. /* [ALI] Shopkeeper indicates mattock(s) */ 709. if (!Blind) makeknown(DWARVISH_MATTOCK); 710. } 711. verbalize(NOTANGRY(shkp) ? 712. "Will you please leave your %s%s outside?" : 713. "Leave the %s%s outside.", 714. tool, plur(cnt)); 715. should_block = TRUE; 716. #ifdef STEED 717. } else if (u.usteed) { 718. verbalize(NOTANGRY(shkp) ? 719. "Will you please leave %s outside?" : 720. "Leave %s outside.", y_monnam(u.usteed)); 721. should_block = TRUE; 722. #endif 723. } else { 724. should_block = (Fast && (sobj_at(PICK_AXE, u.ux, u.uy) || 725. sobj_at(DWARVISH_MATTOCK, u.ux, u.uy))); 726. } 727. if (should_block) (void) dochug(shkp); /* shk gets extra move */ 728. } 729. return; 730. } 731. 732. /* 733. Decide whether two unpaid items are mergable; caller is responsible for 734. making sure they're unpaid and the same type of object; we check the price 735. quoted by the shopkeeper and also that they both belong to the same shk. 736. */ 737. boolean 738. same_price(obj1, obj2) 739. struct obj *obj1, *obj2; 740. { 741. register struct monst *shkp1, *shkp2; 742. register struct bill_x *bp1 = 0, *bp2 = 0; 743. register boolean are_mergable = FALSE; 744. 745. /* look up the first object by finding shk whose bill it's on */ 746. for (shkp1 = next_shkp(fmon, TRUE); shkp1; 747. shkp1 = next_shkp(shkp1->nmon, TRUE)) 748. if ((bp1 = onbill(obj1, shkp1, TRUE)) != 0) break; 749. /* second object is probably owned by same shk; if not, look harder */ 750. if (shkp1 && (bp2 = onbill(obj2, shkp1, TRUE)) != 0) { 751. shkp2 = shkp1; 752. } else { 753. for (shkp2 = next_shkp(fmon, TRUE); shkp2; 754. shkp2 = next_shkp(shkp2->nmon, TRUE)) 755. if ((bp2 = onbill(obj2, shkp2, TRUE)) != 0) break; 756. } 757. 758. if (!bp1 || !bp2) impossible("same_price: object wasn't on any bill!"); 759. else are_mergable = (shkp1 == shkp2 && bp1->price == bp2->price); 760. return are_mergable; 761. } 762. 763. /* 764. * Figure out how much is owed to a given shopkeeper. 765. * At present, we ignore any amount robbed from the shop, to avoid 766. * turning the `$' command into a way to discover that the current 767. * level is bones data which has a shk on the warpath. 768. */ 769. STATIC_OVL long 770. shop_debt(eshkp) 771. struct eshk *eshkp; 772. { 773. struct bill_x *bp; 774. int ct; 775. long debt = eshkp->debit; 776. 777. for (bp = eshkp->bill_p, ct = eshkp->billct; ct > 0; bp++, ct--) 778. debt += bp->price * bp->bquan; 779. return debt; 780. } 781. 782. /* called in response to the `$' command */ 783. void 784. shopper_financial_report() 785. { 786. struct monst *shkp, *this_shkp = shop_keeper(inside_shop(u.ux, u.uy)); 787. struct eshk *eshkp; 788. long amt; 789. int pass; 790. 791. if (this_shkp && 792. !(ESHK(this_shkp)->credit || shop_debt(ESHK(this_shkp)))) { 793. You("have no credit or debt in here."); 794. this_shkp = 0; /* skip first pass */ 795. } 796. 797. /* pass 0: report for the shop we're currently in, if any; 798. pass 1: report for all other shops on this level. */ 799. for (pass = this_shkp ? 0 : 1; pass <= 1; pass++) 800. for (shkp = next_shkp(fmon, FALSE); 801. shkp; shkp = next_shkp(shkp->nmon, FALSE)) { 802. if ((shkp != this_shkp) ^ pass) continue; 803. eshkp = ESHK(shkp); 804. if ((amt = eshkp->credit) != 0) 805. You("have %ld %s credit at %s %s.", 806. amt, currency(amt), s_suffix(shkname(shkp)), 807. shtypes[eshkp->shoptype - SHOPBASE].name); 808. else if (shkp == this_shkp) 809. You("have no credit in here."); 810. if ((amt = shop_debt(eshkp)) != 0) 811. You("owe %s %ld %s.", 812. shkname(shkp), amt, currency(amt)); 813. else if (shkp == this_shkp) 814. You("don't owe any money here."); 815. } 816. } 817. 818. #endif /* OVL1 */ 819. #ifdef OVLB 820. 821. int 822. inhishop(mtmp) 823. register struct monst *mtmp; 824. { 825. return(index(in_rooms(mtmp->mx, mtmp->my, SHOPBASE), 826. ESHK(mtmp)->shoproom) && 827. on_level(&(ESHK(mtmp)->shoplevel), &u.uz)); 828. } 829. 830. struct monst * 831. shop_keeper(rmno) 832. register char rmno; 833. { 834. struct monst *shkp = rmno >= ROOMOFFSET ? 835. rooms[rmno - ROOMOFFSET].resident : 0; 836. 837. if (shkp) { 838. if (NOTANGRY(shkp)) { 839. if (ESHK(shkp)->surcharge) pacify_shk(shkp); 840. } else { 841. if (!ESHK(shkp)->surcharge) rile_shk(shkp); 842. } 843. } 844. return shkp; 845. } 846. 847. boolean 848. tended_shop(sroom) 849. register struct mkroom *sroom; 850. { 851. register struct monst *mtmp = sroom->resident; 852. 853. if (!mtmp) 854. return(FALSE); 855. else 856. return((boolean)(inhishop(mtmp))); 857. } 858. 859. STATIC_OVL struct bill_x * 860. onbill(obj, shkp, silent) 861. register struct obj *obj; 862. register struct monst *shkp; 863. register boolean silent; 864. { 865. if (shkp) { 866. register struct bill_x *bp = ESHK(shkp)->bill_p; 867. register int ct = ESHK(shkp)->billct; 868. 869. while (--ct >= 0) 870. if (bp->bo_id == obj->o_id) { 871. if (!obj->unpaid) pline("onbill: paid obj on bill?"); 872. return bp; 873. } else bp++; 874. } 875. if(obj->unpaid & !silent) pline("onbill: unpaid obj not on bill?"); 876. return (struct bill_x *)0; 877. } 878. 879. /* Delete the contents of the given object. */ 880. void 881. delete_contents(obj) 882. register struct obj *obj; 883. { 884. register struct obj *curr; 885. 886. while ((curr = obj->cobj) != 0) { 887. if (Has_contents(curr)) delete_contents(curr); 888. obj_extract_self(curr); 889. if (evades_destruction(curr)) { 890. switch (obj->where) { 891. case OBJ_FREE: 892. case OBJ_ONBILL: 893. impossible("indestructible object %s", 894. obj->where == OBJ_FREE ? "free" : "on bill"); 895. obfree(curr, (struct obj *)0); 896. break; 897. case OBJ_FLOOR: 898. place_object(curr, obj->ox, obj->oy); 899. /* No indestructible objects currently stack */ 900. break; 901. case OBJ_CONTAINED: 902. add_to_container(obj->ocontainer, curr); 903. break; 904. case OBJ_INVENT: 905. if (!flooreffects(curr, u.ux, u.uy, "fall")) 906. place_object(curr, u.ux, u.uy); 907. break; 908. case OBJ_MINVENT: 909. if (!flooreffects(curr, 910. obj->ocarry->mx, obj->ocarry->my, "fall")) 911. place_object(curr, obj->ocarry->mx, obj->ocarry->my); 912. break; 913. case OBJ_MIGRATING: 914. add_to_migration(curr); 915. /* Copy migration destination */ 916. curr->ox = obj->ox; 917. curr->oy = obj->oy; 918. curr->owornmask = obj->owornmask; 919. break; 920. case OBJ_BURIED: 921. add_to_buried(curr); 922. curr->ox = obj->ox; 923. curr->oy = obj->oy; 924. break; 925. default: 926. panic("delete_contents"); 927. break; 928. } 929. } 930. else 931. obfree(curr, (struct obj *)0); 932. } 933. } 934. 935. /* called with two args on merge */ 936. void 937. obfree(obj, merge) 938. register struct obj *obj, *merge; 939. { 940. register struct bill_x *bp; 941. register struct bill_x *bpm; 942. register struct monst *shkp; 943. 944. #ifdef STEED 945. if (obj == usaddle) dismount_steed(DISMOUNT_GENERIC); 946. #endif 947. 948. if (obj->otyp == LEASH && obj->leashmon) o_unleash(obj); 949. if (obj->oclass == SPBOOK_CLASS) book_disappears(obj); 950. if (obj->oclass == FOOD_CLASS) food_disappears(obj); 951. /* [ALI] Enforce new rules: Containers must have their contents 952. * deleted while still in situ so that we can place any 953. * indestructible objects they may contain. 954. */ 955. if (Has_contents(obj)) { 956. FILE *fp; 957. int known; 958. xchar x, y; 959. struct obj *otmp; 960. pline("BUG: obfree() called on non-empty container. See buglog for details."); 961. fp = fopen_datafile("buglog", "a", TROUBLEPREFIX); 962. if (fp) { 963. (void) fprintf(fp, 964. "%08ld: BUG: obfree() called on non-empty container.\n", 965. yyyymmdd((time_t)0L)); 966. known = objects[obj->otyp].oc_name_known; 967. objects[obj->otyp].oc_name_known = 1; 968. obj->known = obj->bknown = obj->dknown = obj->rknown = 1; 969. (void) fprintf(fp, "Container: %s\n", doname(obj)); 970. objects[obj->otyp].oc_name_known = known; 971. (void) fprintf(fp, "ID: %d\n", obj->o_id); 972. (void) fprintf(fp, "Contents of %s:\n", the(xname(obj))); 973. for(otmp = obj->cobj; otmp; otmp = obj->nobj) { 974. known = objects[otmp->otyp].oc_name_known; 975. objects[otmp->otyp].oc_name_known = 1; 976. otmp->known = otmp->bknown = 977. otmp->dknown = otmp->rknown = 1; 978. (void) fprintf(fp, "\t%s\n", doname(otmp)); 979. objects[otmp->otyp].oc_name_known = known; 980. } 981. switch (obj->where) { 982. case OBJ_FREE: 983. (void) fprintf(fp, "Container is on free list.\n"); 984. break; 985. case OBJ_FLOOR: 986. (void) fprintf(fp, 987. "Container is on the floor at (%d, %d)\n", 988. obj->ox, obj->oy); 989. break; 990. case OBJ_CONTAINED: 991. otmp = obj->ocontainer; 992. known = objects[otmp->otyp].oc_name_known; 993. objects[otmp->otyp].oc_name_known = 1; 994. otmp->known = otmp->bknown = 995. otmp->dknown = otmp->rknown = 1; 996. get_obj_location(otmp, &x, &y, 997. BURIED_TOO | CONTAINED_TOO); 998. (void) fprintf(fp, 999. "Container is contained in %s at (%d, %d)\n", 1000. doname(otmp), x, y); 1001. objects[otmp->otyp].oc_name_known = known; 1002. break; 1003. case OBJ_INVENT: 1004. (void) fprintf(fp, 1005. "Container is in hero's inventory\n"); 1006. break; 1007. case OBJ_MINVENT: 1008. get_obj_location(otmp, &x, &y, 0); 1009. (void) fprintf(fp, 1010. "Container is in %s's inventory at (%d, %d)\n", 1011. s_suffix(noit_mon_nam(obj->ocarry)), x, y); 1012. break; 1013. case OBJ_MIGRATING: 1014. (void) fprintf(fp, 1015. "Container is migrating to level %d of %s\n", 1016. otmp->oy, dungeons[otmp->ox].dname); 1017. break; 1018. case OBJ_BURIED: 1019. (void) fprintf(fp, "Container is buried at (%d, %d)\n", 1020. obj->ox, obj->oy); 1021. break; 1022. case OBJ_ONBILL: 1023. (void) fprintf(fp, "Container is on shopping bill.\n"); 1024. break; 1025. default: 1026. (void) fprintf(fp, 1027. "Container is nowhere (%d).\n", obj->where); 1028. break; 1029. } 1030. (void) fprintf(fp, "\n"); 1031. fclose(fp); 1032. } 1033. } 1034. if (Has_contents(obj)) delete_contents(obj); 1035. 1036. shkp = 0; 1037. if (obj->unpaid) { 1038. /* look for a shopkeeper who owns this object */ 1039. for (shkp = next_shkp(fmon, TRUE); shkp; 1040. shkp = next_shkp(shkp->nmon, TRUE)) 1041. if (onbill(obj, shkp, TRUE)) break; 1042. } 1043. /* sanity check, more or less */ 1044. if (!shkp) shkp = shop_keeper(*u.ushops); 1045. /* 1046. * Note: `shkp = shop_keeper(*u.ushops)' used to be 1047. * unconditional. But obfree() is used all over 1048. * the place, so making its behavior be dependent 1049. * upon player location doesn't make much sense. 1050. */ 1051. 1052. if ((bp = onbill(obj, shkp, FALSE)) != 0) { 1053. if(!merge){ 1054. bp->useup = 1; 1055. obj->unpaid = 0; /* only for doinvbill */ 1056. add_to_billobjs(obj); 1057. return; 1058. } 1059. bpm = onbill(merge, shkp, FALSE); 1060. if(!bpm){ 1061. /* this used to be a rename */ 1062. impossible("obfree: not on bill??"); 1063. return; 1064. } else { 1065. /* this was a merger */ 1066. bpm->bquan += bp->bquan; 1067. ESHK(shkp)->billct--; 1068. #ifdef DUMB 1069. { 1070. /* DRS/NS 2.2.6 messes up -- Peter Kendell */ 1071. int indx = ESHK(shkp)->billct; 1072. *bp = ESHK(shkp)->bill_p[indx]; 1073. } 1074. #else 1075. *bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct]; 1076. #endif 1077. } 1078. } 1079. dealloc_obj(obj); 1080. } 1081. #endif /* OVLB */ 1082. #ifdef OVL3 1083. 1084. STATIC_OVL long 1085. check_credit(tmp, shkp) 1086. long tmp; 1087. register struct monst *shkp; 1088. { 1089. long credit = ESHK(shkp)->credit; 1090. 1091. if(credit == 0L) return(tmp); 1092. if(credit >= tmp) { 1093. pline_The("price is deducted from your credit."); 1094. ESHK(shkp)->credit -=tmp; 1095. tmp = 0L; 1096. } else { 1097. pline_The("price is partially covered by your credit."); 1098. ESHK(shkp)->credit = 0L; 1099. tmp -= credit; 1100. } 1101. return(tmp); 1102. } 1103. 1104. STATIC_OVL void 1105. pay(tmp,shkp) 1106. long tmp; 1107. register struct monst *shkp; 1108. { 1109. long robbed = ESHK(shkp)->robbed; 1110. long balance = ((tmp <= 0L) ? tmp : check_credit(tmp, shkp)); 1111. 1112. #ifndef GOLDOBJ 1113. u.ugold -= balance; 1114. shkp->mgold += balance; 1115. #else 1116. if (balance > 0) money2mon(shkp, balance); 1117. else if (balance < 0) money2u(shkp, -balance); 1118. #endif 1119. flags.botl = 1; 1120. if(robbed) { 1121. robbed -= tmp; 1122. if(robbed < 0) robbed = 0L; 1123. ESHK(shkp)->robbed = robbed; 1124. } 1125. } 1126. #endif /*OVL3*/ 1127. #ifdef OVLB 1128. 1129. /* return shkp to home position */ 1130. void 1131. home_shk(shkp, killkops) 1132. register struct monst *shkp; 1133. register boolean killkops; 1134. { 1135. register xchar x = ESHK(shkp)->shk.x, y = ESHK(shkp)->shk.y; 1136. 1137. (void) mnearto(shkp, x, y, TRUE); 1138. level.flags.has_shop = 1; 1139. if (killkops) { 1140. #ifdef KOPS 1141. kops_gone(TRUE); 1142. #else 1143. You_feel("vaguely apprehensive."); 1144. #endif 1145. pacify_guards(); 1146. } 1147. after_shk_move(shkp); 1148. } 1149. 1150. STATIC_OVL boolean 1151. angry_shk_exists() 1152. { 1153. register struct monst *shkp; 1154. 1155. for (shkp = next_shkp(fmon, FALSE); 1156. shkp; shkp = next_shkp(shkp->nmon, FALSE)) 1157. if (ANGRY(shkp)) return(TRUE); 1158. return(FALSE); 1159. } 1160. 1161. /* remove previously applied surcharge from all billed items */ 1162. STATIC_OVL void 1163. pacify_shk(shkp) 1164. register struct monst *shkp; 1165. { 1166. NOTANGRY(shkp) = TRUE; /* make peaceful */ 1167. if (ESHK(shkp)->surcharge) { 1168. register struct bill_x *bp = ESHK(shkp)->bill_p; 1169. register int ct = ESHK(shkp)->billct; 1170. 1171. ESHK(shkp)->surcharge = FALSE; 1172. while (ct-- > 0) { 1173. register long reduction = (bp->price + 3L) / 4L; 1174. bp->price -= reduction; /* undo 33% increase */ 1175. bp++; 1176. } 1177. } 1178. } 1179. 1180. /* add aggravation surcharge to all billed items */ 1181. STATIC_OVL void 1182. rile_shk(shkp) 1183. register struct monst *shkp; 1184. { 1185. NOTANGRY(shkp) = FALSE; /* make angry */ 1186. if (!ESHK(shkp)->surcharge) { 1187. register struct bill_x *bp = ESHK(shkp)->bill_p; 1188. register int ct = ESHK(shkp)->billct; 1189. 1190. ESHK(shkp)->surcharge = TRUE; 1191. while (ct-- > 0) { 1192. register long surcharge = (bp->price + 2L) / 3L; 1193. bp->price += surcharge; 1194. bp++; 1195. } 1196. } 1197. } 1198. 1199. /* wakeup and/or unparalyze shopkeeper */ 1200. STATIC_OVL void 1201. rouse_shk(shkp, verbosely) 1202. struct monst *shkp; 1203. boolean verbosely; 1204. { 1205. if (!shkp->mcanmove || shkp->msleeping) { 1206. /* greed induced recovery... */ 1207. if (verbosely && canspotmon(shkp)) 1208. pline("%s %s.", Monnam(shkp), 1209. shkp->msleeping ? "wakes up" : "can move again"); 1210. shkp->msleeping = 0; 1211. shkp->mfrozen = 0; 1212. shkp->mcanmove = 1; 1213. } 1214. } 1215. 1216. void 1217. make_happy_shk(shkp, silentkops) 1218. register struct monst *shkp; 1219. register boolean silentkops; 1220. { 1221. boolean wasmad = ANGRY(shkp); 1222. struct eshk *eshkp = ESHK(shkp); 1223. boolean guilty = wasmad || 1224. eshkp->surcharge || eshkp->following || eshkp->robbed; 1225. 1226. pacify_shk(shkp); 1227. eshkp->following = 0; 1228. eshkp->robbed = 0L; 1229. if (guilty && !Role_if(PM_ROGUE)) { 1230. adjalign(sgn(u.ualign.type)); 1231. You("feel your guilt vanish."); 1232. } 1233. if(!inhishop(shkp)) { 1234. char shk_nam[BUFSZ]; 1235. boolean vanished = canseemon(shkp); 1236. 1237. Strcpy(shk_nam, mon_nam(shkp)); 1238. if (on_level(&eshkp->shoplevel, &u.uz)) { 1239. home_shk(shkp, FALSE); 1240. /* didn't disappear if shk can still be seen */ 1241. if (canseemon(shkp)) vanished = FALSE; 1242. } else { 1243. /* if sensed, does disappear regardless whether seen */ 1244. if (sensemon(shkp)) vanished = TRUE; 1245. /* can't act as porter for the Amulet, even if shk 1246. happens to be going farther down rather than up */ 1247. mdrop_special_objs(shkp); 1248. /* arrive near shop's door */ 1249. migrate_to_level(shkp, ledger_no(&eshkp->shoplevel), 1250. MIGR_APPROX_XY, &eshkp->shd); 1251. } 1252. if (vanished) 1253. pline("Satisfied, %s suddenly disappears!", shk_nam); 1254. } else if(wasmad) 1255. pline("%s calms down.", Monnam(shkp)); 1256. 1257. if(!angry_shk_exists()) { 1258. #ifdef KOPS 1259. kops_gone(silentkops); 1260. #endif 1261. pacify_guards(); 1262. } 1263. } 1264. 1265. void 1266. hot_pursuit(shkp) 1267. register struct monst *shkp; 1268. { 1269. if(!shkp->isshk) return; 1270. 1271. rile_shk(shkp); 1272. (void) strncpy(ESHK(shkp)->customer, plname, PL_NSIZ); 1273. ESHK(shkp)->following = 1; 1274. } 1275. 1276. /* used when the shkp is teleported or falls (ox == 0) out of his shop, 1277. * or when the player is not on a costly_spot and he 1278. * damages something inside the shop. these conditions 1279. * must be checked by the calling function. 1280. */ 1281. void 1282. make_angry_shk(shkp, ox, oy) 1283. register struct monst *shkp; 1284. register xchar ox,oy; 1285. { 1286. xchar sx, sy; 1287. struct eshk *eshkp = ESHK(shkp); 1288. 1289. /* all pending shop transactions are now "past due" */ 1290. if (eshkp->billct || eshkp->debit || eshkp->loan || eshkp->credit) { 1291. eshkp->robbed += (addupbill(shkp) + eshkp->debit + eshkp->loan); 1292. eshkp->robbed -= eshkp->credit; 1293. if (eshkp->robbed < 0L) eshkp->robbed = 0L; 1294. /* billct, debit, loan, and credit will be cleared by setpaid */ 1295. setpaid(shkp); 1296. } 1297. 1298. /* If you just used a wand of teleportation to send the shk away, you 1299. might not be able to see her any more. Monnam would yield "it", 1300. which makes this message look pretty silly, so temporarily restore 1301. her original location during the call to Monnam. */ 1302. sx = shkp->mx, sy = shkp->my; 1303. if (isok(ox, oy) && cansee(ox, oy) && !cansee(sx, sy)) 1304. shkp->mx = ox, shkp->my = oy; 1305. pline("%s %s!", Monnam(shkp), 1306. !ANGRY(shkp) ? "gets angry" : "is furious"); 1307. shkp->mx = sx, shkp->my = sy; 1308. hot_pursuit(shkp); 1309. } 1310. 1311. STATIC_VAR const char no_money[] = "Moreover, you%s have no money."; 1312. STATIC_VAR const char not_enough_money[] = 1313. "Besides, you don't have enough to interest %s."; 1314. 1315. #else 1316. STATIC_VAR const char no_money[]; 1317. STATIC_VAR const char not_enough_money[]; 1318. #endif /*OVLB*/ 1319. 1320. #ifdef OVL3 1321. 1322. STATIC_OVL long 1323. cheapest_item(shkp) /* delivers the cheapest item on the list */ 1324. register struct monst *shkp; 1325. { 1326. register int ct = ESHK(shkp)->billct; 1327. register struct bill_x *bp = ESHK(shkp)->bill_p; 1328. register long gmin = (bp->price * bp->bquan); 1329. 1330. while(ct--){ 1331. if(bp->price * bp->bquan < gmin) 1332. gmin = bp->price * bp->bquan; 1333. bp++; 1334. } 1335. return(gmin); 1336. } 1337. #endif /*OVL3*/ 1338. #ifdef OVL0 1339. 1340. int 1341. dopay() 1342. { 1343. register struct eshk *eshkp; 1344. register struct monst *shkp; 1345. struct monst *nxtm, *resident; 1346. long ltmp; 1347. #ifdef GOLDOBJ 1348. long umoney; 1349. #endif 1350. int pass, tmp, sk = 0, seensk = 0; 1351. boolean paid = FALSE, stashed_gold = (hidden_gold() > 0L); 1352. 1353. multi = 0; 1354. 1355. /* find how many shk's there are, how many are in */ 1356. /* sight, and are you in a shop room with one. */ 1357. nxtm = resident = 0; 1358. for (shkp = next_shkp(fmon, FALSE); 1359. shkp; shkp = next_shkp(shkp->nmon, FALSE)) { 1360. sk++; 1361. if (ANGRY(shkp) && distu(shkp->mx, shkp->my) <= 2) nxtm = shkp; 1362. if (canspotmon(shkp)) seensk++; 1363. if (inhishop(shkp) && (*u.ushops == ESHK(shkp)->shoproom)) 1364. resident = shkp; 1365. } 1366. 1367. if (nxtm) { /* Player should always appease an */ 1368. shkp = nxtm; /* irate shk standing next to them. */ 1369. goto proceed; 1370. } 1371. 1372. /* KMH -- Permit paying adjacent gypsies */ 1373. for (nxtm = fmon; nxtm; nxtm = nxtm->nmon) { 1374. if (!nxtm->isgyp || !nxtm->mpeaceful || 1375. distu(nxtm->mx, nxtm->my) > 2 || !canspotmon(nxtm)) 1376. continue; 1377. shkp = nxtm; 1378. sk++; 1379. seensk++; 1380. } 1381. 1382. if ((!sk && (!Blind || Blind_telepat)) || (!Blind && !seensk)) { 1383. There("appears to be no shopkeeper here to receive your payment."); 1384. return(0); 1385. } 1386. 1387. if(!seensk) { 1388. You_cant("see..."); 1389. return(0); 1390. } 1391. 1392. /* the usual case. allow paying at a distance when */ 1393. /* inside a tended shop. should we change that? */ 1394. if(sk == 1 && resident) { 1395. shkp = resident; 1396. goto proceed; 1397. } 1398. 1399. if (seensk == 1) { 1400. /* KMH -- Permit paying gypsies */ 1401. if (shkp && shkp->isgyp) { 1402. gypsy_chat(shkp); 1403. return (1); 1404. } 1405. 1406. for (shkp = next_shkp(fmon, FALSE); 1407. shkp; shkp = next_shkp(shkp->nmon, FALSE)) 1408. if (canspotmon(shkp)) break; 1409. if (shkp != resident && distu(shkp->mx, shkp->my) > 2) { 1410. pline("%s is not near enough to receive your payment.", 1411. Monnam(shkp)); 1412. return(0); 1413. } 1414. } else { 1415. struct monst *mtmp; 1416. coord cc; 1417. int cx, cy; 1418. 1419. pline("Pay whom?"); 1420. cc.x = u.ux; 1421. cc.y = u.uy; 1422. if (getpos(&cc, TRUE, "the creature you want to pay") < 0) 1423. return 0; /* player pressed ESC */ 1424. cx = cc.x; 1425. cy = cc.y; 1426. if(cx < 0) { 1427. pline("Try again..."); 1428. return(0); 1429. } 1430. if(u.ux == cx && u.uy == cy) { 1431. You("are generous to yourself."); 1432. return(0); 1433. } 1434. mtmp = m_at(cx, cy); 1435. if(!mtmp) { 1436. There("is no one there to receive your payment."); 1437. return(0); 1438. } 1439. /* KMH -- Permit paying gypsies */ 1440. if (mtmp->isgyp && mtmp->mpeaceful) { 1441. if (distu(mtmp->mx, mtmp->my) <= 2) { 1442. gypsy_chat(mtmp); 1443. return (1); 1444. } 1445. } else 1446. if(!mtmp->isshk) { 1447. pline("%s is not interested in your payment.", 1448. Monnam(mtmp)); 1449. return(0); 1450. } 1451. if (mtmp != resident && distu(mtmp->mx, mtmp->my) > 2) { 1452. pline("%s is too far to receive your payment.", 1453. Monnam(mtmp)); 1454. return(0); 1455. } 1456. shkp = mtmp; 1457. } 1458. 1459. if(!shkp) { 1460. #ifdef DEBUG 1461. pline("dopay: null shkp."); 1462. #endif 1463. return(0); 1464. } 1465. proceed: 1466. eshkp = ESHK(shkp); 1467. ltmp = eshkp->robbed; 1468. 1469. /* wake sleeping shk when someone who owes money offers payment */ 1470. if (ltmp || eshkp->billct || eshkp->debit) 1471. rouse_shk(shkp, TRUE); 1472. 1473. if (!shkp->mcanmove || shkp->msleeping) { /* still asleep/paralyzed */ 1474. pline("%s %s.", Monnam(shkp), 1475. rn2(2) ? "seems to be napping" : "doesn't respond"); 1476. return 0; 1477. } 1478. 1479. if(shkp != resident && NOTANGRY(shkp)) { 1480. #ifdef GOLDOBJ 1481. umoney = money_cnt(invent); 1482. #endif 1483. if(!ltmp) 1484. You("do not owe %s anything.", mon_nam(shkp)); 1485. #ifndef GOLDOBJ 1486. else if(!u.ugold) { 1487. #else 1488. else if(!umoney) { 1489. #endif 1490. You("%shave no money.", stashed_gold ? "seem to " : ""); 1491. if(stashed_gold) 1492. 1493. #ifndef GOLDOBJ 1494. pline("But you have some gold stashed away."); 1495. #else 1496. pline("But you have some money stashed away."); 1497. #endif 1498. } else { 1499. #ifndef GOLDOBJ 1500. long ugold = u.ugold; 1501. if(ugold > ltmp) { 1502. #else 1503. if(umoney > ltmp) { 1504. #endif 1505. You("give %s the %ld gold piece%s %s asked for.", 1506. mon_nam(shkp), ltmp, plur(ltmp), mhe(shkp)); 1507. pay(ltmp, shkp); 1508. } else { 1509. #ifndef GOLDOBJ 1510. You("give %s all your%s gold.", mon_nam(shkp), 1511. #else 1512. You("give %s all your%s money.", mon_nam(shkp), 1513. #endif 1514. stashed_gold ? " openly kept" : ""); 1515. #ifndef GOLDOBJ 1516. pay(u.ugold, shkp); 1517. if (stashed_gold) pline("But you have hidden gold!"); 1518. #else 1519. pay(umoney, shkp); 1520. if (stashed_gold) pline("But you have hidden money!"); 1521. #endif 1522. } 1523. #ifndef GOLDOBJ 1524. if((ugold < ltmp/2L) || (ugold < ltmp && stashed_gold)) 1525. #else 1526. if((umoney < ltmp/2L) || (umoney < ltmp && stashed_gold)) 1527. #endif 1528. pline("Unfortunately, %s doesn't look satisfied.", 1529. mhe(shkp)); 1530. else 1531. make_happy_shk(shkp, FALSE); 1532. } 1533. return(1); 1534. } 1535. 1536. /* ltmp is still eshkp->robbed here */ 1537. if (!eshkp->billct && !eshkp->debit) { 1538. #ifdef GOLDOBJ 1539. umoney = money_cnt(invent); 1540. #endif 1541. if(!ltmp && NOTANGRY(shkp)) { 1542. You("do not owe %s anything.", mon_nam(shkp)); 1543. #ifndef GOLDOBJ 1544. if (!u.ugold) 1545. #else 1546. if (!umoney) 1547. #endif 1548. pline(no_money, stashed_gold ? " seem to" : ""); 1549. 1550. #ifdef OTHER_SERVICES 1551. /* else */ 1552. shk_other_services(); 1553. #endif 1554. 1555. } else if(ltmp) { 1556. pline("%s is after blood, not money!", Monnam(shkp)); 1557. #ifndef GOLDOBJ 1558. if(u.ugold < ltmp/2L || 1559. (u.ugold < ltmp && stashed_gold)) { 1560. if (!u.ugold) 1561. #else 1562. if(umoney < ltmp/2L || 1563. (umoney < ltmp && stashed_gold)) { 1564. if (!umoney) 1565. #endif 1566. pline(no_money, stashed_gold ? " seem to" : ""); 1567. else pline(not_enough_money, mhim(shkp)); 1568. return(1); 1569. } 1570. pline("But since %s shop has been robbed recently,", 1571. mhis(shkp)); 1572. pline("you %scompensate %s for %s losses.", 1573. #ifndef GOLDOBJ 1574. (u.ugold < ltmp) ? 1575. #else 1576. (umoney < ltmp) ? 1577. #endif 1578. "partially " : "", 1579. mon_nam(shkp), mhis(shkp)); 1580. #ifndef GOLDOBJ 1581. pay(u.ugold < ltmp ? u.ugold : ltmp, shkp); 1582. #else 1583. pay(umoney < ltmp ? umoney : ltmp, shkp); 1584. #endif 1585. make_happy_shk(shkp, FALSE); 1586. } else { 1587. /* shopkeeper is angry, but has not been robbed -- 1588. * door broken, attacked, etc. */ 1589. pline("%s is after your hide, not your money!", 1590. Monnam(shkp)); 1591. #ifndef GOLDOBJ 1592. if(u.ugold < 1000L) { 1593. if (!u.ugold) 1594. #else 1595. if(umoney < 1000L) { 1596. if (!umoney) 1597. #endif 1598. pline(no_money, stashed_gold ? " seem to" : ""); 1599. else pline(not_enough_money, mhim(shkp)); 1600. return(1); 1601. } 1602. You("try to appease %s by giving %s 1000 gold pieces.", 1603. x_monnam(shkp, ARTICLE_THE, "angry", 0, FALSE), 1604. mhim(shkp)); 1605. pay(1000L,shkp); 1606. if (strncmp(eshkp->customer, plname, PL_NSIZ) || rn2(3)) 1607. make_happy_shk(shkp, FALSE); 1608. else 1609. pline("But %s is as angry as ever.", mon_nam(shkp)); 1610. } 1611. return(1); 1612. } 1613. if(shkp != resident) { 1614. impossible("dopay: not to shopkeeper?"); 1615. if(resident) setpaid(resident); 1616. return(0); 1617. } 1618. /* pay debt, if any, first */ 1619. if(eshkp->debit) { 1620. long dtmp = eshkp->debit; 1621. long loan = eshkp->loan; 1622. char sbuf[BUFSZ]; 1623. #ifdef GOLDOBJ 1624. umoney = money_cnt(invent); 1625. #endif 1626. Sprintf(sbuf, "You owe %s %ld %s ", 1627. shkname(shkp), dtmp, currency(dtmp)); 1628. if(loan) { 1629. if(loan == dtmp) 1630. Strcat(sbuf, "you picked up in the store."); 1631. else Strcat(sbuf, 1632. "for gold picked up and the use of merchandise."); 1633. } else Strcat(sbuf, "for the use of merchandise."); 1634. pline(sbuf); 1635. #ifndef GOLDOBJ 1636. if (u.ugold + eshkp->credit < dtmp) { 1637. pline("But you don't%s have enough gold%s.", 1638. #else 1639. if (umoney + eshkp->credit < dtmp) { 1640. pline("But you don't%s have enough money%s.", 1641. #endif 1642. 1643. stashed_gold ? " seem to" : "", 1644. eshkp->credit ? " or credit" : ""); 1645. return(1); 1646. } else { 1647. if (eshkp->credit >= dtmp) { 1648. eshkp->credit -= dtmp; 1649. eshkp->debit = 0L; 1650. eshkp->loan = 0L; 1651. Your("debt is covered by your credit."); 1652. } else if (!eshkp->credit) { 1653. #ifndef GOLDOBJ 1654. u.ugold -= dtmp; 1655. shkp->mgold += dtmp; 1656. #else 1657. money2mon(shkp, dtmp); 1658. #endif 1659. eshkp->debit = 0L; 1660. eshkp->loan = 0L; 1661. You("pay that debt."); 1662. flags.botl = 1; 1663. } else { 1664. dtmp -= eshkp->credit; 1665. eshkp->credit = 0L; 1666. #ifndef GOLDOBJ 1667. u.ugold -= dtmp; 1668. shkp->mgold += dtmp; 1669. #else 1670. money2mon(shkp, dtmp); 1671. #endif 1672. eshkp->debit = 0L; 1673. eshkp->loan = 0L; 1674. pline("That debt is partially offset by your credit."); 1675. You("pay the remainder."); 1676. flags.botl = 1; 1677. } 1678. paid = TRUE; 1679. } 1680. } 1681. /* now check items on bill */ 1682. if (eshkp->billct) { 1683. register boolean itemize; 1684. #ifndef GOLDOBJ 1685. if (!u.ugold && !eshkp->credit) { 1686. #else 1687. umoney = money_cnt(invent); 1688. if (!umoney && !eshkp->credit) { 1689. #endif 1690. You("%shave no money or credit%s.", 1691. stashed_gold ? "seem to " : "", 1692. paid ? " left" : ""); 1693. return(0); 1694. } 1695. #ifndef GOLDOBJ 1696. if ((u.ugold + eshkp->credit) < cheapest_item(shkp)) { 1697. #else 1698. if ((umoney + eshkp->credit) < cheapest_item(shkp)) { 1699. #endif 1700. You("don't have enough money to buy%s the item%s you picked.", 1701. eshkp->billct > 1 ? " any of" : "", plur(eshkp->billct)); 1702. if(stashed_gold) 1703. #ifndef GOLDOBJ 1704. pline("Maybe you have some gold stashed away?"); 1705. #else 1706. pline("Maybe you have some money stashed away?"); 1707. #endif 1708. return(0); 1709. } 1710. 1711. /* this isn't quite right; it itemizes without asking if the 1712. * single item on the bill is partly used up and partly unpaid */ 1713. itemize = (eshkp->billct > 1 ? yn("Itemized billing?") == 'y' : 1); 1714. 1715. for (pass = 0; pass <= 1; pass++) { 1716. tmp = 0; 1717. while (tmp < eshkp->billct) { 1718. struct obj *otmp; 1719. register struct bill_x *bp = &(eshkp->bill_p[tmp]); 1720. 1721. /* find the object on one of the lists */ 1722. if ((otmp = bp_to_obj(bp)) != 0) { 1723. /* if completely used up, object quantity is stale; 1724. restoring it to its original value here avoids 1725. making the partly-used-up code more complicated */ 1726. if (bp->useup) otmp->quan = bp->bquan; 1727. } else { 1728. impossible("Shopkeeper administration out of order."); 1729. setpaid(shkp); /* be nice to the player */ 1730. return 1; 1731. } 1732. if (pass == bp->useup && otmp->quan == bp->bquan) { 1733. /* pay for used-up items on first pass and others 1734. * on second, so player will be stuck in the store 1735. * less often; things which are partly used up 1736. * are processed on both passes */ 1737. tmp++; 1738. } else { 1739. switch (dopayobj(shkp, bp, &otmp, pass, itemize)) { 1740. case PAY_CANT: 1741. return 1; /*break*/ 1742. case PAY_BROKE: 1743. paid = TRUE; 1744. goto thanks; /*break*/ 1745. case PAY_SKIP: 1746. tmp++; 1747. continue; /*break*/ 1748. case PAY_SOME: 1749. paid = TRUE; 1750. if (itemize) bot(); 1751. continue; /*break*/ 1752. case PAY_BUY: 1753. paid = TRUE; 1754. break; 1755. } 1756. if (itemize) bot(); 1757. *bp = eshkp->bill_p[--eshkp->billct]; 1758. } 1759. } 1760. } 1761. thanks: 1762. if (!itemize) 1763. update_inventory(); /* Done in dopayobj() if itemize. */ 1764. } 1765. if(!ANGRY(shkp) && paid) 1766. verbalize("Thank you for shopping in %s %s!", 1767. s_suffix(shkname(shkp)), 1768. shtypes[eshkp->shoptype - SHOPBASE].name); 1769. return(1); 1770. } 1771. 1772. #ifdef OTHER_SERVICES 1773. /* 1774. ** FUNCTION shk_other_services 1775. ** 1776. ** Called when you don't owe any money. Called after all checks have been 1777. ** made (in shop, not angry shopkeeper, etc.) 1778. */ 1779. static void 1780. shk_other_services() 1781. { 1782. char *slang; /* What shk calls you */ 1783. struct monst *shkp; /* The shopkeeper */ 1784. /*WAC - Windowstuff*/ 1785. winid tmpwin; 1786. anything any; 1787. menu_item *selected; 1788. int n; 1789. 1790. /* Do you want to use other services */ 1791. if (yn("Do you wish to try our other services?") != 'y' ) return; 1792. 1793. /* Init your name */ 1794. if (!is_human(youmonst.data)) 1795. slang = "ugly"; 1796. else 1797. slang = (flags.female) ? "lady" : "buddy"; 1798. 1799. /* Init the shopkeeper */ 1800. shkp = shop_keeper(/* roomno= */*u.ushops); 1801. if (!ESHK(shkp)->services) return; 1802. 1803. /* 1804. ** Figure out what services he offers 1805. ** 1806. ** i = identify 1807. ** a = appraise weapon's worth 1808. ** u = uncurse 1809. ** w = weapon-works (including poison) 1810. ** p = poison weapon 1811. ** r = armor-works 1812. ** c = charge wands 1813. */ 1814. /*WAC - did this using the windowing system...*/ 1815. any.a_void = 0; /* zero out all bits */ 1816. tmpwin = create_nhwindow(NHW_MENU); 1817. start_menu(tmpwin); 1818. 1819. /* All shops can identify (some better than others) */ 1820. any.a_int = 1; 1821. if (ESHK(shkp)->services & (SHK_ID_BASIC|SHK_ID_PREMIUM)) 1822. add_menu(tmpwin, NO_GLYPH, &any , 'i', 0, ATR_NONE, 1823. "Identify", MENU_UNSELECTED); 1824. 1825. /* All shops can uncurse */ 1826. any.a_int = 2; 1827. if (ESHK(shkp)->services & (SHK_UNCURSE)) 1828. add_menu(tmpwin, NO_GLYPH, &any , 'u', 0, ATR_NONE, 1829. "Uncurse", MENU_UNSELECTED); 1830. 1831. /* Weapon appraisals. Weapon & general stores can do this. */ 1832. if ((ESHK(shkp)->services & (SHK_UNCURSE)) && 1833. (shk_class_match(WEAPON_CLASS, shkp))) { 1834. any.a_int = 3; 1835. add_menu(tmpwin, NO_GLYPH, &any , 'a', 0, ATR_NONE, 1836. "Appraise", MENU_UNSELECTED); 1837. } 1838. 1839. /* Weapon-works! Only a weapon store. */ 1840. if ((ESHK(shkp)->services & (SHK_SPECIAL_A|SHK_SPECIAL_B|SHK_SPECIAL_C)) 1841. && (shk_class_match(WEAPON_CLASS, shkp) == SHK_MATCH)) { 1842. any.a_int = 4; 1843. if (ESHK(shkp)->services & (SHK_SPECIAL_A|SHK_SPECIAL_B)) 1844. add_menu(tmpwin, NO_GLYPH, &any , 'w', 0, ATR_NONE, 1845. "Weapon-works", MENU_UNSELECTED); 1846. else 1847. add_menu(tmpwin, NO_GLYPH, &any , 'p', 0, ATR_NONE, 1848. "Poison", MENU_UNSELECTED); 1849. } 1850. 1851. /* Armor-works */ 1852. if ((ESHK(shkp)->services & (SHK_SPECIAL_A|SHK_SPECIAL_B)) 1853. && (shk_class_match(ARMOR_CLASS, shkp) == SHK_MATCH)) { 1854. any.a_int = 5; 1855. add_menu(tmpwin, NO_GLYPH, &any , 'r', 0, ATR_NONE, 1856. "Armor-works", MENU_UNSELECTED); 1857. } 1858. 1859. /* Charging: / ( = */ 1860. if ((ESHK(shkp)->services & (SHK_SPECIAL_A|SHK_SPECIAL_B)) && 1861. ((shk_class_match(WAND_CLASS, shkp) == SHK_MATCH) || 1862. (shk_class_match(TOOL_CLASS, shkp) == SHK_MATCH) || 1863. (shk_class_match(SPBOOK_CLASS, shkp) == SHK_MATCH) || 1864. (shk_class_match(RING_CLASS, shkp) == SHK_MATCH))) { 1865. any.a_int = 6; 1866. add_menu(tmpwin, NO_GLYPH, &any , 'c', 0, ATR_NONE, 1867. "Charge", MENU_UNSELECTED); 1868. } 1869. 1870. end_menu(tmpwin, "Services Available:"); 1871. n = select_menu(tmpwin, PICK_ONE, &selected); 1872. destroy_nhwindow(tmpwin); 1873. 1874. if (n > 0) 1875. switch (selected[0].item.a_int) { 1876. case 1: 1877. shk_identify(slang, shkp); 1878. break; 1879. 1880. case 2: 1881. shk_uncurse(slang, shkp); 1882. break; 1883. 1884. case 3: 1885. shk_appraisal(slang, shkp); 1886. break; 1887. 1888. case 4: 1889. shk_weapon_works(slang, shkp); 1890. break; 1891. 1892. case 5: 1893. shk_armor_works(slang, shkp); 1894. break; 1895. 1896. case 6: 1897. shk_charge(slang, shkp); 1898. break; 1899. default: 1900. pline ("Unknown Service"); 1901. break; 1902. } 1903. } 1904. #endif /* OTHER_SERVICES */ 1905. 1906. #endif /*OVL0*/ 1907. #ifdef OVL3 1908. 1909. /* return 2 if used-up portion paid */ 1910. /* 1 if paid successfully */ 1911. /* 0 if not enough money */ 1912. /* -1 if skip this object */ 1913. /* -2 if no money/credit left */ 1914. STATIC_OVL int 1915. dopayobj(shkp, bp, obj_p, which, itemize) 1916. register struct monst *shkp; 1917. register struct bill_x *bp; 1918. struct obj **obj_p; 1919. int which; /* 0 => used-up item, 1 => other (unpaid or lost) */ 1920. boolean itemize; 1921. { 1922. register struct obj *obj = *obj_p; 1923. long ltmp, quan, save_quan; 1924. #ifdef GOLDOBJ 1925. long umoney = money_cnt(invent); 1926. #endif 1927. int buy; 1928. boolean stashed_gold = (hidden_gold() > 0L), 1929. consumed = (which == 0); 1930. 1931. if(!obj->unpaid && !bp->useup){ 1932. impossible("Paid object on bill??"); 1933. return PAY_BUY; 1934. } 1935. #ifndef GOLDOBJ 1936. if(itemize && u.ugold + ESHK(shkp)->credit == 0L){ 1937. #else 1938. if(itemize && umoney + ESHK(shkp)->credit == 0L){ 1939. #endif 1940. You("%shave no money or credit left.", 1941. stashed_gold ? "seem to " : ""); 1942. return PAY_BROKE; 1943. } 1944. /* we may need to temporarily adjust the object, if part of the 1945. original quantity has been used up but part remains unpaid */ 1946. save_quan = obj->quan; 1947. if (consumed) { 1948. /* either completely used up (simple), or split needed */ 1949. quan = bp->bquan; 1950. if (quan > obj->quan) /* difference is amount used up */ 1951. quan -= obj->quan; 1952. } else { 1953. /* dealing with ordinary unpaid item */ 1954. quan = obj->quan; 1955. } 1956. obj->quan = quan; /* to be used by doname() */ 1957. obj->unpaid = 0; /* ditto */ 1958. ltmp = bp->price * quan; 1959. buy = PAY_BUY; /* flag; if changed then return early */ 1960. 1961. if (itemize) { 1962. char qbuf[BUFSZ]; 1963. Sprintf(qbuf,"%s for %ld %s. Pay?", quan == 1L ? 1964. Doname2(obj) : doname(obj), ltmp, currency(ltmp)); 1965. if (yn(qbuf) == 'n') { 1966. buy = PAY_SKIP; /* don't want to buy */ 1967. } else if (quan < bp->bquan && !consumed) { /* partly used goods */ 1968. obj->quan = bp->bquan - save_quan; /* used up amount */ 1969. verbalize("%s for the other %s before buying %s.", 1970. ANGRY(shkp) ? "Pay" : "Please pay", xname(obj), 1971. save_quan > 1L ? "these" : "this one"); 1972. buy = PAY_SKIP; /* shk won't sell */ 1973. } 1974. } 1975. #ifndef GOLDOBJ 1976. if (buy == PAY_BUY && u.ugold + ESHK(shkp)->credit < ltmp) { 1977. You("don't%s have gold%s enough to pay for %s.", 1978. #else 1979. if (buy == PAY_BUY && umoney + ESHK(shkp)->credit < ltmp) { 1980. You("don't%s have money%s enough to pay for %s.", 1981. #endif 1982. stashed_gold ? " seem to" : "", 1983. (ESHK(shkp)->credit > 0L) ? " or credit" : "", 1984. doname(obj)); 1985. buy = itemize ? PAY_SKIP : PAY_CANT; 1986. } 1987. 1988. if (buy != PAY_BUY) { 1989. /* restore unpaid object to original state */ 1990. obj->quan = save_quan; 1991. obj->unpaid = 1; 1992. return buy; 1993. } 1994. 1995. pay(ltmp, shkp); 1996. shk_names_obj(shkp, obj, consumed ? 1997. "paid for %s at a cost of %ld gold piece%s.%s" : 1998. "bought %s for %ld gold piece%s.%s", ltmp, ""); 1999. obj->quan = save_quan; /* restore original count */ 2000. /* quan => amount just bought, save_quan => remaining unpaid count */ 2001. if (consumed) { 2002. if (quan != bp->bquan) { 2003. /* eliminate used-up portion; remainder is still unpaid */ 2004. bp->bquan = obj->quan; 2005. obj->unpaid = 1; 2006. bp->useup = 0; 2007. buy = PAY_SOME; 2008. } else { /* completely used-up, so get rid of it */ 2009. obj_extract_self(obj); 2010. /* assert( obj == *obj_p ); */ 2011. dealloc_obj(obj); 2012. *obj_p = 0; /* destroy pointer to freed object */ 2013. } 2014. } else if (itemize) 2015. update_inventory(); /* Done just once in dopay() if !itemize. */ 2016. return buy; 2017. } 2018. #endif /*OVL3*/ 2019. #ifdef OVLB 2020. 2021. static coord repo_location; /* repossession context */ 2022. 2023. /* routine called after dying (or quitting) */ 2024. boolean 2025. paybill(croaked) 2026. int croaked; /* -1: escaped dungeon; 0: quit; 1: died */ 2027. { 2028. register struct monst *mtmp, *mtmp2, *resident= (struct monst *)0; 2029. register boolean taken = FALSE; 2030. register int numsk = 0; 2031. 2032. /* if we escaped from the dungeon, shopkeepers can't reach us; 2033. shops don't occur on level 1, but this could happen if hero 2034. level teleports out of the dungeon and manages not to die */ 2035. if (croaked < 0) return FALSE; 2036. 2037. /* this is where inventory will end up if any shk takes it */ 2038. repo_location.x = repo_location.y = 0; 2039. 2040. /* give shopkeeper first crack */ 2041. if ((mtmp = shop_keeper(*u.ushops)) && inhishop(mtmp)) { 2042. numsk++; 2043. resident = mtmp; 2044. taken = inherits(resident, numsk, croaked); 2045. } 2046. for (mtmp = next_shkp(fmon, FALSE); 2047. mtmp; mtmp = next_shkp(mtmp2, FALSE)) { 2048. mtmp2 = mtmp->nmon; 2049. if (mtmp != resident) { 2050. /* for bones: we don't want a shopless shk around */ 2051. if(!on_level(&(ESHK(mtmp)->shoplevel), &u.uz)) 2052. mongone(mtmp); 2053. else { 2054. numsk++; 2055. taken |= inherits(mtmp, numsk, croaked); 2056. } 2057. } 2058. } 2059. if(numsk == 0) return(FALSE); 2060. return(taken); 2061. } 2062. 2063. STATIC_OVL boolean 2064. inherits(shkp, numsk, croaked) 2065. struct monst *shkp; 2066. int numsk; 2067. int croaked; 2068. { 2069. long loss = 0L; 2070. #ifdef GOLDOBJ 2071. long umoney; 2072. #endif 2073. struct eshk *eshkp = ESHK(shkp); 2074. boolean take = FALSE, taken = FALSE; 2075. int roomno = *u.ushops; 2076. char takes[BUFSZ]; 2077. 2078. /* the simplifying principle is that first-come */ 2079. /* already took everything you had. */ 2080. if (numsk > 1) { 2081. if (cansee(shkp->mx, shkp->my) && croaked) 2082. pline("%s %slooks at your corpse%s and %s.", 2083. Monnam(shkp), 2084. (!shkp->mcanmove || shkp->msleeping) ? "wakes up, " : "", 2085. !rn2(2) ? (shkp->female ? ", shakes her head," : 2086. ", shakes his head,") : "", 2087. !inhishop(shkp) ? "disappears" : "sighs"); 2088. rouse_shk(shkp, FALSE); /* wake shk for bones */ 2089. taken = (roomno == eshkp->shoproom); 2090. goto skip; 2091. } 2092. 2093. /* get one case out of the way: you die in the shop, the */ 2094. /* shopkeeper is peaceful, nothing stolen, nothing owed. */ 2095. if(roomno == eshkp->shoproom && inhishop(shkp) && 2096. !eshkp->billct && !eshkp->robbed && !eshkp->debit && 2097. NOTANGRY(shkp) && !eshkp->following) { 2098. if (invent) 2099. pline("%s gratefully inherits all your possessions.", 2100. shkname(shkp)); 2101. set_repo_loc(eshkp); 2102. goto clear; 2103. } 2104. 2105. if (eshkp->billct || eshkp->debit || eshkp->robbed) { 2106. if(roomno == eshkp->shoproom && inhishop(shkp)) 2107. loss = addupbill(shkp) + eshkp->debit; 2108. if (loss < eshkp->robbed) loss = eshkp->robbed; 2109. take = TRUE; 2110. } 2111. 2112. if (eshkp->following || ANGRY(shkp) || take) { 2113. #ifndef GOLDOBJ 2114. if (!invent && !u.ugold) goto skip; 2115. #else 2116. if (!invent) goto skip; 2117. umoney = money_cnt(invent); 2118. #endif 2119. takes[0] = '\0'; 2120. if (!shkp->mcanmove || shkp->msleeping) 2121. Strcat(takes, "wakes up and "); 2122. if (distu(shkp->mx, shkp->my) > 2) 2123. Strcat(takes, "comes and "); 2124. Strcat(takes, "takes"); 2125. 2126. #ifndef GOLDOBJ 2127. if (loss > u.ugold || !loss || roomno == eshkp->shoproom) { 2128. eshkp->robbed -= u.ugold; 2129. if (eshkp->robbed < 0L) eshkp->robbed = 0L; 2130. shkp->mgold += u.ugold; 2131. u.ugold = 0L; 2132. #else 2133. if (loss > umoney || !loss || roomno == eshkp->shoproom) { 2134. eshkp->robbed -= umoney; 2135. if (eshkp->robbed < 0L) eshkp->robbed = 0L; 2136. if (umoney > 0) money2mon(shkp, umoney); 2137. #endif 2138. flags.botl = 1; 2139. pline("%s %s all your possessions.", 2140. shkname(shkp), takes); 2141. taken = TRUE; 2142. /* where to put player's invent (after disclosure) */ 2143. set_repo_loc(eshkp); 2144. } else { 2145. #ifndef GOLDOBJ 2146. shkp->mgold += loss; 2147. u.ugold -= loss; 2148. #else 2149. money2mon(shkp, loss); 2150. #endif 2151. flags.botl = 1; 2152. pline("%s %s the %ld %s %sowed %s.", 2153. Monnam(shkp), takes, 2154. loss, currency(loss), 2155. strncmp(eshkp->customer, plname, PL_NSIZ) ? 2156. "" : "you ", 2157. shkp->female ? "her" : "him"); 2158. /* shopkeeper has now been paid in full */ 2159. pacify_shk(shkp); 2160. eshkp->following = 0; 2161. eshkp->robbed = 0L; 2162. } 2163. skip: 2164. /* in case we create bones */ 2165. rouse_shk(shkp, FALSE); /* wake up */ 2166. if(!inhishop(shkp)) 2167. home_shk(shkp, FALSE); 2168. } 2169. clear: 2170. setpaid(shkp); 2171. return(taken); 2172. } 2173. 2174. STATIC_OVL void 2175. set_repo_loc(eshkp) 2176. struct eshk *eshkp; 2177. { 2178. register xchar ox, oy; 2179. 2180. /* if you're not in this shk's shop room, or if you're in its doorway 2181. or entry spot, then your gear gets dumped all the way inside */ 2182. if (*u.ushops != eshkp->shoproom || 2183. IS_DOOR(levl[u.ux][u.uy].typ) || 2184. (u.ux == eshkp->shk.x && u.uy == eshkp->shk.y)) { 2185. /* shk.x,shk.y is the position immediately in 2186. * front of the door -- move in one more space 2187. */ 2188. ox = eshkp->shk.x; 2189. oy = eshkp->shk.y; 2190. ox += sgn(ox - eshkp->shd.x); 2191. oy += sgn(oy - eshkp->shd.y); 2192. } else { /* already inside this shk's shop */ 2193. ox = u.ux; 2194. oy = u.uy; 2195. } 2196. /* finish_paybill will deposit invent here */ 2197. repo_location.x = ox; 2198. repo_location.y = oy; 2199. } 2200. 2201. /* called at game exit, after inventory disclosure but before making bones */ 2202. void 2203. finish_paybill() 2204. { 2205. register struct obj *otmp; 2206. int ox = repo_location.x, 2207. oy = repo_location.y; 2208. 2209. #if 0 /* don't bother */ 2210. if (ox == 0 && oy == 0) impossible("finish_paybill: no location"); 2211. #endif 2212. /* normally done by savebones(), but that's too late in this case */ 2213. unleash_all(); 2214. /* transfer all of the character's inventory to the shop floor */ 2215. while ((otmp = invent) != 0) { 2216. otmp->owornmask = 0L; /* perhaps we should call setnotworn? */ 2217. otmp->lamplit = 0; /* avoid "goes out" msg from freeinv */ 2218. if (rn2(5)) curse(otmp); /* normal bones treatment for invent */ 2219. obj_extract_self(otmp); 2220. place_object(otmp, ox, oy); 2221. } 2222. } 2223. 2224. /* find obj on one of the lists */ 2225. STATIC_OVL struct obj * 2226. bp_to_obj(bp) 2227. register struct bill_x *bp; 2228. { 2229. register struct obj *obj; 2230. register unsigned int id = bp->bo_id; 2231. 2232. if(bp->useup) 2233. obj = o_on(id, billobjs); 2234. else 2235. obj = find_oid(id); 2236. return obj; 2237. } 2238. 2239. /* 2240. * Look for o_id on all lists but billobj. Return obj or NULL if not found. 2241. * Its OK for restore_timers() to call this function, there should not 2242. * be any timeouts on the billobjs chain. 2243. */ 2244. struct obj * 2245. find_oid(id) 2246. unsigned id; 2247. { 2248. struct obj *obj; 2249. struct monst *mon, *mmtmp[3]; 2250. int i; 2251. 2252. /* first check various obj lists directly */ 2253. if ((obj = o_on(id, invent)) != 0) return obj; 2254. if ((obj = o_on(id, fobj)) != 0) return obj; 2255. if ((obj = o_on(id, level.buriedobjlist)) != 0) return obj; 2256. if ((obj = o_on(id, migrating_objs)) != 0) return obj; 2257. 2258. /* not found yet; check inventory for members of various monst lists */ 2259. mmtmp[0] = fmon; 2260. mmtmp[1] = migrating_mons; 2261. mmtmp[2] = mydogs; /* for use during level changes */ 2262. for (i = 0; i < 3; i++) 2263. for (mon = mmtmp[i]; mon; mon = mon->nmon) 2264. if ((obj = o_on(id, mon->minvent)) != 0) return obj; 2265. 2266. /* not found at all */ 2267. return (struct obj *)0; 2268. } 2269. #endif /*OVLB*/ 2270. #ifdef OVL3 2271. 2272. /* calculate the value that the shk will charge for [one of] an object */ 2273. STATIC_OVL long 2274. get_cost(obj, shkp) 2275. register struct obj *obj; 2276. register struct monst *shkp; /* if angry, impose a surcharge */ 2277. { 2278. register long tmp = getprice(obj, FALSE); 2279. 2280. if (!tmp) tmp = 5L; 2281. /* shopkeeper may notice if the player isn't very knowledgeable - 2282. especially when gem prices are concerned */ 2283. if (!obj->dknown || !objects[obj->otyp].oc_name_known) { 2284. if (obj->oclass == GEM_CLASS && 2285. objects[obj->otyp].oc_material == GLASS) { 2286. int i; 2287. /* get a value that's 'random' from game to game, but the 2288. same within the same game */ 2289. boolean pseudorand = 2290. (((int)u.ubirthday % obj->otyp) >= obj->otyp/2); 2291. 2292. /* all gems are priced high - real or not */ 2293. switch(obj->otyp - LAST_GEM) { 2294. case 1: /* white */ 2295. i = pseudorand ? DIAMOND : OPAL; 2296. break; 2297. case 2: /* blue */ 2298. i = pseudorand ? SAPPHIRE : AQUAMARINE; 2299. break; 2300. case 3: /* red */ 2301. i = pseudorand ? RUBY : JASPER; 2302. break; 2303. case 4: /* yellowish brown */ 2304. i = pseudorand ? AMBER : TOPAZ; 2305. break; 2306. case 5: /* orange */ 2307. i = pseudorand ? JACINTH : AGATE; 2308. break; 2309. case 6: /* yellow */ 2310. i = pseudorand ? CITRINE : CHRYSOBERYL; 2311. break; 2312. case 7: /* black */ 2313. i = pseudorand ? BLACK_OPAL : JET; 2314. break; 2315. case 8: /* green */ 2316. i = pseudorand ? EMERALD : JADE; 2317. break; 2318. case 9: /* violet */ 2319. i = pseudorand ? AMETHYST : FLUORITE; 2320. break; 2321. default: impossible("bad glass gem %d?", obj->otyp); 2322. i = STRANGE_OBJECT; 2323. break; 2324. } 2325. tmp = (long) objects[i].oc_cost; 2326. } else if (!(obj->o_id % 4)) /* arbitrarily impose surcharge */ 2327. tmp += tmp / 3L; 2328. } 2329. #ifdef TOURIST 2330. if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV/2)) 2331. || (uarmu && !uarm && !uarmc)) /* touristy shirt visible */ 2332. tmp += tmp / 3L; 2333. else 2334. #endif 2335. if (uarmh && uarmh->otyp == DUNCE_CAP) 2336. tmp += tmp / 3L; 2337. 2338. if (ACURR(A_CHA) > 18) tmp /= 2L; 2339. else if (ACURR(A_CHA) > 17) tmp -= tmp / 3L; 2340. else if (ACURR(A_CHA) > 15) tmp -= tmp / 4L; 2341. else if (ACURR(A_CHA) < 6) tmp *= 2L; 2342. else if (ACURR(A_CHA) < 8) tmp += tmp / 2L; 2343. else if (ACURR(A_CHA) < 11) tmp += tmp / 3L; 2344. if (tmp <= 0L) tmp = 1L; 2345. else if (obj->oartifact) tmp *= 4L; 2346. 2347. /* character classes who are discriminated against... */ 2348. /* barbarians are gullible... */ 2349. if (Role_if(PM_BARBARIAN)) tmp *= 3L; 2350. /* rogues are untrustworthy... */ 2351. if (Role_if(PM_ROGUE)) tmp *= 2L; 2352. /* samurais are from out of town... */ 2353. if (Role_if(PM_SAMURAI)) tmp *= 2L; 2354. 2355. /* anger surcharge should match rile_shk's */ 2356. if (shkp && ESHK(shkp)->surcharge) tmp += (tmp + 2L) / 3L; 2357. 2358. #ifdef BLACKMARKET 2359. /* KMH, balance patch -- healthstone replaces rotting/health */ 2360. if (Is_blackmarket(&u.uz)) { 2361. if (obj->oclass==RING_CLASS || obj->oclass==AMULET_CLASS || 2362. obj->oclass==POTION_CLASS || obj->oclass==SCROLL_CLASS || 2363. obj->oclass==SPBOOK_CLASS || obj->oclass==WAND_CLASS || 2364. obj->otyp==LUCKSTONE || obj->otyp==LOADSTONE || 2365. obj->otyp==HEALTHSTONE || objects[obj->otyp].oc_magic) { 2366. tmp *= 50; 2367. } else { 2368. tmp *= 25; 2369. } 2370. } 2371. #endif /* BLACKMARKET */ 2372. 2373. return tmp; 2374. } 2375. #endif /*OVL3*/ 2376. #ifdef OVLB 2377. 2378. /* returns the price of a container's content. the price 2379. * of the "top" container is added in the calling functions. 2380. * a different price quoted for selling as vs. buying. 2381. */ 2382. long 2383. contained_cost(obj, shkp, price, usell, unpaid_only) 2384. register struct obj *obj; 2385. register struct monst *shkp; 2386. long price; 2387. register boolean usell; 2388. register boolean unpaid_only; 2389. { 2390. register struct obj *otmp; 2391. 2392. /* the price of contained objects */ 2393. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { 2394. if (otmp->oclass == COIN_CLASS) continue; 2395. /* the "top" container is evaluated by caller */ 2396. if (usell) { 2397. if (saleable(shkp, otmp) && 2398. !otmp->unpaid && otmp->oclass != BALL_CLASS && 2399. #if defined(UNPOLYPILE) 2400. !is_hazy(otmp) && 2401. #endif 2402. !(otmp->oclass == FOOD_CLASS && otmp->oeaten) && 2403. !(Is_candle(otmp) && otmp->age < 2404. 20L * (long)objects[otmp->otyp].oc_cost)) 2405. price += set_cost(otmp, shkp); 2406. } else if (!otmp->no_charge && 2407. (!unpaid_only || (unpaid_only && otmp->unpaid))) { 2408. price += get_cost(otmp, shkp) * otmp->quan; 2409. } 2410. 2411. if (Has_contents(otmp)) 2412. price += contained_cost(otmp, shkp, price, usell, unpaid_only); 2413. } 2414. 2415. return(price); 2416. } 2417. 2418. long 2419. contained_gold(obj) 2420. register struct obj *obj; 2421. { 2422. register struct obj *otmp; 2423. register long value = 0L; 2424. 2425. /* accumulate contained gold */ 2426. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) 2427. if (otmp->oclass == COIN_CLASS) 2428. value += otmp->quan; 2429. else if (Has_contents(otmp)) 2430. value += contained_gold(otmp); 2431. 2432. return(value); 2433. } 2434. 2435. STATIC_OVL void 2436. dropped_container(obj, shkp, sale) 2437. register struct obj *obj; 2438. register struct monst *shkp; 2439. register boolean sale; 2440. { 2441. register struct obj *otmp; 2442. 2443. /* the "top" container is treated in the calling fn */ 2444. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { 2445. if (otmp->oclass == COIN_CLASS) continue; 2446. 2447. if (!otmp->unpaid && !(sale && saleable(shkp, otmp))) 2448. otmp->no_charge = 1; 2449. 2450. if (Has_contents(otmp)) 2451. dropped_container(otmp, shkp, sale); 2452. } 2453. } 2454. 2455. void 2456. picked_container(obj) 2457. register struct obj *obj; 2458. { 2459. register struct obj *otmp; 2460. 2461. /* the "top" container is treated in the calling fn */ 2462. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { 2463. if (otmp->oclass == COIN_CLASS) continue; 2464. 2465. if (otmp->no_charge) 2466. otmp->no_charge = 0; 2467. 2468. if (Has_contents(otmp)) 2469. picked_container(otmp); 2470. } 2471. } 2472. #endif /*OVLB*/ 2473. #ifdef OVL3 2474. 2475. /* calculate how much the shk will pay when buying [all of] an object */ 2476. STATIC_OVL long 2477. set_cost(obj, shkp) 2478. register struct obj *obj; 2479. register struct monst *shkp; 2480. { 2481. long tmp = getprice(obj, TRUE) * obj->quan; 2482. 2483. #ifdef TOURIST 2484. if ((Role_if(PM_TOURIST) && u.ulevel < (MAXULEV/2)) 2485. || (uarmu && !uarm && !uarmc)) /* touristy shirt visible */ 2486. tmp /= 3L; 2487. else 2488. #endif 2489. if (uarmh && uarmh->otyp == DUNCE_CAP) 2490. tmp /= 3L; 2491. else 2492. tmp /= 2L; 2493. 2494. /* shopkeeper may notice if the player isn't very knowledgeable - 2495. especially when gem prices are concerned */ 2496. if (!obj->dknown || !objects[obj->otyp].oc_name_known) { 2497. if (obj->oclass == GEM_CLASS) { 2498. /* different shop keepers give different prices */ 2499. if (objects[obj->otyp].oc_material == GEMSTONE || 2500. objects[obj->otyp].oc_material == GLASS) { 2501. tmp = (obj->otyp % (6 - shkp->m_id % 3)); 2502. tmp = (tmp + 3) * obj->quan; 2503. } 2504. } else if (tmp > 1L && !rn2(4)) 2505. tmp -= tmp / 4L; 2506. } 2507. return tmp; 2508. } 2509. 2510. #endif /*OVL3*/ 2511. #ifdef OVLB 2512. 2513. /* called from doinv(invent.c) for inventory of unpaid objects */ 2514. long 2515. unpaid_cost(unp_obj) 2516. register struct obj *unp_obj; /* known to be unpaid */ 2517. { 2518. register struct bill_x *bp = (struct bill_x *)0; 2519. register struct monst *shkp; 2520. 2521. for(shkp = next_shkp(fmon, TRUE); shkp; 2522. shkp = next_shkp(shkp->nmon, TRUE)) 2523. if ((bp = onbill(unp_obj, shkp, TRUE)) != 0) break; 2524. 2525. /* onbill() gave no message if unexpected problem occurred */ 2526. if(!bp) impossible("unpaid_cost: object wasn't on any bill!"); 2527. 2528. return bp ? unp_obj->quan * bp->price : 0L; 2529. } 2530. 2531. STATIC_OVL void 2532. add_one_tobill(obj, dummy) 2533. register struct obj *obj; 2534. register boolean dummy; 2535. { 2536. register struct monst *shkp; 2537. register struct bill_x *bp; 2538. register int bct; 2539. register char roomno = *u.ushops; 2540. 2541. if (!roomno) return; 2542. if (!(shkp = shop_keeper(roomno))) return; 2543. if (!inhishop(shkp)) return; 2544. 2545. if (onbill(obj, shkp, FALSE) || /* perhaps thrown away earlier */ 2546. (obj->oclass == FOOD_CLASS && obj->oeaten)) 2547. return; 2548. 2549. if (ESHK(shkp)->billct == BILLSZ) { 2550. You("got that for free!"); 2551. return; 2552. } 2553. 2554. /* To recognize objects the shopkeeper is not interested in. -dgk 2555. */ 2556. if (obj->no_charge) { 2557. obj->no_charge = 0; 2558. return; 2559. } 2560. 2561. bct = ESHK(shkp)->billct; 2562. bp = &(ESHK(shkp)->bill_p[bct]); 2563. bp->bo_id = obj->o_id; 2564. bp->bquan = obj->quan; 2565. if(dummy) { /* a dummy object must be inserted into */ 2566. bp->useup = 1; /* the billobjs chain here. crucial for */ 2567. add_to_billobjs(obj); /* eating floorfood in shop. see eat.c */ 2568. } else bp->useup = 0; 2569. bp->price = get_cost(obj, shkp); 2570. ESHK(shkp)->billct++; 2571. obj->unpaid = 1; 2572. } 2573. 2574. STATIC_OVL void 2575. add_to_billobjs(obj) 2576. struct obj *obj; 2577. { 2578. if (obj->where != OBJ_FREE) 2579. panic("add_to_billobjs: obj not free"); 2580. if (obj->timed) 2581. obj_stop_timers(obj); 2582. 2583. obj->nobj = billobjs; 2584. billobjs = obj; 2585. obj->where = OBJ_ONBILL; 2586. } 2587. 2588. /* recursive billing of objects within containers. */ 2589. STATIC_OVL void 2590. bill_box_content(obj, ininv, dummy, shkp) 2591. register struct obj *obj; 2592. register boolean ininv, dummy; 2593. register struct monst *shkp; 2594. { 2595. register struct obj *otmp; 2596. 2597. for (otmp = obj->cobj; otmp; otmp = otmp->nobj) { 2598. if (otmp->oclass == COIN_CLASS) continue; 2599. 2600. /* the "top" box is added in addtobill() */ 2601. if (!otmp->no_charge) 2602. add_one_tobill(otmp, dummy); 2603. if (Has_contents(otmp)) 2604. bill_box_content(otmp, ininv, dummy, shkp); 2605. } 2606. 2607. } 2608. 2609. /* shopkeeper tells you what you bought or sold, sometimes partly IDing it */ 2610. STATIC_OVL void 2611. shk_names_obj(shkp, obj, fmt, amt, arg) 2612. struct monst *shkp; 2613. struct obj *obj; 2614. const char *fmt; /* "%s %ld %s %s", doname(obj), amt, plur(amt), arg */ 2615. long amt; 2616. const char *arg; 2617. { 2618. char *obj_name, fmtbuf[BUFSZ]; 2619. boolean was_unknown = !obj->dknown; 2620. 2621. obj->dknown = TRUE; 2622. /* Use real name for ordinary weapons/armor, and spell-less 2623. * scrolls/books (that is, blank and mail), but only if the 2624. * object is within the shk's area of interest/expertise. 2625. */ 2626. if (!objects[obj->otyp].oc_magic && saleable(shkp, obj) && 2627. (obj->oclass == WEAPON_CLASS || obj->oclass == ARMOR_CLASS || 2628. obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS || 2629. obj->otyp == MIRROR)) { 2630. was_unknown |= !objects[obj->otyp].oc_name_known; 2631. makeknown(obj->otyp); 2632. } 2633. obj_name = doname(obj); 2634. /* Use an alternate message when extra information is being provided */ 2635. if (was_unknown) { 2636. Sprintf(fmtbuf, "%%s; you %s", fmt); 2637. obj_name[0] = highc(obj_name[0]); 2638. pline(fmtbuf, obj_name, (obj->quan > 1) ? "them" : "it", 2639. amt, plur(amt), arg); 2640. } else { 2641. You(fmt, obj_name, amt, plur(amt), arg); 2642. } 2643. } 2644. 2645. void 2646. addtobill(obj, ininv, dummy, silent) 2647. register struct obj *obj; 2648. register boolean ininv, dummy, silent; 2649. { 2650. register struct monst *shkp; 2651. register char roomno = *u.ushops; 2652. long ltmp = 0L, cltmp = 0L, gltmp = 0L; 2653. register boolean container = Has_contents(obj); 2654. 2655. if(!*u.ushops) return; 2656. 2657. if(!(shkp = shop_keeper(roomno))) return; 2658. 2659. if(!inhishop(shkp)) return; 2660. 2661. if(/* perhaps we threw it away earlier */ 2662. onbill(obj, shkp, FALSE) || 2663. (obj->oclass == FOOD_CLASS && obj->oeaten) 2664. ) return; 2665. 2666. if(ESHK(shkp)->billct == BILLSZ) { 2667. You("got that for free!"); 2668. return; 2669. } 2670. 2671. if(obj->oclass == COIN_CLASS) { 2672. costly_gold(obj->ox, obj->oy, obj->quan); 2673. return; 2674. } 2675. 2676. if(!obj->no_charge) 2677. ltmp = get_cost(obj, shkp); 2678. 2679. if (obj->no_charge && !container) { 2680. obj->no_charge = 0; 2681. return; 2682. } 2683. 2684. if(container) { 2685. if(obj->cobj == (struct obj *)0) { 2686. if(obj->no_charge) { 2687. obj->no_charge = 0; 2688. return; 2689. } else { 2690. add_one_tobill(obj, dummy); 2691. goto speak; 2692. } 2693. } else { 2694. cltmp += contained_cost(obj, shkp, cltmp, FALSE, FALSE); 2695. gltmp += contained_gold(obj); 2696. } 2697. 2698. if(ltmp) add_one_tobill(obj, dummy); 2699. if(cltmp) bill_box_content(obj, ininv, dummy, shkp); 2700. picked_container(obj); /* reset contained obj->no_charge */ 2701. 2702. ltmp += cltmp; 2703. 2704. if(gltmp) { 2705. costly_gold(obj->ox, obj->oy, gltmp); 2706. if(!ltmp) return; 2707. } 2708. 2709. if(obj->no_charge) 2710. obj->no_charge = 0; 2711. 2712. } else /* i.e., !container */ 2713. add_one_tobill(obj, dummy); 2714. speak: 2715. if (shkp->mcanmove && !shkp->msleeping && !silent) { 2716. char buf[BUFSZ]; 2717. 2718. if(!ltmp) { 2719. pline("%s has no interest in %s.", Monnam(shkp), 2720. the(xname(obj))); 2721. return; 2722. } 2723. Strcpy(buf, "\"For you, "); 2724. if (ANGRY(shkp)) Strcat(buf, "scum "); 2725. else { 2726. static const char *honored[5] = { 2727. "good", "honored", "most gracious", "esteemed", 2728. "most renowned and sacred" 2729. }; 2730. Strcat(buf, honored[rn2(4) + u.uevent.udemigod]); 2731. if (!is_human(youmonst.data)) Strcat(buf, " creature"); 2732. else 2733. Strcat(buf, (flags.female) ? " lady" : " sir"); 2734. } 2735. if(ininv) { 2736. long quan = obj->quan; 2737. obj->quan = 1L; /* fool xname() into giving singular */ 2738. pline("%s; only %ld %s %s.\"", buf, ltmp, 2739. (quan > 1L) ? "per" : "for this", xname(obj)); 2740. obj->quan = quan; 2741. } else 2742. pline("%s will cost you %ld %s%s.", 2743. The(xname(obj)), ltmp, currency(ltmp), 2744. (obj->quan > 1L) ? " each" : ""); 2745. } else if(!silent) { 2746. if(ltmp) pline_The("list price of %s is %ld %s%s.", 2747. the(xname(obj)), ltmp, currency(ltmp), 2748. (obj->quan > 1L) ? " each" : ""); 2749. else pline("%s does not notice.", Monnam(shkp)); 2750. } 2751. } 2752. 2753. void 2754. splitbill(obj, otmp) 2755. register struct obj *obj, *otmp; 2756. { 2757. /* otmp has been split off from obj */ 2758. register struct bill_x *bp; 2759. register long tmp; 2760. register struct monst *shkp = shop_keeper(*u.ushops); 2761. 2762. if(!shkp || !inhishop(shkp)) { 2763. impossible("splitbill: no resident shopkeeper??"); 2764. return; 2765. } 2766. bp = onbill(obj, shkp, FALSE); 2767. if(!bp) { 2768. impossible("splitbill: not on bill?"); 2769. return; 2770. } 2771. if(bp->bquan < otmp->quan) { 2772. impossible("Negative quantity on bill??"); 2773. } 2774. if(bp->bquan == otmp->quan) { 2775. impossible("Zero quantity on bill??"); 2776. } 2777. bp->bquan -= otmp->quan; 2778. 2779. if(ESHK(shkp)->billct == BILLSZ) otmp->unpaid = 0; 2780. else { 2781. tmp = bp->price; 2782. bp = &(ESHK(shkp)->bill_p[ESHK(shkp)->billct]); 2783. bp->bo_id = otmp->o_id; 2784. bp->bquan = otmp->quan; 2785. bp->useup = 0; 2786. bp->price = tmp; 2787. ESHK(shkp)->billct++; 2788. } 2789. } 2790. 2791. STATIC_OVL void 2792. sub_one_frombill(obj, shkp) 2793. register struct obj *obj; 2794. register struct monst *shkp; 2795. { 2796. register struct bill_x *bp; 2797. 2798. if((bp = onbill(obj, shkp, FALSE)) != 0) { 2799. register struct obj *otmp; 2800. 2801. obj->unpaid = 0; 2802. if(bp->bquan > obj->quan){ 2803. otmp = newobj(0); 2804. *otmp = *obj; 2805. bp->bo_id = otmp->o_id = flags.ident++; 2806. otmp->where = OBJ_FREE; 2807. otmp->quan = (bp->bquan -= obj->quan); 2808. otmp->owt = 0; /* superfluous */ 2809. otmp->onamelth = 0; 2810. otmp->oxlth = 0; 2811. otmp->oattached = OATTACHED_NOTHING; 2812. bp->useup = 1; 2813. add_to_billobjs(otmp); 2814. return; 2815. } 2816. ESHK(shkp)->billct--; 2817. #ifdef DUMB 2818. { 2819. /* DRS/NS 2.2.6 messes up -- Peter Kendell */ 2820. int indx = ESHK(shkp)->billct; 2821. *bp = ESHK(shkp)->bill_p[indx]; 2822. } 2823. #else 2824. *bp = ESHK(shkp)->bill_p[ESHK(shkp)->billct]; 2825. #endif 2826. return; 2827. } else if (obj->unpaid) { 2828. impossible("sub_one_frombill: unpaid object not on bill"); 2829. obj->unpaid = 0; 2830. } 2831. } 2832. 2833. /* recursive check of unpaid objects within nested containers. */ 2834. void 2835. subfrombill(obj, shkp) 2836. register struct obj *obj; 2837. register struct monst *shkp; 2838. { 2839. register struct obj *otmp; 2840. 2841. sub_one_frombill(obj, shkp); 2842. 2843. if (Has_contents(obj)) 2844. for(otmp = obj->cobj; otmp; otmp = otmp->nobj) { 2845. if(otmp->oclass == COIN_CLASS) continue; 2846. 2847. if (Has_contents(otmp)) 2848. subfrombill(otmp, shkp); 2849. else 2850. sub_one_frombill(otmp, shkp); 2851. } 2852. } 2853. 2854. #endif /*OVLB*/ 2855. #ifdef OVL3 2856. 2857. STATIC_OVL long 2858. stolen_container(obj, shkp, price, ininv, destruction) 2859. register struct obj *obj; 2860. register struct monst *shkp; 2861. long price; 2862. register boolean ininv, destruction; 2863. { 2864. register struct obj *otmp; 2865. 2866. if (!(destruction && evades_destruction(obj))) { 2867. if(ininv && obj->unpaid) 2868. price += get_cost(obj, shkp); 2869. else { 2870. if(!obj->no_charge) 2871. price += get_cost(obj, shkp); 2872. obj->no_charge = 0; 2873. } 2874. } 2875. 2876. /* the price of contained objects, if any */ 2877. for(otmp = obj->cobj; otmp; otmp = otmp->nobj) { 2878. 2879. if(otmp->oclass == COIN_CLASS) continue; 2880. 2881. if (!Has_contents(otmp)) { 2882. if (!(destruction && evades_destruction(otmp))) { 2883. if(ininv) { 2884. if(otmp->unpaid) 2885. price += otmp->quan * get_cost(otmp, shkp); 2886. } else { 2887. if(!otmp->no_charge) { 2888. if(otmp->oclass != FOOD_CLASS || !otmp->oeaten) 2889. price += otmp->quan * get_cost(otmp, shkp); 2890. } 2891. otmp->no_charge = 0; 2892. } 2893. } 2894. } else 2895. price += stolen_container(otmp, shkp, price, ininv, 2896. destruction); 2897. } 2898. 2899. return(price); 2900. } 2901. #endif /*OVL3*/ 2902. #ifdef OVLB 2903. 2904. long 2905. stolen_value(obj, x, y, peaceful, silent, destruction) 2906. register struct obj *obj; 2907. register xchar x, y; 2908. register boolean peaceful, silent, destruction; 2909. { 2910. register long value = 0L, gvalue = 0L; 2911. register struct monst *shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); 2912. 2913. if (!shkp || !inhishop(shkp)) 2914. return (0L); 2915. 2916. if(obj->oclass == COIN_CLASS) { 2917. gvalue += obj->quan; 2918. } else if (Has_contents(obj)) { 2919. register boolean ininv = !!count_unpaid(obj->cobj); 2920. 2921. value += stolen_container(obj, shkp, value, ininv, destruction); 2922. if(!ininv) gvalue += contained_gold(obj); 2923. } else if (!obj->no_charge && saleable(shkp, obj) && 2924. !(destruction && evades_destruction(obj))) { 2925. value += get_cost(obj, shkp); 2926. } 2927. 2928. if(gvalue + value == 0L) return(0L); 2929. 2930. value += gvalue; 2931. 2932. if(peaceful) { 2933. boolean credit_use = !!ESHK(shkp)->credit; 2934. value = check_credit(value, shkp); 2935. /* 'peaceful' affects general treatment, but doesn't affect 2936. * the fact that other code expects that all charges after the 2937. * shopkeeper is angry are included in robbed, not debit */ 2938. if (ANGRY(shkp)) 2939. ESHK(shkp)->robbed += value; 2940. else 2941. ESHK(shkp)->debit += value; 2942. 2943. if(!silent) { 2944. const char *still = ""; 2945. 2946. if (credit_use) { 2947. if (ESHK(shkp)->credit) { 2948. You("have %ld %s credit remaining.", 2949. ESHK(shkp)->credit, currency(ESHK(shkp)->credit)); 2950. return value; 2951. } else if (!value) { 2952. You("have no credit remaining."); 2953. return 0; 2954. } 2955. still = "still "; 2956. } 2957. if(obj->oclass == COIN_CLASS) 2958. You("%sowe %s %ld %s!", still, 2959. mon_nam(shkp), value, currency(value)); 2960. else 2961. You("%sowe %s %ld %s for %s!", still, 2962. mon_nam(shkp), value, currency(value), 2963. obj->quan > 1L ? "them" : "it"); 2964. } 2965. } else { 2966. ESHK(shkp)->robbed += value; 2967. 2968. if(!silent) { 2969. if(cansee(shkp->mx, shkp->my)) { 2970. Norep("%s booms: \"%s, you are a thief!\"", 2971. Monnam(shkp), plname); 2972. } else Norep("You hear a scream, \"Thief!\""); 2973. } 2974. hot_pursuit(shkp); 2975. (void) angry_guards(FALSE); 2976. } 2977. return(value); 2978. } 2979. 2980. /* auto-response flag for/from "sell foo?" 'a' => 'y', 'q' => 'n' */ 2981. static char sell_response = 'a'; 2982. static int sell_how = SELL_NORMAL; 2983. /* can't just use sell_response='y' for auto_credit because the 'a' response 2984. shouldn't carry over from ordinary selling to credit selling */ 2985. static boolean auto_credit = FALSE; 2986. 2987. void 2988. sellobj_state(deliberate) 2989. int deliberate; 2990. { 2991. /* If we're deliberately dropping something, there's no automatic 2992. response to the shopkeeper's "want to sell" query; however, if we 2993. accidentally drop anything, the shk will buy it/them without asking. 2994. This retains the old pre-query risk that slippery fingers while in 2995. shops entailed: you drop it, you've lost it. 2996. */ 2997. sell_response = (deliberate != SELL_NORMAL) ? '\0' : 'a'; 2998. sell_how = deliberate; 2999. auto_credit = FALSE; 3000. } 3001. 3002. void 3003. sellobj(obj, x, y) 3004. register struct obj *obj; 3005. xchar x, y; 3006. { 3007. register struct monst *shkp; 3008. register struct eshk *eshkp; 3009. long ltmp = 0L, cltmp = 0L, gltmp = 0L, offer; 3010. boolean saleitem, cgold = FALSE, container = Has_contents(obj); 3011. boolean isgold = (obj->oclass == COIN_CLASS); 3012. boolean only_partially_your_contents = FALSE; 3013. 3014. if(!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || 3015. !inhishop(shkp)) return; 3016. if(!costly_spot(x, y)) return; 3017. if(!*u.ushops) return; 3018. 3019. if(obj->unpaid && !container && !isgold) { 3020. sub_one_frombill(obj, shkp); 3021. return; 3022. } 3023. if(container) { 3024. /* find the price of content before subfrombill */ 3025. cltmp += contained_cost(obj, shkp, cltmp, TRUE, FALSE); 3026. /* find the value of contained gold */ 3027. gltmp += contained_gold(obj); 3028. cgold = (gltmp > 0L); 3029. } 3030. 3031. saleitem = saleable(shkp, obj); 3032. if(!isgold && !obj->unpaid && saleitem) 3033. ltmp = set_cost(obj, shkp); 3034. 3035. offer = ltmp + cltmp; 3036. 3037. /* get one case out of the way: nothing to sell, and no gold */ 3038. if(!isgold && 3039. ((offer + gltmp) == 0L || sell_how == SELL_DONTSELL)) { 3040. register boolean unpaid = (obj->unpaid || 3041. (container && count_unpaid(obj->cobj))); 3042. 3043. if(container) { 3044. dropped_container(obj, shkp, FALSE); 3045. if(!obj->unpaid && !saleitem) 3046. obj->no_charge = 1; 3047. if(obj->unpaid || count_unpaid(obj->cobj)) 3048. subfrombill(obj, shkp); 3049. } else obj->no_charge = 1; 3050. 3051. if(!unpaid && (sell_how != SELL_DONTSELL)) 3052. pline("%s seems uninterested.", Monnam(shkp)); 3053. return; 3054. } 3055. 3056. /* you dropped something of your own - probably want to sell it */ 3057. rouse_shk(shkp, TRUE); /* wake up sleeping or paralyzed shk */ 3058. eshkp = ESHK(shkp); 3059. 3060. if (ANGRY(shkp)) { /* they become shop-objects, no pay */ 3061. pline("Thank you, scum!"); 3062. subfrombill(obj, shkp); 3063. return; 3064. } 3065. 3066. if(eshkp->robbed) { /* shkp is not angry? */ 3067. if(isgold) offer = obj->quan; 3068. else if(cgold) offer += cgold; 3069. if((eshkp->robbed -= offer < 0L)) 3070. eshkp->robbed = 0L; 3071. if(offer) verbalize( 3072. "Thank you for your contribution to restock this recently plundered shop."); 3073. subfrombill(obj, shkp); 3074. return; 3075. } 3076. 3077. if(isgold || cgold) { 3078. if(!cgold) gltmp = obj->quan; 3079. 3080. if(eshkp->debit >= gltmp) { 3081. if(eshkp->loan) { /* you carry shop's gold */ 3082. if(eshkp->loan >= gltmp) 3083. eshkp->loan -= gltmp; 3084. else eshkp->loan = 0L; 3085. } 3086. eshkp->debit -= gltmp; 3087. Your("debt is %spaid off.", 3088. eshkp->debit ? "partially " : ""); 3089. } else { 3090. long delta = gltmp - eshkp->debit; 3091. 3092. eshkp->credit += delta; 3093. if(eshkp->debit) { 3094. eshkp->debit = 0L; 3095. eshkp->loan = 0L; 3096. Your("debt is paid off."); 3097. } 3098. pline("%ld %s %s added to your credit.", 3099. delta, currency(delta), delta > 1L ? "are" : "is"); 3100. } 3101. if(offer) goto move_on; 3102. else { 3103. if(!isgold) { 3104. if (container) 3105. dropped_container(obj, shkp, FALSE); 3106. if (!obj->unpaid && !saleitem) obj->no_charge = 1; 3107. subfrombill(obj, shkp); 3108. } 3109. return; 3110. } 3111. } 3112. move_on: 3113. if((!saleitem && !(container && cltmp > 0L)) 3114. || eshkp->billct == BILLSZ 3115. || obj->oclass == BALL_CLASS 3116. || obj->oclass == CHAIN_CLASS || offer == 0L 3117. #if defined(UNPOLYPILE) 3118. || is_hazy(obj) 3119. #endif 3120. || (obj->oclass == FOOD_CLASS && obj->oeaten) 3121. || (Is_candle(obj) && 3122. obj->age < 20L * (long)objects[obj->otyp].oc_cost)) { 3123. pline("%s seems uninterested%s.", Monnam(shkp), 3124. cgold ? " in the rest" : ""); 3125. if (container) 3126. dropped_container(obj, shkp, FALSE); 3127. obj->no_charge = 1; 3128. return; 3129. } 3130. 3131. #ifndef GOLDOBJ 3132. if(!shkp->mgold) { 3133. #else 3134. if(!money_cnt(shkp->minvent)) { 3135. #endif 3136. char c, qbuf[BUFSZ]; 3137. long tmpcr = ((offer * 9L) / 10L) + (offer <= 1L); 3138. 3139. if (sell_how == SELL_NORMAL || auto_credit) { 3140. c = sell_response = 'y'; 3141. } else if (sell_response != 'n') { 3142. pline("%s cannot pay you at present.", Monnam(shkp)); 3143. Sprintf(qbuf, 3144. "Will you accept %ld %s in credit for %s?", 3145. tmpcr, currency(tmpcr), doname(obj)); 3146. /* won't accept 'a' response here */ 3147. /* KLY - 3/2000 yes, we will, it's a damn nuisance 3148. to have to constantly hit 'y' to sell for credit */ 3149. c = ynaq(qbuf); 3150. if (c == 'a') { 3151. c = 'y'; 3152. auto_credit = TRUE; 3153. } 3154. } else /* previously specified "quit" */ 3155. c = 'n'; 3156. 3157. if (c == 'y') { 3158. shk_names_obj(shkp, obj, (sell_how != SELL_NORMAL) ? 3159. "traded %s for %ld zorkmid%s in %scredit." : 3160. "relinquish %s and acquire %ld zorkmid%s in %scredit.", 3161. tmpcr, 3162. (eshkp->credit > 0L) ? "additional " : ""); 3163. eshkp->credit += tmpcr; 3164. subfrombill(obj, shkp); 3165. } else { 3166. if (c == 'q') sell_response = 'n'; 3167. if (container) 3168. dropped_container(obj, shkp, FALSE); 3169. if (!obj->unpaid) obj->no_charge = 1; 3170. subfrombill(obj, shkp); 3171. } 3172. } else { 3173. char qbuf[BUFSZ]; 3174. #ifndef GOLDOBJ 3175. boolean short_funds = (offer > shkp->mgold); 3176. if (short_funds) offer = shkp->mgold; 3177. #else 3178. long shkmoney = money_cnt(shkp->minvent); 3179. boolean short_funds = (offer > shkmoney); 3180. if (short_funds) offer = shkmoney; 3181. #endif 3182. if (!sell_response) { 3183. only_partially_your_contents = 3184. (contained_cost(obj, shkp, 0L, FALSE, FALSE) != 3185. contained_cost(obj, shkp, 0L, FALSE, TRUE)); 3186. Sprintf(qbuf, 3187. "%s offers%s %ld gold piece%s for%s %s %s. Sell %s?", 3188. Monnam(shkp), short_funds ? " only" : "", 3189. offer, plur(offer), 3190. (!ltmp && cltmp && only_partially_your_contents) ? 3191. " your items in" : (!ltmp && cltmp) ? " the contents of" : "", 3192. obj->unpaid ? "the" : "your", cxname(obj), 3193. (obj->quan == 1L && 3194. !(!ltmp && cltmp && only_partially_your_contents)) ? 3195. "it" : "them"); 3196. } else qbuf[0] = '\0'; /* just to pacify lint */ 3197. 3198. switch (sell_response ? sell_response : ynaq(qbuf)) { 3199. case 'q': sell_response = 'n'; 3200. case 'n': if (container) 3201. dropped_container(obj, shkp, FALSE); 3202. if (!obj->unpaid) obj->no_charge = 1; 3203. subfrombill(obj, shkp); 3204. break; 3205. case 'a': sell_response = 'y'; 3206. case 'y': if (container) 3207. dropped_container(obj, shkp, TRUE); 3208. if (!obj->unpaid && !saleitem) obj->no_charge = 1; 3209. subfrombill(obj, shkp); 3210. pay(-offer, shkp); 3211. shk_names_obj(shkp, obj, (sell_how != SELL_NORMAL) ? 3212. (!ltmp && cltmp && only_partially_your_contents) ? 3213. "sold some items inside %s for %ld gold pieces%s.%s" : 3214. "sold %s for %ld gold piece%s.%s" : 3215. "relinquish %s and receive %ld gold piece%s in compensation.%s", 3216. offer, ""); 3217. break; 3218. default: impossible("invalid sell response"); 3219. } 3220. } 3221. } 3222. 3223. int 3224. doinvbill(mode) 3225. int mode; /* 0: deliver count 1: paged */ 3226. { 3227. #ifdef __SASC 3228. void sasc_bug(struct obj *, unsigned); 3229. #endif 3230. struct monst *shkp; 3231. struct eshk *eshkp; 3232. struct bill_x *bp, *end_bp; 3233. struct obj *obj; 3234. long totused; 3235. char *buf_p; 3236. winid datawin; 3237. 3238. shkp = shop_keeper(*u.ushops); 3239. if (!shkp || !inhishop(shkp)) { 3240. if (mode != 0) impossible("doinvbill: no shopkeeper?"); 3241. return 0; 3242. } 3243. eshkp = ESHK(shkp); 3244. 3245. if (mode == 0) { 3246. /* count expended items, so that the `I' command can decide 3247. whether to include 'x' in its prompt string */ 3248. int cnt = !eshkp->debit ? 0 : 1; 3249. 3250. for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct]; 3251. bp < end_bp; bp++) 3252. if (bp->useup || 3253. ((obj = bp_to_obj(bp)) != 0 && obj->quan < bp->bquan)) 3254. cnt++; 3255. return cnt; 3256. } 3257. 3258. datawin = create_nhwindow(NHW_MENU); 3259. putstr(datawin, 0, "Unpaid articles already used up:"); 3260. putstr(datawin, 0, ""); 3261. 3262. totused = 0L; 3263. for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct]; 3264. bp < end_bp; bp++) { 3265. obj = bp_to_obj(bp); 3266. if(!obj) { 3267. impossible("Bad shopkeeper administration."); 3268. goto quit; 3269. } 3270. if(bp->useup || bp->bquan > obj->quan) { 3271. long oquan, uquan, thisused; 3272. unsigned save_unpaid; 3273. 3274. save_unpaid = obj->unpaid; 3275. oquan = obj->quan; 3276. uquan = (bp->useup ? bp->bquan : bp->bquan - oquan); 3277. thisused = bp->price * uquan; 3278. totused += thisused; 3279. obj->unpaid = 0; /* ditto */ 3280. /* Why 'x'? To match `I x', more or less. */ 3281. buf_p = xprname(obj, (char *)0, 'x', FALSE, thisused, uquan); 3282. #ifdef __SASC 3283. /* SAS/C 6.2 can't cope for some reason */ 3284. sasc_bug(obj,save_unpaid); 3285. #else 3286. obj->unpaid = save_unpaid; 3287. #endif 3288. putstr(datawin, 0, buf_p); 3289. } 3290. } 3291. if (eshkp->debit) { 3292. /* additional shop debt which has no itemization available */ 3293. if (totused) putstr(datawin, 0, ""); 3294. totused += eshkp->debit; 3295. buf_p = xprname((struct obj *)0, 3296. "usage charges and/or other fees", 3297. GOLD_SYM, FALSE, eshkp->debit, 0L); 3298. putstr(datawin, 0, buf_p); 3299. } 3300. buf_p = xprname((struct obj *)0, "Total:", '*', FALSE, totused, 0L); 3301. putstr(datawin, 0, ""); 3302. putstr(datawin, 0, buf_p); 3303. display_nhwindow(datawin, FALSE); 3304. quit: 3305. destroy_nhwindow(datawin); 3306. return(0); 3307. } 3308. 3309. #define HUNGRY 2 3310. 3311. STATIC_OVL long 3312. getprice(obj, shk_buying) 3313. register struct obj *obj; 3314. boolean shk_buying; 3315. { 3316. register long tmp = (long) objects[obj->otyp].oc_cost; 3317. 3318. if (obj->oartifact) { 3319. tmp = arti_cost(obj); 3320. if (shk_buying) tmp /= 4; 3321. } 3322. switch(obj->oclass) { 3323. case FOOD_CLASS: 3324. /* simpler hunger check, (2-4)*cost */ 3325. if (u.uhs >= HUNGRY && !shk_buying) tmp *= (long) u.uhs; 3326. if (obj->oeaten) tmp = 0L; 3327. break; 3328. case WAND_CLASS: 3329. if (obj->spe == -1) tmp = 0L; 3330. break; 3331. case POTION_CLASS: 3332. if (obj->otyp == POT_WATER && !obj->blessed && !obj->cursed) 3333. tmp = 0L; 3334. break; 3335. case ARMOR_CLASS: 3336. case WEAPON_CLASS: 3337. if (obj->spe > 0) tmp += 10L * (long) obj->spe; 3338. #ifdef FIREARMS 3339. /* Don't buy activated explosives! */ 3340. if (is_grenade(obj) && obj->oarmed) tmp = 0L; 3341. #endif 3342. break; 3343. case TOOL_CLASS: 3344. if (Is_candle(obj) && 3345. obj->age < 20L * (long)objects[obj->otyp].oc_cost) 3346. tmp /= 2L; 3347. else if (obj->otyp == TORCH) { 3348. if (obj->age == 0) { 3349. tmp = 0L; 3350. } 3351. else if (obj->age < 25) { 3352. tmp /= 4L; 3353. } 3354. else if (obj->age < 50) { 3355. tmp /= 2L; 3356. } 3357. } 3358. break; 3359. } 3360. return tmp; 3361. } 3362. 3363. /* shk catches thrown pick-axe */ 3364. struct monst * 3365. shkcatch(obj, x, y) 3366. register struct obj *obj; 3367. register xchar x, y; 3368. { 3369. register struct monst *shkp; 3370. 3371. if (!(shkp = shop_keeper(inside_shop(x, y))) || 3372. !inhishop(shkp)) return(0); 3373. 3374. if (shkp->mcanmove && !shkp->msleeping && 3375. (*u.ushops != ESHK(shkp)->shoproom || !inside_shop(u.ux, u.uy)) && 3376. dist2(shkp->mx, shkp->my, x, y) < 3 && 3377. /* if it is the shk's pos, you hit and anger him */ 3378. (shkp->mx != x || shkp->my != y)) { 3379. if (mnearto(shkp, x, y, TRUE)) 3380. verbalize("Out of my way, scum!"); 3381. if (cansee(x, y)) { 3382. pline("%s nimbly%s catches %s.", 3383. Monnam(shkp), 3384. (x == shkp->mx && y == shkp->my) ? "" : " reaches over and", 3385. the(xname(obj))); 3386. if (!canspotmon(shkp)) 3387. map_invisible(x, y); 3388. delay_output(); 3389. mark_synch(); 3390. } 3391. subfrombill(obj, shkp); 3392. (void) mpickobj(shkp, obj); 3393. return shkp; 3394. } 3395. return (struct monst *)0; 3396. } 3397. 3398. void 3399. add_damage(x, y, cost) 3400. register xchar x, y; 3401. long cost; 3402. { 3403. struct damage *tmp_dam; 3404. char *shops; 3405. 3406. if (IS_DOOR(levl[x][y].typ)) { 3407. struct monst *mtmp; 3408. 3409. /* Don't schedule for repair unless it's a real shop entrance */ 3410. for (shops = in_rooms(x, y, SHOPBASE); *shops; shops++) 3411. if ((mtmp = shop_keeper(*shops)) != 0 && 3412. x == ESHK(mtmp)->shd.x && y == ESHK(mtmp)->shd.y) 3413. break; 3414. if (!*shops) return; 3415. } 3416. for (tmp_dam = level.damagelist; tmp_dam; tmp_dam = tmp_dam->next) 3417. if (tmp_dam->place.x == x && tmp_dam->place.y == y) { 3418. tmp_dam->cost += cost; 3419. return; 3420. } 3421. tmp_dam = (struct damage *)alloc((unsigned)sizeof(struct damage)); 3422. tmp_dam->when = monstermoves; 3423. tmp_dam->place.x = x; 3424. tmp_dam->place.y = y; 3425. tmp_dam->cost = cost; 3426. tmp_dam->typ = levl[x][y].typ; 3427. tmp_dam->next = level.damagelist; 3428. level.damagelist = tmp_dam; 3429. /* If player saw damage, display as a wall forever */ 3430. if (cansee(x, y)) 3431. levl[x][y].seenv = SVALL; 3432. } 3433. 3434. #endif /*OVLB*/ 3435. #ifdef OVL0 3436. 3437. /* 3438. * Do something about damage. Either (!croaked) try to repair it, or 3439. * (croaked) just discard damage structs for non-shared locations, since 3440. * they'll never get repaired. Assume that shared locations will get 3441. * repaired eventually by the other shopkeeper(s). This might be an erroneous 3442. * assumption (they might all be dead too), but we have no reasonable way of 3443. * telling that. 3444. */ 3445. STATIC_OVL 3446. void 3447. remove_damage(shkp, croaked) 3448. register struct monst *shkp; 3449. register boolean croaked; 3450. { 3451. register struct damage *tmp_dam, *tmp2_dam; 3452. register boolean did_repair = FALSE, saw_door = FALSE; 3453. register boolean saw_floor = FALSE, stop_picking = FALSE; 3454. register boolean saw_untrap = FALSE; 3455. uchar saw_walls = 0; 3456. 3457. tmp_dam = level.damagelist; 3458. tmp2_dam = 0; 3459. while (tmp_dam) { 3460. register xchar x = tmp_dam->place.x, y = tmp_dam->place.y; 3461. char shops[5]; 3462. int disposition; 3463. 3464. disposition = 0; 3465. Strcpy(shops, in_rooms(x, y, SHOPBASE)); 3466. if (index(shops, ESHK(shkp)->shoproom)) { 3467. if (croaked) 3468. disposition = (shops[1])? 0 : 1; 3469. else if (stop_picking) 3470. disposition = repair_damage(shkp, tmp_dam, FALSE); 3471. else { 3472. /* Defer the stop_occupation() until after repair msgs */ 3473. if (closed_door(x, y)) 3474. stop_picking = picking_at(x, y); 3475. disposition = repair_damage(shkp, tmp_dam, FALSE); 3476. if (!disposition) 3477. stop_picking = FALSE; 3478. } 3479. } 3480. 3481. if (!disposition) { 3482. tmp2_dam = tmp_dam; 3483. tmp_dam = tmp_dam->next; 3484. continue; 3485. } 3486. 3487. if (disposition > 1) { 3488. did_repair = TRUE; 3489. if (cansee(x, y)) { 3490. if (IS_WALL(levl[x][y].typ)) 3491. saw_walls++; 3492. else if (IS_DOOR(levl[x][y].typ)) 3493. saw_door = TRUE; 3494. else if (disposition == 3) /* untrapped */ 3495. saw_untrap = TRUE; 3496. else 3497. saw_floor = TRUE; 3498. } 3499. } 3500. 3501. tmp_dam = tmp_dam->next; 3502. if (!tmp2_dam) { 3503. free((genericptr_t)level.damagelist); 3504. level.damagelist = tmp_dam; 3505. } else { 3506. free((genericptr_t)tmp2_dam->next); 3507. tmp2_dam->next = tmp_dam; 3508. } 3509. } 3510. if (!did_repair) 3511. return; 3512. if (saw_walls) { 3513. pline("Suddenly, %s section%s of wall close%s up!", 3514. (saw_walls == 1) ? "a" : (saw_walls <= 3) ? 3515. "some" : "several", 3516. (saw_walls == 1) ? "" : "s", (saw_walls == 1) ? "s" : ""); 3517. if (saw_door) 3518. pline_The("shop door reappears!"); 3519. if (saw_floor) 3520. pline_The("floor is repaired!"); 3521. } else { 3522. if (saw_door) 3523. pline("Suddenly, the shop door reappears!"); 3524. else if (saw_floor) 3525. pline("Suddenly, the floor damage is gone!"); 3526. else if (saw_untrap) 3527. pline("Suddenly, the trap is removed from the floor!"); 3528. else if (inside_shop(u.ux, u.uy) == ESHK(shkp)->shoproom) 3529. You_feel("more claustrophobic than before."); 3530. else if (flags.soundok && !rn2(10)) 3531. Norep("The dungeon acoustics noticeably change."); 3532. } 3533. if (stop_picking) 3534. stop_occupation(); 3535. } 3536. 3537. /* 3538. * 0: repair postponed, 1: silent repair (no messages), 2: normal repair 3539. * 3: untrap 3540. */ 3541. int 3542. repair_damage(shkp, tmp_dam, catchup) 3543. register struct monst *shkp; 3544. register struct damage *tmp_dam; 3545. boolean catchup; /* restoring a level */ 3546. { 3547. register xchar x, y, i; 3548. xchar litter[9]; 3549. register struct monst *mtmp; 3550. register struct obj *otmp; 3551. register struct trap *ttmp; 3552. 3553. if ((monstermoves - tmp_dam->when) < REPAIR_DELAY) 3554. return(0); 3555. if (shkp->msleeping || !shkp->mcanmove || ESHK(shkp)->following) 3556. return(0); 3557. x = tmp_dam->place.x; 3558. y = tmp_dam->place.y; 3559. if (!IS_ROOM(tmp_dam->typ)) { 3560. if (x == u.ux && y == u.uy) 3561. if (!Passes_walls) 3562. return(0); 3563. if (x == shkp->mx && y == shkp->my) 3564. return(0); 3565. if ((mtmp = m_at(x, y)) && (!passes_walls(mtmp->data))) 3566. return(0); 3567. } 3568. if ((ttmp = t_at(x, y)) != 0) { 3569. if (x == u.ux && y == u.uy) 3570. if (!Passes_walls) 3571. return(0); 3572. if (ttmp->ttyp == LANDMINE || ttmp->ttyp == BEAR_TRAP) { 3573. /* convert to an object */ 3574. otmp = mksobj((ttmp->ttyp == LANDMINE) ? LAND_MINE : 3575. BEARTRAP, TRUE, FALSE); 3576. otmp->quan= 1; 3577. otmp->owt = weight(otmp); 3578. (void) mpickobj(shkp, otmp); 3579. } 3580. deltrap(ttmp); 3581. if(IS_DOOR(tmp_dam->typ)) { 3582. levl[x][y].doormask = D_CLOSED; /* arbitrary */ 3583. block_point(x, y); 3584. } else if (IS_WALL(tmp_dam->typ)) { 3585. levl[x][y].typ = tmp_dam->typ; 3586. block_point(x, y); 3587. } 3588. newsym(x, y); 3589. return(3); 3590. } 3591. if (IS_ROOM(tmp_dam->typ)) { 3592. /* No messages, because player already filled trap door */ 3593. return(1); 3594. } 3595. if ((tmp_dam->typ == levl[x][y].typ) && 3596. (!IS_DOOR(tmp_dam->typ) || (levl[x][y].doormask > D_BROKEN))) 3597. /* No messages if player already replaced shop door */ 3598. return(1); 3599. levl[x][y].typ = tmp_dam->typ; 3600. (void) memset((genericptr_t)litter, 0, sizeof(litter)); 3601. if ((otmp = level.objects[x][y]) != 0) { 3602. /* Scatter objects haphazardly into the shop */ 3603. #define NEED_UPDATE 1 3604. #define OPEN 2 3605. #define INSHOP 4 3606. #define horiz(i) ((i%3)-1) 3607. #define vert(i) ((i/3)-1) 3608. for (i = 0; i < 9; i++) { 3609. if ((i == 4) || (!ZAP_POS(levl[x+horiz(i)][y+vert(i)].typ))) 3610. continue; 3611. litter[i] = OPEN; 3612. if (inside_shop(x+horiz(i), 3613. y+vert(i)) == ESHK(shkp)->shoproom) 3614. litter[i] |= INSHOP; 3615. } 3616. if (Punished && !u.uswallow && 3617. ((uchain->ox == x && uchain->oy == y) || 3618. (uball->ox == x && uball->oy == y))) { 3619. /* 3620. * Either the ball or chain is in the repair location. 3621. * 3622. * Take the easy way out and put ball&chain under hero. 3623. */ 3624. verbalize("Get your junk out of my wall!"); 3625. unplacebc(); /* pick 'em up */ 3626. placebc(); /* put 'em down */ 3627. } 3628. while ((otmp = level.objects[x][y]) != 0) 3629. /* Don't mess w/ boulders -- just merge into wall */ 3630. if ((otmp->otyp == BOULDER) || (otmp->otyp == ROCK)) { 3631. obj_extract_self(otmp); 3632. obfree(otmp, (struct obj *)0); 3633. } else { 3634. while (!(litter[i = rn2(9)] & INSHOP)); 3635. remove_object(otmp); 3636. place_object(otmp, x+horiz(i), y+vert(i)); 3637. litter[i] |= NEED_UPDATE; 3638. } 3639. } 3640. if (catchup) return 1; /* repair occurred while off level */ 3641. 3642. block_point(x, y); 3643. if(IS_DOOR(tmp_dam->typ)) { 3644. levl[x][y].doormask = D_CLOSED; /* arbitrary */ 3645. newsym(x, y); 3646. } else { 3647. /* don't set doormask - it is (hopefully) the same as it was */ 3648. /* if not, perhaps save it with the damage array... */ 3649. 3650. if (IS_WALL(tmp_dam->typ) && cansee(x, y)) { 3651. /* Player sees actual repair process, so they KNOW it's a wall */ 3652. levl[x][y].seenv = SVALL; 3653. newsym(x, y); 3654. } 3655. /* Mark this wall as "repaired". There currently is no code */ 3656. /* to do anything about repaired walls, so don't do it. */ 3657. } 3658. for (i = 0; i < 9; i++) 3659. if (litter[i] & NEED_UPDATE) 3660. newsym(x+horiz(i), y+vert(i)); 3661. return(2); 3662. #undef NEED_UPDATE 3663. #undef OPEN 3664. #undef INSHOP 3665. #undef vert 3666. #undef horiz 3667. } 3668. #endif /*OVL0*/ 3669. #ifdef OVL3 3670. /* 3671. * shk_move: return 1: moved 0: didn't -1: let m_move do it -2: died 3672. */ 3673. int 3674. shk_move(shkp) 3675. register struct monst *shkp; 3676. { 3677. register xchar gx,gy,omx,omy; 3678. register int udist; 3679. register schar appr; 3680. register struct eshk *eshkp = ESHK(shkp); 3681. int z; 3682. boolean uondoor = FALSE, satdoor, avoid = FALSE, badinv; 3683. 3684. omx = shkp->mx; 3685. omy = shkp->my; 3686. 3687. if (inhishop(shkp)) 3688. remove_damage(shkp, FALSE); 3689. 3690. if((udist = distu(omx,omy)) < 3 && 3691. (shkp->data != &mons[PM_GRID_BUG] || (omx==u.ux || omy==u.uy))) { 3692. if(ANGRY(shkp) || 3693. (Conflict && !resist(shkp, RING_CLASS, 0, 0))) { 3694. if(Displaced) 3695. Your("displaced image doesn't fool %s!", 3696. mon_nam(shkp)); 3697. (void) mattacku(shkp); 3698. return(0); 3699. } 3700. if(eshkp->following) { 3701. if(strncmp(eshkp->customer, plname, PL_NSIZ)) { 3702. verbalize("%s, %s! I was looking for %s.", 3703. Hello(shkp), plname, eshkp->customer); 3704. eshkp->following = 0; 3705. return(0); 3706. } 3707. if(moves > followmsg+4) { 3708. verbalize("%s, %s! Didn't you forget to pay?", 3709. Hello(shkp), plname); 3710. followmsg = moves; 3711. if (!rn2(9)) { 3712. pline("%s doesn't like customers who don't pay.", 3713. Monnam(shkp)); 3714. rile_shk(shkp); 3715. } 3716. } 3717. if(udist < 2) 3718. return(0); 3719. } 3720. } 3721. 3722. appr = 1; 3723. gx = eshkp->shk.x; 3724. gy = eshkp->shk.y; 3725. satdoor = (gx == omx && gy == omy); 3726. if(eshkp->following || ((z = holetime()) >= 0 && z*z <= udist)){ 3727. /* [This distance check used to apply regardless of 3728. whether the shk was following, but that resulted in 3729. m_move() sometimes taking the shk out of the shop if 3730. the player had fenced him in with boulders or traps. 3731. Such voluntary abandonment left unpaid objects in 3732. invent, triggering billing impossibilities on the 3733. next level once the character fell through the hole.] */ 3734. if (udist > 4 && eshkp->following && !eshkp->billct) 3735. return(-1); /* leave it to m_move */ 3736. gx = u.ux; 3737. gy = u.uy; 3738. } else if(ANGRY(shkp)) { 3739. /* Move towards the hero if the shopkeeper can see him. */ 3740. if(shkp->mcansee && m_canseeu(shkp)) { 3741. gx = u.ux; 3742. gy = u.uy; 3743. } 3744. avoid = FALSE; 3745. } else { 3746. #define GDIST(x,y) (dist2(x,y,gx,gy)) 3747. #ifdef BLACKMARKET 3748. if ((Is_blackmarket(&u.uz) && u.umonnum>0 && 3749. mons[u.umonnum].mlet != S_HUMAN) || 3750. /* WAC Let you out if you're stuck inside */ 3751. (!Is_blackmarket(&u.uz) && (Invis 3752. #ifdef STEED 3753. || u.usteed 3754. #endif 3755. ) && !inside_shop(u.ux, u.uy))) 3756. #else /* BLACKMARKET */ 3757. if(Invis 3758. #ifdef STEED 3759. || u.usteed 3760. #endif 3761. ) 3762. #endif /* BLACKMARKET */ 3763. { 3764. avoid = FALSE; 3765. } else { 3766. uondoor = (u.ux == eshkp->shd.x && u.uy == eshkp->shd.y); 3767. if(uondoor) { 3768. badinv = (carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK) || 3769. (Fast && (sobj_at(PICK_AXE, u.ux, u.uy) || 3770. sobj_at(DWARVISH_MATTOCK, u.ux, u.uy)))); 3771. if(satdoor && badinv) 3772. return(0); 3773. avoid = !badinv; 3774. } else { 3775. avoid = (*u.ushops && distu(gx,gy) > 8); 3776. badinv = FALSE; 3777. } 3778. 3779. if(((!eshkp->robbed && !eshkp->billct && !eshkp->debit) 3780. || avoid) && GDIST(omx,omy) < 3) { 3781. if (!badinv && !onlineu(omx,omy)) 3782. return(0); 3783. if(satdoor) 3784. appr = gx = gy = 0; 3785. } 3786. } 3787. } 3788. 3789. z = move_special(shkp,inhishop(shkp),appr,uondoor,avoid,omx,omy,gx,gy); 3790. if (z > 0) after_shk_move(shkp); 3791. 3792. return z; 3793. } 3794. 3795. /* called after shopkeeper moves, in case the move causes re-entry into shop */ 3796. void 3797. after_shk_move(shkp) 3798. struct monst *shkp; 3799. { 3800. struct eshk *eshkp = ESHK(shkp); 3801. 3802. if (eshkp->bill_p == (struct bill_x *) -1000 && inhishop(shkp)) { 3803. /* reset bill_p, need to re-calc player's occupancy too */ 3804. eshkp->bill_p = &eshkp->bill[0]; 3805. check_special_room(FALSE); 3806. } 3807. } 3808. 3809. #endif /*OVL3*/ 3810. #ifdef OVLB 3811. 3812. /* for use in levl_follower (mondata.c) */ 3813. boolean 3814. is_fshk(mtmp) 3815. register struct monst *mtmp; 3816. { 3817. return((boolean)(mtmp->isshk && ESHK(mtmp)->following)); 3818. } 3819. 3820. /* You are digging in the shop. */ 3821. void 3822. shopdig(fall) 3823. register int fall; 3824. { 3825. register struct monst *shkp = shop_keeper(*u.ushops); 3826. int lang; 3827. const char *grabs = "grabs"; 3828. 3829. if(!shkp) return; 3830. 3831. /* 0 == can't speak, 1 == makes animal noises, 2 == speaks */ 3832. lang = 0; 3833. if (shkp->msleeping || !shkp->mcanmove || is_silent(shkp->data)) 3834. ; /* lang stays 0 */ 3835. else if (shkp->data->msound <= MS_ANIMAL) 3836. lang = 1; 3837. else if (shkp->data->msound >= MS_HUMANOID) 3838. lang = 2; 3839. 3840. if(!inhishop(shkp)) { 3841. if (Role_if(PM_KNIGHT)) { 3842. You_feel("like a common thief."); 3843. adjalign(-sgn(u.ualign.type)); 3844. } 3845. /* WAC He may not be here now, but... */ 3846. make_angry_shk(shkp, 0, 0); /* No spot in particular*/ 3847. return; 3848. } 3849. 3850. if(!fall) { 3851. if (lang == 2) { 3852. if(u.utraptype == TT_PIT) 3853. verbalize( 3854. "Be careful, %s, or you might fall through the floor.", 3855. flags.female ? "madam" : "sir"); 3856. else 3857. verbalize("%s, do not damage the floor here!", 3858. flags.female ? "Madam" : "Sir"); 3859. } 3860. if (Role_if(PM_KNIGHT)) { 3861. You_feel("like a common thief."); 3862. adjalign(-sgn(u.ualign.type)); 3863. } 3864. } else if(!um_dist(shkp->mx, shkp->my, 5) && 3865. !shkp->msleeping && shkp->mcanmove && 3866. (ESHK(shkp)->billct || ESHK(shkp)->debit)) { 3867. register struct obj *obj, *obj2; 3868. if (nolimbs(shkp->data)) { 3869. grabs = "knocks off"; 3870. #if 0 3871. /* This is what should happen, but for balance 3872. * reasons, it isn't currently. 3873. */ 3874. if (lang == 2) 3875. pline("%s curses %s inability to grab your backpack!", 3876. shkname(shkp), mhim(shkp)); 3877. rile_shk(shkp); 3878. return; 3879. #endif 3880. } 3881. if (distu(shkp->mx, shkp->my) > 2) { 3882. mnexto(shkp); 3883. /* for some reason the shopkeeper can't come next to you */ 3884. if (distu(shkp->mx, shkp->my) > 2) { 3885. if (lang == 2) 3886. pline("%s curses you in anger and frustration!", 3887. shkname(shkp)); 3888. rile_shk(shkp); 3889. return; 3890. } else 3891. pline("%s %s, and %s your backpack!", 3892. shkname(shkp), 3893. makeplural(locomotion(shkp->data,"leap")), grabs); 3894. } else 3895. pline("%s %s your backpack!", shkname(shkp), grabs); 3896. 3897. for(obj = invent; obj; obj = obj2) { 3898. obj2 = obj->nobj; 3899. if ((obj->owornmask & ~(W_SWAPWEP|W_QUIVER)) != 0 || 3900. (obj == uswapwep && u.twoweap) || 3901. (obj->otyp == LEASH && obj->leashmon)) continue; 3902. if (obj == current_wand) continue; 3903. setnotworn(obj); 3904. freeinv(obj); 3905. subfrombill(obj, shkp); 3906. (void) add_to_minv(shkp, obj); /* may free obj */ 3907. } 3908. } else 3909. /* WAC He may not be here now, but... */ 3910. rile_shk(shkp); 3911. } 3912. 3913. #ifdef KOPS 3914. /* modified by M. Campostrini (campo@sunthpi3.difi.unipi.it) */ 3915. /* to allow for multiple choices of kops */ 3916. STATIC_OVL void 3917. makekops(mm) 3918. coord *mm; 3919. { 3920. int kop_cnt[5]; 3921. int kop_pm[5]; 3922. int ik, cnt; 3923. coord *mc; 3924. 3925. kop_pm[0] = PM_KEYSTONE_KOP; 3926. kop_pm[1] = PM_KOP_SERGEANT; 3927. kop_pm[2] = PM_KOP_LIEUTENANT; 3928. kop_pm[3] = PM_KOP_KAPTAIN; 3929. kop_pm[4] = 0; 3930. 3931. cnt = abs(depth(&u.uz)) + rnd(5); 3932. 3933. #ifdef BLACKMARKET 3934. if (Is_blackmarket(&u.uz)) { 3935. kop_pm[0] = PM_SOLDIER; 3936. kop_pm[1] = PM_SERGEANT; 3937. kop_pm[2] = PM_LIEUTENANT; 3938. kop_pm[3] = PM_CAPTAIN; 3939. kop_pm[4] = 0; 3940. 3941. cnt = 7 + rnd(10); 3942. } 3943. #endif /* BLACKMARKET */ 3944. 3945. kop_cnt[0] = cnt; 3946. kop_cnt[1] = (cnt / 3) + 1; /* at least one sarge */ 3947. kop_cnt[2] = (cnt / 6); /* maybe a lieutenant */ 3948. kop_cnt[3] = (cnt / 9); /* and maybe a kaptain */ 3949. 3950. mc = (coord *)alloc(cnt * sizeof(coord)); 3951. for (ik=0; kop_pm[ik]; ik++) { 3952. if (!(mvitals[kop_pm[ik]].mvflags & G_GONE)) { 3953. cnt = epathto(mc, kop_cnt[ik], mm->x, mm->y, &mons[kop_pm[ik]]); 3954. while(--cnt >= 0) 3955. (void) makemon(&mons[kop_pm[ik]], mc[cnt].x, mc[cnt].y, NO_MM_FLAGS); 3956. } 3957. } 3958. free((genericptr_t)mc); 3959. } 3960. #endif /* KOPS */ 3961. 3962. void 3963. pay_for_damage(dmgstr, cant_mollify) 3964. const char *dmgstr; 3965. boolean cant_mollify; 3966. { 3967. register struct monst *shkp = (struct monst *)0; 3968. char shops_affected[5]; 3969. register boolean uinshp = (*u.ushops != '\0'); 3970. char qbuf[80]; 3971. register xchar x, y; 3972. boolean dugwall = !strcmp(dmgstr, "dig into") || /* wand */ 3973. !strcmp(dmgstr, "damage"); /* pick-axe */ 3974. struct damage *tmp_dam, *appear_here = 0; 3975. /* any number >= (80*80)+(24*24) would do, actually */ 3976. long cost_of_damage = 0L; 3977. unsigned int nearest_shk = 7000, nearest_damage = 7000; 3978. int picks = 0; 3979. 3980. for (tmp_dam = level.damagelist; 3981. (tmp_dam && (tmp_dam->when == monstermoves)); 3982. tmp_dam = tmp_dam->next) { 3983. char *shp; 3984. 3985. if (!tmp_dam->cost) 3986. continue; 3987. cost_of_damage += tmp_dam->cost; 3988. Strcpy(shops_affected, 3989. in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE)); 3990. for (shp = shops_affected; *shp; shp++) { 3991. struct monst *tmp_shk; 3992. unsigned int shk_distance; 3993. 3994. if (!(tmp_shk = shop_keeper(*shp))) 3995. continue; 3996. if (tmp_shk == shkp) { 3997. unsigned int damage_distance = 3998. distu(tmp_dam->place.x, tmp_dam->place.y); 3999. 4000. if (damage_distance < nearest_damage) { 4001. nearest_damage = damage_distance; 4002. appear_here = tmp_dam; 4003. } 4004. continue; 4005. } 4006. if (!inhishop(tmp_shk)) 4007. continue; 4008. shk_distance = distu(tmp_shk->mx, tmp_shk->my); 4009. if (shk_distance > nearest_shk) 4010. continue; 4011. if ((shk_distance == nearest_shk) && picks) { 4012. if (rn2(++picks)) 4013. continue; 4014. } else 4015. picks = 1; 4016. shkp = tmp_shk; 4017. nearest_shk = shk_distance; 4018. appear_here = tmp_dam; 4019. nearest_damage = distu(tmp_dam->place.x, tmp_dam->place.y); 4020. } 4021. } 4022. 4023. if (!cost_of_damage || !shkp) 4024. return; 4025. 4026. x = appear_here->place.x; 4027. y = appear_here->place.y; 4028. 4029. /* not the best introduction to the shk... */ 4030. (void) strncpy(ESHK(shkp)->customer,plname,PL_NSIZ); 4031. 4032. /* if the shk is already on the war path, be sure it's all out */ 4033. if(ANGRY(shkp) || ESHK(shkp)->following) { 4034. hot_pursuit(shkp); 4035. return; 4036. } 4037. 4038. /* if the shk is not in their shop.. */ 4039. if(!*in_rooms(shkp->mx,shkp->my,SHOPBASE)) { 4040. if(!cansee(shkp->mx, shkp->my)) 4041. return; 4042. goto getcad; 4043. } 4044. 4045. if(uinshp) { 4046. if(um_dist(shkp->mx, shkp->my, 1) && 4047. !um_dist(shkp->mx, shkp->my, 3)) { 4048. pline("%s leaps towards you!", shkname(shkp)); 4049. mnexto(shkp); 4050. } 4051. if(um_dist(shkp->mx, shkp->my, 1)) goto getcad; 4052. } else { 4053. /* 4054. * Make shkp show up at the door. Effect: If there is a monster 4055. * in the doorway, have the hero hear the shopkeeper yell a bit, 4056. * pause, then have the shopkeeper appear at the door, having 4057. * yanked the hapless critter out of the way. 4058. */ 4059. if (MON_AT(x, y)) { 4060. if(flags.soundok) { 4061. You_hear("an angry voice:"); 4062. verbalize("Out of my way, scum!"); 4063. wait_synch(); 4064. #if defined(UNIX) || defined(VMS) 4065. # if defined(SYSV) || defined(ULTRIX) || defined(VMS) 4066. (void) 4067. # endif 4068. sleep(1); 4069. #endif 4070. } 4071. } 4072. (void) mnearto(shkp, x, y, TRUE); 4073. } 4074. 4075. if((um_dist(x, y, 1) && !uinshp) || cant_mollify || 4076. #ifndef GOLDOBJ 4077. (u.ugold + ESHK(shkp)->credit) < cost_of_damage 4078. #else 4079. (money_cnt(invent) + ESHK(shkp)->credit) < cost_of_damage 4080. #endif 4081. || !rn2(50)) { 4082. if(um_dist(x, y, 1) && !uinshp) { 4083. pline("%s shouts:", shkname(shkp)); 4084. verbalize("Who dared %s my %s?", dmgstr, 4085. dugwall ? "shop" : "door"); 4086. } else { 4087. getcad: 4088. verbalize("How dare you %s my %s?", dmgstr, 4089. dugwall ? "shop" : "door"); 4090. } 4091. hot_pursuit(shkp); 4092. return; 4093. } 4094. 4095. if (Invis) Your("invisibility does not fool %s!", shkname(shkp)); 4096. Sprintf(qbuf,"\"Cad! You did %ld %s worth of damage!\" Pay? ", 4097. cost_of_damage, currency(cost_of_damage)); 4098. if(yn(qbuf) != 'n') { 4099. cost_of_damage = check_credit(cost_of_damage, shkp); 4100. #ifndef GOLDOBJ 4101. u.ugold -= cost_of_damage; 4102. shkp->mgold += cost_of_damage; 4103. #else 4104. money2mon(shkp, cost_of_damage); 4105. #endif 4106. flags.botl = 1; 4107. pline("Mollified, %s accepts your restitution.", 4108. shkname(shkp)); 4109. /* move shk back to his home loc */ 4110. home_shk(shkp, FALSE); 4111. pacify_shk(shkp); 4112. } else { 4113. verbalize("Oh, yes! You'll pay!"); 4114. hot_pursuit(shkp); 4115. adjalign(-sgn(u.ualign.type)); 4116. } 4117. } 4118. #endif /*OVLB*/ 4119. #ifdef OVL0 4120. /* called in dokick.c when we kick an object that might be in a store */ 4121. boolean 4122. costly_spot(x, y) 4123. register xchar x, y; 4124. { 4125. register struct monst *shkp; 4126. 4127. if (!level.flags.has_shop) return FALSE; 4128. shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); 4129. if(!shkp || !inhishop(shkp)) return(FALSE); 4130. 4131. return((boolean)(inside_shop(x, y) && 4132. !(x == ESHK(shkp)->shk.x && 4133. y == ESHK(shkp)->shk.y))); 4134. } 4135. #endif /*OVL0*/ 4136. #ifdef OVLB 4137. 4138. /* called by dotalk(sounds.c) when #chatting; returns obj if location 4139. contains shop goods and shopkeeper is willing & able to speak */ 4140. struct obj * 4141. shop_object(x, y) 4142. register xchar x, y; 4143. { 4144. register struct obj *otmp; 4145. register struct monst *shkp; 4146. 4147. if(!(shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) || !inhishop(shkp)) 4148. return(struct obj *)0; 4149. 4150. for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) 4151. if (otmp->oclass != COIN_CLASS) 4152. break; 4153. /* note: otmp might have ->no_charge set, but that's ok */ 4154. return (otmp && costly_spot(x, y) && NOTANGRY(shkp) 4155. && shkp->mcanmove && !shkp->msleeping) 4156. ? otmp : (struct obj *)0; 4157. } 4158. 4159. /* give price quotes for all objects linked to this one (ie, on this spot) */ 4160. void 4161. price_quote(first_obj) 4162. register struct obj *first_obj; 4163. { 4164. register struct obj *otmp; 4165. char buf[BUFSZ], price[40]; 4166. long cost; 4167. int cnt = 0; 4168. winid tmpwin; 4169. struct monst *shkp = shop_keeper(inside_shop(u.ux, u.uy)); 4170. 4171. tmpwin = create_nhwindow(NHW_MENU); 4172. putstr(tmpwin, 0, "Fine goods for sale:"); 4173. putstr(tmpwin, 0, ""); 4174. for (otmp = first_obj; otmp; otmp = otmp->nexthere) { 4175. if (otmp->oclass == COIN_CLASS) continue; 4176. cost = (otmp->no_charge || otmp == uball || otmp == uchain) ? 0L : 4177. get_cost(otmp, (struct monst *)0); 4178. if (Has_contents(otmp)) 4179. cost += contained_cost(otmp, shkp, 0L, FALSE, FALSE); 4180. if (!cost) { 4181. Strcpy(price, "no charge"); 4182. } else { 4183. Sprintf(price, "%ld %s%s", cost, currency(cost), 4184. otmp->quan > 1L ? " each" : ""); 4185. } 4186. Sprintf(buf, "%s, %s", doname(otmp), price); 4187. putstr(tmpwin, 0, buf), cnt++; 4188. } 4189. if (cnt > 1) { 4190. display_nhwindow(tmpwin, TRUE); 4191. } else if (cnt == 1) { 4192. if (first_obj->no_charge || first_obj == uball || first_obj == uchain){ 4193. pline("%s!", buf); /* buf still contains the string */ 4194. } else { 4195. /* print cost in slightly different format, so can't reuse buf */ 4196. cost = get_cost(first_obj, (struct monst *)0); 4197. if (Has_contents(first_obj)) 4198. cost += contained_cost(first_obj, shkp, 0L, FALSE, FALSE); 4199. pline("%s, price %ld %s%s%s", doname(first_obj), 4200. cost, currency(cost), first_obj->quan > 1L ? " each" : "", 4201. shk_embellish(first_obj, cost)); 4202. } 4203. } 4204. destroy_nhwindow(tmpwin); 4205. } 4206. #endif /*OVLB*/ 4207. #ifdef OVL3 4208. 4209. STATIC_OVL const char * 4210. shk_embellish(itm, cost) 4211. register struct obj *itm; 4212. long cost; 4213. { 4214. if (!rn2(3)) { 4215. register int o, choice = rn2(5); 4216. if (choice == 0) choice = (cost < 100L ? 1 : cost < 500L ? 2 : 3); 4217. switch (choice) { 4218. case 4: 4219. if (cost < 10L) break; else o = itm->oclass; 4220. if (o == FOOD_CLASS) return ", gourmets' delight!"; 4221. if (objects[itm->otyp].oc_name_known 4222. ? objects[itm->otyp].oc_magic 4223. : (o == AMULET_CLASS || o == RING_CLASS || 4224. o == WAND_CLASS || o == POTION_CLASS || 4225. o == SCROLL_CLASS || o == SPBOOK_CLASS)) 4226. return ", painstakingly developed!"; 4227. return ", superb craftsmanship!"; 4228. case 3: return ", finest quality."; 4229. case 2: return ", an excellent choice."; 4230. case 1: return ", a real bargain."; 4231. default: break; 4232. } 4233. } else if (itm->oartifact) { 4234. return ", one of a kind!"; 4235. } 4236. return "."; 4237. } 4238. #endif /*OVL3*/ 4239. #ifdef OVLB 4240. 4241. /* First 4 supplied by Ronen and Tamar, remainder by development team */ 4242. const char *Izchak_speaks[]={ 4243. "%s says: 'These shopping malls give me a headache.'", 4244. "%s says: 'Slow down. Think clearly.'", 4245. "%s says: 'You need to take things one at a time.'", 4246. "%s says: 'I don't like poofy coffee... give me Columbian Supremo.'", 4247. "%s says that getting the devteam's agreement on anything is difficult.", 4248. "%s says that he has noticed those who serve their deity will prosper.", 4249. "%s says: 'Don't try to steal from me - I have friends in high places!'", 4250. "%s says: 'You may well need something from this shop in the future.'", 4251. "%s comments about the Valley of the Dead as being a gateway." 4252. }; 4253. 4254. void 4255. shk_chat(shkp) 4256. struct monst *shkp; 4257. { 4258. struct eshk *eshk; 4259. #ifdef GOLDOBJ 4260. long shkmoney; 4261. #endif 4262. if (!shkp->isshk) { 4263. /* The monster type is shopkeeper, but this monster is 4264. not actually a shk, which could happen if someone 4265. wishes for a shopkeeper statue and then animates it. 4266. (Note: shkname() would be "" in a case like this.) */ 4267. pline("%s asks whether you've seen any untended shops recently.", 4268. Monnam(shkp)); 4269. /* [Perhaps we ought to check whether this conversation 4270. is taking place inside an untended shop, but a shopless 4271. shk can probably be expected to be rather disoriented.] */ 4272. return; 4273. } 4274. 4275. eshk = ESHK(shkp); 4276. if (ANGRY(shkp)) 4277. pline("%s mentions how much %s dislikes %s customers.", 4278. shkname(shkp), mhe(shkp), 4279. eshk->robbed ? "non-paying" : "rude"); 4280. else if (eshk->following) { 4281. if (strncmp(eshk->customer, plname, PL_NSIZ)) { 4282. verbalize("%s %s! I was looking for %s.", 4283. Hello(shkp), plname, eshk->customer); 4284. eshk->following = 0; 4285. } else { 4286. verbalize("%s %s! Didn't you forget to pay?", 4287. Hello(shkp), plname); 4288. } 4289. } else if (eshk->billct) { 4290. register long total = addupbill(shkp) + eshk->debit; 4291. pline("%s says that your bill comes to %ld %s.", 4292. shkname(shkp), total, currency(total)); 4293. } else if (eshk->debit) 4294. pline("%s reminds you that you owe %s %ld %s.", 4295. shkname(shkp), mhim(shkp), 4296. eshk->debit, currency(eshk->debit)); 4297. else if (eshk->credit) 4298. pline("%s encourages you to use your %ld %s of credit.", 4299. shkname(shkp), eshk->credit, currency(eshk->credit)); 4300. else if (eshk->robbed) 4301. pline("%s complains about a recent robbery.", shkname(shkp)); 4302. #ifndef GOLDOBJ 4303. else if (shkp->mgold < 50) 4304. #else 4305. else if ((shkmoney = money_cnt(shkp->minvent)) < 50) 4306. #endif 4307. pline("%s complains that business is bad.", shkname(shkp)); 4308. #ifndef GOLDOBJ 4309. else if (shkp->mgold > 4000) 4310. #else 4311. else if (shkmoney > 4000) 4312. #endif 4313. pline("%s says that business is good.", shkname(shkp)); 4314. else if (strcmp(shkname(shkp), "Izchak") == 0) 4315. pline(Izchak_speaks[rn2(SIZE(Izchak_speaks))],shkname(shkp)); 4316. else 4317. pline("%s talks about the problem of shoplifters.",shkname(shkp)); 4318. } 4319. 4320. #ifdef KOPS 4321. STATIC_OVL void 4322. kops_gone(silent) 4323. register boolean silent; 4324. { 4325. register int cnt = 0; 4326. register struct monst *mtmp, *mtmp2; 4327. 4328. for (mtmp = fmon; mtmp; mtmp = mtmp2) { 4329. mtmp2 = mtmp->nmon; 4330. if (mtmp->data->mlet == S_KOP) { 4331. if (canspotmon(mtmp)) cnt++; 4332. mongone(mtmp); 4333. } 4334. } 4335. if (cnt && !silent) 4336. pline_The("Kop%s (disappointed) vanish%s into thin air.", 4337. plur(cnt), cnt == 1 ? "es" : ""); 4338. } 4339. #endif /* KOPS */ 4340. 4341. #endif /*OVLB*/ 4342. #ifdef OVL3 4343. 4344. STATIC_OVL long 4345. cost_per_charge(shkp, otmp, altusage) 4346. struct monst *shkp; 4347. struct obj *otmp; 4348. boolean altusage; /* some items have an "alternate" use with different cost */ 4349. { 4350. long tmp = 0L; 4351. 4352. if(!shkp || !inhishop(shkp)) return(0L); /* insurance */ 4353. tmp = get_cost(otmp, shkp); 4354. 4355. /* The idea is to make the exhaustive use of */ 4356. /* an unpaid item more expensive than buying */ 4357. /* it outright. */ 4358. /* KMH, balance patch -- removed abusive orbs */ 4359. if(otmp->otyp == MAGIC_LAMP /*|| 4360. otmp->otyp == ORB_OF_DESTRUCTION*/) { /* 1 */ 4361. /* normal use (ie, as light source) of a magic lamp never 4362. degrades its value, but not charging anything would make 4363. identifcation too easy; charge an amount comparable to 4364. what is charged for an ordinary lamp (don't bother with 4365. angry shk surchage) */ 4366. if (!altusage) tmp = (long) objects[OIL_LAMP].oc_cost; 4367. else tmp += tmp / 3L; /* djinni is being released */ 4368. } else if(otmp->otyp == MAGIC_MARKER) { /* 70 - 100 */ 4369. /* no way to determine in advance */ 4370. /* how many charges will be wasted. */ 4371. /* so, arbitrarily, one half of the */ 4372. /* price per use. */ 4373. tmp /= 2L; 4374. } else if(otmp->otyp == BAG_OF_TRICKS || /* 1 - 20 */ 4375. otmp->otyp == MEDICAL_KIT || 4376. otmp->otyp == HORN_OF_PLENTY) { 4377. tmp /= 5L; 4378. } else if(otmp->otyp == CRYSTAL_BALL || /* 1 - 5 */ 4379. /*otmp->otyp == ORB_OF_ENCHANTMENT || 4380. otmp->otyp == ORB_OF_CHARGING ||*/ 4381. otmp->otyp == OIL_LAMP || /* 1 - 10 */ 4382. otmp->otyp == BRASS_LANTERN || 4383. (otmp->otyp >= MAGIC_FLUTE && 4384. otmp->otyp <= DRUM_OF_EARTHQUAKE) || /* 5 - 9 */ 4385. otmp->oclass == WAND_CLASS) { /* 3 - 11 */ 4386. if (otmp->spe > 1) tmp /= 4L; 4387. } else if (otmp->otyp == TORCH) { 4388. tmp /= 2L; 4389. } else if (otmp->oclass == SPBOOK_CLASS) { 4390. /* Normal use is studying. Alternate use is using up a charge */ 4391. if (altusage) tmp /= 10L; /* 2 - 4 */ 4392. else tmp -= tmp / 5L; 4393. } else if (otmp->otyp == CAN_OF_GREASE || 4394. otmp->otyp == TINNING_KIT 4395. #ifdef TOURIST 4396. || otmp->otyp == EXPENSIVE_CAMERA 4397. #endif 4398. ) { 4399. tmp /= 10L; 4400. } else if (otmp->otyp == POT_OIL) { 4401. tmp /= 5L; 4402. } 4403. return(tmp); 4404. } 4405. #endif /*OVL3*/ 4406. #ifdef OVLB 4407. 4408. /* Charge the player for partial use of an unpaid object. 4409. * 4410. * Note that bill_dummy_object() should be used instead 4411. * when an object is completely used. 4412. */ 4413. void 4414. check_unpaid_usage(otmp, altusage) 4415. struct obj *otmp; 4416. boolean altusage; 4417. { 4418. struct monst *shkp; 4419. const char *fmt, *arg1, *arg2; 4420. long tmp; 4421. 4422. /* MRKR: Torches are a special case. As weapons they can have */ 4423. /* a 'charge' == plus value, which is independent of their */ 4424. /* use as a light source. */ 4425. 4426. /* WAC - now checks for items that aren't carried */ 4427. if ((!otmp->unpaid || !*u.ushops || 4428. (otmp->spe <= 0 && objects[otmp->otyp].oc_charged && 4429. otmp->otyp != TORCH)) 4430. && (carried(otmp) || !costly_spot(otmp->ox, otmp->oy) || 4431. otmp->no_charge)) 4432. return; 4433. if (!(shkp = shop_keeper(*u.ushops)) || !inhishop(shkp)) 4434. return; 4435. if ((tmp = cost_per_charge(shkp, otmp, altusage)) == 0L) 4436. return; 4437. 4438. arg1 = arg2 = ""; 4439. if (otmp->oclass == SPBOOK_CLASS && !altusage) { 4440. fmt = "%sYou owe%s %ld %s."; 4441. arg1 = rn2(2) ? "This is no free library, cad! " : ""; 4442. arg2 = ESHK(shkp)->debit > 0L ? " an additional" : ""; 4443. } else if (otmp->otyp == POT_OIL) { 4444. fmt = "%s%sThat will cost you %ld %s (Yendorian Fuel Tax)."; 4445. } else { 4446. fmt = "%s%sUsage fee, %ld %s."; 4447. if (!rn2(3)) arg1 = "Hey! "; 4448. if (!rn2(3)) arg2 = "Ahem. "; 4449. } 4450. 4451. if (shkp->mcanmove || !shkp->msleeping) 4452. verbalize(fmt, arg1, arg2, tmp, currency(tmp)); 4453. ESHK(shkp)->debit += tmp; 4454. exercise(A_WIS, TRUE); /* you just got info */ 4455. } 4456. 4457. /* for using charges of unpaid objects "used in the normal manner" */ 4458. void 4459. check_unpaid(otmp) 4460. struct obj *otmp; 4461. { 4462. check_unpaid_usage(otmp, FALSE); /* normal item use */ 4463. } 4464. 4465. void 4466. costly_gold(x, y, amount) 4467. register xchar x, y; 4468. register long amount; 4469. { 4470. register long delta; 4471. register struct monst *shkp; 4472. register struct eshk *eshkp; 4473. 4474. if(!costly_spot(x, y)) return; 4475. /* shkp now guaranteed to exist by costly_spot() */ 4476. shkp = shop_keeper(*in_rooms(x, y, SHOPBASE)); 4477. 4478. eshkp = ESHK(shkp); 4479. if(eshkp->credit >= amount) { 4480. if(eshkp->credit > amount) 4481. Your("credit is reduced by %ld %s.", 4482. amount, currency(amount)); 4483. else Your("credit is erased."); 4484. eshkp->credit -= amount; 4485. } else { 4486. delta = amount - eshkp->credit; 4487. if(eshkp->credit) 4488. Your("credit is erased."); 4489. if(eshkp->debit) 4490. Your("debt increases by %ld %s.", 4491. delta, currency(delta)); 4492. else You("owe %s %ld %s.", 4493. shkname(shkp), delta, currency(delta)); 4494. eshkp->debit += delta; 4495. eshkp->loan += delta; 4496. eshkp->credit = 0L; 4497. } 4498. } 4499. 4500. /* used in domove to block diagonal shop-exit */ 4501. /* x,y should always be a door */ 4502. boolean 4503. block_door(x,y) 4504. register xchar x, y; 4505. { 4506. register int roomno = *in_rooms(x, y, SHOPBASE); 4507. register struct monst *shkp; 4508. 4509. if(roomno < 0 || !IS_SHOP(roomno)) return(FALSE); 4510. if(!IS_DOOR(levl[x][y].typ)) return(FALSE); 4511. if(roomno != *u.ushops) return(FALSE); 4512. 4513. if(!(shkp = shop_keeper((char)roomno)) || !inhishop(shkp)) 4514. return(FALSE); 4515. 4516. if(shkp->mx == ESHK(shkp)->shk.x && shkp->my == ESHK(shkp)->shk.y 4517. /* Actually, the shk should be made to block _any_ 4518. * door, including a door the player digs, if the 4519. * shk is within a 'jumping' distance. 4520. */ 4521. && ESHK(shkp)->shd.x == x && ESHK(shkp)->shd.y == y 4522. && shkp->mcanmove && !shkp->msleeping 4523. && (ESHK(shkp)->debit || ESHK(shkp)->billct || 4524. ESHK(shkp)->robbed)) { 4525. pline("%s%s blocks your way!", shkname(shkp), 4526. Invis ? " senses your motion and" : ""); 4527. return(TRUE); 4528. } 4529. return(FALSE); 4530. } 4531. 4532. /* used in domove to block diagonal shop-entry */ 4533. /* u.ux, u.uy should always be a door */ 4534. boolean 4535. block_entry(x,y) 4536. register xchar x, y; 4537. { 4538. register xchar sx, sy; 4539. register int roomno; 4540. register struct monst *shkp; 4541. 4542. if(!(IS_DOOR(levl[u.ux][u.uy].typ) && 4543. levl[u.ux][u.uy].doormask == D_BROKEN)) return(FALSE); 4544. 4545. roomno = *in_rooms(x, y, SHOPBASE); 4546. if(roomno < 0 || !IS_SHOP(roomno)) return(FALSE); 4547. if(!(shkp = shop_keeper((char)roomno)) || !inhishop(shkp)) 4548. return(FALSE); 4549. 4550. if(ESHK(shkp)->shd.x != u.ux || ESHK(shkp)->shd.y != u.uy) 4551. return(FALSE); 4552. 4553. sx = ESHK(shkp)->shk.x; 4554. sy = ESHK(shkp)->shk.y; 4555. 4556. /* KMH, balacne patch -- allow other picks */ 4557. if(shkp->mx == sx && shkp->my == sy 4558. && shkp->mcanmove && !shkp->msleeping 4559. && (x == sx-1 || x == sx+1 || y == sy-1 || y == sy+1) 4560. && (Invis || carrying(PICK_AXE) || carrying(DWARVISH_MATTOCK) 4561. #ifdef STEED 4562. || u.usteed 4563. #endif 4564. )) { 4565. pline("%s%s blocks your way!", shkname(shkp), 4566. Invis ? " senses your motion and" : ""); 4567. return(TRUE); 4568. } 4569. return(FALSE); 4570. } 4571. 4572. #endif /* OVLB */ 4573. #ifdef OVL2 4574. 4575. char * 4576. shk_your(buf, obj) 4577. char *buf; 4578. struct obj *obj; 4579. { 4580. if (!shk_owns(buf, obj) && !mon_owns(buf, obj)) 4581. Strcpy(buf, carried(obj) ? "your" : "the"); 4582. return buf; 4583. } 4584. 4585. char * 4586. Shk_Your(buf, obj) 4587. char *buf; 4588. struct obj *obj; 4589. { 4590. (void) shk_your(buf, obj); 4591. *buf = highc(*buf); 4592. return buf; 4593. } 4594. 4595. STATIC_OVL char * 4596. shk_owns(buf, obj) 4597. char *buf; 4598. struct obj *obj; 4599. { 4600. struct monst *shkp; 4601. xchar x, y; 4602. 4603. if (get_obj_location(obj, &x, &y, 0) && 4604. (obj->unpaid || 4605. (obj->where==OBJ_FLOOR && !obj->no_charge && costly_spot(x,y)))) { 4606. shkp = shop_keeper(inside_shop(x, y)); 4607. return strcpy(buf, shkp ? s_suffix(shkname(shkp)) : "the"); 4608. } 4609. return (char *)0; 4610. } 4611. 4612. STATIC_OVL char * 4613. mon_owns(buf, obj) 4614. char *buf; 4615. struct obj *obj; 4616. { 4617. if (obj->where == OBJ_MINVENT) 4618. return strcpy(buf, s_suffix(mon_nam(obj->ocarry))); 4619. return (char *)0; 4620. } 4621. 4622. #endif /* OVL2 */ 4623. #ifdef OVLB 4624. 4625. #ifdef __SASC 4626. void 4627. sasc_bug(struct obj *op, unsigned x){ 4628. op->unpaid=x; 4629. } 4630. #endif 4631. 4632. #ifdef OTHER_SERVICES 4633. static NEARDATA const char identify_types[] = { ALL_CLASSES, 0 }; 4634. static NEARDATA const char weapon_types[] = { WEAPON_CLASS, TOOL_CLASS, 0 }; 4635. static NEARDATA const char armor_types[] = { ARMOR_CLASS, 0 }; 4636. 4637. /* 4638. ** FUNCTION shk_identify 4639. ** 4640. ** Pay the shopkeeper to identify an item. 4641. */ 4642. static NEARDATA const char ident_chars[] = "bp"; 4643. 4644. static void 4645. shk_identify(slang, shkp) 4646. char *slang; 4647. struct monst *shkp; 4648. { 4649. register struct obj *obj; /* The object to identify */ 4650. int charge, mult; /* Cost to identify */ 4651. /* 4652. char sbuf[BUFSZ]; 4653. */ 4654. boolean guesswork; /* Will shkp be guessing? */ 4655. boolean ripoff=FALSE; /* Shkp ripping you off? */ 4656. char ident_type; 4657. 4658. /* Pick object */ 4659. if ( !(obj = getobj(identify_types, "have identified"))) return; 4660. 4661. /* Will shk be guessing? */ 4662. if ((guesswork = !shk_obj_match(obj, shkp))) 4663. { 4664. verbalize("I don't handle that sort of item, but I could try..."); 4665. } 4666. 4667. /* Here we go */ 4668. /* KMH -- fixed */ 4669. if (ESHK(shkp)->services & (SHK_ID_BASIC|SHK_ID_PREMIUM) == 4670. SHK_ID_BASIC|SHK_ID_PREMIUM) { 4671. ident_type = yn_function("[B]asic service or [P]remier", 4672. ident_chars, '\0'); 4673. if (ident_type == '\0') return; 4674. } else if (ESHK(shkp)->services & SHK_ID_BASIC) { 4675. verbalize("I only offer basic identification."); 4676. ident_type = 'b'; 4677. } else if (ESHK(shkp)->services & SHK_ID_PREMIUM) { 4678. verbalize("I only make complete identifications."); 4679. ident_type = 'p'; 4680. } 4681. 4682. /* 4683. ** Shopkeeper is ripping you off if: 4684. ** Basic service and object already known. 4685. ** Premier service, object known, + know blessed/cursed and 4686. ** rustproof, etc. 4687. */ 4688. if (obj->dknown && objects[obj->otyp].oc_name_known) 4689. { 4690. if (ident_type=='b') ripoff=TRUE; 4691. if (ident_type=='p' && obj->bknown && obj->rknown && obj->known) ripoff=TRUE; 4692. } 4693. 4694. /* Compute the charge */ 4695. 4696. if (ripoff) 4697. { 4698. if (no_cheat) { 4699. verbalize("That item's already identified!"); 4700. return; 4701. } 4702. /* Object already identified: Try and cheat the customer. */ 4703. pline("%s chuckles greedily...", mon_nam(shkp)); 4704. mult = 1; 4705. 4706. /* basic */ 4707. } else if (ident_type=='b') mult = 1; 4708. 4709. /* premier */ 4710. else mult = 2; 4711. 4712. switch (obj->oclass) { 4713. case AMULET_CLASS: charge = 375 * mult; 4714. break; 4715. case WEAPON_CLASS: charge = 75 * mult; 4716. break; 4717. case ARMOR_CLASS: charge = 100 * mult; 4718. break; 4719. case FOOD_CLASS: charge = 25 * mult; 4720. break; 4721. case SCROLL_CLASS: charge = 150 * mult; 4722. break; 4723. case SPBOOK_CLASS: charge = 250 * mult; 4724. break; 4725. case POTION_CLASS: charge = 150 * mult; 4726. break; 4727. case RING_CLASS: charge = 300 * mult; 4728. break; 4729. case WAND_CLASS: charge = 200 * mult; 4730. break; 4731. case TOOL_CLASS: charge = 50 * mult; 4732. break; 4733. case GEM_CLASS: charge = 500 * mult; 4734. break; 4735. default: charge = 75 * mult; 4736. break; 4737. } 4738. 4739. /* Artifacts cost more to deal with */ 4740. /* KMH -- Avoid floating-point */ 4741. if (obj->oartifact) charge = charge * 3 / 2; 4742. 4743. /* Smooth out the charge a bit (lower bound only) */ 4744. shk_smooth_charge(&charge, 25, 750); 4745. 4746. /* Go ahead? */ 4747. if (shk_offer_price(slang, charge, shkp) == FALSE) return; 4748. 4749. /* Shopkeeper deviousness */ 4750. if (ident_type == 'b') { 4751. if (Hallucination) { 4752. pline("You hear %s tell you it's a pot of flowers.", 4753. mon_nam(shkp)); 4754. return; 4755. } else if (Confusion) { 4756. pline("%s tells you but you forget.", mon_nam(shkp)); 4757. return; 4758. } 4759. } 4760. 4761. /* Is shopkeeper guessing? */ 4762. if (guesswork) 4763. { 4764. /* 4765. ** Identify successful if rn2() < #. 4766. */ 4767. if (!rn2(ident_type == 'b' ? 4 : 2)) { 4768. verbalize("Success!"); 4769. /* Rest of msg will come from identify(); */ 4770. } else { 4771. verbalize("Sorry. I guess it's not your lucky day."); 4772. return; 4773. } 4774. } 4775. 4776. /* Premier service */ 4777. if (ident_type == 'p') { 4778. identify(obj); 4779. } else { 4780. /* Basic */ 4781. makeknown(obj->otyp); 4782. obj->dknown = 1; 4783. prinv((char *)0, obj, 0L); /* Print result */ 4784. } 4785. } 4786. 4787. 4788. /* 4789. ** FUNCTION shk_uncurse 4790. ** 4791. ** Uncurse an item for the customer 4792. */ 4793. static void 4794. shk_uncurse(slang, shkp) 4795. char *slang; 4796. struct monst *shkp; 4797. { 4798. struct obj *obj; /* The object picked */ 4799. int charge; /* How much to uncurse */ 4800. 4801. /* Pick object */ 4802. if ( !(obj = getobj(identify_types, "uncurse"))) return; 4803. 4804. /* Charge is same as cost */ 4805. charge = get_cost(obj, shop_keeper(/* roomno= */*u.ushops)); 4806. 4807. /* Artifacts cost more to deal with */ 4808. /* KMH -- Avoid floating-point */ 4809. if (obj->oartifact) charge = charge * 3 / 2; 4810. 4811. /* Smooth out the charge a bit */ 4812. shk_smooth_charge(&charge, 50, 250); 4813. 4814. /* Go ahead? */ 4815. if (shk_offer_price(slang, charge, shkp) == FALSE) return; 4816. 4817. /* Shopkeeper responses */ 4818. /* KMH -- fixed bknown, curse(), bless(), uncurse() */ 4819. if (!obj->bknown && !Role_if(PM_PRIEST) && !Role_if(PM_NECROMANCER) && 4820. !no_cheat) 4821. { 4822. /* Not identified! */ 4823. pline("%s snickers and says \"See, nice and uncursed!\"", 4824. mon_nam(shkp)); 4825. obj->bknown = FALSE; 4826. } 4827. else if (Confusion) 4828. { 4829. /* Curse the item! */ 4830. You("accidentally ask for the item to be cursed"); 4831. curse(obj); 4832. } 4833. else if (Hallucination) 4834. { 4835. /* 4836. ** Let's have some fun: If you're hallucinating, 4837. ** then there's a chance for the object to be blessed! 4838. */ 4839. if (!rn2(4)) 4840. { 4841. pline("Distracted by your blood-shot %s, the shopkeeper", 4842. makeplural(body_part(EYE))); 4843. pline("accidentally blesses the item!"); 4844. bless(obj); 4845. } 4846. else 4847. { 4848. You("can't see straight and point to the wrong item"); 4849. } 4850. } 4851. else 4852. { 4853. verbalize("All done - safe to handle, now!"); 4854. uncurse(obj); 4855. } 4856. } 4857. 4858. 4859. /* 4860. ** FUNCTION shk_appraisal 4861. ** 4862. ** Appraise a weapon or armor 4863. */ 4864. static const char basic_damage[] = 4865. "Basic damage against small foes %s, against large foes %s."; 4866. 4867. static void 4868. shk_appraisal(slang, shkp) 4869. char *slang; 4870. struct monst *shkp; 4871. { 4872. struct obj *obj; /* The object picked */ 4873. int charge; /* How much for appraisal */ 4874. boolean guesswork; /* Shopkeeper unsure? */ 4875. char ascii_wsdam[5]; /* Ascii form of damage */ 4876. char ascii_wldam[5]; 4877. 4878. 4879. /* Pick object */ 4880. if ( !(obj = getobj(weapon_types, "appraise"))) return; 4881. 4882. charge = get_cost(obj, shop_keeper(/* roomno= */*u.ushops)) / 3; 4883. 4884. /* Smooth out the charge a bit */ 4885. shk_smooth_charge(&charge, 5, 50); 4886. 4887. /* If not identified, complain. */ 4888. /* KMH -- Why should it matter? */ 4889. /* if ( ! (obj->known && objects[obj->otyp].oc_name_known) ) 4890. { 4891. verbalize("This weapon needs to be identified first!"); 4892. return; 4893. } else */ 4894. if (shk_class_match(WEAPON_CLASS, shkp) == SHK_MATCH) 4895. { 4896. verbalize("Ok, %s, let's see what we have here.", slang); 4897. guesswork = FALSE; 4898. } 4899. else 4900. { 4901. verbalize("Mind you, I'm not an expert in this field."); 4902. guesswork = TRUE; 4903. } 4904. 4905. /* Go ahead? */ 4906. if (shk_offer_price(slang, charge, shkp) == FALSE) return; 4907. 4908. /* Shopkeeper deviousness */ 4909. if (Confusion) 4910. { 4911. pline("The numbers get all mixed up in your head."); 4912. return; 4913. } 4914. else if (Hallucination) 4915. { 4916. You("hear %s say it'll \"knock 'em dead\"", 4917. mon_nam(shkp)); 4918. return; 4919. } 4920. 4921. /* Convert damage to ascii */ 4922. Sprintf(ascii_wsdam, "%d", objects[obj->otyp].oc_wsdam); 4923. Sprintf(ascii_wldam, "%d", objects[obj->otyp].oc_wldam); 4924. 4925. /* Will shopkeeper be unsure? */ 4926. if (guesswork) 4927. { 4928. switch (rn2(10)) 4929. { 4930. case 1: 4931. /* Shkp's an idiot */ 4932. verbalize("Sorry, %s, but I'm not certain.", slang); 4933. break; 4934. 4935. case 2: 4936. /* Not sure about large foes */ 4937. verbalize(basic_damage, ascii_wsdam, "?"); 4938. break; 4939. 4940. case 3: 4941. /* Not sure about small foes */ 4942. verbalize(basic_damage, "?", ascii_wldam); 4943. break; 4944. 4945. default: 4946. verbalize(basic_damage, ascii_wsdam, ascii_wldam); 4947. break; 4948. 4949. } 4950. } 4951. else 4952. { 4953. verbalize(basic_damage, ascii_wsdam, ascii_wldam); 4954. } 4955. } 4956. 4957. 4958. /* 4959. ** FUNCTION shk_weapon_works 4960. ** 4961. ** Perform ops on weapon for customer 4962. */ 4963. static const char we_offer[] = "We offer the finest service available!"; 4964. static void 4965. shk_weapon_works(slang, shkp) 4966. char *slang; 4967. struct monst *shkp; 4968. { 4969. struct obj *obj; 4970. int charge; 4971. winid tmpwin; 4972. anything any; 4973. menu_item *selected; 4974. int service; 4975. int n; 4976. 4977. /* Pick weapon */ 4978. if (ESHK(shkp)->services & (SHK_SPECIAL_A | SHK_SPECIAL_B)) 4979. obj = getobj(weapon_types, "improve"); 4980. else 4981. obj = getobj(weapon_types, "poison"); 4982. if (!obj) return; 4983. 4984. /* Check if you asked for a non weapon tool to be improved */ 4985. if (obj->oclass == TOOL_CLASS && !is_weptool(obj)) 4986. pline("%s grins greedily...", mon_nam(shkp)); 4987. 4988. if (ESHK(shkp)->services & (SHK_SPECIAL_A | SHK_SPECIAL_B)) { 4989. any.a_void = 0; /* zero out all bits */ 4990. tmpwin = create_nhwindow(NHW_MENU); 4991. start_menu(tmpwin); 4992. 4993. if (ESHK(shkp)->services & SHK_SPECIAL_A) { 4994. any.a_int = 1; 4995. add_menu(tmpwin, NO_GLYPH, &any , 'w', 0, ATR_NONE, 4996. "Ward against damage", MENU_UNSELECTED); 4997. } 4998. if (ESHK(shkp)->services & SHK_SPECIAL_B) { 4999. any.a_int = 2; 5000. add_menu(tmpwin, NO_GLYPH, &any , 'e', 0, ATR_NONE, 5001. "Enchant", MENU_UNSELECTED); 5002. } 5003. 5004. /* Can object be poisoned? */ 5005. if (is_poisonable(obj) && (ESHK(shkp)->services & SHK_SPECIAL_C)) { 5006. any.a_int = 3; 5007. add_menu(tmpwin, NO_GLYPH, &any , 'p', 0, ATR_NONE, 5008. "Poison", MENU_UNSELECTED); 5009. } 5010. 5011. end_menu(tmpwin, "Weapon-works:"); 5012. n = select_menu(tmpwin, PICK_ONE, &selected); 5013. destroy_nhwindow(tmpwin); 5014. if (n > 0) 5015. service = selected[0].item.a_int; 5016. else 5017. service = 0; 5018. } else 5019. service = 3; 5020. 5021. /* Here we go */ 5022. if (service > 0) 5023. verbalize(we_offer); 5024. else 5025. pline(Never_mind); 5026. 5027. switch(service) { 5028. case 0: 5029. break; 5030. 5031. case 1: 5032. verbalize("This'll leave your %s untouchable!", xname(obj)); 5033. 5034. /* Costs more the more eroded it is (oeroded 0-3 * 2) */ 5035. charge = 500 * (obj->oeroded + obj->oeroded2 + 1); 5036. if (obj->oeroded + obj->oeroded2 > 2) 5037. verbalize("This thing's in pretty sad condition, %s", slang); 5038. 5039. /* Another warning if object is naturally rustproof */ 5040. if (obj->oerodeproof || !is_damageable(obj)) 5041. pline("%s gives you a suspciously happy smile...", 5042. mon_nam(shkp)); 5043. 5044. /* Artifacts cost more to deal with */ 5045. if (obj->oartifact) charge = charge * 3 / 2; 5046. 5047. /* Smooth out the charge a bit */ 5048. shk_smooth_charge(&charge, 200, 1500); 5049. 5050. if (shk_offer_price(slang, charge, shkp) == FALSE) return; 5051. 5052. /* Have some fun, but for this $$$ it better work. */ 5053. if (Confusion) 5054. You("fall over in appreciation"); 5055. else if (Hallucination) 5056. Your(" - tin roof, un-rusted!"); 5057. 5058. obj->oeroded = obj->oeroded2 = 0; 5059. obj->rknown = TRUE; 5060. obj->oerodeproof = TRUE; 5061. break; 5062. 5063. case 2: 5064. verbalize("Guaranteed not to harm your weapon, or your money back!"); 5065. /* 5066. ** The higher the enchantment, the more costly! 5067. ** Gets to the point where you need to rob fort ludios 5068. ** in order to get it to +5!! 5069. */ 5070. charge = (obj->spe+1) * (obj->spe+1) * 625; 5071. 5072. if (obj->spe < 0) charge = 100; 5073. 5074. /* Artifacts cost more to deal with */ 5075. if (obj->oartifact) charge *= 2; 5076. 5077. /* Smooth out the charge a bit (lower bound only) */ 5078. shk_smooth_charge(&charge, 50, NOBOUND); 5079. 5080. if (shk_offer_price(slang, charge, shkp) == FALSE) return; 5081. if (obj->spe+1 > 5) { 5082. verbalize("I can't enchant this any higher!"); 5083. charge = 0; 5084. break; 5085. } 5086. /* Have some fun! */ 5087. if (Confusion) 5088. Your("%s unexpectedly!", aobjnam(obj, "vibrate")); 5089. else if (Hallucination) 5090. Your("%s to evaporate into thin air!", aobjnam(obj, "seem")); 5091. /* ...No actual vibrating and no evaporating */ 5092. 5093. if (obj->otyp == WORM_TOOTH) { 5094. obj->otyp = CRYSKNIFE; 5095. Your("weapon seems sharper now."); 5096. obj->cursed = 0; 5097. break; 5098. } 5099. 5100. obj->spe++; 5101. break; 5102. 5103. case 3: 5104. verbalize("Just imagine what poisoned %s can do!", xname(obj)); 5105. 5106. charge = 10 * obj->quan; 5107. 5108. if (shk_offer_price(slang, charge, shkp) == FALSE) return; 5109. 5110. obj->opoisoned = TRUE; 5111. break; 5112. 5113. default: 5114. impossible("Unknown Weapon Enhancement"); 5115. break; 5116. } 5117. } 5118. 5119. 5120. /* 5121. ** FUNCTION shk_armor_works 5122. ** 5123. ** Perform ops on armor for customer 5124. */ 5125. static void 5126. shk_armor_works(slang, shkp) 5127. char *slang; 5128. struct monst *shkp; 5129. { 5130. struct obj *obj; 5131. int charge; 5132. /*WAC - Windowstuff*/ 5133. winid tmpwin; 5134. anything any; 5135. menu_item *selected; 5136. int n; 5137. 5138. /* Pick armor */ 5139. if ( !(obj = getobj(armor_types, "improve"))) return; 5140. 5141. /* Here we go */ 5142. /*WAC - did this using the windowing system...*/ 5143. any.a_void = 0; /* zero out all bits */ 5144. tmpwin = create_nhwindow(NHW_MENU); 5145. start_menu(tmpwin); 5146. any.a_int = 1; 5147. if (ESHK(shkp)->services & (SHK_SPECIAL_A)) 5148. add_menu(tmpwin, NO_GLYPH, &any , 'r', 0, ATR_NONE, "Rust/Fireproof", MENU_UNSELECTED); 5149. any.a_int = 2; 5150. if (ESHK(shkp)->services & (SHK_SPECIAL_B)) 5151. add_menu(tmpwin, NO_GLYPH, &any , 'e', 0, ATR_NONE, "Enchant", MENU_UNSELECTED); 5152. end_menu(tmpwin, "Armor-works:"); 5153. n = select_menu(tmpwin, PICK_ONE, &selected); 5154. destroy_nhwindow(tmpwin); 5155. 5156. verbalize(we_offer); 5157. 5158. if (n > 0) 5159. switch(selected[0].item.a_int) { 5160. case 1: 5161. if (!flags.female && is_human(youmonst.data)) 5162. verbalize("They'll call you the man of stainless steel!"); 5163. 5164. /* Costs more the more rusty it is (oeroded 0-3) */ 5165. charge = 300 * (obj->oeroded+1); 5166. if (obj->oeroded > 2) verbalize("Yikes! This thing's a mess!"); 5167. 5168. /* Artifacts cost more to deal with */ 5169. /* KMH -- Avoid floating-point */ 5170. if (obj->oartifact) charge = charge * 3 / 2; 5171. 5172. /* Smooth out the charge a bit */ 5173. shk_smooth_charge(&charge, 100, 1000); 5174. 5175. if (shk_offer_price(slang, charge, shkp) == FALSE) return; 5176. 5177. /* Have some fun, but for this $$$ it better work. */ 5178. if (Confusion) 5179. You("forget how to put your %s back on!", xname(obj)); 5180. else if (Hallucination) 5181. You("mistake your %s for a pot and...", xname(obj)); 5182. 5183. obj->oeroded = 0; 5184. obj->rknown = TRUE; 5185. obj->oerodeproof = TRUE; 5186. break; 5187. 5188. case 2: 5189. verbalize("Nobody will ever hit on you again."); 5190. 5191. /* Higher enchantment levels cost more. */ 5192. charge = (obj->spe+1) * (obj->spe+1) * 500; 5193. 5194. if (obj->spe < 0) charge = 100; 5195. 5196. /* Artifacts cost more to deal with */ 5197. if (obj->oartifact) charge *= 2; 5198. 5199. /* Smooth out the charge a bit */ 5200. shk_smooth_charge(&charge, 50, NOBOUND); 5201. 5202. if (shk_offer_price(slang, charge, shkp) == FALSE) return; 5203. if (obj->spe+1 > 3) { 5204. verbalize("I can't enchant this any higher!"); 5205. charge = 0; 5206. break; 5207. } 5208. /* Have some fun! */ 5209. if (Hallucination) Your("%s looks dented.", xname(obj)); 5210. 5211. if (obj->otyp >= GRAY_DRAGON_SCALES && 5212. obj->otyp <= YELLOW_DRAGON_SCALES) { 5213. /* dragon scales get turned into dragon scale mail */ 5214. Your("%s merges and hardens!", xname(obj)); 5215. setworn((struct obj *)0, W_ARM); 5216. /* assumes same order */ 5217. obj->otyp = GRAY_DRAGON_SCALE_MAIL + 5218. obj->otyp - GRAY_DRAGON_SCALES; 5219. obj->cursed = 0; 5220. obj->known = 1; 5221. setworn(obj, W_ARM); 5222. break; 5223. } 5224. 5225. obj->spe++; 5226. adj_abon(obj, 1); 5227. break; 5228. 5229. default: 5230. pline ("Unknown Armor Enhancement"); 5231. break; 5232. } 5233. } 5234. 5235. 5236. /* 5237. ** FUNCTION shk_charge 5238. ** 5239. ** Charge something (for a price!) 5240. */ 5241. static NEARDATA const char wand_types[] = { WAND_CLASS, 0 }; 5242. static NEARDATA const char tool_types[] = { TOOL_CLASS, 0 }; 5243. static NEARDATA const char ring_types[] = { RING_CLASS, 0 }; 5244. static NEARDATA const char spbook_types[] = { SPBOOK_CLASS, 0 }; 5245. 5246. static void 5247. shk_charge(slang, shkp) 5248. char *slang; 5249. struct monst *shkp; 5250. { 5251. struct obj *obj = NULL; /* The object picked */ 5252. struct obj *tobj; /* Temp obj */ 5253. char type; /* Basic/premier service */ 5254. int charge; /* How much to charge customer */ 5255. char invlet; /* Inventory letter */ 5256. 5257. /* What type of shop are we? */ 5258. if (shk_class_match(WAND_CLASS, shkp) == SHK_MATCH) 5259. obj = getobj(wand_types, "charge"); 5260. else if (shk_class_match(TOOL_CLASS, shkp) == SHK_MATCH) 5261. obj = getobj(tool_types, "charge"); 5262. else if (shk_class_match(RING_CLASS, shkp) == SHK_MATCH) 5263. obj = getobj(ring_types, "charge"); 5264. else if (shk_class_match(SPBOOK_CLASS, shkp) == SHK_MATCH) 5265. obj = getobj(spbook_types, "charge"); 5266. if (!obj) return; 5267. 5268. /* 5269. ** Wand shops can offer special service! 5270. ** Extra charges (for a lot of extra money!) 5271. */ 5272. if (obj->oclass == WAND_CLASS) 5273. { 5274. /* What type of service? */ 5275. if ((ESHK(shkp)->services & (SHK_SPECIAL_A|SHK_SPECIAL_B)) == 5276. (SHK_SPECIAL_A|SHK_SPECIAL_B)) { 5277. type = yn_function("[B]asic service or [P]remier", 5278. ident_chars, '\0'); 5279. if (type == '\0') return; 5280. } else if (ESHK(shkp)->services & SHK_SPECIAL_A) { 5281. pline ("I only perform basic charging."); 5282. type = 'b'; 5283. } else if (ESHK(shkp)->services & SHK_SPECIAL_B) { 5284. pline ("I only perform complete charging."); 5285. type = 'p'; 5286. } 5287. } 5288. else 5289. { 5290. type = 'b'; 5291. } 5292. 5293. /* Compute charge */ 5294. if (type == 'b') 5295. charge = 300; 5296. else 5297. charge = 1000; 5298. 5299. /* Wands of wishing should be hard to get recharged */ 5300. if (/*obj->oclass == WAND_CLASS &&*/ obj->otyp == WAN_WISHING) 5301. charge *= 3; 5302. else /* Smooth out the charge a bit */ 5303. shk_smooth_charge(&charge, 100, 1000); 5304. 5305. /* Go for it? */ 5306. if (shk_offer_price(slang, charge, shkp) == FALSE) return; 5307. 5308. /* Shopkeeper deviousness */ 5309. if ((Confusion || Hallucination) && !no_cheat) 5310. { 5311. pline("%s says it's charged and pushes you toward the door", 5312. Monnam(shkp)); 5313. return; 5314. } 5315. 5316. /* Do it */ 5317. invlet = obj->invlet; 5318. recharge(obj, (type=='b') ? 0 : 1); 5319. 5320. /* 5321. ** Did the object blow up? We need to check this in a way 5322. ** that has nothing to do with dereferencing the obj pointer. 5323. ** We saved the inventory letter of this item; now cycle 5324. ** through all objects and see if there is an object 5325. ** with that letter. 5326. */ 5327. for(obj=0, tobj=invent; tobj; tobj=tobj->nobj) 5328. if(tobj->invlet == invlet) 5329. { 5330. obj = tobj; 5331. break; 5332. } 5333. if (!obj) 5334. { 5335. verbalize("Oops! Sorry about that..."); 5336. return; 5337. } 5338. 5339. /* Wands get special treatment */ 5340. if (obj->oclass == WAND_CLASS) 5341. { 5342. /* Wand of wishing? */ 5343. if (obj->otyp == WAN_WISHING) 5344. { 5345. /* Premier gives you ONE more charge */ 5346. /* KMH -- Okay, but that's pretty generous */ 5347. if (type == 'p') obj->spe++; 5348. 5349. /* Fun */ 5350. verbalize("Since you'll have everything you always wanted,"); 5351. verbalize("...How about loaning me some money?"); 5352. #ifndef GOLDOBJ 5353. shkp->mgold += u.ugold; 5354. u.ugold = 0; 5355. #else 5356. money2mon(shkp, money_cnt(invent)); 5357. #endif 5358. makeknown(obj->otyp); 5359. bot(); 5360. } 5361. else 5362. { 5363. /* 5364. ** Basic: recharge() will have given 1 charge. 5365. ** Premier: recharge() will have given 5-10, say. 5366. ** Add a few more still. 5367. */ 5368. if (obj->spe < 16) obj->spe += rn1(5,5); 5369. else if (obj->spe < 20) obj->spe += 1; 5370. } 5371. } 5372. } 5373. 5374. 5375. /* 5376. ** FUNCTION shk_obj_match 5377. ** 5378. ** Does object "obj" match the type of shop? 5379. */ 5380. static boolean 5381. shk_obj_match(obj, shkp) 5382. struct obj *obj; 5383. struct monst *shkp; 5384. { 5385. /* object matches type of shop? */ 5386. return(saleable(shkp, obj)); 5387. } 5388. 5389. 5390. /* 5391. ** FUNCTION shk_offer_price 5392. ** 5393. ** Tell customer how much it'll cost, ask if he wants to pay, 5394. ** and deduct from $$ if agreable. 5395. */ 5396. static boolean 5397. shk_offer_price(slang, charge, shkp) 5398. char *slang; 5399. long charge; 5400. struct monst *shkp; 5401. { 5402. char sbuf[BUFSZ]; 5403. long credit = ESHK(shkp)->credit; 5404. 5405. /* Ask y/n if player wants to pay */ 5406. Sprintf(sbuf, "It'll cost you %ld zorkmid%s. Interested?", 5407. charge, plur(charge)); 5408. 5409. if ( yn(sbuf) != 'y' ) { 5410. verbalize("It's your call, %s.", slang); 5411. return(FALSE); 5412. } 5413. 5414. /* Player _wants_ to pay, but can he? */ 5415. /* WAC -- Check the credit: but don't use check_credit 5416. * since we don't want to charge him for part of it if he can't pay for all 5417. * of it 5418. */ 5419. #ifndef GOLDOBJ 5420. if (charge > (u.ugold + credit)) { 5421. #else 5422. if (charge > (money_cnt(invent) + credit)) { 5423. #endif 5424. verbalize("Cash on the spot, %s, and you ain't got the dough!", 5425. slang); 5426. return(FALSE); 5427. } 5428. 5429. /* Charge the customer */ 5430. charge = check_credit (charge, shkp); /* Deduct the credit first */ 5431. 5432. #ifndef GOLDOBJ 5433. u.ugold -= charge; 5434. shkp->mgold += charge; 5435. #else 5436. money2mon(shkp, charge); 5437. #endif 5438. bot(); 5439. 5440. return(TRUE); 5441. } 5442. 5443. 5444. /* 5445. ** FUNCTION shk_smooth_charge 5446. ** 5447. ** Smooth out the lower/upper bounds on the price to get something 5448. ** done. Make sure that it (1) varies depending on charisma and 5449. ** (2) is constant. 5450. */ 5451. static void 5452. shk_smooth_charge(pcharge, lower, upper) 5453. int *pcharge; 5454. int lower; 5455. int upper; 5456. { 5457. int charisma; 5458. int bonus; 5459. 5460. /* KMH -- Avoid using floating-point arithmetic */ 5461. if(ACURR(A_CHA) > 21) *pcharge *= 11; 5462. else if(ACURR(A_CHA) > 18) *pcharge *= 12; 5463. else if(ACURR(A_CHA) > 15) *pcharge *= 13; 5464. else if(ACURR(A_CHA) > 12) *pcharge *= 14; 5465. else if(ACURR(A_CHA) > 10) *pcharge *= 15; 5466. else if(ACURR(A_CHA) > 8) *pcharge *= 16; 5467. else if(ACURR(A_CHA) > 7) *pcharge *= 17; 5468. else if(ACURR(A_CHA) > 6) *pcharge *= 18; 5469. else if(ACURR(A_CHA) > 5) *pcharge *= 19; 5470. else if(ACURR(A_CHA) > 4) *pcharge *= 20; 5471. else *pcharge *= 21; 5472. *pcharge /= 10; 5473. 5474. #ifdef BLACKMARKET 5475. if (Is_blackmarket(&u.uz)) *pcharge *= 3; 5476. #endif 5477. /* Skip upper stuff? */ 5478. if (upper == NOBOUND) goto check_lower; 5479. 5480. /* This should give us something like a charisma of 5 to 25. */ 5481. charisma = ABASE(A_CHA) + ABON(A_CHA) + ATEMP(A_CHA); 5482. 5483. /* Now: 0 to 10 = 0. 11 and up = 1 to whatever. */ 5484. if (charisma <= 10) 5485. charisma = 0; 5486. else 5487. charisma -= 10; 5488. 5489. /* Charismatic players get smaller upper bounds */ 5490. bonus=((upper/50)*charisma); 5491. 5492. /* Adjust upper. Upper > lower! */ 5493. upper -= bonus; 5494. upper = (upper>=lower) ? upper : lower; 5495. 5496. /* Ok, do the min/max stuff */ 5497. if (*pcharge > upper) *pcharge=upper; 5498. check_lower: 5499. if (*pcharge < lower) *pcharge=lower; 5500. } 5501. 5502. #endif /* OTHER_SERVICES */ 5503. 5504. 5505. #endif /* OVLB */ 5506. 5507. #ifdef DEBUG 5508. int 5509. wiz_debug_cmd() /* in this case, display your bill(s) */ 5510. { 5511. int win, special = 0; 5512. struct obj *obj; 5513. struct monst *shkp, *ushkp; 5514. struct bill_x *bp; 5515. int ct; 5516. char buf[BUFSIZ]; 5517. char buf2[BUFSIZ]; 5518. 5519. win = create_nhwindow(NHW_MENU); 5520. ushkp = shop_keeper(*u.ushops); 5521. shkp = next_shkp(fmon, TRUE); 5522. if (!shkp) { 5523. shkp = ushkp; 5524. special++; 5525. } 5526. if (!shkp) 5527. putstr(win, 0, "No shopkeepers with bills"); 5528. else 5529. for (; shkp; ) { 5530. bp = ESHK(shkp)->bill_p; 5531. ct = ESHK(shkp)->billct; 5532. if (ct) { 5533. Sprintf(buf, "Your bill with %s", noit_mon_nam(shkp)); 5534. if (shkp == ushkp) { 5535. Strcat(buf, " (here)"); 5536. ushkp = NULL; 5537. } 5538. Strcat(buf, ":"); 5539. putstr(win, 0, buf); 5540. putstr(win, 0, "Price Quan Used? Object"); 5541. while (--ct >= 0) { 5542. obj = bp_to_obj(bp); 5543. if (obj) { 5544. if (!obj->unpaid) 5545. *buf2='*'; /* Bad entry */ 5546. Strcpy(obj->unpaid ? buf2 : buf2 + 1, xname(obj)); 5547. } 5548. else 5549. Sprintf(buf2, "Unknown, with ID %d", bp->bo_id); 5550. Sprintf(buf, "%-7d %-7d %-7s %s", bp->price, bp->bquan, 5551. bp->useup ? "Yes" : "No", buf2); 5552. putstr(win, 0, buf); 5553. bp++; 5554. } 5555. } 5556. else { 5557. Sprintf(buf, "You do not owe %s anything.", noit_mon_nam(shkp)); 5558. putstr(win, 0, buf); 5559. } 5560. if (special) 5561. break; 5562. shkp = next_shkp(shkp->nmon, TRUE); 5563. if (!shkp) { 5564. shkp = ushkp; 5565. special++; 5566. } 5567. if (shkp) 5568. putstr(win, 0, ""); 5569. } 5570. display_nhwindow(win, FALSE); 5571. destroy_nhwindow(win); 5572. return 0; 5573. } 5574. #endif /* DEBUG */ 5575. 5576. /*shk.c*/