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.3 2003/08/26 23:52:50 drhodus 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 boolean is_wood[WANDS];
56 const char *press_space = " --press space to continue--";
58 const char *const wand_materials[WAND_MATERIALS] = {
92 const char *const gems[GEMS] = {
109 const char *const syllables[MAXSYLLABLES] = {
156 const char *com_desc;
159 const struct id_com_s com_id_tab[COMS] = {
160 '?', "? prints help",
161 'r', "r read scroll",
162 '/', "/ identify object",
165 'w', "w wield a weapon",
169 'T', "T take armor off",
171 'P', "P put on ring",
173 'R', "R remove ring",
175 'd', "d drop object",
176 'b', "b down & left",
177 'c', "c call object",
178 'n', "n down & right",
179 '\0', "<SHIFT><dir>: run that way",
180 ')', ") print current weapon",
181 '\0', "<CTRL><dir>: run till adjacent",
182 ']', "] print current armor",
183 'f', "f<dir> fight till death or near death",
184 '=', "= print current rings",
185 't', "t<dir> throw something",
186 '\001', "^A print Hp-raise average",
187 'm', "m<dir> move onto without picking up",
188 'z', "z<dir> zap a wand in a direction",
189 'o', "o examine/set options",
190 '^', "^<dir> identify trap type",
191 '\022', "^R redraw screen",
192 '&', "& save screen into 'rogue.screen'",
193 's', "s search for trap/secret door",
194 '\020', "^P repeat last message",
195 '>', "> go down a staircase",
196 '\033', "^[ cancel command",
197 '<', "< go up a staircase",
199 '.', ". rest for a turn",
201 ',', ", pick something up",
202 '!', "! shell escape",
204 'F', "F<dir> fight till either of you dies",
205 'I', "I inventory single item",
206 'v', "v print version number",
207 'q', "q quaff potion"
210 extern boolean wizard;
211 extern char *m_names[], *more;
213 inventory(pack, mask)
218 short i = 0, j, maxlen = 0, n;
219 char descs[MAX_PACK_COUNT+1][DCOLS];
222 obj = pack->next_object;
225 message("your pack is empty", 0);
229 if (obj->what_is & mask) {
231 descs[i][1] = obj->ichar;
232 descs[i][2] = ((obj->what_is & ARMOR) && obj->is_protected)
235 get_desc(obj, descs[i]+4);
236 if ((n = strlen(descs[i])) > maxlen) {
241 obj = obj->next_object;
243 (void) strcpy(descs[i++], press_space);
244 if (maxlen < 27) maxlen = 27;
245 col = DCOLS - (maxlen + 2);
247 for (row = 0; ((row < i) && (row < DROWS)); row++) {
249 for (j = col; j < DCOLS; j++) {
250 descs[row-1][j-col] = mvinch(row, j);
252 descs[row-1][j-col] = 0;
254 mvaddstr(row, col, descs[row]);
263 for (j = 1; ((j < i) && (j < DROWS)); j++) {
264 mvaddstr(j, col, descs[j-1]);
273 while (ch != CANCEL) {
275 message("Character you want help for (* for all):", 0);
283 char save[(((COMS / 2) + (COMS % 2)) + 1)][DCOLS];
284 short rows = (((COMS / 2) + (COMS % 2)) + 1);
285 boolean need_two_screens;
288 need_two_screens = 1;
293 for (i = 0; i < rows; i++) {
294 for (j = 0; j < DCOLS; j++) {
295 save[i][j] = mvinch(i, j);
299 for (i = 0; i < rows; i++) {
303 for (i = 0; i < (rows-1); i++) {
305 if (((i + i) < COMS) && ((i+i+k) < COMS)) {
306 mvaddstr(i, 0, com_id_tab[i+i+k].com_desc);
308 if (((i + i + 1) < COMS) && ((i+i+k+1) < COMS)) {
309 mvaddstr(i, (DCOLS/2),
310 com_id_tab[i+i+k+1].com_desc);
314 mvaddstr(rows - 1, 0, need_two_screens ? more : press_space);
318 if (need_two_screens) {
320 need_two_screens = 0;
323 for (i = 0; i < rows; i++) {
325 for (j = 0; j < DCOLS; j++) {
332 if (!pr_com_id(ch)) {
333 if (!pr_motion_char(ch)) {
335 message("unknown character", 0);
349 if (!get_com_id(&i, ch)) {
353 message(com_id_tab[i].com_desc, 0);
357 get_com_id(index, ch)
363 for (i = 0; i < COMS; i++) {
364 if (com_id_tab[i].com_char == ch) {
391 char until[18], buf[DCOLS];
396 (void) strcpy(until, "until adjascent");
401 (void) get_com_id(&n, ch);
402 sprintf(buf, "run %s %s", com_id_tab[n].com_desc + 8, until);
414 char *t[MAX_ID_TITLE_LEN];
416 for (i = 0; i <= 32; i++) {
417 j = get_rand(0, (POTIONS - 1));
418 k = get_rand(0, (POTIONS - 1));
419 memcpy(t, id_potions[j].title, MAX_ID_TITLE_LEN);
420 memcpy(id_potions[j].title, id_potions[k].title, MAX_ID_TITLE_LEN);
429 for (i = 0; i < SCROLS; i++) {
430 sylls = get_rand(2, 5);
431 (void) strcpy(id_scrolls[i].title, "'");
433 for (j = 0; j < sylls; j++) {
434 s = get_rand(1, (MAXSYLLABLES-1));
435 (void) strcat(id_scrolls[i].title, syllables[s]);
437 n = strlen(id_scrolls[i].title);
438 (void) strcpy(id_scrolls[i].title+(n-1), "' ");
446 const char *item_name;
451 if (obj->what_is == AMULET) {
452 (void) strcpy(desc, "the amulet of Yendor ");
455 item_name = name_of(obj);
457 if (obj->what_is == GOLD) {
458 sprintf(desc, "%d pieces of gold", obj->quantity);
462 if (obj->what_is != ARMOR) {
463 if (obj->quantity == 1) {
464 (void) strcpy(desc, "a ");
466 sprintf(desc, "%d ", obj->quantity);
469 if (obj->what_is == FOOD) {
470 if (obj->which_kind == RATION) {
471 if (obj->quantity > 1) {
472 sprintf(desc, "%d rations of ", obj->quantity);
474 (void) strcpy(desc, "some ");
477 (void) strcpy(desc, "a ");
479 (void) strcat(desc, item_name);
482 id_table = get_id_table(obj);
487 if (obj->what_is & (WEAPON | ARMOR | WAND | RING)) {
491 switch(id_table[obj->which_kind].id_status) {
494 switch(obj->what_is) {
496 (void) strcat(desc, item_name);
497 (void) strcat(desc, "entitled: ");
498 (void) strcat(desc, id_table[obj->which_kind].title);
501 (void) strcat(desc, id_table[obj->which_kind].title);
502 (void) strcat(desc, item_name);
506 if (obj->identified ||
507 (id_table[obj->which_kind].id_status == IDENTIFIED)) {
510 if (id_table[obj->which_kind].id_status == CALLED) {
513 (void) strcat(desc, id_table[obj->which_kind].title);
514 (void) strcat(desc, item_name);
517 if (obj->identified) {
520 (void) strcpy(desc, id_table[obj->which_kind].title);
523 if (obj->identified) {
526 (void) strcat(desc, name_of(obj));
531 CALL: switch(obj->what_is) {
536 (void) strcat(desc, item_name);
537 (void) strcat(desc, "called ");
538 (void) strcat(desc, id_table[obj->which_kind].title);
543 ID: switch(obj->what_is) {
546 (void) strcat(desc, item_name);
547 (void) strcat(desc, id_table[obj->which_kind].real);
550 if (wizard || obj->identified) {
551 if ((obj->which_kind == DEXTERITY) ||
552 (obj->which_kind == ADD_STRENGTH)) {
553 sprintf(more_info, "%s%d ", ((obj->class > 0) ? "+" : ""),
555 (void) strcat(desc, more_info);
558 (void) strcat(desc, item_name);
559 (void) strcat(desc, id_table[obj->which_kind].real);
562 (void) strcat(desc, item_name);
563 (void) strcat(desc, id_table[obj->which_kind].real);
564 if (wizard || obj->identified) {
565 sprintf(more_info, "[%d]", obj->class);
566 (void) strcat(desc, more_info);
570 sprintf(desc, "%s%d ", ((obj->d_enchant >= 0) ? "+" : ""),
572 (void) strcat(desc, id_table[obj->which_kind].title);
573 sprintf(more_info, "[%d] ", get_armor_class(obj));
574 (void) strcat(desc, more_info);
577 sprintf(desc+strlen(desc), "%s%d,%s%d ",
578 ((obj->hit_enchant >= 0) ? "+" : ""), obj->hit_enchant,
579 ((obj->d_enchant >= 0) ? "+" : ""), obj->d_enchant);
580 (void) strcat(desc, name_of(obj));
586 if (!strncmp(desc, "a ", 2)) {
587 if (is_vowel(desc[2])) {
588 for (i = strlen(desc) + 1; i > 1; i--) {
594 if (obj->in_use_flags & BEING_WIELDED) {
595 (void) strcat(desc, "in hand");
596 } else if (obj->in_use_flags & BEING_WORN) {
597 (void) strcat(desc, "being worn");
598 } else if (obj->in_use_flags & ON_LEFT_HAND) {
599 (void) strcat(desc, "on left hand");
600 } else if (obj->in_use_flags & ON_RIGHT_HAND) {
601 (void) strcat(desc, "on right hand");
605 get_wand_and_ring_materials()
608 boolean used[WAND_MATERIALS];
610 for (i = 0; i < WAND_MATERIALS; i++) {
613 for (i = 0; i < WANDS; i++) {
615 j = get_rand(0, WAND_MATERIALS-1);
618 (void) strcpy(id_wands[i].title, wand_materials[j]);
619 is_wood[i] = (j > MAX_METAL);
621 for (i = 0; i < GEMS; i++) {
624 for (i = 0; i < RINGS; i++) {
626 j = get_rand(0, GEMS-1);
629 (void) strcpy(id_rings[i].title, gems[j]);
640 ch = ichar ? ichar : pack_letter("inventory what?", ALL_OBJECTS);
645 if (!(obj = get_letter_object(ch))) {
646 message("no such item.", 0);
650 desc[1] = ((obj->what_is & ARMOR) && obj->is_protected) ? '}' : ')';
653 get_desc(obj, desc+3);
661 switch(obj->what_is) {
675 return((struct id *) 0);
678 inv_armor_weapon(is_weapon)
683 single_inv(rogue.weapon->ichar);
685 message("not wielding anything", 0);
689 single_inv(rogue.armor->ichar);
691 message("not wearing anything", 0);
702 message("what do you want identified?", 0);
706 if ((ch >= 'A') && (ch <= 'Z')) {
707 id = m_names[ch-'A'];
708 } else if (ch < 32) {
727 id = "wall of a room";
748 id = "wand or staff";
763 id = "the Amulet of Yendor";
766 id = "unknown character";
771 sprintf(buf, "'%c': %s", ch, id);