forked from muspellsson/omega-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinv.c
1773 lines (1594 loc) · 44.1 KB
/
inv.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
/* omega copyright (C) by Laurence Raphael Brothers, 1987,1988,1989 */
/* inv.c */
/* functions having to do with player item inventory */
#ifdef MSDOS_SUPPORTED_ANTIQUE
# include "curses.h"
#else
# ifdef AMIGA
# include <curses210.h>
# elif defined(USE_OPCURSES)
# include "../opcurses/curses.h"
# else
# include <curses.h>
# endif
#endif
#include "glob.h"
static void inv_display_munge(void);
static void inv_display_refresh(void);
/* drops money, heh heh */
void drop_money(void)
{
pob money;
money = detach_money(0);
if (money != NULL) {
if (Current_Environment == E_CITY) {
print1("As soon as the money leaves your hand,");
print2("a horde of scrofulous beggars snatch it up and are gone!");
free( money );
}
else drop_at(Player.x,Player.y,money);
}
else setgamestatus(SKIP_MONSTERS);
}
/* returns some money from player back into "money" item.
for giving and dropping money */
pob detach_money(long howmuch)
/* if howmuch == 0, ask the player. otherwise, just get howmuch. */
{
long c;
pob cash=NULL;
if ( howmuch == 0 )
c = get_money(Player.cash);
else
c = howmuch;
if (c != ABORT) {
Player.cash -= c;
cash = ((pob) checkmalloc(sizeof(objtype)));
make_cash(cash,difficulty());
cash->basevalue = c;
}
return(cash);
}
/* gets a legal amount of money or ABORT */
long get_money(long limit)
{
long c;
c = parsenum("How much money? ");
if (c > limit) {
print3("Forget it, buddy.");
return(ABORT);
}
else return(c);
}
/* pick up from some location x,y */
/* Lift entire itemlist off ground, pass it to inventory control, which
may drop things back onto the now null ground */
void pickup_at (int x, int y)
{
char response;
pol ol;
pol temp;
resetgamestatus(FAST_MOVE);
ol = Level->site[x][y].things;
Level->site[x][y].things = 0;
while (ol != 0)
{
clearmsg1();
response = cinema_ynq(strjoin("Pick up: ", itemid(ol->thing)));
if ('q' == response)
break;
if (response == 'y')
gain_item(ol->thing);
else
drop_at(x,y,ol->thing);
temp = ol;
ol = ol->next;
temp->next = 0;
temp->thing = 0;
free(temp);
}
while (ol != 0)
{
temp = ol;
ol = ol->next;
temp->next = 0;
temp->thing = 0;
free(temp);
}
}
/* WDT -- convert from a char (keypress) to an item index in
* player inventory */
/* Item identifiers, in this case the letters of the alphabet minus
* any letters already used for commands. Yes, there are more here
* than could be needed, but I don't want to short myself for later.
*/
signed char inventory_keymap[] = "-abcfghimnoqruvwyz";
int key_to_index(signed char key)
{
int i;
assert( MAXITEMS>0 ); /* must have room for an item, or this loop will
* die! */
for (i=0; i<MAXITEMS; i++) {
if (key == inventory_keymap[i])
return (signed char)i;
}
return O_UP_IN_AIR;
}
signed char index_to_key(signed int index)
{
if ( index < MAXITEMS )
return inventory_keymap[index];
else return '-';
}
/* criteria for being able to put some item in some slot */
/* WDT -- why on earth does the 'slottable' function print stuff???? */
int aux_slottable(pob o, int slot)
{
int ok = TRUE;
if (o == NULL) ok = FALSE;
else if (slot == O_ARMOR) {
if (o->objchar != ARMOR) {
ok = FALSE;
}
}
else if (slot == O_SHIELD) {
if (o->objchar != SHIELD) {
ok = FALSE;
}
}
else if (slot == O_BOOTS) {
if (o->objchar != BOOTS) {
ok = FALSE;
}
}
else if (slot == O_CLOAK) {
if (o->objchar != CLOAK) {
ok = FALSE;
}
}
else if (slot >= O_RING1) {
if (o->objchar != RING) {
ok = FALSE;
}
}
return(ok);
}
/* put all of o on objlist at x,y on Level->depth */
/* Not necessarily dropped by character; just dropped... */
void drop_at(int x, int y, pob o)
{
pol tmp;
pob cpy;
if (Current_Environment != E_COUNTRYSIDE) {
if ((Level->site[x][y].locchar != VOID_CHAR) &&
(Level->site[x][y].locchar != ABYSS)) {
cpy = copy_obj( o );
tmp = ((pol) checkmalloc(sizeof(oltype)));
cpy->used = FALSE;
tmp->thing = cpy;
tmp->next = Level->site[x][y].things;
Level->site[x][y].things = tmp;
}
else if (Level->site[x][y].p_locf == L_VOID_STATION)
setgamestatus(PREPARED_VOID);
}
}
/* put n of o on objlist at x,y on Level->depth */
void p_drop_at(int x, int y, int n, pob o)
{
pol tmp;
if (Current_Environment != E_COUNTRYSIDE) {
if ((Level->site[x][y].locchar != VOID_CHAR) &&
(Level->site[x][y].locchar != ABYSS)) {
tmp = ((pol) checkmalloc(sizeof(oltype)));
tmp->thing = copy_obj( o );
tmp->thing->used = FALSE;
tmp->thing->number = n;
print2("Dropped ");
nprint2(itemid(tmp->thing));
morewait();
tmp->next = Level->site[x][y].things;
Level->site[x][y].things = tmp;
}
else if (Level->site[x][y].p_locf == L_VOID_STATION)
setgamestatus(PREPARED_VOID);
}
}
/* returns a string for identified items */
char *itemid(pob obj)
{
char tstr[80];
if (obj->objchar==CASH){
strcpy(Str4,obj->truename);
return(Str4);
}
else {
if (Objects[obj->id].known > obj->known)
obj->known = Objects[obj->id].known;
setnumstr(obj,tstr);
strcpy(Str4,tstr);
if (obj->known == 0)
strcat(Str4,obj->objstr);
else if (obj->known == 1) {
if (obj->id == OB_YENDOR || obj->id == OB_KARNAK ||
obj->id == OB_STARGEM )
strcat(Str4, "the ");
strcat(Str4,obj->truename);
}
else {
if (obj->id == OB_YENDOR || obj->id == OB_KARNAK ||
obj->id == OB_STARGEM )
strcat(Str4, "the ");
if (obj->usef == I_NOTHING && Objects[obj->id].usef != I_NOTHING)
strcat(Str4, "disenchanted ");
if (obj->blessing < 0) {
strcat(Str4, "cursed ");
strcat(Str4, obj->cursestr);
}
else if (obj->blessing > 0) {
strcat(Str4, "blessed ");
strcat(Str4, obj->truename);
}
else strcat(Str4,obj->truename);
if (obj->number > 1) strcat(Str4,"s");
switch (obj->objchar) {
case STICK:
setchargestr(obj,tstr);
strcat(Str4,tstr);
break;
case MISSILEWEAPON:
case ARMOR:
case RING:
case SHIELD:
case WEAPON:
setplustr(obj,tstr);
strcat(Str4, tstr);
break;
default: strcat(Str4,""); break;
}
}
return(Str4);
}
}
char *cashstr(void)
{
if (difficulty() < 3) return("copper pieces");
else if (difficulty() < 5) return("silver pieces");
else if (difficulty() < 7) return("gold pieces");
else if (difficulty() < 8) return("semiprecious gems");
else if (difficulty() < 9) return("mithril pieces");
else if (difficulty() < 10) return("precious gems");
else return("orichalc pieces");
}
/* return an object's plus as a string */
void setplustr(pob obj, char *pstr)
{
pstr[0] = ' ';
pstr[1] = (obj->plus < 0 ? '-' : '+' );
if (abs(obj->plus) < 10) {
pstr[2] = '0' + abs(obj->plus);
pstr[3] = 0;
}
else {
pstr[2] = '0' + abs(obj->plus / 10);
pstr[3] = '0' + abs(obj->plus % 10);
pstr[4] = 0;
}
}
/* return an object's number as a string */
void setnumstr(pob obj, char *nstr)
{
if (obj->number < 2)
nstr[0] = 0;
else if (obj->number < 10) {
nstr[0] = '0' + obj->number;
nstr[1] = 'x';
nstr[2] = ' ';
nstr[3] = 0;
}
else if (obj->number < 41) {
nstr[0] = '0' + ((int)(obj->number / 10));
nstr[1] = '0' + (obj->number % 10);
nstr[2] = 'x';
nstr[3] = ' ';
nstr[4] = 0;
}
else strcpy(nstr,"lots of ");
}
/* return object with charges */
void setchargestr(pob obj, char *cstr)
{
cstr[0] = ' ';
cstr[1] = '[';
if (obj->charge < 0) {
cstr[2]='d';
cstr[3]='e';
cstr[4]='a';
cstr[5]='d';
cstr[6]=']';
cstr[7]=0;
}
else if (obj->charge < 10) {
cstr[2] = '0' + obj->charge;
cstr[3] = ']';
cstr[4] = 0;
}
else {
cstr[2] = '0' + ((int)(obj->charge / 10));
cstr[3] = '0' + (obj->charge % 10);
cstr[4] = ']';
cstr[5] = 0;
}
}
void give_money(struct monster *m)
{
pob cash;
cash = detach_money(0);
if (cash == NULL)
setgamestatus(SKIP_MONSTERS);
else givemonster(m,cash);
}
void lawbringer_gets_gem(pmt m, pob o)
{
clearmsg();
print1("The LawBringer accepts the gem reverently.");
print2("He raises it above his head, where it bursts into lambent flame!");
morewait();
print1("You are bathed in a shimmering golden light.");
print2("You feel embedded in an infinite matrix of ordered energy.");
morewait();
if (Imprisonment > 0)
Imprisonment = 0;
if (Player.rank[ORDER] == -1) {
print2("You have been forgiven. You feel like a Paladin....");
Player.rank[ORDER] = 1;
}
Player.alignment += 200;
Player.pow = Player.maxpow = Player.pow * 2;
gain_experience(2000);
setgamestatus(GAVE_STARGEM);
/* WDT HACK!!! Where else would this ever get freed?? */
free_obj(o, TRUE);
}
void givemonster(pmt m, pob o)
{
/* special case -- give gem to LawBringer */
if ((m->id == LAWBRINGER) && (o->id == OB_STARGEM))
lawbringer_gets_gem(m,o);
else {
if (m->uniqueness == COMMON) {
strcpy(Str3,"The ");
strcat(Str3,m->monstring);
}
else strcpy(Str3,m->monstring);
if (m_statusp(m,GREEDY) || m_statusp(m,NEEDY)) {
m_pickup(m,o);
strcat(Str3," takes your gift");
print1(Str3);
Player.alignment++;
if (m_statusp(m,GREEDY) && (true_item_value(o) < (long) m->level*100))
nprint1("...but does not appear satisfied.");
else if (m_statusp(m,NEEDY) &&
(true_item_value(o) < (long) Level->depth*Level->depth))
nprint1("...and looks chasteningly at you.");
else {
nprint1("...and seems happy with it.");
m_status_reset(m,HOSTILE);
m_status_reset(m,GREEDY);
m_status_reset(m,NEEDY);
}
}
else if (m_statusp(m,HUNGRY)) {
if (((m->id == HORSE) && (o->id == OB_GRAIN)) || /* grain */
((m->id != HORSE) &&
((o->usef == I_FOOD) || (o->usef == I_POISON_FOOD)))) {
strcat(Str3," wolfs down your food ... ");
print1(Str3);
m_status_reset(m,HUNGRY);
m_status_reset(m,HOSTILE);
if (o->usef == I_POISON_FOOD) {
Player.alignment -= 2;
nprint1("...and chokes on the poisoned ration!");
morewait();
m_status_set(m,HOSTILE);
m_damage(m,100,POISON);
}
else nprint1("...and now seems satiated.");
morewait();
free_obj(o, TRUE);
}
else {
strcat(Str3," spurns your offering and leaves it on the ground.");
print1(Str3);
drop_at(m->x,m->y,o);
}
}
else {
strcat(Str3," doesn't care for your offering and drops it.");
print1(Str3);
drop_at(m->x,m->y,o);
}
}
}
/* will clear all, not just one of an object. */
void conform_lost_object(pob obj)
{
if (obj != NULL) conform_lost_objects(obj->number,obj);
}
/* removes n of object from inventory; frees object if appropriate. */
void dispose_lost_objects(int n, pob obj)
{
int i,conformed=FALSE,subtracted=FALSE;
if (obj == NULL)
return;
for(i=0;i<MAXITEMS;i++)
if (Player.possessions[i] == obj) {
if (! subtracted) {
obj->number -= n;
subtracted = TRUE;
}
if (obj->number < 1) {
if (!conformed) {
conform_unused_object(obj);
conformed = TRUE;
}
Player.possessions[i] = NULL;
}
}
if (obj->number < 1)
free_obj( obj, TRUE );
}
/* removes n of object from inventory without freeing object.
Removes all instances of pointer (might be 2 handed weapon, etc) */
void conform_lost_objects(int n, pob obj)
{
int i,conformed=FALSE,subtracted=FALSE;
if (obj != NULL) for(i=0;i<MAXITEMS;i++)
if (Player.possessions[i] == obj) {
if (! subtracted) {
obj->number -= n;
subtracted = TRUE;
}
if (obj->number < 1) {
if (!conformed) {
conform_unused_object(obj);
conformed = TRUE;
}
Player.possessions[i] = NULL;
}
}
}
/* clears unused possession */
void conform_unused_object(pob obj)
{
if (obj->used) {
obj->used = FALSE;
item_use(obj);
inv_display_munge();
}
calc_melee();
}
/* select an item from inventory */
/* if itype is NULL_ITEM, any kind of item is acceptable.
if itype is CASH, any kind of item or '$' (cash) is acceptable.
if itype is FOOD, CORPSE or FOOD is acceptable, but only FOOD is
listed in the possibilities.
if itype is any other object type (eg SCROLL, POTION, etc.), only
that type of item is acceptable or is listed */
int item_is_selectable (Symbol itype, struct object * item)
{
if (!item) return FALSE;
if (CASH == itype) return TRUE;
if (NULL_ITEM == itype) return TRUE;
if (item->objchar == itype) return TRUE;
if (FOOD == itype && CORPSE == item->objchar) return TRUE;
return FALSE;
}
int getitem (Symbol itype)
{
return getitem_prompt(0, itype);
}
int getitem_prompt (char * prompt, Symbol itype)
{
char key;
char *line3;
char invstr[64];
char selectstr[80];
int i, k;
int again;
int found = FALSE;
int drewmenu = FALSE;
found = ((itype == NULL_ITEM) || ((itype == CASH) && (Player.cash > 0)));
/* build invstr, which lists all valid selections that the user can make */
invstr[0] = 0;
k = 0;
for(i = 1; i < MAXITEMS; ++i)
{
if (item_is_selectable(itype, Player.possessions[i]))
{
found = TRUE;
invstr[k++] = index_to_key(i);
invstr[k] = 0;
}
}
if (!found)
{
print3("Nothing appropriate.");
return ABORT;
}
if (itype == CASH)
{
invstr[k++] = CASH & 0xff;
invstr[k] = 0;
}
/* gotta let the user see what everything means... */
invstr[k++] = '?';
invstr[k] = 0;
line3 = NULL;
/* build prompt... */
selectstr[0] = 0;
if (prompt) strcpy(selectstr, prompt);
strcat(selectstr, "Select an item. (");
i = 0;
k = strlen(selectstr);
while (TRUE)
{
if ('?' == invstr[i]) break;
selectstr[k++] = invstr[i++];
selectstr[k++] = ',';
if (k > 75) break;
}
selectstr[k-1] = ')';
selectstr[k] = 0;
/* get input from the user */
do
{
again = FALSE;
key = cinema_interact(invstr, selectstr, " ? to display items", line3);
line3 = NULL;
if ('?' == key)
{
again = TRUE;
drewmenu = TRUE;
for (i = 1; i < MAXITEMS; ++i)
{
if (item_is_selectable(itype, Player.possessions[i]))
display_inventory_slot(i, FALSE);
}
}
else if ((CASH & 0xff) == key && (CASH != itype))
{
again = TRUE;
line3 = "You cannot select cash now.";
}
}
while (again);
if (drewmenu) xredraw();
if (-1 == key) return ABORT; /* cinema_interact() returns -1 for ESC */
if ((CASH & 0xff) == key) return CASHVALUE;
return key_to_index(key);
}
/* true if the numerical index based on 'a' == 1 turns out to be either
out of the range of the possessions array or a null item */
int badobject(char slotchar)
{
int slot = slotchar + 1 - 'a';
if ((slot<1) || (slot >= MAXITEMS)) return(TRUE);
else return(Player.possessions[slot] == NULL);
}
#ifndef MSDOS_SUPPORTED_ANTIQUE
/* this takes the numerical index directly for the same effect as badobject*/
int baditem(int slotnum)
{
if ((slotnum<1) || (slotnum >= MAXITEMS)) return(TRUE);
else return(Player.possessions[slotnum] == NULL);
}
#endif
/* formerly add_item_to_pack */
void gain_item(pob o)
{
if (o->uniqueness == UNIQUE_MADE)
Objects[o->id].uniqueness = UNIQUE_TAKEN;
if (o->objchar == CASH) {
print2("You gained some cash.");
Player.cash += o->basevalue;
free_obj(o,TRUE);
dataprint();
}
else if (optionp(PACKADD)) {
if (! get_to_pack(o)) {
Player.possessions[O_UP_IN_AIR] = o;
do_inventory_control();
}
}
else {
Player.possessions[O_UP_IN_AIR] = o;
do_inventory_control();
}
}
/* tosses the item into the pack, making it the first reachable item */
void push_pack(pob o)
{
int i;
for (i = Player.packptr; i > 0; i--)
Player.pack[i] = Player.pack[i-1];
Player.pack[0] = o;
Player.packptr++;
}
/* Adds item to pack list */
void add_to_pack(pob o)
{
if (Player.packptr >= MAXPACK) {
print3("Your pack is full. The item drops to the ground.");
drop_at(Player.x,Player.y,o);
}
else {
push_pack(o);
print3("Putting item in pack.");
}
}
/* Adds item to pack list, maybe going into inventory mode if pack is full */
int get_to_pack(pob o)
{
if (Player.packptr >= MAXPACK) {
print3("Your pack is full.");
morewait();
return(FALSE);
}
else {
push_pack(o);
print3("Putting item in pack.");
return(TRUE);
}
}
int pack_item_cost(int index)
{
int cost;
if (index > 20) {
cost = 17;
}
else if (index > 15) {
cost = 7;
}
else cost = 2;
return cost;
}
/* WDT -- 'response' must be an index into the pack. */
void use_pack_item(int response, int slot)
{
pob item; int i;
i = pack_item_cost(response);
if (i > 10) {
cinema_scene("You begin to rummage through your pack.",NULL,NULL);
}
if (i > 5) {
cinema_scene("You search your pack for the item.",NULL,NULL);
}
print3("You take the item from your pack.");
morewait();
Command_Duration += i;
item = Player.possessions[slot] = Player.pack[response];
for(i=response;i<Player.packptr-1;i++)
Player.pack[i] = Player.pack[i+1];
Player.pack[--Player.packptr] = NULL;
if ((slot == O_READY_HAND || slot == O_WEAPON_HAND) &&
twohandedp(item->id))
{
if (Player.possessions[O_READY_HAND] == NULL)
Player.possessions[O_READY_HAND] = item;
if (Player.possessions[O_WEAPON_HAND] == NULL)
Player.possessions[O_WEAPON_HAND] = item;
}
if (item_useable(item,slot)) {
item->used = TRUE;
item_use(item);
inv_display_munge();
morewait();
if (item->number > 1) pack_extra_items(item);
}
}
/* WDT HACK! This ought to be in scr.c, along with its companion. However,
* right now it's only used in the function directly below. */
int aux_display_pack(int start_item, int slot)
{
int i=start_item, items;
char *depth_string;
menuclear();
#if 0
/* WDT: I decided to remove these lines, since the purpose of this routine
* is to generate a pack menu, not update the message line. This is
* especially important now that I'm making the inventory system use the
* new 'Cinema' message box (which will stop the message corruption
* problems that were epidemic). */
if (Player.packptr < 1) print3("Pack is empty.");
else if (Player.packptr <= start_item) print3("You see the leather at the bottom of the pack.");
#else
/* These cases are not terribly important, but they can happen. */
if (Player.packptr < 1 || Player.packptr <= start_item)
return start_item;
#endif
else
{
items = 0;
for(i=start_item;i<Player.packptr && items<ScreenLength-5;i++) {
if ( aux_slottable(Player.pack[i],slot) ) {
if (pack_item_cost(i) > 10)
depth_string = "**";
else if (pack_item_cost(i) > 5)
depth_string = "* ";
else depth_string = " ";
sprintf(Str1, " %c: %s %s\n", i + 'a', depth_string,
itemid(Player.pack[i]));
if (items == 0)
menuprint("Items in Pack:\n");
menuprint(Str1);
items++;
}
}
if (items == 0)
menuprint("You see nothing useful for that slot in the pack.");
else {
menuprint("\n*: Takes some time to reach; **: buried very deeply.");
}
showmenu();
}
return i;
}
/* takes something from pack, puts to slot,
* or to 'up-in-air', one of which at least must be empty */
int aux_take_from_pack(int slot)
{
char response,pack_item, last_item;
int quit = FALSE,ok=TRUE;
if (Player.possessions[slot] != NULL)
slot = O_UP_IN_AIR;
if (Player.possessions[slot] != NULL)
print3("slot is not empty!");
else if (Player.packptr < 1)
print3("Pack is empty!");
else {
pack_item = 0;
do {
ok = TRUE;
last_item = aux_display_pack(pack_item,slot);
if (last_item == Player.packptr && pack_item == 0 )
print1("Enter pack slot letter or ESCAPE to quit.");
else if (last_item == Player.packptr)
print1("Enter pack slot letter, - to go back, or ESCAPE to quit.");
else if (pack_item == 0)
print1("Enter pack slot letter, + to see more, or ESCAPE to quit.");
else
print1("Enter pack slot letter, + or - to see more, or ESCAPE to quit.");
response = mcigetc();
if (response == '?') {
/* WDT HACK -- display some help instead. */
print1("Help not implemented (sorry).");
morewait();
ok = FALSE;
}
else if (response == ESCAPE) quit = TRUE;
else if (response == '+') {
if (last_item < Player.packptr)
pack_item = last_item;
ok = FALSE;
}
else if (response == '-') {
/* WDT HACK: this _should_ make us page up. Sadly,
* I have no way of calculating how much I'll be paging up.
* This is fixable, but I have no idea how much work... As
* a hack, I'm just returning to the first page of the listing.
*/
pack_item = 0;
ok = FALSE;
}
else{
ok = ((response >= 'a') && (response < 'a'+Player.packptr));
if (ok) ok = slottable(Player.pack[response-'a'],slot);
}
} while (! ok);
if (! quit) {
use_pack_item(response - 'a',slot);
}
}
inv_display_munge();
return slot;
}
/* takes something from pack, puts to slot,
or to 'up-in-air', one of which at least must be empty */
int aux_top_take_from_pack(int slot, int display)
{
char response;
int quit = FALSE,ok=TRUE;
if (Player.possessions[slot] != NULL)
slot = O_UP_IN_AIR;
if (Player.possessions[slot] != NULL)
print3("slot is not empty!");
else if (Player.packptr == 0)
print3("Pack is empty!");
else {
do {
ok = TRUE;
print1("Enter pack slot letter, or ? to show pack, or ESCAPE to quit.");
response = mcigetc();
if (response == '?') {
display_pack();
inv_display_munge();
ok = FALSE;
}
else if (response == ESCAPE) quit = TRUE;
else{
ok = ((response >= 'a') && (response < 'a'+Player.packptr));
if (ok) ok = slottable(Player.pack[response-'a'],slot);
}
} while (! ok);
if (! quit) use_pack_item(response - 'a',slot);
}
return slot;
}
int take_from_pack(int slot, int display)
{
if (optionp(TOPINV)) return aux_top_take_from_pack(slot,display);
else return aux_take_from_pack(slot);
}
#ifndef MSDOS_SUPPORTED_ANTIQUE
/* General interface to inventory */
void item_inventory(int topline)
{
if (topline) {
display_possessions();
inventory_control();
}
else top_inventory_control();
}
#endif
void do_inventory_control(void)
{
if (optionp(TOPINV)) top_inventory_control();
else {
menuclear();
display_possessions();
inventory_control();
}
}
/* inventory_control assumes a few setup things have been done,
* like loading the O_UP_IN_AIR item, etc.
* Each action uses up a little time. If only inspection actions
* are taken, no time is used up. */
void inventory_control(void)
{
int slot = O_UP_IN_AIR,done=FALSE;
int response;
char letter;
#ifdef MSDOS_SUPPORTED_ANTIQUE
int simple = 0;
#endif
/* Start out assuming that we'll need to redraw. */
inv_display_munge();
clearmsg3();
do {
checkclear();
print1("Action [d,e,l,p,s,t,x,>,<,?,ESCAPE]:");
inv_display_refresh();
show_inventory_slot(slot,FALSE);
display_inventory_slot(O_UP_IN_AIR,FALSE);
move_slot(slot,slot,MAXITEMS);
response = mcigetc();
switch(response) {
case 12:
case 18: /* ^l, ^r */
display_possessions();
break;
case 'd':
if (Player.possessions[O_UP_IN_AIR] != NULL)
{
drop_from_slot(O_UP_IN_AIR);
display_inventory_slot(O_UP_IN_AIR, FALSE);
}
else if (Player.possessions[slot] != NULL)
{
drop_from_slot(slot);
show_inventory_slot(slot, FALSE);
}
else print3("Nothing in selected slot!");
Command_Duration++;