/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Timothy C. Stoehr.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* inventory.c
*
* This source herein may be modified and/or distributed by anybody who
* so desires, with the following restrictions:
* 1.) No portion of this notice shall be removed.
* 2.) Credit shall not be taken for the creation of this source.
* 3.) This code is not to be traded, sold, or used for personal
* gain or profit.
*
*/
#include <stdarg.h>
#include "rogue.h"
boolean is_wood[WANDS];
const char *press_space = " --press space to continue--";
struct id_com_s {
short com_char;
const char *com_desc;
};
static const struct id_com_s com_id_tab[COMS] = {
{'?', "? prints help"},
{'r', "r read scroll"},
{'/', "/ identify object"},
{'e', "e eat food"},
{'h', "h left "},
{'w', "w wield a weapon"},
{'j', "j down"},
{'W', "W wear armor"},
{'k', "k up"},
{'T', "T take armor off"},
{'l', "l right"},
{'P', "P put on ring"},
{'y', "y up & left"},
{'R', "R remove ring"},
{'u', "u up & right"},
{'d', "d drop object"},
{'b', "b down & left"},
{'c', "c call object"},
{'n', "n down & right"},
{'\0', "<SHIFT><dir>: run that way"},
{')', ") print current weapon"},
{'\0', "<CTRL><dir>: run till adjacent"},
{']', "] print current armor"},
{'f', "f<dir> fight till death or near death"},
{'=', "= print current rings"},
{'t', "t<dir> throw something"},
{'\001', "^A print Hp-raise average"},
{'m', "m<dir> move onto without picking up"},
{'z', "z<dir> zap a wand in a direction"},
{'o', "o examine/set options"},
{'^', "^<dir> identify trap type"},
{'\022', "^R redraw screen"},
{'&', "& save screen into 'rogue.screen'"},
{'s', "s search for trap/secret door"},
{'\020', "^P repeat last message"},
{'>', "> go down a staircase"},
{'\033', "^[ cancel command"},
{'<', "< go up a staircase"},
{'S', "S save game"},
{'.', ". rest for a turn"},
{'Q', "Q quit"},
{',', ", pick something up"},
{'!', "! shell escape"},
{'i', "i inventory"},
{'F', "F<dir> fight till either of you dies"},
{'I', "I inventory single item"},
{'v', "v print version number"},
{'q', "q quaff potion" }
};
static int get_com_id(int *, short);
static int pr_com_id(int);
static int pr_motion_char(int);
void
inventory(const object *pack, unsigned short mask)
{
object *obj;
short i = 0, j;
size_t maxlen = 0, n;
short row, col;
struct {
short letter;
short sepchar;
char desc[DCOLS];
char savebuf[DCOLS+8];
} descs[MAX_PACK_COUNT+1];
obj = pack->next_object;
if (!obj) {
messagef(0, "your pack is empty");
return;
}
while (obj) {
if (obj->what_is & mask) {
descs[i].letter = obj->ichar;
descs[i].sepchar = ((obj->what_is & ARMOR) && obj->is_protected)
? '}' : ')';
get_desc(obj, descs[i].desc, sizeof(descs[i].desc));
n = strlen(descs[i].desc) + 4;
if (n > maxlen) {
maxlen = n;
}
i++;
/*assert(i<=MAX_PACK_COUNT);*/
}
obj = obj->next_object;
}
if (maxlen < 27) maxlen = 27;
if (maxlen > DCOLS-2) maxlen = DCOLS-2;
col = DCOLS - (maxlen + 2);
if (ch == CANCEL) {
return;
}
if (!(obj = get_letter_object(ch))) {
messagef(0, "no such item.");
return;
}
ch2 = ((obj->what_is & ARMOR) && obj->is_protected) ? '}' : ')';
get_desc(obj, desc, sizeof(desc));
messagef(0, "%c%c %s", ch, ch2, desc);
}
struct id *
get_id_table(const object *obj)
{
switch(obj->what_is) {
case SCROL:
return(id_scrolls);
case POTION:
return(id_potions);
case WAND:
return(id_wands);
case RING:
return(id_rings);
case WEAPON:
return(id_weapons);
case ARMOR:
return(id_armors);
}
return((struct id *)0);
}
if ((ch >= 'A') && (ch <= 'Z')) {
id = m_names[ch-'A'];
} else if (ch < 32) {
check_message();
return;
} else {
switch(ch) {
case '@':
id = "you";
break;
case '%':
id = "staircase";
break;
case '^':
id = "trap";
break;
case '+':
id = "door";
break;
case '-':
case '|':
id = "wall of a room";
break;
case '.':
id = "floor";
break;
case '#':
id = "passage";
break;
case ' ':
id = "solid rock";
break;
case '=':
id = "ring";
break;
case '?':
id = "scroll";
break;
case '!':
id = "potion";
break;
case '/':
id = "wand or staff";
break;
case ')':
id = "weapon";
break;
case ']':
id = "armor";
break;
case '*':
id = "gold";
break;
case ':':
id = "food";
break;
case ',':
id = "the Amulet of Yendor";
break;
default:
id = "unknown character";
break;
}
}
check_message();
messagef(0, "'%c': %s", ch, id);
}