]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/inventory.c
1 /* $NetBSD: inventory.c,v 1.4 1997/05/17 19:26:24 pk 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
41 static char sccsid
[] = "@(#)inventory.c 8.1 (Berkeley) 5/31/93";
43 static char rcsid
[] = "$NetBSD: inventory.c,v 1.4 1997/05/17 19:26:24 pk Exp $";
50 * This source herein may be modified and/or distributed by anybody who
51 * so desires, with the following restrictions:
52 * 1.) No portion of this notice shall be removed.
53 * 2.) Credit shall not be taken for the creation of this source.
54 * 3.) This code is not to be traded, sold, or used for personal
61 boolean is_wood
[WANDS
];
62 char *press_space
= " --press space to continue--";
64 char *wand_materials
[WAND_MATERIALS
] = {
115 char *syllables
[MAXSYLLABLES
] = {
165 struct id_com_s com_id_tab
[COMS
] = {
166 '?', "? prints help",
167 'r', "r read scroll",
168 '/', "/ identify object",
171 'w', "w wield a weapon",
175 'T', "T take armor off",
177 'P', "P put on ring",
179 'R', "R remove ring",
181 'd', "d drop object",
182 'b', "b down & left",
183 'c', "c call object",
184 'n', "n down & right",
185 '\0', "<SHIFT><dir>: run that way",
186 ')', ") print current weapon",
187 '\0', "<CTRL><dir>: run till adjacent",
188 ']', "] print current armor",
189 'f', "f<dir> fight till death or near death",
190 '=', "= print current rings",
191 't', "t<dir> throw something",
192 '\001', "^A print Hp-raise average",
193 'm', "m<dir> move onto without picking up",
194 'z', "z<dir> zap a wand in a direction",
195 'o', "o examine/set options",
196 '^', "^<dir> identify trap type",
197 '\022', "^R redraw screen",
198 '&', "& save screen into 'rogue.screen'",
199 's', "s search for trap/secret door",
200 '\020', "^P repeat last message",
201 '>', "> go down a staircase",
202 '\033', "^[ cancel command",
203 '<', "< go up a staircase",
205 '.', ". rest for a turn",
207 ',', ", pick something up",
208 '!', "! shell escape",
210 'F', "F<dir> fight till either of you dies",
211 'I', "I inventory single item",
212 'v', "v print version number",
213 'q', "q quaff potion"
216 extern boolean wizard
;
217 extern char *m_names
[], *more
;
219 inventory(pack
, mask
)
224 short i
= 0, j
, maxlen
= 0, n
;
225 char descs
[MAX_PACK_COUNT
+1][DCOLS
];
228 obj
= pack
->next_object
;
231 message("your pack is empty", 0);
235 if (obj
->what_is
& mask
) {
237 descs
[i
][1] = obj
->ichar
;
238 descs
[i
][2] = ((obj
->what_is
& ARMOR
) && obj
->is_protected
)
241 get_desc(obj
, descs
[i
]+4);
242 if ((n
= strlen(descs
[i
])) > maxlen
) {
247 obj
= obj
->next_object
;
249 (void) strcpy(descs
[i
++], press_space
);
250 if (maxlen
< 27) maxlen
= 27;
251 col
= DCOLS
- (maxlen
+ 2);
253 for (row
= 0; ((row
< i
) && (row
< DROWS
)); row
++) {
255 for (j
= col
; j
< DCOLS
; j
++) {
256 descs
[row
-1][j
-col
] = mvinch(row
, j
);
258 descs
[row
-1][j
-col
] = 0;
260 mvaddstr(row
, col
, descs
[row
]);
269 for (j
= 1; ((j
< i
) && (j
< DROWS
)); j
++) {
270 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
;
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);
355 if (!get_com_id(&i
, ch
)) {
359 message(com_id_tab
[i
].com_desc
, 0);
363 get_com_id(index
, ch
)
369 for (i
= 0; i
< COMS
; i
++) {
370 if (com_id_tab
[i
].com_char
== ch
) {
397 char until
[18], buf
[DCOLS
];
402 (void) strcpy(until
, "until adjascent");
407 (void) get_com_id(&n
, ch
);
408 sprintf(buf
, "run %s %s", com_id_tab
[n
].com_desc
+ 8, until
);
422 for (i
= 0; i
<= 32; i
++) {
423 j
= get_rand(0, (POTIONS
- 1));
424 k
= get_rand(0, (POTIONS
- 1));
425 t
= id_potions
[j
].title
;
426 id_potions
[j
].title
= id_potions
[k
].title
;
427 id_potions
[k
].title
= t
;
436 for (i
= 0; i
< SCROLS
; i
++) {
437 sylls
= get_rand(2, 5);
438 (void) strcpy(id_scrolls
[i
].title
, "'");
440 for (j
= 0; j
< sylls
; j
++) {
441 s
= get_rand(1, (MAXSYLLABLES
-1));
442 (void) strcat(id_scrolls
[i
].title
, syllables
[s
]);
444 n
= strlen(id_scrolls
[i
].title
);
445 (void) strcpy(id_scrolls
[i
].title
+(n
-1), "' ");
458 if (obj
->what_is
== AMULET
) {
459 (void) strcpy(desc
, "the amulet of Yendor ");
462 item_name
= name_of(obj
);
464 if (obj
->what_is
== GOLD
) {
465 sprintf(desc
, "%d pieces of gold", obj
->quantity
);
469 if (obj
->what_is
!= ARMOR
) {
470 if (obj
->quantity
== 1) {
471 (void) strcpy(desc
, "a ");
473 sprintf(desc
, "%d ", obj
->quantity
);
476 if (obj
->what_is
== FOOD
) {
477 if (obj
->which_kind
== RATION
) {
478 if (obj
->quantity
> 1) {
479 sprintf(desc
, "%d rations of ", obj
->quantity
);
481 (void) strcpy(desc
, "some ");
484 (void) strcpy(desc
, "a ");
486 (void) strcat(desc
, item_name
);
489 id_table
= get_id_table(obj
);
494 if (obj
->what_is
& (WEAPON
| ARMOR
| WAND
| RING
)) {
498 switch(id_table
[obj
->which_kind
].id_status
) {
501 switch(obj
->what_is
) {
503 (void) strcat(desc
, item_name
);
504 (void) strcat(desc
, "entitled: ");
505 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
508 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
509 (void) strcat(desc
, item_name
);
513 if (obj
->identified
||
514 (id_table
[obj
->which_kind
].id_status
== IDENTIFIED
)) {
517 if (id_table
[obj
->which_kind
].id_status
== CALLED
) {
520 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
521 (void) strcat(desc
, item_name
);
524 if (obj
->identified
) {
527 (void) strcpy(desc
, id_table
[obj
->which_kind
].title
);
530 if (obj
->identified
) {
533 (void) strcat(desc
, name_of(obj
));
538 CALL
: switch(obj
->what_is
) {
543 (void) strcat(desc
, item_name
);
544 (void) strcat(desc
, "called ");
545 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
550 ID
: switch(obj
->what_is
) {
553 (void) strcat(desc
, item_name
);
554 (void) strcat(desc
, id_table
[obj
->which_kind
].real
);
557 if (wizard
|| obj
->identified
) {
558 if ((obj
->which_kind
== DEXTERITY
) ||
559 (obj
->which_kind
== ADD_STRENGTH
)) {
560 sprintf(more_info
, "%s%d ", ((obj
->class > 0) ? "+" : ""),
562 (void) strcat(desc
, more_info
);
565 (void) strcat(desc
, item_name
);
566 (void) strcat(desc
, id_table
[obj
->which_kind
].real
);
569 (void) strcat(desc
, item_name
);
570 (void) strcat(desc
, id_table
[obj
->which_kind
].real
);
571 if (wizard
|| obj
->identified
) {
572 sprintf(more_info
, "[%d]", obj
->class);
573 (void) strcat(desc
, more_info
);
577 sprintf(desc
, "%s%d ", ((obj
->d_enchant
>= 0) ? "+" : ""),
579 (void) strcat(desc
, id_table
[obj
->which_kind
].title
);
580 sprintf(more_info
, "[%d] ", get_armor_class(obj
));
581 (void) strcat(desc
, more_info
);
584 sprintf(desc
+strlen(desc
), "%s%d,%s%d ",
585 ((obj
->hit_enchant
>= 0) ? "+" : ""), obj
->hit_enchant
,
586 ((obj
->d_enchant
>= 0) ? "+" : ""), obj
->d_enchant
);
587 (void) strcat(desc
, name_of(obj
));
593 if (!strncmp(desc
, "a ", 2)) {
594 if (is_vowel(desc
[2])) {
595 for (i
= strlen(desc
) + 1; i
> 1; i
--) {
601 if (obj
->in_use_flags
& BEING_WIELDED
) {
602 (void) strcat(desc
, "in hand");
603 } else if (obj
->in_use_flags
& BEING_WORN
) {
604 (void) strcat(desc
, "being worn");
605 } else if (obj
->in_use_flags
& ON_LEFT_HAND
) {
606 (void) strcat(desc
, "on left hand");
607 } else if (obj
->in_use_flags
& ON_RIGHT_HAND
) {
608 (void) strcat(desc
, "on right hand");
612 get_wand_and_ring_materials()
615 boolean used
[WAND_MATERIALS
];
617 for (i
= 0; i
< WAND_MATERIALS
; i
++) {
620 for (i
= 0; i
< WANDS
; i
++) {
622 j
= get_rand(0, WAND_MATERIALS
-1);
625 (void) strcpy(id_wands
[i
].title
, wand_materials
[j
]);
626 is_wood
[i
] = (j
> MAX_METAL
);
628 for (i
= 0; i
< GEMS
; i
++) {
631 for (i
= 0; i
< RINGS
; i
++) {
633 j
= get_rand(0, GEMS
-1);
636 (void) strcpy(id_rings
[i
].title
, gems
[j
]);
647 ch
= ichar
? ichar
: pack_letter("inventory what?", ALL_OBJECTS
);
652 if (!(obj
= get_letter_object(ch
))) {
653 message("no such item.", 0);
657 desc
[1] = ((obj
->what_is
& ARMOR
) && obj
->is_protected
) ? '}' : ')';
660 get_desc(obj
, desc
+3);
668 switch(obj
->what_is
) {
682 return((struct id
*) 0);
685 inv_armor_weapon(is_weapon
)
690 single_inv(rogue
.weapon
->ichar
);
692 message("not wielding anything", 0);
696 single_inv(rogue
.armor
->ichar
);
698 message("not wearing anything", 0);
709 message("what do you want identified?", 0);
713 if ((ch
>= 'A') && (ch
<= 'Z')) {
714 id
= m_names
[ch
-'A'];
715 } else if (ch
< 32) {
734 id
= "wall of a room";
755 id
= "wand or staff";
770 id
= "the Amulet of Yendor";
773 id
= "unknown character";
778 sprintf(buf
, "'%c': %s", ch
, id
);