]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/inventory.c
1 /* $NetBSD: inventory.c,v 1.9 2003/08/07 09:37:38 agc 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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)inventory.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: inventory.c,v 1.9 2003/08/07 09:37:38 agc Exp $");
47 * This source herein may be modified and/or distributed by anybody who
48 * so desires, with the following restrictions:
49 * 1.) No portion of this notice shall be removed.
50 * 2.) Credit shall not be taken for the creation of this source.
51 * 3.) This code is not to be traded, sold, or used for personal
58 boolean is_wood
[WANDS
];
59 const char *press_space
= " --press space to continue--";
61 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"},
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" }
214 inventory(pack
, mask
)
219 short i
= 0, j
, maxlen
= 0, n
;
220 char descs
[MAX_PACK_COUNT
+1][DCOLS
];
223 obj
= pack
->next_object
;
226 message("your pack is empty", 0);
230 if (obj
->what_is
& mask
) {
232 descs
[i
][1] = obj
->ichar
;
233 descs
[i
][2] = ((obj
->what_is
& ARMOR
) && obj
->is_protected
)
236 get_desc(obj
, descs
[i
]+4);
237 if ((n
= strlen(descs
[i
])) > maxlen
) {
242 obj
= obj
->next_object
;
244 (void) strcpy(descs
[i
++], press_space
);
245 if (maxlen
< 27) maxlen
= 27;
246 col
= DCOLS
- (maxlen
+ 2);
248 for (row
= 0; ((row
< i
) && (row
< DROWS
)); row
++) {
250 for (j
= col
; j
< DCOLS
; j
++) {
251 descs
[row
-1][j
-col
] = mvinch(row
, j
);
253 descs
[row
-1][j
-col
] = 0;
255 mvaddstr(row
, col
, descs
[row
]);
264 for (j
= 1; ((j
< i
) && (j
< DROWS
)); j
++) {
265 mvaddstr(j
, col
, descs
[j
-1]);
275 while (ch
!= CANCEL
) {
277 message("Character you want help for (* for all):", 0);
285 char save
[(((COMS
/ 2) + (COMS
% 2)) + 1)][DCOLS
];
286 short rows
= (((COMS
/ 2) + (COMS
% 2)) + 1);
287 boolean need_two_screens
= FALSE
;
290 need_two_screens
= 1;
295 for (i
= 0; i
< rows
; i
++) {
296 for (j
= 0; j
< DCOLS
; j
++) {
297 save
[i
][j
] = mvinch(i
, j
);
301 for (i
= 0; i
< rows
; i
++) {
305 for (i
= 0; i
< (rows
-1); i
++) {
307 if (((i
+ i
) < COMS
) && ((i
+i
+k
) < COMS
)) {
308 mvaddstr(i
, 0, com_id_tab
[i
+i
+k
].com_desc
);
310 if (((i
+ i
+ 1) < COMS
) && ((i
+i
+k
+1) < COMS
)) {
311 mvaddstr(i
, (DCOLS
/2),
312 com_id_tab
[i
+i
+k
+1].com_desc
);
316 mvaddstr(rows
- 1, 0, need_two_screens
? more
: press_space
);
320 if (need_two_screens
) {
322 need_two_screens
= 0;
325 for (i
= 0; i
< rows
; i
++) {
327 for (j
= 0; j
< DCOLS
; j
++) {
334 if (!pr_com_id(ch
)) {
335 if (!pr_motion_char(ch
)) {
337 message("unknown character", 0);
352 if (!get_com_id(&i
, ch
)) {
356 message(com_id_tab
[i
].com_desc
, 0);
361 get_com_id(indexp
, ch
)
367 for (i
= 0; i
< COMS
; i
++) {
368 if (com_id_tab
[i
].com_char
== ch
) {
396 char until
[18], buf
[DCOLS
];
401 (void) strcpy(until
, "until adjascent");
406 (void) get_com_id(&n
, ch
);
407 sprintf(buf
, "run %s %s", com_id_tab
[n
].com_desc
+ 8, until
);
420 char t
[MAX_ID_TITLE_LEN
];
422 for (i
= 0; i
<= 32; i
++) {
423 j
= get_rand(0, (POTIONS
- 1));
424 k
= get_rand(0, (POTIONS
- 1));
425 memcpy(t
, id_potions
[j
].title
, MAX_ID_TITLE_LEN
);
426 memcpy(id_potions
[j
].title
, id_potions
[k
].title
, MAX_ID_TITLE_LEN
);
427 memcpy(id_potions
[k
].title
, t
, MAX_ID_TITLE_LEN
);
437 for (i
= 0; i
< SCROLS
; i
++) {
438 sylls
= get_rand(2, 5);
439 (void) strcpy(id_scrolls
[i
].title
, "'");
441 for (j
= 0; j
< sylls
; j
++) {
442 s
= get_rand(1, (MAXSYLLABLES
-1));
443 (void) strcat(id_scrolls
[i
].title
, syllables
[s
]);
445 n
= strlen(id_scrolls
[i
].title
);
446 (void) strcpy(id_scrolls
[i
].title
+(n
-1), "' ");
455 const char *item_name
;
460 if (obj
->what_is
== AMULET
) {
461 (void) strcpy(desc
, "the amulet of Yendor ");
464 item_name
= name_of(obj
);
466 if (obj
->what_is
== GOLD
) {
467 sprintf(desc
, "%d pieces of gold", obj
->quantity
);
471 if (obj
->what_is
!= ARMOR
) {
472 if (obj
->quantity
== 1) {
473 (void) strcpy(desc
, "a ");
475 sprintf(desc
, "%d ", obj
->quantity
);
478 if (obj
->what_is
== FOOD
) {
479 if (obj
->which_kind
== RATION
) {
480 if (obj
->quantity
> 1) {
481 sprintf(desc
, "%d rations of ", obj
->quantity
);
483 (void) strcpy(desc
, "some ");
486 (void) strcpy(desc
, "a ");
488 (void) strcat(desc
, item_name
);
491 id_table
= get_id_table(obj
);
496 if (obj
->what_is
& (WEAPON
| ARMOR
| WAND
| RING
)) {
500 switch(id_table
[obj
->which_kind
].id_status
) {
503 switch(obj
->what_is
) {
505 (void) strcat(desc
, item_name
);
506 (void) strcat(desc
, "entitled: ");
507 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
510 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
511 (void) strcat(desc
, item_name
);
515 if (obj
->identified
||
516 (id_table
[obj
->which_kind
].id_status
== IDENTIFIED
)) {
519 if (id_table
[obj
->which_kind
].id_status
== CALLED
) {
522 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
523 (void) strcat(desc
, item_name
);
526 if (obj
->identified
) {
529 (void) strcpy(desc
, id_table
[obj
->which_kind
].title
);
532 if (obj
->identified
) {
535 (void) strcat(desc
, name_of(obj
));
540 CALL
: switch(obj
->what_is
) {
545 (void) strcat(desc
, item_name
);
546 (void) strcat(desc
, "called ");
547 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
552 ID
: switch(obj
->what_is
) {
555 (void) strcat(desc
, item_name
);
556 (void) strcat(desc
, id_table
[obj
->which_kind
].real
);
559 if (wizard
|| obj
->identified
) {
560 if ((obj
->which_kind
== DEXTERITY
) ||
561 (obj
->which_kind
== ADD_STRENGTH
)) {
562 sprintf(more_info
, "%s%d ", ((obj
->class > 0) ? "+" : ""),
564 (void) strcat(desc
, more_info
);
567 (void) strcat(desc
, item_name
);
568 (void) strcat(desc
, id_table
[obj
->which_kind
].real
);
571 (void) strcat(desc
, item_name
);
572 (void) strcat(desc
, id_table
[obj
->which_kind
].real
);
573 if (wizard
|| obj
->identified
) {
574 sprintf(more_info
, "[%d]", obj
->class);
575 (void) strcat(desc
, more_info
);
579 sprintf(desc
, "%s%d ", ((obj
->d_enchant
>= 0) ? "+" : ""),
581 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
582 sprintf(more_info
, "[%d] ", get_armor_class(obj
));
583 (void) strcat(desc
, more_info
);
586 sprintf(desc
+strlen(desc
), "%s%d,%s%d ",
587 ((obj
->hit_enchant
>= 0) ? "+" : ""), obj
->hit_enchant
,
588 ((obj
->d_enchant
>= 0) ? "+" : ""), obj
->d_enchant
);
589 (void) strcat(desc
, name_of(obj
));
595 if (!strncmp(desc
, "a ", 2)) {
596 if (is_vowel(desc
[2])) {
597 for (i
= strlen(desc
) + 1; i
> 1; i
--) {
603 if (obj
->in_use_flags
& BEING_WIELDED
) {
604 (void) strcat(desc
, "in hand");
605 } else if (obj
->in_use_flags
& BEING_WORN
) {
606 (void) strcat(desc
, "being worn");
607 } else if (obj
->in_use_flags
& ON_LEFT_HAND
) {
608 (void) strcat(desc
, "on left hand");
609 } else if (obj
->in_use_flags
& ON_RIGHT_HAND
) {
610 (void) strcat(desc
, "on right hand");
615 get_wand_and_ring_materials()
618 boolean used
[WAND_MATERIALS
];
620 for (i
= 0; i
< WAND_MATERIALS
; i
++) {
623 for (i
= 0; i
< WANDS
; i
++) {
625 j
= get_rand(0, WAND_MATERIALS
-1);
628 (void) strcpy(id_wands
[i
].title
, wand_materials
[j
]);
629 is_wood
[i
] = (j
> MAX_METAL
);
631 for (i
= 0; i
< GEMS
; i
++) {
634 for (i
= 0; i
< RINGS
; i
++) {
636 j
= get_rand(0, GEMS
-1);
639 (void) strcpy(id_rings
[i
].title
, gems
[j
]);
651 ch
= ichar
? ichar
: pack_letter("inventory what?", ALL_OBJECTS
);
656 if (!(obj
= get_letter_object(ch
))) {
657 message("no such item.", 0);
661 desc
[1] = ((obj
->what_is
& ARMOR
) && obj
->is_protected
) ? '}' : ')';
664 get_desc(obj
, desc
+3);
672 switch(obj
->what_is
) {
686 return((struct id
*) 0);
690 inv_armor_weapon(is_weapon
)
695 single_inv(rogue
.weapon
->ichar
);
697 message("not wielding anything", 0);
701 single_inv(rogue
.armor
->ichar
);
703 message("not wearing anything", 0);
715 message("what do you want identified?", 0);
719 if ((ch
>= 'A') && (ch
<= 'Z')) {
720 id
= m_names
[ch
-'A'];
721 } else if (ch
< 32) {
740 id
= "wall of a room";
761 id
= "wand or staff";
776 id
= "the Amulet of Yendor";
779 id
= "unknown character";
784 sprintf(buf
, "'%c': %s", ch
, id
);