forked from dungeons-of-moria/icmoria
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.c
2054 lines (1841 loc) · 59.7 KB
/
store.c
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
/* store.c */
/**/
#include "imoria.h"
#include "dungeon.h"
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void store_init()
{
// { Initializes the stores with owners -RAK- }
int i1, i2, i3;
ENTER("store_init","s");
i1 = MAX_OWNERS / MAX_STORES;
for (i2 = 0; i2 < MAX_STORES; i2++) {
stores[i2].owner = MAX_STORES*(randint(i1)-1) + i2;
stores[i2].insult_cur = 0;
stores[i2].store_open.year = 0;
stores[i2].store_open.month = 0;
stores[i2].store_open.day = 0;
stores[i2].store_open.hour = 0;
stores[i2].store_open.secs = 0;
stores[i2].store_ctr = 0;
for (i3=0; i3 <= STORE_INVEN_MAX; i3++) {
stores[i2].store_inven[i3].sitem = blank_treasure;
stores[i2].store_inven[i3].scost = 0;
} /* end for i3 */
} /* end for i2 */
// for (i2 = 0; i2 < max_stores; i2++) {
// printf("store owner[%ld] = %s\n", i2, owners[stores[i2].owner].owner_name);
// }
LEAVE("store_init","s");
} /* end store_init */
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void bank_init()
{
// { Initialize the bank -DMF- }
integer starting;
starting = (randint(2000) + 1000) * 1000;
bank[IRON] = starting div 8;
bank[COPPER] = starting div 30;
bank[SILVER] = starting div 50;
bank[GOLD] = starting div 250;
bank[PLATINUM] = starting div 5000;
bank[MITHRIL] = starting div 100000;
bank[TOTAL_] = (bank[MITHRIL] * coin_value[MITHRIL] + bank[PLATINUM] *
coin_value[PLATINUM]) div GOLD_VALUE + bank[GOLD];
// for(starting = TOTAL_; starting <= MITHRIL; starting++) {
// printf("bank[%ld] = %ld\n", starting, bank[starting]);
// }
}; /* end bank_init */
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void sm__rndcash(integer *amt, integer target)
{
*amt = (199*(*amt)+randint(2*target)) div 200;
}
//////////////////////////////////////////////////////////////////////
void store_maint()
{
/*{ Initialize and up-keep the store's inventory. -RAK- }*/
integer i1,i2,cnt,store_ctr;
/*printf ("\n enter store_maint\n"); fflush(stdout);*/
for ( ; stores[S_BLACK_MARKET].store_ctr > 0 ; ) {
store_destroy(S_BLACK_MARKET,stores[S_BLACK_MARKET].store_ctr,false);
}
for (i1 = 0; i1 < MAX_STORES; i1++) {
stores[i1].insult_cur = 0;
store_ctr = stores[i1].store_ctr;
if (store_ctr > STORE_MAX_INVEN) {
/* too much stuff */
for (i2=0 , cnt=(store_ctr-STORE_MAX_INVEN+2); i2 < cnt; i2++) {
store_destroy(i1,randint(stores[i1].store_ctr),false);
}
} else if (store_ctr < STORE_MIN_INVEN) {
/* make new stuff */
for (i2=0 , cnt=(STORE_MIN_INVEN-store_ctr+2); i2 < cnt; i2++) {
store_create(i1);
}
} else {
/* make some, ruin some */
for (i2=0 , cnt=(1+randint(STORE_TURN_AROUND)); i2 < cnt; i2++) {
store_destroy(i1,randint(stores[i1].store_ctr),true);
}
for (i2=0 , cnt=(1+randint(STORE_TURN_AROUND)); i2 < cnt; i2++) {
store_create(i1);
}
}
store_ctr = stores[i1].store_ctr;
if (i1 == S_INN) {
if (randint(8) == 1) {
for (i2 = 0; i2 < store_ctr; i2++) {
store_destroy(i1,i2,false);
}
for (i2 = 0; i2 < STORE_MIN_INVEN+2; i2++) {
store_create(i1);
}
}
}
} /* end for */
sm__rndcash(&(bank[IRON]),500000);
sm__rndcash(&(bank[COPPER]),200000);
sm__rndcash(&(bank[SILVER]),100000);
sm__rndcash(&(bank[GOLD]),50000);
sm__rndcash(&(bank[PLATINUM]),5000);
sm__rndcash(&(bank[MITHRIL]),1000);
bank[TOTAL_] = (bank[MITHRIL] * MITHRIL_VALUE + bank[PLATINUM] *
PLATINUM_VALUE) div GOLD_VALUE + bank[GOLD];
// printf ("\n exit store_maint\n"); fflush(stdout);
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void store_create(integer store_num)
{
/*{ Creates an item and inserts it into store's inven -RAK- }*/
integer i1,tries,cur_pos,dummy;
// printf ("\n enter store_create (%ld)",store_num); fflush(stdout);
tries = 0;
popt(&cur_pos);
//with stores[store_num] do;
do {
if (store_num != S_BLACK_MARKET) {
i1 = store_choice[store_num][randint(STORE_CHOICES)-1];
t_list[cur_pos] = inventory_init[i1];
magic_treasure(cur_pos,obj_town_level,false);
} else {
/* black market item */
do {
t_list[cur_pos] = object_list[get_obj_num(obj_town_level*2+
randint(obj_town_level*15),
PLACE_OBJECT_TRIES*2)];
magic_treasure(cur_pos,
obj_town_level*2 + randint(obj_town_level*15),true);
} while (t_list[cur_pos].cost < 500 * GOLD_VALUE);
t_list[cur_pos].cost *= 2;
t_list[cur_pos].flags2 |= Blackmarket_bit;
}
inven_temp->data = t_list[cur_pos];
if (store_check_num(store_num)) {
//with t_list[cur_pos] do;
if (t_list[cur_pos].cost > 0) { /*{ Item must be good }*/
if (t_list[cur_pos].cost <
(owners[stores[store_num].owner].max_cost * GOLD_VALUE)) {
store_carry(store_num,&dummy);
tries = 10;
}
}
}
tries++;
} while(!(tries > 3));
pusht(cur_pos);
// printf ("\n exit store_create"); fflush(stdout);
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void store_destroy(integer store_num,integer item_val,boolean one_of)
{
/*{ Destroy an item in the stores inventory. Note that if }*/
/*{ 'one_of' is false, an entire slot is destroyed -RAK- }*/
integer i2, store_ctr;
//with stores[store_num] do;
inven_temp->data = stores[store_num].store_inven[item_val].sitem;
//with stores[store_num].store_inven[item_val].sitem do;
if ((stores[store_num].store_inven[item_val].sitem.number > 1) &&
(stores[store_num].store_inven[item_val].sitem.subval < 512) &&
(one_of)) {
inven_temp->data.number = 1;
stores[store_num].store_inven[item_val].sitem.number--;
} else {
store_ctr = stores[store_num].store_ctr;
for (i2 = item_val; i2 < store_ctr; i2++) {
stores[store_num].store_inven[i2] = stores[store_num].store_inven[i2+1];
}
stores[store_num].store_inven[store_ctr].sitem = blank_treasure;
stores[store_num].store_inven[store_ctr].scost = 0;
stores[store_num].store_ctr--;
}
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void sc__insert(integer store_num,integer pos,integer icost)
{
/*{ Insert INVEN_MAX at given location }*/
integer i1;
//with stores[store_num] do;
for (i1 = stores[store_num].store_ctr; i1 >= pos; i1--) {
stores[store_num].store_inven[i1+1] = stores[store_num].store_inven[i1];
}
stores[store_num].store_inven[pos].sitem = inven_temp->data;
stores[store_num].store_inven[pos].scost = -icost * GOLD_VALUE;
stores[store_num].store_ctr++;
};
//////////////////////////////////////////////////////////////////////
void store_carry(integer store_num, integer *ipos)
{
/*{ Add the item in INVEN_MAX to stores inventory. -RAK- }*/
integer item_num,item_val;
integer typ,subt,icost,dummy;
boolean flag;
/*{ Store_carry routine }*/
*ipos = 0;
identify(&(inven_temp->data));
unquote(inven_temp->data.name);
known1(inven_temp->data.name);
known2(inven_temp->data.name);
sell_price(store_num,&icost,&dummy,&(inven_temp->data));
if (icost > 0) {
//with inven_temp->data do;
//with stores[store_num] do;
item_val = 0;
item_num = inven_temp->data.number;
typ = inven_temp->data.tval;
subt = inven_temp->data.subval;
flag = false;
do {
item_val++;
//with store_inven[item_val].sitem do;
if (typ == stores[store_num].store_inven[item_val].sitem.tval) {
if (subt == stores[store_num].store_inven[item_val].sitem.subval) {
/*{ Adds to other item }*/
if (subt > 255) {
if (stores[store_num].store_inven[item_val].sitem.number < 24) {
stores[store_num].store_inven[item_val].sitem.number += item_num;
}
flag = true;
}
}
} else if (typ > stores[store_num].store_inven[item_val].sitem.tval) {
/*{ Insert into list }*/
sc__insert(store_num,item_val,icost);
flag = true;
*ipos = item_val;
}
/* end of thrid with */
} while (!((item_val >= stores[store_num].store_ctr) || (flag)));
if (!(flag)) { /*{ Becomes last item in list }*/
sc__insert(store_num,stores[store_num].store_ctr+1,icost);
*ipos = stores[store_num].store_ctr;
}
} /* end if icost */
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
boolean store_check_num(integer store_num)
{
/*{ Check to see if he will be carrying too many objects -RAK- }*/
integer i1;
boolean return_value = false;
//with stores[store_num] do;
if (stores[store_num].store_ctr < STORE_INVEN_MAX) {
return_value = true;
} else if ((inven_temp->data.subval > 255) &&
(inven_temp->data.subval < 512)) {
for (i1 = 0; i1 < stores[store_num].store_ctr; i1++) {
//with store_inven[i1].store_inven[i1].sitem do;
if (stores[store_num].store_inven[i1].sitem.tval ==
inven_temp->data.tval) {
if (stores[store_num].store_inven[i1].sitem.subval ==
inven_temp->data.subval) {
return_value = true;
}
}
} /* end for */
}
return return_value;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
integer sell_price (integer snum,integer *max_sell,integer *min_sell,
treasure_type *item)
{
/*{ Asking price for an item -RAK- }*/
integer i1;
integer return_value = 0;
//with stores[snum] do;
i1 = item_value(item);
if (item->cost > 0) {
i1 += trunc(i1*rgold_adj[owners[stores[snum].owner].owner_race][py.misc.prace]);
if (i1 < 1) {
i1 = 1;
}
*max_sell = trunc(i1*(1+owners[stores[snum].owner].max_inflate));
*min_sell = trunc(i1*(1+owners[stores[snum].owner].min_inflate));
if (*min_sell > *max_sell) {
*min_sell = *max_sell;
}
return_value = i1;
} else { /*{quack}*/
*max_sell = 0;
*min_sell = 0;
return_value = 0;
}
return return_value;
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
integer iv__search_list(integer x1, integer x2)
{
integer i1,i2;
i1 = 0;
i2 = 0;
do {
i1++;
if ((object_list[i1].tval == x1) && (object_list[i1].subval == x2)) {
i2 = object_list[i1].cost;
}
} while (!((i1 == MAX_OBJECTS) || (i2 > 0)));
return (i2 div GOLD_VALUE);
};
//////////////////////////////////////////////////////////////////////
integer item_value(treasure_type *item)
{
/*{ Returns the value for any given object -RAK- }*/
integer return_value;
//with item do;
return_value = item->cost div GOLD_VALUE;
switch (item->tval) {
/*{ Weapons and armor }*/
case bow_crossbow_or_sling:
case hafted_weapon:
case pole_arm:
case sword:
case dagger:
case maul:
case boots:
case gloves_and_gauntlets:
case gem_helm:
case Cloak:
case helm:
case shield:
case hard_armor:
case soft_armor:
if (strstr(item->name,"^") != NULL) {
return_value = iv__search_list(item->tval,item->subval)*item->number;
} else {
switch (item->tval) {
case bow_crossbow_or_sling:
case hafted_weapon:
case pole_arm:
case sword:
case dagger:
case maul:
if (item->tohit < 0) {
return_value = 0;
} else if (item->todam < 0) {
return_value = 0;
} else if (item->toac < 0) {
return_value = 0;
} else {
return_value = ((item->cost div GOLD_VALUE +
(item->tohit+item->todam+item->toac)*100) *
item->number);
}
break;
default:
if (item->toac < 0) {
return_value = 0;
} else {
return_value = ((item->cost div GOLD_VALUE +item->toac*100) *
item->number);
}
break;
} /* end switch */
}
break;
/*{ Ammo }*/
case sling_ammo:
case bolt:
case arrow:
case spike:
if (strstr(item->name,"^") != NULL) {
return_value = iv__search_list(item->tval,1)*(item->number);
} else {
if (item->tohit < 0) {
return_value = 0;
} else if (item->todam < 0) {
return_value = 0;
} else if (item->toac < 0) {
return_value = 0;
} else {
return_value = ((item->cost div GOLD_VALUE +
(item->tohit+item->todam+item->toac)*10)*
(item->number));
}
}
break;
/*{ Potions, Scrolls, and Food }*/
case scroll1:
case scroll2:
case potion1:
case potion2:
case Food:
if (strstr(item->name,"|") != NULL) {
switch (item->tval) {
case scroll1:
case scroll2:
return_value = 20; break;
case potion1:
case potion2:
return_value = 20; break;
case Food:
return_value = 1; break;
}
}
break;
/*{ Rings and amulets }*/
case amulet:
case ring:
if (strstr(item->name,"|") != NULL) {
switch (item->tval) {
case amulet:
return_value = 45; break;
case ring:
return_value = 45; break;
}
} else if (strstr(item->name,"^") != NULL) {
return_value = (item->cost > 0) ? (item->cost div GOLD_VALUE) : 0;
} else {
return_value = (item->cost > 0) ? ((item->cost div GOLD_VALUE) +
trunc(item->cost/COST_ADJ/20.0)*(item->tohit +
item->todam + item->toac + 2*item->p1)) : 0;
}
break;
/*{ Horns and Chimes }*/
case chime:
case horn:
if (strstr(item->name,"|") != NULL) {
switch (item->tval) {
case chime:
return_value = 50; break;
case horn:
return_value = 80; break;
}
} else if (strstr(item->name,"^") == NULL) {
return_value = ((item->cost div GOLD_VALUE) +
trunc(item->cost/COST_ADJ/20.0)*(item->p1));
}
break;
/* { Wands rods, and staffs}*/
case staff:
case rod:
case wand:
if (strstr(item->name,"|") != NULL) {
switch (item->tval) {
case staff:
return_value = 70; break;
case rod:
return_value = 60; break;
case wand:
return_value = 50; break;
}
} else if (strstr(item->name,"^") == NULL) {
return_value = ((item->cost div GOLD_VALUE) +
trunc(item->cost/COST_ADJ/20.0)*(item->p1));
}
break;
/*{Gems and jewelry of all types}*/
case valuable_jewelry:
case valuable_gems:
if (strstr(item->name,"|") != NULL) {
switch (item->tval) {
case valuable_jewelry:
return_value = 20; break;
case valuable_gems:
return_value = 20; break;
}
} else if (strstr(item->name,"^") == NULL) {
return_value = (item->cost div GOLD_VALUE);
}
break;
} /* end switch */
return return_value;
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
boolean check_store_hours(integer st,integer sh)
{
/*{ Check to see if a store is open, message when closed -DMF- }*/
/* st is the S_GENERAL or whatever store it is */
/* sh is the same as st, or -1 for the unnamed stores (S_TRADE_POST and up)*/
string name,prop;
vtype out_val;
char ope;
boolean flag;
boolean return_value = false;
if (sh != -1) {
//with stores[sh].store_open do;
//with py.misc do;
flag = ((PM.cur_age.year > stores[sh].store_open.year) ||
((PM.cur_age.year == stores[sh].store_open.year) &&
((PM.cur_age.month > stores[sh].store_open.month) ||
((PM.cur_age.month == stores[sh].store_open.month) &&
((PM.cur_age.day > stores[sh].store_open.day) ||
((PM.cur_age.day == stores[sh].store_open.day) &&
((PM.cur_age.hour > stores[sh].store_open.hour) ||
((PM.cur_age.hour == stores[sh].store_open.hour) &&
((PM.cur_age.secs > stores[sh].store_open.secs))))))))));
} else {
flag = true;
sh = st;
}
if (flag) {
strcpy(name, store_door[st].name);
insert_str(name,"the entrance to the ","");
ope = store_hours[sh][PM.cur_age.day % 7 + 0] /* was + 1 */
[PM.cur_age.hour div 2 + 0]; /* was + 1 */
switch (ope) {
case ' ' : return_value = true; break;
case 'N' :
case 'W' :
case 'D' :
switch (ope) {
case 'N' : strcpy(prop,"night."); break;
case 'W' : strcpy(prop,"weekend."); break;
case 'D' : strcpy(prop,"day."); break;
}
if (wizard2) {
msg_print("Being a wizard, you break into the shop.");
msg_print("");
return_value = true;
} else {
sprintf(out_val, "Sorry, the %s is closed for the %s", name, prop);
msg_print(out_val);
return_value = false;
}
break;
case 'B' :
sprintf(prop, "Do you wish to play %ld gold to bribe the owner?",
store_bribe[st]);
if (get_yes_no(prop)) {
if (py.misc.money[TOTAL_] >= store_bribe[st]) {
subtract_money(store_bribe[st]*GOLD_VALUE,false);
msg_print("The owner reluctantly lets you in.");
msg_print("");
return_value = true;
} else {
return_value = false;
msg_print("You haven't the money to bribe the owner!");
}
} else {
return_value = false;
msg_print("The owner complains bitterly about being woken up for no reason.");
}
break;
default:
return_value = false;
}
} else {
msg_print("The doors are locked.");
}
return return_value;
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void check_store_hours_and_enter(integer st, integer sh, integer store_num)
{
/* st is the S_GENERAL or whatever store it is */
/* sh is the same as st, or -1 for the unnamed stores (S_TRADE_POST and up)*/
/* store_num should probably always be the same as st */
if (check_store_hours(st, sh)) {
enter_store(store_num);
}
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void st__reset_flag (integer time_spent, integer *flag)
{
if (*flag > 1) {
(*flag) -= time_spent;
if (*flag < 1) {
*flag = 1;
}
}
};
//////////////////////////////////////////////////////////////////////
void spend_time(integer days_spent, vtype place,boolean whole_days)
{
/*{ if not whole_days then it is actually turns... }*/
integer mornings,time_spent,turns_today,t2,i1;
real regen_percent;
boolean new_screen;
vtype out_val;
//with py.misc.cur_age do;
turns_today = PM.cur_age.hour*400 + PM.cur_age.secs;
if (!whole_days) {
time_spent = days_spent; /*{if a 6:00 threshold is passed}*/
new_screen = ((turns_today + time_spent + 2400) div 4800) >
((turns_today + 2400) div 4800);
mornings = (turns_today + time_spent - 2400) div 9600 -
(turns_today - 2400) div 9600;
days_spent = 0;
} else {
time_spent = DAY_LENGTH * days_spent - turns_today;
new_screen = true;
mornings = days_spent;
}
switch (days_spent) {
case 0 :
PM.cur_age.secs += time_spent;
PM.cur_age.hour += PM.cur_age.secs div 400;
PM.cur_age.secs = PM.cur_age.secs % 400;
add_days(&(PM.cur_age),PM.cur_age.hour div 24);
PM.cur_age.hour = PM.cur_age.hour % 24;
break;
case 1 :
if (PM.cur_age.hour < 6) {
sprintf(out_val, "You spend the remainder of the night %s", place);
msg_print(out_val);
PM.cur_age.hour = 8; /*{why get up before shops open?}*/
PM.cur_age.secs = randint(400) - 1;
time_spent = (time_spent - DAY_LENGTH +
400*PM.cur_age.hour + PM.cur_age.secs);
} else {
sprintf(out_val, "You spend the night %s", place);
msg_print(out_val);
PM.cur_age.hour = 8;
add_days(&(PM.cur_age),1);
PM.cur_age.secs = randint(400) - 1;
time_spent += 400*PM.cur_age.hour + PM.cur_age.secs;
}
break;
case 3 :
msg_print("You spend three days in the inn.");
// 10/26/00 --JEB. what the hell was "28+randint(3)" doing in this context?
// add_days(&(PM.cur_age),28+randint(3));
add_days(&(PM.cur_age),3);
PM.cur_age.hour = 8 + randint(4);
PM.cur_age.secs = randint(400) - 1;
time_spent += 400*PM.cur_age.hour + PM.cur_age.secs;
break;
case 7 :
msg_print("You spend the week in the inn.");
add_days(&(PM.cur_age),7);
PM.cur_age.hour = 8 + randint(4);
PM.cur_age.secs = randint(400) - 1;
time_spent += 400*PM.cur_age.hour + PM.cur_age.secs;
break;
}
put_qio();
turn += time_spent;
turn_counter += QUEST_DELAY;
if (new_screen) {
sleep_(1);
}
//with py.flags do;
for (t2 = time_spent; (PF.poisoned > 0) && (t2 > 0);) {
PF.poisoned--;
time_spent--;
switch (con_adj()) {
case -4: take_hit(4,"poison"); break;
case -3: case -2: take_hit(3,"poison"); break;
case -1: take_hit(2,"poison"); break;
case 0: take_hit(1,"poison"); break;
case 1: case 2: case 3:
if ((t2 % 2) == 0) {
take_hit(1,"poison");
}
break;
case 4: case 5:
if ((t2 % 3) == 0) {
take_hit(1,"poison.");
}
break;
case 6:
if ((t2 % 4) == 0) {
take_hit(1,"poison.");
}
break;
} /* end switch */
if (PF.poisoned == 0) {
PF.status &= ~IS_POISONED;
msg_print("You feel better.");
put_qio();
}
} /* end for */
st__reset_flag (time_spent, &(PF.blind) ) ;
st__reset_flag (time_spent, &(PF.confused) ) ;
st__reset_flag (time_spent, &(PF.protection) ) ;
st__reset_flag (time_spent, &(PF.fast) ) ;
st__reset_flag (time_spent, &(PF.slow) ) ;
st__reset_flag (time_spent, &(PF.afraid) ) ;
st__reset_flag (time_spent, &(PF.image) ) ;
st__reset_flag (time_spent, &(PF.protevil) ) ;
st__reset_flag (time_spent, &(PF.invuln) ) ;
st__reset_flag (time_spent, &(PF.hero) ) ;
st__reset_flag (time_spent, &(PF.shero) ) ;
st__reset_flag (time_spent, &(PF.blessed) ) ;
st__reset_flag (time_spent, &(PF.resist_heat) ) ;
st__reset_flag (time_spent, &(PF.resist_cold) ) ;
st__reset_flag (time_spent, &(PF.detect_inv) ) ;
st__reset_flag (time_spent, &(PF.word_recall) ) ;
st__reset_flag (time_spent, &(PF.tim_infra) ) ;
st__reset_flag (time_spent, &(PF.resist_lght) ) ;
st__reset_flag (time_spent, &(PF.free_time) ) ;
st__reset_flag (time_spent, &(PF.ring_fire) ) ;
st__reset_flag (time_spent, &(PF.protmon) ) ;
st__reset_flag (time_spent, &(PF.hoarse) ) ;
st__reset_flag (time_spent, &(PF.magic_prot) ) ;
st__reset_flag (time_spent, &(PF.ring_ice) ) ;
st__reset_flag (time_spent, &(PF.temp_stealth) ) ;
st__reset_flag (time_spent, &(PF.resist_petri) ) ;
st__reset_flag (time_spent, &(PF.blade_ring) ) ;
switch (days_spent) {
case 0: case 1:
PF.foodc -= time_spent;
if (PF.foodc <= PLAYER_FOOD_ALERT) {
/* free food if you were hungry when you got here? */
PF.foodc = PLAYER_FOOD_ALERT + 1;
}
break;
default:
PF.foodc = PLAYER_FOOD_FULL - 1;
break;
}
PF.confuse_monster = false;
for (i1 = 1; i1 <= mornings; i1++) {
store_maint();
}
//with py.misc do;
regen_percent = regen_amount*2*time_spent;
if (regen_percent > 1.00) {
regen_percent = 1.00;
}
if (PM.chp < PM.mhp) {
regenhp(regen_percent);
}
if (PM.chp > PM.mhp) {
PM.chp = PM.mhp;
}
if (PM.cmana < PM.mana) {
regenmana(regen_percent);
}
if (PM.cmana > PM.mana) {
PM.cmana = PM.mana;
}
if (new_screen) {
moria_flag = true;
msg_print("");
}
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void enter_store(integer store_num)
{
/*{ Entering a store -RAK- }*/
integer com_val,cur_top,tics;
treas_ptr trash_ptr;
char command;
boolean exit_flag;
tics = 1;
//with stores[store_num] do;
exit_flag = false;
cur_top = 1;
display_store(store_num,cur_top);
do {
if (get_com("",&command)) {
msg_flag = false;
com_val = (integer)(command);
switch (com_val) {
case 18 : display_store(store_num,cur_top);
case 73 : /*{ Selective Inventory }*/
if (inven_command('I',&trash_ptr,"")) {
display_store(store_num,cur_top);
}
break;
case 32 :
if (cur_top == 1) {
if (stores[store_num].store_ctr > 12) {
cur_top = 13;
display_inventory(store_num,cur_top);
} else {
prt("Entire inventory is shown.",1,1);
}
} else {
cur_top = 1;
display_inventory(store_num,cur_top);
}
break;
case 101 : /*{ Equipment List }*/
if (inven_command('e',&trash_ptr,"")) {
display_store(store_num,cur_top);
}
break;
case 105 : /*{ Inventory }*/
if (inven_command('i',&trash_ptr,"")) {
display_store(store_num,cur_top);
}
break;
case 116 : /*{ Take off }*/
if (inven_command('t',&trash_ptr,"")) {
display_store(store_num,cur_top);
}
break;
case 119 : /*{ Wear }*/
if (inven_command('w',&trash_ptr,"")) {
display_store(store_num,cur_top);
}
break;
case 120 : /*{ Switch weapon }*/
if (inven_command('x',&trash_ptr,"")) {
display_store(store_num,cur_top);
}
break;
case 112 : exit_flag = store_purchase(store_num,&cur_top,false); break;
case 80 : exit_flag = store_purchase(store_num,&cur_top,true); break;
case 115 : exit_flag = store_sell(store_num,cur_top,false); break;
case 83 : exit_flag = store_sell(store_num,cur_top,true); break;
default : prt("Invalid Command.",1,1); break;
} /* end switch */
}
else {
exit_flag = true;
}
adv_time(false);
tics++;
check_kickout_time(tics,2);
} while (!exit_flag);
if (moria_flag) {
clear_rc(1,1);
prt_stat_block();
} else {
draw_cave();
}
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void display_store(integer store_num,integer cur_top)
{
/*{ Displays store -RAK- }*/
//with stores[store_num] do;
clear_screen();
prt(owners[stores[store_num].owner].owner_name,4,10);
prt(" Item",5,1);
prt("Asking Price",5,61);
store_prt_gold();
display_commands();
display_inventory(store_num,cur_top);
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void store_prt_gold()
{
/*{ Displays players gold -RAK- }*/
vtype out_val;
sprintf(out_val,"Gold Remaining : %ld",py.misc.money[TOTAL_]);
prt(out_val,19,18);
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void display_cost(integer store_num,integer pos)
{
/*{ Re-displays only a single cost -RAK- }*/
integer i1,i2;
vtype out_val;
//with stores[store_num] do;
i1 = ((pos-1) % 12);
if (stores[store_num].store_inven[pos].scost < 0) {
i2 = abs(stores[store_num].store_inven[pos].scost);
i2 += (integer)(i2*chr_adj());
sprintf(out_val,"%6ld",(i2 div GOLD_VALUE));
} else {
sprintf(out_val,"%6ld [FIXED]",
(stores[store_num].store_inven[pos].scost div GOLD_VALUE));
}
prt(out_val,i1+6,60);
};
//////////////////////////////////////////////////////////////////////