2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)inventory.c 8.1 (Berkeley) 5/31/93
37 * $FreeBSD: src/games/rogue/inventory.c,v 1.4 1999/11/30 03:49:23 billf Exp $
38 * $DragonFly: src/games/rogue/inventory.c,v 1.4 2006/09/02 19:31:07 pavalos Exp $
44 * This source herein may be modified and/or distributed by anybody who
45 * so desires, with the following restrictions:
46 * 1.) No portion of this notice shall be removed.
47 * 2.) Credit shall not be taken for the creation of this source.
48 * 3.) This code is not to be traded, sold, or used for personal
55 static boolean
pr_com_id(int);
56 static boolean
get_com_id(int *, short);
57 static boolean
pr_motion_char(int);
59 boolean is_wood
[WANDS
];
60 const char *press_space
= " --press space to continue--";
62 const char *const wand_materials
[WAND_MATERIALS
] = {
95 const char *const gems
[GEMS
] = {
112 const char *const syllables
[MAXSYLLABLES
] = {
159 const char *com_desc
;
162 const struct id_com_s com_id_tab
[COMS
] = {
163 { '?', "? prints help" },
164 { 'r', "r read scroll" },
165 { '/', "/ identify object" },
166 { 'e', "e eat food" },
168 { 'w', "w wield a weapon" },
170 { 'W', "W wear armor" },
172 { 'T', "T take armor off" },
174 { 'P', "P put on ring" },
175 { 'y', "y up & left" },
176 { 'R', "R remove ring" },
177 { 'u', "u up & right" },
178 { 'd', "d drop object" },
179 { 'b', "b down & left" },
180 { 'c', "c call object" },
181 { 'n', "n down & right" },
182 { '\0', "<SHIFT><dir>: run that way" },
183 { ')', ") print current weapon" },
184 { '\0', "<CTRL><dir>: run till adjacent" },
185 { ']', "] print current armor" },
186 { 'f', "f<dir> fight till death or near death" },
187 { '=', "= print current rings" },
188 { 't', "t<dir> throw something" },
189 { '\001', "^A print Hp-raise average" },
190 { 'm', "m<dir> move onto without picking up" },
191 { 'z', "z<dir> zap a wand in a direction" },
192 { 'o', "o examine/set options" },
193 { '^', "^<dir> identify trap type" },
194 { '\022', "^R redraw screen" },
195 { '&', "& save screen into 'rogue.screen'" },
196 { 's', "s search for trap/secret door" },
197 { '\020', "^P repeat last message" },
198 { '>', "> go down a staircase" },
199 { '\033', "^[ cancel command" },
200 { '<', "< go up a staircase" },
201 { 'S', "S save game" },
202 { '.', ". rest for a turn" },
204 { ',', ", pick something up" },
205 { '!', "! shell escape" },
206 { 'i', "i inventory" },
207 { 'F', "F<dir> fight till either of you dies" },
208 { 'I', "I inventory single item" },
209 { 'v', "v print version number" },
210 { 'q', "q quaff potion" }
213 extern boolean wizard
;
214 extern char *m_names
[], *more
;
217 inventory(const object
*pack
, unsigned short mask
)
220 short i
= 0, j
, maxlen
= 0, n
;
221 char descs
[MAX_PACK_COUNT
+1][DCOLS
];
224 obj
= pack
->next_object
;
227 message("your pack is empty", 0);
231 if (obj
->what_is
& mask
) {
233 descs
[i
][1] = obj
->ichar
;
234 descs
[i
][2] = ((obj
->what_is
& ARMOR
) && obj
->is_protected
)
237 get_desc(obj
, descs
[i
]+4);
238 if ((n
= strlen(descs
[i
])) > maxlen
) {
243 obj
= obj
->next_object
;
245 strcpy(descs
[i
++], press_space
);
246 if (maxlen
< 27) maxlen
= 27;
247 col
= DCOLS
- (maxlen
+ 2);
249 for (row
= 0; ((row
< i
) && (row
< DROWS
)); row
++) {
251 for (j
= col
; j
< DCOLS
; j
++) {
252 descs
[row
-1][j
-col
] = mvinch(row
, j
);
254 descs
[row
-1][j
-col
] = 0;
256 mvaddstr(row
, col
, descs
[row
]);
265 for (j
= 1; ((j
< i
) && (j
< DROWS
)); j
++) {
266 mvaddstr(j
, col
, descs
[j
-1]);
276 while (ch
!= CANCEL
) {
278 message("Character you want help for (* for all):", 0);
286 char save
[(((COMS
/ 2) + (COMS
% 2)) + 1)][DCOLS
];
287 short rows
= (((COMS
/ 2) + (COMS
% 2)) + 1);
288 boolean need_two_screens
= 0;
291 need_two_screens
= 1;
296 for (i
= 0; i
< rows
; i
++) {
297 for (j
= 0; j
< DCOLS
; j
++) {
298 save
[i
][j
] = mvinch(i
, j
);
302 for (i
= 0; i
< rows
; i
++) {
306 for (i
= 0; i
< (rows
-1); i
++) {
308 if (((i
+ i
) < COMS
) && ((i
+i
+k
) < COMS
)) {
309 mvaddstr(i
, 0, com_id_tab
[i
+i
+k
].com_desc
);
311 if (((i
+ i
+ 1) < COMS
) && ((i
+i
+k
+1) < COMS
)) {
312 mvaddstr(i
, (DCOLS
/2),
313 com_id_tab
[i
+i
+k
+1].com_desc
);
317 mvaddstr(rows
- 1, 0, need_two_screens
? more
: press_space
);
321 if (need_two_screens
) {
323 need_two_screens
= 0;
326 for (i
= 0; i
< rows
; i
++) {
328 for (j
= 0; j
< DCOLS
; j
++) {
335 if (!pr_com_id(ch
)) {
336 if (!pr_motion_char(ch
)) {
338 message("unknown character", 0);
352 if (!get_com_id(&i
, ch
)) {
356 message(com_id_tab
[i
].com_desc
, 0);
361 get_com_id(int *idx
, short ch
)
365 for (i
= 0; i
< COMS
; i
++) {
366 if (com_id_tab
[i
].com_char
== ch
) {
375 pr_motion_char(int ch
)
393 char until
[18], buf
[DCOLS
];
398 strcpy(until
, "until adjascent");
404 sprintf(buf
, "run %s %s", com_id_tab
[n
].com_desc
+ 8, until
);
417 char *t
[MAX_ID_TITLE_LEN
];
419 for (i
= 0; i
<= 32; i
++) {
420 j
= get_rand(0, (POTIONS
- 1));
421 k
= get_rand(0, (POTIONS
- 1));
422 memcpy(t
, id_potions
[j
].title
, MAX_ID_TITLE_LEN
);
423 memcpy(id_potions
[j
].title
, id_potions
[k
].title
, MAX_ID_TITLE_LEN
);
428 make_scroll_titles(void)
433 for (i
= 0; i
< SCROLS
; i
++) {
434 sylls
= get_rand(2, 5);
435 strcpy(id_scrolls
[i
].title
, "'");
437 for (j
= 0; j
< sylls
; j
++) {
438 s
= get_rand(1, (MAXSYLLABLES
-1));
439 strcat(id_scrolls
[i
].title
, syllables
[s
]);
441 n
= strlen(id_scrolls
[i
].title
);
442 strcpy(id_scrolls
[i
].title
+(n
-1), "' ");
447 get_desc(const object
*obj
, char *desc
)
449 const char *item_name
;
454 if (obj
->what_is
== AMULET
) {
455 strcpy(desc
, "the amulet of Yendor ");
458 item_name
= name_of(obj
);
460 if (obj
->what_is
== GOLD
) {
461 sprintf(desc
, "%d pieces of gold", obj
->quantity
);
465 if (obj
->what_is
!= ARMOR
) {
466 if (obj
->quantity
== 1) {
469 sprintf(desc
, "%d ", obj
->quantity
);
472 if (obj
->what_is
== FOOD
) {
473 if (obj
->which_kind
== RATION
) {
474 if (obj
->quantity
> 1) {
475 sprintf(desc
, "%d rations of ", obj
->quantity
);
477 strcpy(desc
, "some ");
482 strcat(desc
, item_name
);
485 id_table
= get_id_table(obj
);
490 if (obj
->what_is
& (WEAPON
| ARMOR
| WAND
| RING
)) {
494 switch(id_table
[obj
->which_kind
].id_status
) {
497 switch(obj
->what_is
) {
499 strcat(desc
, item_name
);
500 strcat(desc
, "entitled: ");
501 strcat(desc
, id_table
[obj
->which_kind
].title
);
504 strcat(desc
, id_table
[obj
->which_kind
].title
);
505 strcat(desc
, item_name
);
509 if (obj
->identified
||
510 (id_table
[obj
->which_kind
].id_status
== IDENTIFIED
)) {
513 if (id_table
[obj
->which_kind
].id_status
== CALLED
) {
516 strcat(desc
, id_table
[obj
->which_kind
].title
);
517 strcat(desc
, item_name
);
520 if (obj
->identified
) {
523 strcpy(desc
, id_table
[obj
->which_kind
].title
);
526 if (obj
->identified
) {
529 strcat(desc
, name_of(obj
));
534 CALL
: switch(obj
->what_is
) {
539 strcat(desc
, item_name
);
540 strcat(desc
, "called ");
541 strcat(desc
, id_table
[obj
->which_kind
].title
);
546 ID
: switch(obj
->what_is
) {
549 strcat(desc
, item_name
);
550 strcat(desc
, id_table
[obj
->which_kind
].real
);
553 if (wizard
|| obj
->identified
) {
554 if ((obj
->which_kind
== DEXTERITY
) ||
555 (obj
->which_kind
== ADD_STRENGTH
)) {
556 sprintf(more_info
, "%s%d ", ((obj
->class > 0) ? "+" : ""),
558 strcat(desc
, more_info
);
561 strcat(desc
, item_name
);
562 strcat(desc
, id_table
[obj
->which_kind
].real
);
565 strcat(desc
, item_name
);
566 strcat(desc
, id_table
[obj
->which_kind
].real
);
567 if (wizard
|| obj
->identified
) {
568 sprintf(more_info
, "[%d]", obj
->class);
569 strcat(desc
, more_info
);
573 sprintf(desc
, "%s%d ", ((obj
->d_enchant
>= 0) ? "+" : ""),
575 strcat(desc
, id_table
[obj
->which_kind
].title
);
576 sprintf(more_info
, "[%d] ", get_armor_class(obj
));
577 strcat(desc
, more_info
);
580 sprintf(desc
+strlen(desc
), "%s%d,%s%d ",
581 ((obj
->hit_enchant
>= 0) ? "+" : ""), obj
->hit_enchant
,
582 ((obj
->d_enchant
>= 0) ? "+" : ""), obj
->d_enchant
);
583 strcat(desc
, name_of(obj
));
589 if (!strncmp(desc
, "a ", 2)) {
590 if (is_vowel(desc
[2])) {
591 for (i
= strlen(desc
) + 1; i
> 1; i
--) {
597 if (obj
->in_use_flags
& BEING_WIELDED
) {
598 strcat(desc
, "in hand");
599 } else if (obj
->in_use_flags
& BEING_WORN
) {
600 strcat(desc
, "being worn");
601 } else if (obj
->in_use_flags
& ON_LEFT_HAND
) {
602 strcat(desc
, "on left hand");
603 } else if (obj
->in_use_flags
& ON_RIGHT_HAND
) {
604 strcat(desc
, "on right hand");
609 get_wand_and_ring_materials(void)
612 boolean used
[WAND_MATERIALS
];
614 for (i
= 0; i
< WAND_MATERIALS
; i
++) {
617 for (i
= 0; i
< WANDS
; i
++) {
619 j
= get_rand(0, WAND_MATERIALS
-1);
622 strcpy(id_wands
[i
].title
, wand_materials
[j
]);
623 is_wood
[i
] = (j
> MAX_METAL
);
625 for (i
= 0; i
< GEMS
; i
++) {
628 for (i
= 0; i
< RINGS
; i
++) {
630 j
= get_rand(0, GEMS
-1);
633 strcpy(id_rings
[i
].title
, gems
[j
]);
638 single_inv(short ichar
)
644 ch
= ichar
? ichar
: pack_letter("inventory what?", ALL_OBJECTS
);
649 if (!(obj
= get_letter_object(ch
))) {
650 message("no such item.", 0);
654 desc
[1] = ((obj
->what_is
& ARMOR
) && obj
->is_protected
) ? '}' : ')';
657 get_desc(obj
, desc
+3);
662 get_id_table(const object
*obj
)
664 switch(obj
->what_is
) {
678 return((struct id
*) 0);
682 inv_armor_weapon(boolean is_weapon
)
686 single_inv(rogue
.weapon
->ichar
);
688 message("not wielding anything", 0);
692 single_inv(rogue
.armor
->ichar
);
694 message("not wearing anything", 0);
706 message("what do you want identified?", 0);
710 if ((ch
>= 'A') && (ch
<= 'Z')) {
711 id
= m_names
[ch
-'A'];
712 } else if (ch
< 32) {
731 id
= "wall of a room";
752 id
= "wand or staff";
767 id
= "the Amulet of Yendor";
770 id
= "unknown character";
775 sprintf(buf
, "'%c': %s", ch
, id
);