-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathiventory.c
638 lines (455 loc) · 10.7 KB
/
iventory.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
#include "larncons.h"
#include "larndata.h"
#include "larnfunc.h"
static int qshowstr(char);
static void t_setup(int);
static void t_endup(int);
static int show2(int);
/* Allow only 26 items (a to z) in the player's inventory */
#define MAXINVEN 26
/* The starting limit to the number of items the player can carry.
The limit should probably be based on player strength and the
weight of the items.
*/
#define MIN_LIMIT 15
/* define a sentinel to place at the end of the sorted inventory.
(speeds up display reads )
*/
#define END_SENTINEL 255
/* declare the player's inventory. These should only be referenced
in this module.
iven - objects in the player's inventory
ivenarg - attribute of each item ( + values, etc )
ivensort - sorted inventory (so we don't sort each time)
*/
signed char iven[MAXINVEN];
signed short ivenarg[MAXINVEN];
unsigned char ivensort[MAXINVEN+1]; /* extra is for sentinel */
static char srcount = 0 ; /* line counter for showstr() */
/*
* Initialize the player's inventory
*/
void init_inventory(void)
{
int i;
for ( i = 0; i < MAXINVEN ; i++ )
{
iven[i] = ivenarg[i] = 0;
ivensort[i] = END_SENTINEL ;
}
ivensort[MAXINVEN] = END_SENTINEL;
/* For zero difficulty games, start the player out with armor and weapon.
We can sort the inventory right away because a dagger is 'later' than
leather armor.
*/
if (c[HARDGAME] <= 0)
{
iven[0] = OLEATHER;
iven[1] = ODAGGER;
ivenarg[0] = ivenarg[1] = c[WEAR] = ivensort[0] = 0;
ivensort[1] = c[WIELD] = 1;
}
}
/*
* show character's inventory
*/
int showstr(char select_allowed)
{
int i, number, item_select;
for (number=3, i=0; i<MAXINVEN; i++)
if (iven[i])
number++; /* count items in inventory */
t_setup(number);
item_select = qshowstr(select_allowed);
t_endup(number);
return item_select;
}
static int qshowstr(char select_allowed)
{
int i, j, k, itemselect = 0;
srcount=0;
if (c[GOLD])
{
lprintf(".) %d gold pieces",(long)c[GOLD]);
srcount++;
}
for (k=(MAXINVEN-1); k>=0; k--)
if (iven[k])
{
for (i=22; i<84; i++)
for (j=0; j<=k; j++)
if (i==iven[j])
{
itemselect = show2(j);
if (itemselect && select_allowed)
goto quitit;
}
k=0;
}
lprintf("\nElapsed time is %d. You have %d mobuls left",(long)((gtime+99)/100+1),(long)((TIMELIMIT-gtime)/100));
itemselect = more(select_allowed);
quitit:
if (select_allowed)
return( (itemselect > 0) ? itemselect : 0 );
else
return( 0 );
}
/*
* subroutine to clear screen depending on # lines to display
*/
static void t_setup(int count)
{
/* how do we clear the screen? */
if (count < 20) {
cl_up(79, count);
cursor(1, 1);
} else {
resetscroll();
clear();
}
}
/*
* subroutine to restore normal display screen depending on t_setup()
*/
static void t_endup(int count)
{
/* how did we clear the screen? */
if (count < 18) {
draws(0,MAXX,0,(count>MAXY) ? MAXY : count);
} else {
drawscreen();
setscroll();
}
}
/*
* function to show the things player is wearing only
*/
int showwear(void)
{
int i, count, itemselect;
itemselect = 0;
srcount = 0;
for (count = 2, i = 0; i < MAXINVEN; i++) {
switch (iven[i]) {
case OLEATHER:
case OPLATE:
case OCHAIN:
case ORING:
case OSTUDLEATHER:
case OSPLINT:
case OPLATEARMOR:
case OSSPLATE:
case OSHIELD:
++count;
break;
}
}
t_setup(count);
for (i = 0; i < MAXINVEN; i++) {
switch (iven[i]) {
case OLEATHER:
case OPLATE:
case OCHAIN:
case ORING:
case OSTUDLEATHER:
case OSPLINT:
case OPLATEARMOR:
case OSSPLATE:
case OSHIELD:
itemselect = show2(i);
break;
}
if (itemselect) break;
}
if (!itemselect) {
itemselect = more(TRUE);
}
t_endup(count);
if (itemselect > 1) {
return itemselect;
}
return 0;
}
/*
* function to show the things player can wield only
*/
int showwield(void)
{
int i, count, itemselect;
itemselect = 0;
srcount = 0;
for (count = 2, i = 0; i < MAXINVEN; i++) {
switch (iven[i]) {
case ODIAMOND:
case ORUBY:
case OEMERALD:
case OSAPPHIRE:
case OBOOK:
case OCHEST:
case OLARNEYE:
case ONOTHEFT:
case OSPIRITSCARAB:
case OCUBEofUNDEAD:
case OPOTION:
case OSCROLL:
++count;
break;
}
}
t_setup(count);
for (i = 0; i < MAXINVEN; i++) {
switch (iven[i]) {
case ODIAMOND:
case ORUBY:
case OEMERALD:
case OSAPPHIRE:
case OBOOK:
case OCHEST:
case OLARNEYE:
case ONOTHEFT:
case OSPIRITSCARAB:
case OCUBEofUNDEAD:
case OPOTION:
case OSCROLL:
itemselect = show2(i);
break;
}
if (itemselect) break;
}
if (!itemselect) {
itemselect = more(TRUE);
}
t_endup(count);
if (itemselect > 1) {
return itemselect;
}
return 0;
}
/*
* function to show the things player can read only
*/
int showread(void)
{
int i, count, itemselect;
itemselect = 0;
srcount = 0;
for (count = 2, i = 0; i < MAXINVEN; i++) {
switch (iven[i]) {
case OBOOK:
case OSCROLL:
++count;
break;
}
}
t_setup(count);
for (i = 0; i < MAXINVEN; i++) {
switch (iven[i]) {
case OBOOK:
case OSCROLL:
itemselect = show2(i);
break;
}
if (itemselect) break;
}
if (!itemselect) {
itemselect = more(TRUE);
}
t_endup(count);
if (itemselect > 1) {
return itemselect;
}
return 0;
}
/*
* function to show the things player can eat only
*/
int showeat(void)
{
int i, count, itemselect;
itemselect = 0;
srcount = 0;
for (count = 2, i = 0; i < MAXINVEN; i++) {
switch (iven[i]) {
case OCOOKIE:
++count;
break;
}
}
t_setup(count);
for (i = 0; i < MAXINVEN; i++) {
switch (iven[i]) {
case OCOOKIE:
itemselect = show2(i);
break;
}
if (itemselect) break;
}
if (!itemselect) {
itemselect = more(TRUE);
}
t_endup(count);
if (itemselect > 1) {
return itemselect;
}
return 0;
}
/*
* function to show the things player can quaff only
*/
int showquaff(void)
{
int i, count, itemselect;
itemselect = 0;
srcount = 0;
for (count = 2, i = 0; i < MAXINVEN; i++) {
switch (iven[i]) {
case OPOTION:
++count;
break;
}
}
t_setup(count);
for (i = 0; i < MAXINVEN; i++) {
switch (iven[i]) {
case OPOTION:
itemselect = show2(i);
break;
}
if (itemselect) break;
}
if (!itemselect) {
itemselect = more(TRUE);
}
t_endup(count);
if (itemselect > 1) {
return itemselect;
}
return 0;
}
void show1(int idx)
{
signed char o;
lprc('\n');
cltoeoln();
o = iven[idx];
lprintf("%c) %s", idx + 'a', objectname[o]);
if (o == OPOTION && potionname[ivenarg[idx]][0] != '\0') {
lprintf(" of%s", idx + 'a',
objectname[o], potionname[ivenarg[idx]]
);
} else if (o == OSCROLL && scrollname[ivenarg[idx]][0] != '\0') {
lprintf(" of%s", idx + 'a',
objectname[o], scrollname[ivenarg[idx]]
);
}
}
int show3(int index)
{
srcount=0;
return show2(index);
}
static int show2(int index)
{
int itemselect = 0;
switch(iven[index])
{
case OPOTION:
case OSCROLL:
case OLARNEYE: case OBOOK: case OSPIRITSCARAB:
case ODIAMOND: case ORUBY: case OCUBEofUNDEAD:
case OEMERALD: case OCHEST: case OCOOKIE:
case OSAPPHIRE: case ONOTHEFT: show1(index); break;
default:
lprc('\n');
cltoeoln();
lprintf("%c) %s",index+'a',objectname[iven[index]]);
if (ivenarg[index]>0)
lprintf(" + %d",(long)ivenarg[index]);
else if (ivenarg[index]<0)
lprintf(" %d",(long)ivenarg[index]);
break;
}
if (c[WIELD]==index) lprcat(" (weapon in hand)");
if ((c[WEAR]==index) || (c[SHIELD]==index)) lprcat(" (being worn)");
if (++srcount>=22)
{
srcount=0;
itemselect = more(TRUE);
clear();
}
return( itemselect );
}
/*
* function to put something in the players inventory
* returns 0 if success, 1 if a failure
*/
int take(int itm, int arg)
{
int i, limit;
/* cursors(); */
if ((limit = 15+(c[LEVEL]>>1)) > MAXINVEN)
limit=MAXINVEN;
for (i=0; i<limit; i++)
if (iven[i]==0)
{
iven[i] = itm; ivenarg[i] = arg; limit=0;
switch(itm)
{
case OPROTRING: case ODAMRING: case OBELT: limit=1; break;
case ODEXRING: c[DEXTERITY] += ivenarg[i]+1; limit=1; break;
case OSTRRING: c[STREXTRA] += ivenarg[i]+1; limit=1; break;
case OCLEVERRING: c[INTELLIGENCE] += ivenarg[i]+1; limit=1; break;
case OHAMMER: c[DEXTERITY] += 10; c[STREXTRA]+=10;
c[INTELLIGENCE]-=10; limit=1; break;
case OORBOFDRAGON: c[SLAYING]++; break;
case OSPIRITSCARAB: c[NEGATESPIRIT]++; break;
case OCUBEofUNDEAD: c[CUBEofUNDEAD]++; break;
case ONOTHEFT: c[NOTHEFT]++; break;
case OSWORDofSLASHING: c[DEXTERITY] +=5; limit=1; break;
};
lprcat("\nYou pick up:"); show3(i);
if (limit) bottomline(); return(0);
}
lprcat("\nYou can't carry anything else"); return(1);
}
/*
* subroutine to drop an object returns 1 if something there already else 0
*/
int drop_object(int k)
{
int itm;
if ((k<0) || (k>=MAXINVEN))
return(0);
itm = iven[k]; cursors();
if (itm==0) { lprintf("\nYou don't have item %c! ",k+'a'); return(1); }
if (item[playerx][playery])
{ lprcat("\nThere's something here already"); return(1); }
if (playery==MAXY-1 && playerx==33) return(1); /* not in entrance */
item[playerx][playery] = itm;
iarg[playerx][playery] = ivenarg[k];
lprcat("\n You drop:"); show3(k); /* show what item you dropped*/
know[playerx][playery] = 0; iven[k]=0;
if (c[WIELD]==k) c[WIELD]= -1; if (c[WEAR]==k) c[WEAR] = -1;
if (c[SHIELD]==k) c[SHIELD]= -1;
adjustcvalues(itm,ivenarg[k]);
dropflag=1; /* say dropped an item so wont ask to pick it up right away */
return(0);
}
/*
* routine to tell if player can carry one more thing
* returns 1 if pockets are full, else 0
*/
int pocketfull(void)
{
int i, limit;
limit = MIN_LIMIT + (c[LEVEL] >> 1);
if (limit > MAXINVEN ) {
limit = MAXINVEN;
}
for (i = 0; i < limit; i++) {
if (iven[i] == 0) {
return 0;
}
}
return 1;
}