forked from msearle5/slicehack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshk.c
More file actions
5204 lines (4753 loc) · 167 KB
/
Copy pathshk.c
File metadata and controls
5204 lines (4753 loc) · 167 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* NetHack 3.6 shk.c $NHDT-Date: 1571436007 2019/10/18 22:00:07 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.171 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
#define PAY_SOME 2
#define PAY_BUY 1
#define PAY_CANT 0 /* too poor */
#define PAY_SKIP (-1)
#define PAY_BROKE (-2)
STATIC_DCL void FDECL(makekops, (coord *));
STATIC_DCL void FDECL(call_kops, (struct monst *, BOOLEAN_P));
STATIC_DCL void FDECL(kops_gone, (BOOLEAN_P));
#define NOTANGRY(mon) ((mon)->mpeaceful)
#define ANGRY(mon) (!NOTANGRY(mon))
#define IS_SHOP(x) (rooms[x].rtype >= SHOPBASE)
#define muteshk(shkp) \
((shkp)->msleeping || !(shkp)->mcanmove \
|| (shkp)->data->msound <= MS_ANIMAL)
extern const struct shclass shtypes[]; /* defined in shknam.c */
STATIC_VAR NEARDATA long int followmsg; /* last time of follow message */
STATIC_VAR const char and_its_contents[] = " and its contents";
STATIC_VAR const char the_contents_of[] = "the contents of ";
STATIC_DCL void FDECL(append_honorific, (char *));
STATIC_DCL long FDECL(addupbill, (struct monst *));
STATIC_DCL void FDECL(pacify_shk, (struct monst *));
STATIC_DCL struct bill_x *FDECL(onbill, (struct obj *, struct monst *,
BOOLEAN_P));
STATIC_DCL struct monst *FDECL(next_shkp, (struct monst *, BOOLEAN_P));
STATIC_DCL long FDECL(shop_debt, (struct eshk *));
STATIC_DCL char *FDECL(shk_owns, (char *, struct obj *));
STATIC_DCL char *FDECL(mon_owns, (char *, struct obj *));
STATIC_DCL void FDECL(clear_unpaid_obj, (struct monst *, struct obj *));
STATIC_DCL void FDECL(clear_unpaid, (struct monst *, struct obj *));
STATIC_DCL long FDECL(check_credit, (long, struct monst *));
STATIC_DCL void FDECL(pay, (long, struct monst *));
STATIC_DCL long FDECL(get_cost, (struct obj *, struct monst *));
STATIC_DCL long FDECL(set_cost, (struct obj *, struct monst *));
STATIC_DCL const char *FDECL(shk_embellish, (struct obj *, long));
STATIC_DCL long FDECL(cost_per_charge, (struct monst *, struct obj *,
BOOLEAN_P));
STATIC_DCL long FDECL(cheapest_item, (struct monst *));
STATIC_DCL int FDECL(dopayobj, (struct monst *, struct bill_x *,
struct obj **, int, BOOLEAN_P));
STATIC_DCL long FDECL(stolen_container, (struct obj *, struct monst *,
long, BOOLEAN_P));
STATIC_DCL long FDECL(getprice, (struct obj *, BOOLEAN_P));
STATIC_DCL void FDECL(shk_names_obj, (struct monst *, struct obj *,
const char *, long, const char *));
STATIC_DCL boolean FDECL(inherits, (struct monst *, int, int, BOOLEAN_P));
STATIC_DCL void FDECL(set_repo_loc, (struct monst *));
STATIC_DCL struct obj *FDECL(bp_to_obj, (struct bill_x *));
STATIC_DCL long FDECL(get_pricing_units, (struct obj *));
STATIC_DCL boolean NDECL(angry_shk_exists);
STATIC_DCL void FDECL(rile_shk, (struct monst *));
STATIC_DCL void FDECL(rouse_shk, (struct monst *, BOOLEAN_P));
STATIC_DCL void FDECL(remove_damage, (struct monst *, BOOLEAN_P));
STATIC_DCL void FDECL(sub_one_frombill, (struct obj *, struct monst *));
STATIC_DCL void FDECL(add_one_tobill, (struct obj *, BOOLEAN_P,
struct monst *));
STATIC_DCL void FDECL(dropped_container, (struct obj *, struct monst *,
BOOLEAN_P));
STATIC_DCL void FDECL(add_to_billobjs, (struct obj *));
STATIC_DCL void FDECL(bill_box_content, (struct obj *, BOOLEAN_P, BOOLEAN_P,
struct monst *));
STATIC_DCL boolean FDECL(rob_shop, (struct monst *));
STATIC_DCL void FDECL(deserted_shop, (char *));
STATIC_DCL boolean FDECL(special_stock, (struct obj *, struct monst *,
BOOLEAN_P));
STATIC_DCL const char *FDECL(cad, (BOOLEAN_P));
/*
invariants: obj->unpaid iff onbill(obj) [unless bp->useup]
obj->quan <= bp->bquan
*/
static const char *angrytexts[] = { "quite upset", "ticked off", "furious" };
/*
* Transfer money from inventory to monster when paying
* shopkeepers, priests, oracle, succubus, and other demons.
* Simple with only gold coins.
* This routine will handle money changing when multiple
* coin types is implemented, only appropriate
* monsters will pay change. (Peaceful shopkeepers, priests
* and the oracle try to maintain goodwill while selling
* their wares or services. Angry monsters and all demons
* will keep anything they get their hands on.
* Returns the amount actually paid, so we can know
* if the monster kept the change.
*/
long
money2mon(mon, amount)
struct monst *mon;
long amount;
{
struct obj *ygold = findgold(invent, TRUE);
if (amount <= 0) {
impossible("%s payment in money2mon!", amount ? "negative" : "zero");
return 0L;
}
if (!ygold || ygold->quan < amount) {
impossible("Paying without %s money?", ygold ? "enough" : "");
return 0L;
}
if (ygold->quan > amount)
ygold = splitobj(ygold, amount);
else if (ygold->owornmask)
remove_worn_item(ygold, FALSE); /* quiver */
freeinv(ygold);
add_to_minv(mon, ygold);
context.botl = 1;
return amount;
}
/*
* Transfer money from monster to inventory.
* Used when the shopkeeper pay for items, and when
* the priest gives you money for an ale.
*/
void
money2u(mon, amount)
struct monst *mon;
long amount;
{
struct obj *mongold = findgold(mon->minvent, TRUE);
if (amount <= 0) {
impossible("%s payment in money2u!", amount ? "negative" : "zero");
return;
}
if (!mongold || mongold->quan < amount) {
impossible("%s paying without %s money?", a_monnam(mon),
mongold ? "enough" : "");
return;
}
if (mongold->quan > amount)
mongold = splitobj(mongold, amount);
obj_extract_self(mongold);
if (!merge_choice(invent, mongold) && inv_cnt(FALSE) >= 52) {
You("have no room for the money!");
dropy(mongold);
} else {
addinv(mongold);
context.botl = 1;
}
}
STATIC_OVL struct monst *
next_shkp(shkp, withbill)
register struct monst *shkp;
register boolean withbill;
{
for (; shkp; shkp = shkp->nmon) {
if (DEADMONSTER(shkp))
continue;
if (shkp->isshk && (ESHK(shkp)->billct || !withbill))
break;
}
if (shkp) {
if (NOTANGRY(shkp)) {
if (ESHK(shkp)->surcharge)
pacify_shk(shkp);
} else {
if (!ESHK(shkp)->surcharge)
rile_shk(shkp);
}
}
return shkp;
}
/* called in mon.c */
void
shkgone(mtmp)
struct monst *mtmp;
{
struct eshk *eshk = ESHK(mtmp);
struct mkroom *sroom = &rooms[eshk->shoproom - ROOMOFFSET];
struct obj *otmp;
char *p;
int sx, sy;
/* [BUG: some of this should be done on the shop level */
/* even when the shk dies on a different level.] */
if (on_level(&eshk->shoplevel, &u.uz)) {
remove_damage(mtmp, TRUE);
sroom->resident = (struct monst *) 0;
if (!search_special(ANY_SHOP))
level.flags.has_shop = 0;
/* items on shop floor revert to ordinary objects */
for (sx = sroom->lx; sx <= sroom->hx; sx++)
for (sy = sroom->ly; sy <= sroom->hy; sy++)
for (otmp = level.objects[sx][sy]; otmp;
otmp = otmp->nexthere)
otmp->no_charge = 0;
/* Make sure bill is set only when the
dead shk is the resident shk. */
if ((p = index(u.ushops, eshk->shoproom)) != 0) {
setpaid(mtmp);
eshk->bill_p = (struct bill_x *) 0;
/* remove eshk->shoproom from u.ushops */
do {
*p = *(p + 1);
} while (*++p);
}
}
}
void
set_residency(shkp, zero_out)
register struct monst *shkp;
register boolean zero_out;
{
if (on_level(&(ESHK(shkp)->shoplevel), &u.uz))
rooms[ESHK(shkp)->shoproom - ROOMOFFSET].resident =
(zero_out) ? (struct monst *) 0 : shkp;
}
void
replshk(mtmp, mtmp2)
register struct monst *mtmp, *mtmp2;
{
rooms[ESHK(mtmp2)->shoproom - ROOMOFFSET].resident = mtmp2;
if (inhishop(mtmp) && *u.ushops == ESHK(mtmp)->shoproom) {
ESHK(mtmp2)->bill_p = &(ESHK(mtmp2)->bill[0]);
}
}
/* do shopkeeper specific structure munging -dlc */
void
restshk(shkp, ghostly)
struct monst *shkp;
boolean ghostly;
{
if (u.uz.dlevel) {
struct eshk *eshkp = ESHK(shkp);
if (eshkp->bill_p != (struct bill_x *) -1000)
eshkp->bill_p = &eshkp->bill[0];
/* shoplevel can change as dungeons move around */
/* savebones guarantees that non-homed shk's will be gone */
if (ghostly) {
assign_level(&eshkp->shoplevel, &u.uz);
if (ANGRY(shkp) && strncmpi(eshkp->customer, plname, PL_NSIZ))
pacify_shk(shkp);
}
}
}
/* Clear the unpaid bit on a single object and its contents. */
STATIC_OVL void
clear_unpaid_obj(shkp, otmp)
struct monst *shkp;
struct obj *otmp;
{
if (Has_contents(otmp))
clear_unpaid(shkp, otmp->cobj);
if (onbill(otmp, shkp, TRUE))
otmp->unpaid = 0;
}
/* Clear the unpaid bit on all of the objects in the list. */
STATIC_OVL void
clear_unpaid(shkp, list)
struct monst *shkp;
struct obj *list;
{
while (list) {
clear_unpaid_obj(shkp, list);
list = list->nobj;
}
}
/* either you paid or left the shop or the shopkeeper died */
void
setpaid(shkp)
register struct monst *shkp;
{
register struct obj *obj;
register struct monst *mtmp;
clear_unpaid(shkp, invent);
clear_unpaid(shkp, fobj);
clear_unpaid(shkp, level.buriedobjlist);
if (thrownobj)
clear_unpaid_obj(shkp, thrownobj);
if (kickedobj)
clear_unpaid_obj(shkp, kickedobj);
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
clear_unpaid(shkp, mtmp->minvent);
for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon)
clear_unpaid(shkp, mtmp->minvent);
while ((obj = billobjs) != 0) {
obj_extract_self(obj);
dealloc_obj(obj);
}
if (shkp) {
ESHK(shkp)->billct = 0;
ESHK(shkp)->credit = 0L;
ESHK(shkp)->debit = 0L;
ESHK(shkp)->loan = 0L;
}
}
STATIC_OVL long
addupbill(shkp)
register struct monst *shkp;
{
register int ct = ESHK(shkp)->billct;
register struct bill_x *bp = ESHK(shkp)->bill_p;
register long total = 0L;
while (ct--) {
total += bp->price * bp->bquan;
bp++;
}
return total;
}
STATIC_OVL void
call_kops(shkp, nearshop)
register struct monst *shkp;
register boolean nearshop;
{
/* Keystone Kops srt@ucla */
register boolean nokops;
if (!shkp)
return;
if (!Deaf)
pline("An alarm sounds!");
nokops = ((mvitals[PM_KEYSTONE_KOP].mvflags & G_GONE)
&& (mvitals[PM_KOP_SERGEANT].mvflags & G_GONE)
&& (mvitals[PM_KOP_LIEUTENANT].mvflags & G_GONE)
&& (mvitals[PM_KOP_KAPTAIN].mvflags & G_GONE));
if (Is_blackmarket(&u.uz)) {
nokops = ((mvitals[PM_SOLDIER].mvflags & G_GONE) &&
(mvitals[PM_SERGEANT].mvflags & G_GONE) &&
(mvitals[PM_LIEUTENANT].mvflags & G_GONE) &&
(mvitals[PM_CAPTAIN].mvflags & G_GONE));
}
if (!angry_guards(!!Deaf) && nokops) {
if (flags.verbose && !Deaf)
pline("But no one seems to respond to it.");
return;
}
if (nokops)
return;
{
coord mm;
if (nearshop && !Is_blackmarket(&u.uz)) {
/* Create swarm around you, if you merely "stepped out" */
if (flags.verbose)
pline_The("Keystone Kops appear!");
mm.x = u.ux;
mm.y = u.uy;
makekops(&mm);
return;
}
if (flags.verbose && !Is_blackmarket(&u.uz))
pline_The("Keystone Kops are after you!");
/* Create swarm near down staircase (hinders return to level) */
if (Is_blackmarket(&u.uz)) {
struct trap *trap = ftrap;
while (trap) {
if (trap->ttyp == MAGIC_PORTAL) {
mm.x = trap->tx;
mm.y = trap->ty;
}
trap = trap->ntrap;
}
} else {
mm.x = xdnstair;
mm.y = ydnstair;
}
makekops(&mm);
/* Create swarm near shopkeeper (hinders return to shop) */
mm.x = shkp->mx;
mm.y = shkp->my;
makekops(&mm);
}
}
void
blkmar_guards(mtmp)
register struct monst *mtmp;
{
register struct monst *mt;
boolean mesg_given = FALSE; /* Only give message if assistants peaceful */
static boolean rlock = FALSE; /* Prevent recursive calls (via wakeup) */
if (rlock) return;
rlock = TRUE;
/* allow black marketeer to leave his shop */
hot_pursuit(mtmp);
/* wake up assistants */
for (mt = fmon; mt; mt = mt->nmon) {
if (DEADMONSTER(mt)) continue;
/* non-tame named monsters are presumably
* black marketeer's assistants */
else if (mt->mpeaceful &&
((!mt->mtame && has_mname(mt) &&
mt->mpeaceful && mt != mtmp) ||
mt->data == &mons[PM_ARMS_DEALER])) {
if (!mesg_given) {
pline("%s calls for help!", noit_Monnam(mtmp));
mesg_given = TRUE;
bars_around_portal(FALSE);
call_kops(mtmp, FALSE);
}
wakeup(mt, FALSE);
setmangry(mt, FALSE);
}
}
rlock = FALSE;
}
/* look for a portal on the level and add or
* remove iron bars on every adjacent square */
void
bars_around_portal(removebars)
boolean removebars;
{
int x, y, dx, dy;
boolean sawit = FALSE;
struct trap *trap = ftrap;
while (trap) {
if (trap->ttyp == MAGIC_PORTAL) break;
trap = trap->ntrap;
}
if (!trap) return;
if (trap->tx == u.ux && trap->ty == u.uy) return;
for (dx = -1; dx <= 1; dx++)
for (dy = -1; dy <= 1; dy++) {
if (!dx && !dy) continue;
x = trap->tx + dx;
y = trap->ty + dy;
if (removebars) {
if (levl[x][y].typ == IRONBARS) {
dissolve_bars(x,y);
if (cansee(x,y))
sawit = TRUE;
}
} else {
if (!IS_ROCK(levl[x][y].typ) && levl[x][y].typ != IRONBARS) {
levl[x][y].typ = IRONBARS;
newsym(x, y);
if (cansee(x,y))
sawit = TRUE;
}
}
}
if (sawit) {
if (removebars)
pline("The iron bars rise back into the ceiling.");
else
pline("Iron bars drop from the ceiling around the magic portal!");
}
}
/* x,y is strictly inside shop */
char
inside_shop(x, y)
register xchar x, y;
{
register char rno;
rno = levl[x][y].roomno;
if ((rno < ROOMOFFSET) || levl[x][y].edge || !IS_SHOP(rno - ROOMOFFSET))
rno = NO_ROOM;
return rno;
}
void
u_left_shop(leavestring, newlev)
char *leavestring;
boolean newlev;
{
struct monst *shkp;
struct eshk *eshkp;
/*
* IF player
* ((didn't leave outright) AND
* ((he is now strictly-inside the shop) OR
* (he wasn't strictly-inside last turn anyway)))
* THEN (there's nothing to do, so just return)
*/
if (!*leavestring && (!levl[u.ux][u.uy].edge || levl[u.ux0][u.uy0].edge))
return;
shkp = shop_keeper(*u.ushops0);
if (!shkp || !inhishop(shkp))
return; /* shk died, teleported, changed levels... */
eshkp = ESHK(shkp);
if (!eshkp->billct && !eshkp->debit) /* bill is settled */
return;
if (!*leavestring && !muteshk(shkp)) {
/*
* Player just stepped onto shop-boundary (known from above logic).
* Try to intimidate him into paying his bill
*/
if (!Deaf && !muteshk(shkp))
verbalize(NOTANGRY(shkp) ? "%s! Please pay before leaving."
: "%s! Don't you leave without paying!",
plname);
else
pline("%s %s that you need to pay before leaving%s",
Shknam(shkp),
NOTANGRY(shkp) ? "points out" : "makes it clear",
NOTANGRY(shkp) ? "." : "!");
return;
}
if (rob_shop(shkp)) {
if (Is_blackmarket(&u.uz))
blkmar_guards(shkp);
else
call_kops(shkp, (!newlev && levl[u.ux0][u.uy0].edge));
}
}
/* robbery from outside the shop via telekinesis or grappling hook */
void
remote_burglary(x, y)
xchar x, y;
{
struct monst *shkp;
struct eshk *eshkp;
shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
if (!shkp || !inhishop(shkp))
return; /* shk died, teleported, changed levels... */
eshkp = ESHK(shkp);
if (!eshkp->billct && !eshkp->debit) /* bill is settled */
return;
if (rob_shop(shkp)) {
if (Is_blackmarket(&u.uz))
blkmar_guards(shkp);
else
/*[might want to set 2nd arg based on distance from shop doorway]*/
call_kops(shkp, FALSE);
}
}
/* shop merchandise has been taken; pay for it with any credit available;
return false if the debt is fully covered by credit, true otherwise */
STATIC_OVL boolean
rob_shop(shkp)
struct monst *shkp;
{
struct eshk *eshkp;
long total;
eshkp = ESHK(shkp);
rouse_shk(shkp, TRUE);
total = (addupbill(shkp) + eshkp->debit);
if (eshkp->credit >= total) {
Your("credit of %ld %s is used to cover your shopping bill.",
eshkp->credit, currency(eshkp->credit));
total = 0L; /* credit gets cleared by setpaid() */
} else {
You("escaped the shop without paying!");
total -= eshkp->credit;
}
setpaid(shkp);
if (!total)
return FALSE;
/* by this point, we know an actual robbery has taken place */
eshkp->robbed += total;
You("stole %ld %s worth of merchandise.", total, currency(total));
if (!Role_if(PM_ROGUE)) /* stealing is unlawful */
adjalign(-sgn(u.ualign.type));
hot_pursuit(shkp);
return TRUE;
}
/* give a message when entering an untended shop (caller has verified that) */
STATIC_OVL void
deserted_shop(enterstring)
/*const*/ char *enterstring;
{
struct monst *mtmp;
struct mkroom *r = &rooms[(int) *enterstring - ROOMOFFSET];
int x, y, m = 0, n = 0;
for (x = r->lx; x <= r->hx; ++x)
for (y = r->ly; y <= r->hy; ++y) {
if (x == u.ux && y == u.uy)
continue;
if ((mtmp = m_at(x, y)) != 0) {
++n;
if (sensemon(mtmp) || ((M_AP_TYPE(mtmp) == M_AP_NOTHING
|| M_AP_TYPE(mtmp) == M_AP_MONSTER)
&& canseemon(mtmp)))
++m;
}
}
if (Blind && !(Blind_telepat || Detect_monsters))
++n; /* force feedback to be less specific */
pline("This shop %s %s.", (m < n) ? "seems to be" : "is",
!n ? "deserted" : "untended");
}
void
u_entered_shop(enterstring)
char *enterstring;
{
register int rt;
register struct monst *shkp;
register struct eshk *eshkp;
static char empty_shops[5];
if (!*enterstring)
return;
if (!(shkp = shop_keeper(*enterstring))) {
if (!index(empty_shops, *enterstring)
&& in_rooms(u.ux, u.uy, SHOPBASE)
!= in_rooms(u.ux0, u.uy0, SHOPBASE))
deserted_shop(enterstring);
Strcpy(empty_shops, u.ushops);
u.ushops[0] = '\0';
return;
}
eshkp = ESHK(shkp);
if (!inhishop(shkp)) {
/* dump core when referenced */
eshkp->bill_p = (struct bill_x *) -1000;
if (!index(empty_shops, *enterstring))
deserted_shop(enterstring);
Strcpy(empty_shops, u.ushops);
u.ushops[0] = '\0';
return;
}
eshkp->bill_p = &(eshkp->bill[0]);
if ((!eshkp->visitct || *eshkp->customer)
&& strncmpi(eshkp->customer, plname, PL_NSIZ)) {
/* You seem to be new here */
eshkp->visitct = 0;
eshkp->following = 0;
(void) strncpy(eshkp->customer, plname, PL_NSIZ);
pacify_shk(shkp);
}
if (muteshk(shkp) || eshkp->following)
return; /* no dialog */
if (Invis) {
pline("%s senses your presence.", shkname(shkp));
if (!Deaf && !muteshk(shkp) && !Is_blackmarket(&u.uz))
verbalize("Invisible customers are not welcome!");
else
pline("%s stands firm as if %s knows you are there.",
Shknam(shkp), noit_mhe(shkp));
return;
}
/* Visible striped prison shirt */
if ((uarmu && (uarmu->otyp == STRIPED_SHIRT)) && !uarm && !uarmc) {
eshkp->pbanned = TRUE;
}
rt = rooms[*enterstring - ROOMOFFSET].rtype;
if (ANGRY(shkp)) {
if (!Deaf && !muteshk(shkp))
verbalize("So, %s, you dare return to %s %s?!", plname,
s_suffix(shkname(shkp)), shtypes[rt - SHOPBASE].name);
else
pline("%s seems %s over your return to %s %s!",
Shknam(shkp), angrytexts[rn2(SIZE(angrytexts))],
noit_mhis(shkp), shtypes[rt - SHOPBASE].name);
} else if (eshkp->robbed) {
if (!Deaf)
pline("%s mutters imprecations against shoplifters.",
Shknam(shkp));
else
pline("%s is combing through %s inventory list.",
Shknam(shkp), noit_mhis(shkp));
} else {
if (!Deaf && !muteshk(shkp) && !eshkp->pbanned)
verbalize("%s, %s! Welcome%s to %s %s!", Hello(shkp), plname,
eshkp->visitct++ ? " again" : "",
s_suffix(shkname(shkp)), shtypes[rt - SHOPBASE].name);
else
You("enter %s %s%s!",
s_suffix(shkname(shkp)),
shtypes[rt - SHOPBASE].name,
eshkp->visitct++ ? " again" : "");
}
/* can't do anything about blocking if teleported in */
if (!inside_shop(u.ux, u.uy) && !Is_blackmarket(&u.uz)) {
boolean should_block;
int cnt;
const char *tool;
struct obj *pick = carrying(PICK_AXE),
*mattock = carrying(DWARVISH_MATTOCK);
if (pick || mattock) {
cnt = 1; /* so far */
if (pick && mattock) { /* carrying both types */
tool = "digging tool";
cnt = 2; /* `more than 1' is all that matters */
} else if (pick) {
tool = "pick-axe";
/* hack: `pick' already points somewhere into inventory */
while ((pick = pick->nobj) != 0)
if (pick->otyp == PICK_AXE)
++cnt;
} else { /* assert(mattock != 0) */
tool = "mattock";
while ((mattock = mattock->nobj) != 0)
if (mattock->otyp == DWARVISH_MATTOCK)
++cnt;
/* [ALI] Shopkeeper identifies mattock(s) */
if (!Blind)
makeknown(DWARVISH_MATTOCK);
}
if (!Deaf && !muteshk(shkp))
verbalize(NOTANGRY(shkp)
? "Will you please leave your %s%s outside?"
: "Leave the %s%s outside.",
tool, plur(cnt));
else
pline("%s %s to let you in with your %s%s.",
Shknam(shkp),
NOTANGRY(shkp) ? "is hesitant" : "refuses",
tool, plur(cnt));
should_block = TRUE;
} else if (eshkp->pbanned && !ANGRY(shkp)) {
verbalize("I don't sell to your kind here.");
should_block = TRUE;
} else if (u.usteed) {
if (!Deaf && !muteshk(shkp))
verbalize(NOTANGRY(shkp) ? "Will you please leave %s outside?"
: "Leave %s outside.",
y_monnam(u.usteed));
else
pline("%s %s to let you in while you're riding %s.",
Shknam(shkp),
NOTANGRY(shkp) ? "doesn't want" : "refuses",
y_monnam(u.usteed));
should_block = TRUE;
} else {
should_block =
(Fast && (sobj_at(PICK_AXE, u.ux, u.uy)
|| sobj_at(DWARVISH_MATTOCK, u.ux, u.uy)));
}
if (should_block)
(void) dochug(shkp); /* shk gets extra move */
}
return;
}
/* called when removing a pick-axe or mattock from a container */
void
pick_pick(obj)
struct obj *obj;
{
struct monst *shkp;
if (obj->unpaid || !is_pick(obj))
return;
shkp = shop_keeper(*u.ushops);
if (shkp && inhishop(shkp)) {
static NEARDATA long pickmovetime = 0L;
/* if you bring a sack of N picks into a shop to sell,
don't repeat this N times when they're taken out */
if (moves != pickmovetime) {
if (!Deaf && !muteshk(shkp))
verbalize("You sneaky %s! Get out of here with that pick!",
cad(FALSE));
else
pline("%s %s your pick!",
Shknam(shkp),
haseyes(shkp->data) ? "glares at"
: "is dismayed because of");
}
pickmovetime = moves;
}
}
/*
Decide whether two unpaid items are mergable; caller is responsible for
making sure they're unpaid and the same type of object; we check the price
quoted by the shopkeeper and also that they both belong to the same shk.
*/
boolean
same_price(obj1, obj2)
struct obj *obj1, *obj2;
{
register struct monst *shkp1, *shkp2;
struct bill_x *bp1 = 0, *bp2 = 0;
boolean are_mergable = FALSE;
/* look up the first object by finding shk whose bill it's on */
for (shkp1 = next_shkp(fmon, TRUE); shkp1;
shkp1 = next_shkp(shkp1->nmon, TRUE))
if ((bp1 = onbill(obj1, shkp1, TRUE)) != 0)
break;
/* second object is probably owned by same shk; if not, look harder */
if (shkp1 && (bp2 = onbill(obj2, shkp1, TRUE)) != 0) {
shkp2 = shkp1;
} else {
for (shkp2 = next_shkp(fmon, TRUE); shkp2;
shkp2 = next_shkp(shkp2->nmon, TRUE))
if ((bp2 = onbill(obj2, shkp2, TRUE)) != 0)
break;
}
if (!bp1 || !bp2)
impossible("same_price: object wasn't on any bill!");
else
are_mergable = (shkp1 == shkp2 && bp1->price == bp2->price);
return are_mergable;
}
/*
* Figure out how much is owed to a given shopkeeper.
* At present, we ignore any amount robbed from the shop, to avoid
* turning the `$' command into a way to discover that the current
* level is bones data which has a shk on the warpath.
*/
STATIC_OVL long
shop_debt(eshkp)
struct eshk *eshkp;
{
struct bill_x *bp;
int ct;
long debt = eshkp->debit;
for (bp = eshkp->bill_p, ct = eshkp->billct; ct > 0; bp++, ct--)
debt += bp->price * bp->bquan;
return debt;
}
/* called in response to the `$' command */
void
shopper_financial_report()
{
struct monst *shkp, *this_shkp = shop_keeper(inside_shop(u.ux, u.uy));
struct eshk *eshkp;
long amt;
int pass;
eshkp = this_shkp ? ESHK(this_shkp) : 0;
if (eshkp && !(eshkp->credit || shop_debt(eshkp))) {
You("have no credit or debt in here.");
this_shkp = 0; /* skip first pass */
}
/* pass 0: report for the shop we're currently in, if any;
pass 1: report for all other shops on this level. */
for (pass = this_shkp ? 0 : 1; pass <= 1; pass++)
for (shkp = next_shkp(fmon, FALSE); shkp;
shkp = next_shkp(shkp->nmon, FALSE)) {
if ((shkp != this_shkp) ^ pass)
continue;
eshkp = ESHK(shkp);
if ((amt = eshkp->credit) != 0)
You("have %ld %s credit at %s %s.", amt, currency(amt),
s_suffix(shkname(shkp)),
shtypes[eshkp->shoptype - SHOPBASE].name);
else if (shkp == this_shkp)
You("have no credit in here.");
if ((amt = shop_debt(eshkp)) != 0)
You("owe %s %ld %s.", shkname(shkp), amt, currency(amt));
else if (shkp == this_shkp)
You("don't owe any money here.");
}
}
int
inhishop(mtmp)
register struct monst *mtmp;
{
struct eshk *eshkp = ESHK(mtmp);
return (index(in_rooms(mtmp->mx, mtmp->my, SHOPBASE), eshkp->shoproom)
&& on_level(&eshkp->shoplevel, &u.uz));
}
struct monst *
shop_keeper(rmno)
char rmno;
{
struct monst *shkp;
shkp = (rmno >= ROOMOFFSET) ? rooms[rmno - ROOMOFFSET].resident : 0;
if (shkp) {
if (has_eshk(shkp)) {
if (NOTANGRY(shkp)) {
if (ESHK(shkp)->surcharge)
pacify_shk(shkp);
} else {
if (!ESHK(shkp)->surcharge)
rile_shk(shkp);
}
} else {
/* would have segfaulted on ESHK dereference previously */
impossible("%s? (rmno=%d, rtype=%d, mnum=%d, \"%s\")",
shkp->isshk ? "shopkeeper career change"
: "shop resident not shopkeeper",
(int) rmno,
(int) rooms[rmno - ROOMOFFSET].rtype,
shkp->mnum,
/* [real shopkeeper name is kept in ESHK, not MNAME] */
has_mname(shkp) ? MNAME(shkp) : "anonymous");
/* not sure if this is appropriate, because it does nothing to
correct the underlying rooms[].resident issue but... */
return (struct monst *) 0;
}
}
return shkp;
}
boolean
tended_shop(sroom)
struct mkroom *sroom;
{
struct monst *mtmp = sroom->resident;
return !mtmp ? FALSE : (boolean) inhishop(mtmp);
}
STATIC_OVL struct bill_x *
onbill(obj, shkp, silent)
struct obj *obj;
struct monst *shkp;
boolean silent;
{
if (shkp) {
register struct bill_x *bp = ESHK(shkp)->bill_p;
register int ct = ESHK(shkp)->billct;
while (--ct >= 0)
if (bp->bo_id == obj->o_id) {
if (!obj->unpaid)
pline("onbill: paid obj on bill?");
return bp;
} else
bp++;
}
if (obj->unpaid && !silent)
pline("onbill: unpaid obj not on bill?");
return (struct bill_x *) 0;
}
/* check whether an object or any of its contents belongs to a shop */
boolean
is_unpaid(obj)
struct obj *obj;
{
return (boolean) (obj->unpaid
|| (Has_contents(obj) && count_unpaid(obj->cobj)));
}
/* Delete the contents of the given object. */
void
delete_contents(obj)