]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/inventory.c
1 /* $NetBSD: inventory.c,v 1.6 1998/11/10 13:01:32 hubertf Exp $ */
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)inventory.c 8.1 (Berkeley) 5/31/93";
44 __RCSID("$NetBSD: inventory.c,v 1.6 1998/11/10 13:01:32 hubertf Exp $");
51 * This source herein may be modified and/or distributed by anybody who
52 * so desires, with the following restrictions:
53 * 1.) No portion of this notice shall be removed.
54 * 2.) Credit shall not be taken for the creation of this source.
55 * 3.) This code is not to be traded, sold, or used for personal
62 boolean is_wood
[WANDS
];
63 const char *press_space
= " --press space to continue--";
65 const char *const wand_materials
[WAND_MATERIALS
] = {
99 const char *const gems
[GEMS
] = {
116 const char *const syllables
[MAXSYLLABLES
] = {
163 const char *com_desc
;
166 const struct id_com_s com_id_tab
[COMS
] = {
167 {'?', "? prints help"},
168 {'r', "r read scroll"},
169 {'/', "/ identify object"},
172 {'w', "w wield a weapon"},
174 {'W', "W wear armor"},
176 {'T', "T take armor off"},
178 {'P', "P put on ring"},
179 {'y', "y up & left"},
180 {'R', "R remove ring"},
181 {'u', "u up & right"},
182 {'d', "d drop object"},
183 {'b', "b down & left"},
184 {'c', "c call object"},
185 {'n', "n down & right"},
186 {'\0', "<SHIFT><dir>: run that way"},
187 {')', ") print current weapon"},
188 {'\0', "<CTRL><dir>: run till adjacent"},
189 {']', "] print current armor"},
190 {'f', "f<dir> fight till death or near death"},
191 {'=', "= print current rings"},
192 {'t', "t<dir> throw something"},
193 {'\001', "^A print Hp-raise average"},
194 {'m', "m<dir> move onto without picking up"},
195 {'z', "z<dir> zap a wand in a direction"},
196 {'o', "o examine/set options"},
197 {'^', "^<dir> identify trap type"},
198 {'\022', "^R redraw screen"},
199 {'&', "& save screen into 'rogue.screen'"},
200 {'s', "s search for trap/secret door"},
201 {'\020', "^P repeat last message"},
202 {'>', "> go down a staircase"},
203 {'\033', "^[ cancel command"},
204 {'<', "< go up a staircase"},
205 {'S', "S save game"},
206 {'.', ". rest for a turn"},
208 {',', ", pick something up"},
209 {'!', "! shell escape"},
210 {'i', "i inventory"},
211 {'F', "F<dir> fight till either of you dies"},
212 {'I', "I inventory single item"},
213 {'v', "v print version number"},
214 {'q', "q quaff potion" }
218 inventory(pack
, mask
)
223 short i
= 0, j
, maxlen
= 0, n
;
224 char descs
[MAX_PACK_COUNT
+1][DCOLS
];
227 obj
= pack
->next_object
;
230 message("your pack is empty", 0);
234 if (obj
->what_is
& mask
) {
236 descs
[i
][1] = obj
->ichar
;
237 descs
[i
][2] = ((obj
->what_is
& ARMOR
) && obj
->is_protected
)
240 get_desc(obj
, descs
[i
]+4);
241 if ((n
= strlen(descs
[i
])) > maxlen
) {
246 obj
= obj
->next_object
;
248 (void) strcpy(descs
[i
++], press_space
);
249 if (maxlen
< 27) maxlen
= 27;
250 col
= DCOLS
- (maxlen
+ 2);
252 for (row
= 0; ((row
< i
) && (row
< DROWS
)); row
++) {
254 for (j
= col
; j
< DCOLS
; j
++) {
255 descs
[row
-1][j
-col
] = mvinch(row
, j
);
257 descs
[row
-1][j
-col
] = 0;
259 mvaddstr(row
, col
, descs
[row
]);
268 for (j
= 1; ((j
< i
) && (j
< DROWS
)); j
++) {
269 mvaddstr(j
, col
, descs
[j
-1]);
279 while (ch
!= CANCEL
) {
281 message("Character you want help for (* for all):", 0);
289 char save
[(((COMS
/ 2) + (COMS
% 2)) + 1)][DCOLS
];
290 short rows
= (((COMS
/ 2) + (COMS
% 2)) + 1);
291 boolean need_two_screens
= FALSE
;
294 need_two_screens
= 1;
299 for (i
= 0; i
< rows
; i
++) {
300 for (j
= 0; j
< DCOLS
; j
++) {
301 save
[i
][j
] = mvinch(i
, j
);
305 for (i
= 0; i
< rows
; i
++) {
309 for (i
= 0; i
< (rows
-1); i
++) {
311 if (((i
+ i
) < COMS
) && ((i
+i
+k
) < COMS
)) {
312 mvaddstr(i
, 0, com_id_tab
[i
+i
+k
].com_desc
);
314 if (((i
+ i
+ 1) < COMS
) && ((i
+i
+k
+1) < COMS
)) {
315 mvaddstr(i
, (DCOLS
/2),
316 com_id_tab
[i
+i
+k
+1].com_desc
);
320 mvaddstr(rows
- 1, 0, need_two_screens
? more
: press_space
);
324 if (need_two_screens
) {
326 need_two_screens
= 0;
329 for (i
= 0; i
< rows
; i
++) {
331 for (j
= 0; j
< DCOLS
; j
++) {
338 if (!pr_com_id(ch
)) {
339 if (!pr_motion_char(ch
)) {
341 message("unknown character", 0);
356 if (!get_com_id(&i
, ch
)) {
360 message(com_id_tab
[i
].com_desc
, 0);
365 get_com_id(index
, ch
)
371 for (i
= 0; i
< COMS
; i
++) {
372 if (com_id_tab
[i
].com_char
== ch
) {
400 char until
[18], buf
[DCOLS
];
405 (void) strcpy(until
, "until adjascent");
410 (void) get_com_id(&n
, ch
);
411 sprintf(buf
, "run %s %s", com_id_tab
[n
].com_desc
+ 8, until
);
426 for (i
= 0; i
<= 32; i
++) {
427 j
= get_rand(0, (POTIONS
- 1));
428 k
= get_rand(0, (POTIONS
- 1));
429 t
= id_potions
[j
].title
;
430 id_potions
[j
].title
= id_potions
[k
].title
;
431 id_potions
[k
].title
= t
;
441 for (i
= 0; i
< SCROLS
; i
++) {
442 sylls
= get_rand(2, 5);
443 (void) strcpy(id_scrolls
[i
].title
, "'");
445 for (j
= 0; j
< sylls
; j
++) {
446 s
= get_rand(1, (MAXSYLLABLES
-1));
447 (void) strcat(id_scrolls
[i
].title
, syllables
[s
]);
449 n
= strlen(id_scrolls
[i
].title
);
450 (void) strcpy(id_scrolls
[i
].title
+(n
-1), "' ");
459 const char *item_name
;
464 if (obj
->what_is
== AMULET
) {
465 (void) strcpy(desc
, "the amulet of Yendor ");
468 item_name
= name_of(obj
);
470 if (obj
->what_is
== GOLD
) {
471 sprintf(desc
, "%d pieces of gold", obj
->quantity
);
475 if (obj
->what_is
!= ARMOR
) {
476 if (obj
->quantity
== 1) {
477 (void) strcpy(desc
, "a ");
479 sprintf(desc
, "%d ", obj
->quantity
);
482 if (obj
->what_is
== FOOD
) {
483 if (obj
->which_kind
== RATION
) {
484 if (obj
->quantity
> 1) {
485 sprintf(desc
, "%d rations of ", obj
->quantity
);
487 (void) strcpy(desc
, "some ");
490 (void) strcpy(desc
, "a ");
492 (void) strcat(desc
, item_name
);
495 id_table
= get_id_table(obj
);
500 if (obj
->what_is
& (WEAPON
| ARMOR
| WAND
| RING
)) {
504 switch(id_table
[obj
->which_kind
].id_status
) {
507 switch(obj
->what_is
) {
509 (void) strcat(desc
, item_name
);
510 (void) strcat(desc
, "entitled: ");
511 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
514 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
515 (void) strcat(desc
, item_name
);
519 if (obj
->identified
||
520 (id_table
[obj
->which_kind
].id_status
== IDENTIFIED
)) {
523 if (id_table
[obj
->which_kind
].id_status
== CALLED
) {
526 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
527 (void) strcat(desc
, item_name
);
530 if (obj
->identified
) {
533 (void) strcpy(desc
, id_table
[obj
->which_kind
].title
);
536 if (obj
->identified
) {
539 (void) strcat(desc
, name_of(obj
));
544 CALL
: switch(obj
->what_is
) {
549 (void) strcat(desc
, item_name
);
550 (void) strcat(desc
, "called ");
551 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
556 ID
: switch(obj
->what_is
) {
559 (void) strcat(desc
, item_name
);
560 (void) strcat(desc
, id_table
[obj
->which_kind
].real
);
563 if (wizard
|| obj
->identified
) {
564 if ((obj
->which_kind
== DEXTERITY
) ||
565 (obj
->which_kind
== ADD_STRENGTH
)) {
566 sprintf(more_info
, "%s%d ", ((obj
->class > 0) ? "+" : ""),
568 (void) strcat(desc
, more_info
);
571 (void) strcat(desc
, item_name
);
572 (void) strcat(desc
, id_table
[obj
->which_kind
].real
);
575 (void) strcat(desc
, item_name
);
576 (void) strcat(desc
, id_table
[obj
->which_kind
].real
);
577 if (wizard
|| obj
->identified
) {
578 sprintf(more_info
, "[%d]", obj
->class);
579 (void) strcat(desc
, more_info
);
583 sprintf(desc
, "%s%d ", ((obj
->d_enchant
>= 0) ? "+" : ""),
585 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
586 sprintf(more_info
, "[%d] ", get_armor_class(obj
));
587 (void) strcat(desc
, more_info
);
590 sprintf(desc
+strlen(desc
), "%s%d,%s%d ",
591 ((obj
->hit_enchant
>= 0) ? "+" : ""), obj
->hit_enchant
,
592 ((obj
->d_enchant
>= 0) ? "+" : ""), obj
->d_enchant
);
593 (void) strcat(desc
, name_of(obj
));
599 if (!strncmp(desc
, "a ", 2)) {
600 if (is_vowel(desc
[2])) {
601 for (i
= strlen(desc
) + 1; i
> 1; i
--) {
607 if (obj
->in_use_flags
& BEING_WIELDED
) {
608 (void) strcat(desc
, "in hand");
609 } else if (obj
->in_use_flags
& BEING_WORN
) {
610 (void) strcat(desc
, "being worn");
611 } else if (obj
->in_use_flags
& ON_LEFT_HAND
) {
612 (void) strcat(desc
, "on left hand");
613 } else if (obj
->in_use_flags
& ON_RIGHT_HAND
) {
614 (void) strcat(desc
, "on right hand");
619 get_wand_and_ring_materials()
622 boolean used
[WAND_MATERIALS
];
624 for (i
= 0; i
< WAND_MATERIALS
; i
++) {
627 for (i
= 0; i
< WANDS
; i
++) {
629 j
= get_rand(0, WAND_MATERIALS
-1);
632 (void) strcpy(id_wands
[i
].title
, wand_materials
[j
]);
633 is_wood
[i
] = (j
> MAX_METAL
);
635 for (i
= 0; i
< GEMS
; i
++) {
638 for (i
= 0; i
< RINGS
; i
++) {
640 j
= get_rand(0, GEMS
-1);
643 (void) strcpy(id_rings
[i
].title
, gems
[j
]);
655 ch
= ichar
? ichar
: pack_letter("inventory what?", ALL_OBJECTS
);
660 if (!(obj
= get_letter_object(ch
))) {
661 message("no such item.", 0);
665 desc
[1] = ((obj
->what_is
& ARMOR
) && obj
->is_protected
) ? '}' : ')';
668 get_desc(obj
, desc
+3);
676 switch(obj
->what_is
) {
690 return((struct id
*) 0);
694 inv_armor_weapon(is_weapon
)
699 single_inv(rogue
.weapon
->ichar
);
701 message("not wielding anything", 0);
705 single_inv(rogue
.armor
->ichar
);
707 message("not wearing anything", 0);
719 message("what do you want identified?", 0);
723 if ((ch
>= 'A') && (ch
<= 'Z')) {
724 id
= m_names
[ch
-'A'];
725 } else if (ch
< 32) {
744 id
= "wall of a room";
765 id
= "wand or staff";
780 id
= "the Amulet of Yendor";
783 id
= "unknown character";
788 sprintf(buf
, "'%c': %s", ch
, id
);