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
39 static char sccsid[] = "@(#)inventory.c 8.1 (Berkeley) 5/31/93";
41 static const char rcsid[] =
42 "$FreeBSD: src/games/rogue/inventory.c,v 1.4 1999/11/30 03:49:23 billf Exp $";
48 * This source herein may be modified and/or distributed by anybody who
49 * so desires, with the following restrictions:
50 * 1.) No portion of this notice shall be removed.
51 * 2.) Credit shall not be taken for the creation of this source.
52 * 3.) This code is not to be traded, sold, or used for personal
59 boolean is_wood[WANDS];
60 const char *press_space = " --press space to continue--";
62 const char *const wand_materials[WAND_MATERIALS] = {
96 const char *const gems[GEMS] = {
113 const char *const syllables[MAXSYLLABLES] = {
160 const char *com_desc;
163 const struct id_com_s com_id_tab[COMS] = {
164 '?', "? prints help",
165 'r', "r read scroll",
166 '/', "/ identify object",
169 'w', "w wield a weapon",
173 'T', "T take armor off",
175 'P', "P put on ring",
177 'R', "R remove ring",
179 'd', "d drop object",
180 'b', "b down & left",
181 'c', "c call object",
182 'n', "n down & right",
183 '\0', "<SHIFT><dir>: run that way",
184 ')', ") print current weapon",
185 '\0', "<CTRL><dir>: run till adjacent",
186 ']', "] print current armor",
187 'f', "f<dir> fight till death or near death",
188 '=', "= print current rings",
189 't', "t<dir> throw something",
190 '\001', "^A print Hp-raise average",
191 'm', "m<dir> move onto without picking up",
192 'z', "z<dir> zap a wand in a direction",
193 'o', "o examine/set options",
194 '^', "^<dir> identify trap type",
195 '\022', "^R redraw screen",
196 '&', "& save screen into 'rogue.screen'",
197 's', "s search for trap/secret door",
198 '\020', "^P repeat last message",
199 '>', "> go down a staircase",
200 '\033', "^[ cancel command",
201 '<', "< go up a staircase",
203 '.', ". rest for a turn",
205 ',', ", pick something up",
206 '!', "! shell escape",
208 'F', "F<dir> fight till either of you dies",
209 'I', "I inventory single item",
210 'v', "v print version number",
211 'q', "q quaff potion"
214 extern boolean wizard;
215 extern char *m_names[], *more;
217 inventory(pack, mask)
222 short i = 0, j, maxlen = 0, n;
223 char descs[MAX_PACK_COUNT+1][DCOLS];
226 obj = pack->next_object;
229 message("your pack is empty", 0);
233 if (obj->what_is & mask) {
235 descs[i][1] = obj->ichar;
236 descs[i][2] = ((obj->what_is & ARMOR) && obj->is_protected)
239 get_desc(obj, descs[i]+4);
240 if ((n = strlen(descs[i])) > maxlen) {
245 obj = obj->next_object;
247 (void) strcpy(descs[i++], press_space);
248 if (maxlen < 27) maxlen = 27;
249 col = DCOLS - (maxlen + 2);
251 for (row = 0; ((row < i) && (row < DROWS)); row++) {
253 for (j = col; j < DCOLS; j++) {
254 descs[row-1][j-col] = mvinch(row, j);
256 descs[row-1][j-col] = 0;
258 mvaddstr(row, col, descs[row]);
267 for (j = 1; ((j < i) && (j < DROWS)); j++) {
268 mvaddstr(j, col, descs[j-1]);
277 while (ch != CANCEL) {
279 message("Character you want help for (* for all):", 0);
287 char save[(((COMS / 2) + (COMS % 2)) + 1)][DCOLS];
288 short rows = (((COMS / 2) + (COMS % 2)) + 1);
289 boolean need_two_screens;
292 need_two_screens = 1;
297 for (i = 0; i < rows; i++) {
298 for (j = 0; j < DCOLS; j++) {
299 save[i][j] = mvinch(i, j);
303 for (i = 0; i < rows; i++) {
307 for (i = 0; i < (rows-1); i++) {
309 if (((i + i) < COMS) && ((i+i+k) < COMS)) {
310 mvaddstr(i, 0, com_id_tab[i+i+k].com_desc);
312 if (((i + i + 1) < COMS) && ((i+i+k+1) < COMS)) {
313 mvaddstr(i, (DCOLS/2),
314 com_id_tab[i+i+k+1].com_desc);
318 mvaddstr(rows - 1, 0, need_two_screens ? more : press_space);
322 if (need_two_screens) {
324 need_two_screens = 0;
327 for (i = 0; i < rows; i++) {
329 for (j = 0; j < DCOLS; j++) {
336 if (!pr_com_id(ch)) {
337 if (!pr_motion_char(ch)) {
339 message("unknown character", 0);
353 if (!get_com_id(&i, ch)) {
357 message(com_id_tab[i].com_desc, 0);
361 get_com_id(index, ch)
367 for (i = 0; i < COMS; i++) {
368 if (com_id_tab[i].com_char == ch) {
395 char until[18], buf[DCOLS];
400 (void) strcpy(until, "until adjascent");
405 (void) get_com_id(&n, ch);
406 sprintf(buf, "run %s %s", com_id_tab[n].com_desc + 8, until);
420 for (i = 0; i <= 32; i++) {
421 j = get_rand(0, (POTIONS - 1));
422 k = get_rand(0, (POTIONS - 1));
423 t = id_potions[j].title;
424 id_potions[j].title = id_potions[k].title;
425 id_potions[k].title = t;
434 for (i = 0; i < SCROLS; i++) {
435 sylls = get_rand(2, 5);
436 (void) strcpy(id_scrolls[i].title, "'");
438 for (j = 0; j < sylls; j++) {
439 s = get_rand(1, (MAXSYLLABLES-1));
440 (void) strcat(id_scrolls[i].title, syllables[s]);
442 n = strlen(id_scrolls[i].title);
443 (void) strcpy(id_scrolls[i].title+(n-1), "' ");
451 const char *item_name;
456 if (obj->what_is == AMULET) {
457 (void) strcpy(desc, "the amulet of Yendor ");
460 item_name = name_of(obj);
462 if (obj->what_is == GOLD) {
463 sprintf(desc, "%d pieces of gold", obj->quantity);
467 if (obj->what_is != ARMOR) {
468 if (obj->quantity == 1) {
469 (void) strcpy(desc, "a ");
471 sprintf(desc, "%d ", obj->quantity);
474 if (obj->what_is == FOOD) {
475 if (obj->which_kind == RATION) {
476 if (obj->quantity > 1) {
477 sprintf(desc, "%d rations of ", obj->quantity);
479 (void) strcpy(desc, "some ");
482 (void) strcpy(desc, "a ");
484 (void) strcat(desc, item_name);
487 id_table = get_id_table(obj);
492 if (obj->what_is & (WEAPON | ARMOR | WAND | RING)) {
496 switch(id_table[obj->which_kind].id_status) {
499 switch(obj->what_is) {
501 (void) strcat(desc, item_name);
502 (void) strcat(desc, "entitled: ");
503 (void) strcat(desc, id_table[obj->which_kind].title);
506 (void) strcat(desc, id_table[obj->which_kind].title);
507 (void) strcat(desc, item_name);
511 if (obj->identified ||
512 (id_table[obj->which_kind].id_status == IDENTIFIED)) {
515 if (id_table[obj->which_kind].id_status == CALLED) {
518 (void) strcat(desc, id_table[obj->which_kind].title);
519 (void) strcat(desc, item_name);
522 if (obj->identified) {
525 (void) strcpy(desc, id_table[obj->which_kind].title);
528 if (obj->identified) {
531 (void) strcat(desc, name_of(obj));
536 CALL: switch(obj->what_is) {
541 (void) strcat(desc, item_name);
542 (void) strcat(desc, "called ");
543 (void) strcat(desc, id_table[obj->which_kind].title);
548 ID: switch(obj->what_is) {
551 (void) strcat(desc, item_name);
552 (void) strcat(desc, id_table[obj->which_kind].real);
555 if (wizard || obj->identified) {
556 if ((obj->which_kind == DEXTERITY) ||
557 (obj->which_kind == ADD_STRENGTH)) {
558 sprintf(more_info, "%s%d ", ((obj->class > 0) ? "+" : ""),
560 (void) strcat(desc, more_info);
563 (void) strcat(desc, item_name);
564 (void) strcat(desc, id_table[obj->which_kind].real);
567 (void) strcat(desc, item_name);
568 (void) strcat(desc, id_table[obj->which_kind].real);
569 if (wizard || obj->identified) {
570 sprintf(more_info, "[%d]", obj->class);
571 (void) strcat(desc, more_info);
575 sprintf(desc, "%s%d ", ((obj->d_enchant >= 0) ? "+" : ""),
577 (void) strcat(desc, id_table[obj->which_kind].title);
578 sprintf(more_info, "[%d] ", get_armor_class(obj));
579 (void) strcat(desc, more_info);
582 sprintf(desc+strlen(desc), "%s%d,%s%d ",
583 ((obj->hit_enchant >= 0) ? "+" : ""), obj->hit_enchant,
584 ((obj->d_enchant >= 0) ? "+" : ""), obj->d_enchant);
585 (void) strcat(desc, name_of(obj));
591 if (!strncmp(desc, "a ", 2)) {
592 if (is_vowel(desc[2])) {
593 for (i = strlen(desc) + 1; i > 1; i--) {
599 if (obj->in_use_flags & BEING_WIELDED) {
600 (void) strcat(desc, "in hand");
601 } else if (obj->in_use_flags & BEING_WORN) {
602 (void) strcat(desc, "being worn");
603 } else if (obj->in_use_flags & ON_LEFT_HAND) {
604 (void) strcat(desc, "on left hand");
605 } else if (obj->in_use_flags & ON_RIGHT_HAND) {
606 (void) strcat(desc, "on right hand");
610 get_wand_and_ring_materials()
613 boolean used[WAND_MATERIALS];
615 for (i = 0; i < WAND_MATERIALS; i++) {
618 for (i = 0; i < WANDS; i++) {
620 j = get_rand(0, WAND_MATERIALS-1);
623 (void) strcpy(id_wands[i].title, wand_materials[j]);
624 is_wood[i] = (j > MAX_METAL);
626 for (i = 0; i < GEMS; i++) {
629 for (i = 0; i < RINGS; i++) {
631 j = get_rand(0, GEMS-1);
634 (void) strcpy(id_rings[i].title, gems[j]);
645 ch = ichar ? ichar : pack_letter("inventory what?", ALL_OBJECTS);
650 if (!(obj = get_letter_object(ch))) {
651 message("no such item.", 0);
655 desc[1] = ((obj->what_is & ARMOR) && obj->is_protected) ? '}' : ')';
658 get_desc(obj, desc+3);
666 switch(obj->what_is) {
680 return((struct id *) 0);
683 inv_armor_weapon(is_weapon)
688 single_inv(rogue.weapon->ichar);
690 message("not wielding anything", 0);
694 single_inv(rogue.armor->ichar);
696 message("not wearing anything", 0);
707 message("what do you want identified?", 0);
711 if ((ch >= 'A') && (ch <= 'Z')) {
712 id = m_names[ch-'A'];
713 } else if (ch < 32) {
732 id = "wall of a room";
753 id = "wand or staff";
768 id = "the Amulet of Yendor";
771 id = "unknown character";
776 sprintf(buf, "'%c': %s", ch, id);