inventory.c revision 1.13 1 1.13 dholland /* $NetBSD: inventory.c,v 1.13 2008/01/14 03:50:01 dholland Exp $ */
2 1.3 cgd
3 1.1 cgd /*
4 1.3 cgd * Copyright (c) 1988, 1993
5 1.3 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * This code is derived from software contributed to Berkeley by
8 1.1 cgd * Timothy C. Stoehr.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.9 agc * 3. Neither the name of the University nor the names of its contributors
19 1.1 cgd * may be used to endorse or promote products derived from this software
20 1.1 cgd * without specific prior written permission.
21 1.1 cgd *
22 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 cgd * SUCH DAMAGE.
33 1.1 cgd */
34 1.1 cgd
35 1.5 lukem #include <sys/cdefs.h>
36 1.1 cgd #ifndef lint
37 1.3 cgd #if 0
38 1.3 cgd static char sccsid[] = "@(#)inventory.c 8.1 (Berkeley) 5/31/93";
39 1.3 cgd #else
40 1.13 dholland __RCSID("$NetBSD: inventory.c,v 1.13 2008/01/14 03:50:01 dholland Exp $");
41 1.3 cgd #endif
42 1.1 cgd #endif /* not lint */
43 1.1 cgd
44 1.1 cgd /*
45 1.1 cgd * inventory.c
46 1.1 cgd *
47 1.1 cgd * This source herein may be modified and/or distributed by anybody who
48 1.1 cgd * so desires, with the following restrictions:
49 1.1 cgd * 1.) No portion of this notice shall be removed.
50 1.1 cgd * 2.) Credit shall not be taken for the creation of this source.
51 1.1 cgd * 3.) This code is not to be traded, sold, or used for personal
52 1.1 cgd * gain or profit.
53 1.1 cgd *
54 1.1 cgd */
55 1.1 cgd
56 1.11 dholland #include <stdarg.h>
57 1.1 cgd #include "rogue.h"
58 1.1 cgd
59 1.1 cgd boolean is_wood[WANDS];
60 1.6 hubertf const char *press_space = " --press space to continue--";
61 1.1 cgd
62 1.13 dholland static const char *const wand_materials[WAND_MATERIALS] = {
63 1.1 cgd "steel ",
64 1.1 cgd "bronze ",
65 1.1 cgd "gold ",
66 1.1 cgd "silver ",
67 1.1 cgd "copper ",
68 1.1 cgd "nickel ",
69 1.1 cgd "cobalt ",
70 1.1 cgd "tin ",
71 1.1 cgd "iron ",
72 1.1 cgd "magnesium ",
73 1.1 cgd "chrome ",
74 1.1 cgd "carbon ",
75 1.1 cgd "platinum ",
76 1.1 cgd "silicon ",
77 1.1 cgd "titanium ",
78 1.1 cgd
79 1.1 cgd "teak ",
80 1.1 cgd "oak ",
81 1.1 cgd "cherry ",
82 1.1 cgd "birch ",
83 1.1 cgd "pine ",
84 1.1 cgd "cedar ",
85 1.1 cgd "redwood ",
86 1.1 cgd "balsa ",
87 1.1 cgd "ivory ",
88 1.1 cgd "walnut ",
89 1.1 cgd "maple ",
90 1.1 cgd "mahogany ",
91 1.1 cgd "elm ",
92 1.1 cgd "palm ",
93 1.1 cgd "wooden "
94 1.1 cgd };
95 1.1 cgd
96 1.13 dholland static const char *const gems[GEMS] = {
97 1.1 cgd "diamond ",
98 1.1 cgd "stibotantalite ",
99 1.1 cgd "lapi-lazuli ",
100 1.1 cgd "ruby ",
101 1.1 cgd "emerald ",
102 1.1 cgd "sapphire ",
103 1.1 cgd "amethyst ",
104 1.1 cgd "quartz ",
105 1.1 cgd "tiger-eye ",
106 1.1 cgd "opal ",
107 1.1 cgd "agate ",
108 1.1 cgd "turquoise ",
109 1.1 cgd "pearl ",
110 1.1 cgd "garnet "
111 1.1 cgd };
112 1.1 cgd
113 1.13 dholland static const char *const syllables[MAXSYLLABLES] = {
114 1.1 cgd "blech ",
115 1.1 cgd "foo ",
116 1.1 cgd "barf ",
117 1.1 cgd "rech ",
118 1.1 cgd "bar ",
119 1.1 cgd "blech ",
120 1.1 cgd "quo ",
121 1.1 cgd "bloto ",
122 1.1 cgd "oh ",
123 1.1 cgd "caca ",
124 1.1 cgd "blorp ",
125 1.1 cgd "erp ",
126 1.1 cgd "festr ",
127 1.1 cgd "rot ",
128 1.1 cgd "slie ",
129 1.1 cgd "snorf ",
130 1.1 cgd "iky ",
131 1.1 cgd "yuky ",
132 1.1 cgd "ooze ",
133 1.1 cgd "ah ",
134 1.1 cgd "bahl ",
135 1.1 cgd "zep ",
136 1.1 cgd "druhl ",
137 1.1 cgd "flem ",
138 1.1 cgd "behil ",
139 1.1 cgd "arek ",
140 1.1 cgd "mep ",
141 1.1 cgd "zihr ",
142 1.1 cgd "grit ",
143 1.1 cgd "kona ",
144 1.1 cgd "kini ",
145 1.1 cgd "ichi ",
146 1.1 cgd "tims ",
147 1.1 cgd "ogr ",
148 1.1 cgd "oo ",
149 1.1 cgd "ighr ",
150 1.1 cgd "coph ",
151 1.1 cgd "swerr ",
152 1.1 cgd "mihln ",
153 1.1 cgd "poxi "
154 1.1 cgd };
155 1.1 cgd
156 1.1 cgd #define COMS 48
157 1.1 cgd
158 1.1 cgd struct id_com_s {
159 1.1 cgd short com_char;
160 1.6 hubertf const char *com_desc;
161 1.1 cgd };
162 1.1 cgd
163 1.13 dholland static const struct id_com_s com_id_tab[COMS] = {
164 1.5 lukem {'?', "? prints help"},
165 1.5 lukem {'r', "r read scroll"},
166 1.5 lukem {'/', "/ identify object"},
167 1.5 lukem {'e', "e eat food"},
168 1.5 lukem {'h', "h left "},
169 1.5 lukem {'w', "w wield a weapon"},
170 1.5 lukem {'j', "j down"},
171 1.5 lukem {'W', "W wear armor"},
172 1.5 lukem {'k', "k up"},
173 1.5 lukem {'T', "T take armor off"},
174 1.5 lukem {'l', "l right"},
175 1.5 lukem {'P', "P put on ring"},
176 1.5 lukem {'y', "y up & left"},
177 1.5 lukem {'R', "R remove ring"},
178 1.5 lukem {'u', "u up & right"},
179 1.5 lukem {'d', "d drop object"},
180 1.5 lukem {'b', "b down & left"},
181 1.5 lukem {'c', "c call object"},
182 1.5 lukem {'n', "n down & right"},
183 1.5 lukem {'\0', "<SHIFT><dir>: run that way"},
184 1.5 lukem {')', ") print current weapon"},
185 1.5 lukem {'\0', "<CTRL><dir>: run till adjacent"},
186 1.5 lukem {']', "] print current armor"},
187 1.5 lukem {'f', "f<dir> fight till death or near death"},
188 1.5 lukem {'=', "= print current rings"},
189 1.5 lukem {'t', "t<dir> throw something"},
190 1.5 lukem {'\001', "^A print Hp-raise average"},
191 1.5 lukem {'m', "m<dir> move onto without picking up"},
192 1.5 lukem {'z', "z<dir> zap a wand in a direction"},
193 1.5 lukem {'o', "o examine/set options"},
194 1.5 lukem {'^', "^<dir> identify trap type"},
195 1.5 lukem {'\022', "^R redraw screen"},
196 1.5 lukem {'&', "& save screen into 'rogue.screen'"},
197 1.5 lukem {'s', "s search for trap/secret door"},
198 1.5 lukem {'\020', "^P repeat last message"},
199 1.5 lukem {'>', "> go down a staircase"},
200 1.5 lukem {'\033', "^[ cancel command"},
201 1.5 lukem {'<', "< go up a staircase"},
202 1.5 lukem {'S', "S save game"},
203 1.5 lukem {'.', ". rest for a turn"},
204 1.5 lukem {'Q', "Q quit"},
205 1.5 lukem {',', ", pick something up"},
206 1.5 lukem {'!', "! shell escape"},
207 1.5 lukem {'i', "i inventory"},
208 1.5 lukem {'F', "F<dir> fight till either of you dies"},
209 1.5 lukem {'I', "I inventory single item"},
210 1.5 lukem {'v', "v print version number"},
211 1.5 lukem {'q', "q quaff potion" }
212 1.1 cgd };
213 1.1 cgd
214 1.5 lukem void
215 1.13 dholland inventory(const object *pack, unsigned short mask)
216 1.1 cgd {
217 1.1 cgd object *obj;
218 1.11 dholland short i = 0, j;
219 1.11 dholland size_t maxlen = 0, n;
220 1.1 cgd short row, col;
221 1.1 cgd
222 1.11 dholland struct {
223 1.11 dholland short letter;
224 1.11 dholland short sepchar;
225 1.11 dholland char desc[DCOLS];
226 1.12 dholland char savebuf[DCOLS+8];
227 1.11 dholland } descs[MAX_PACK_COUNT+1];
228 1.11 dholland
229 1.11 dholland
230 1.1 cgd obj = pack->next_object;
231 1.1 cgd
232 1.1 cgd if (!obj) {
233 1.11 dholland messagef(0, "your pack is empty");
234 1.1 cgd return;
235 1.1 cgd }
236 1.1 cgd while (obj) {
237 1.1 cgd if (obj->what_is & mask) {
238 1.11 dholland descs[i].letter = obj->ichar;
239 1.11 dholland descs[i].sepchar = ((obj->what_is & ARMOR) && obj->is_protected)
240 1.1 cgd ? '}' : ')';
241 1.11 dholland get_desc(obj, descs[i].desc, sizeof(descs[i].desc));
242 1.11 dholland n = strlen(descs[i].desc) + 4;
243 1.11 dholland if (n > maxlen) {
244 1.1 cgd maxlen = n;
245 1.1 cgd }
246 1.11 dholland i++;
247 1.11 dholland /*assert(i<=MAX_PACK_COUNT);*/
248 1.1 cgd }
249 1.1 cgd obj = obj->next_object;
250 1.1 cgd }
251 1.1 cgd if (maxlen < 27) maxlen = 27;
252 1.11 dholland if (maxlen > DCOLS-2) maxlen = DCOLS-2;
253 1.1 cgd col = DCOLS - (maxlen + 2);
254 1.1 cgd
255 1.11 dholland for (row = 0; ((row <= i) && (row < DROWS)); row++) {
256 1.11 dholland for (j = col; j < DCOLS; j++) {
257 1.11 dholland descs[row].savebuf[j-col] = mvinch(row, j);
258 1.11 dholland }
259 1.11 dholland descs[row].savebuf[j-col] = 0;
260 1.11 dholland if (row < i) {
261 1.12 dholland mvprintw(row, col, " %c%c %s",
262 1.12 dholland descs[row].letter, descs[row].sepchar,
263 1.11 dholland descs[row].desc);
264 1.11 dholland }
265 1.11 dholland else {
266 1.11 dholland mvaddstr(row, col, press_space);
267 1.1 cgd }
268 1.1 cgd clrtoeol();
269 1.1 cgd }
270 1.1 cgd refresh();
271 1.1 cgd wait_for_ack();
272 1.1 cgd
273 1.1 cgd move(0, 0);
274 1.1 cgd clrtoeol();
275 1.1 cgd
276 1.11 dholland for (j = 1; ((j <= i) && (j < DROWS)); j++) {
277 1.11 dholland mvaddstr(j, col, descs[j].savebuf);
278 1.1 cgd }
279 1.1 cgd }
280 1.1 cgd
281 1.5 lukem void
282 1.13 dholland id_com(void)
283 1.1 cgd {
284 1.1 cgd int ch = 0;
285 1.1 cgd short i, j, k;
286 1.1 cgd
287 1.1 cgd while (ch != CANCEL) {
288 1.1 cgd check_message();
289 1.11 dholland messagef(0, "Character you want help for (* for all):");
290 1.1 cgd
291 1.1 cgd refresh();
292 1.1 cgd ch = getchar();
293 1.1 cgd
294 1.1 cgd switch(ch) {
295 1.1 cgd case LIST:
296 1.1 cgd {
297 1.1 cgd char save[(((COMS / 2) + (COMS % 2)) + 1)][DCOLS];
298 1.1 cgd short rows = (((COMS / 2) + (COMS % 2)) + 1);
299 1.5 lukem boolean need_two_screens = FALSE;
300 1.1 cgd
301 1.1 cgd if (rows > LINES) {
302 1.1 cgd need_two_screens = 1;
303 1.1 cgd rows = LINES;
304 1.1 cgd }
305 1.1 cgd k = 0;
306 1.1 cgd
307 1.1 cgd for (i = 0; i < rows; i++) {
308 1.1 cgd for (j = 0; j < DCOLS; j++) {
309 1.1 cgd save[i][j] = mvinch(i, j);
310 1.1 cgd }
311 1.1 cgd }
312 1.1 cgd MORE:
313 1.1 cgd for (i = 0; i < rows; i++) {
314 1.1 cgd move(i, 0);
315 1.1 cgd clrtoeol();
316 1.1 cgd }
317 1.1 cgd for (i = 0; i < (rows-1); i++) {
318 1.1 cgd if (i < (LINES-1)) {
319 1.1 cgd if (((i + i) < COMS) && ((i+i+k) < COMS)) {
320 1.1 cgd mvaddstr(i, 0, com_id_tab[i+i+k].com_desc);
321 1.1 cgd }
322 1.1 cgd if (((i + i + 1) < COMS) && ((i+i+k+1) < COMS)) {
323 1.1 cgd mvaddstr(i, (DCOLS/2),
324 1.1 cgd com_id_tab[i+i+k+1].com_desc);
325 1.1 cgd }
326 1.1 cgd }
327 1.1 cgd }
328 1.1 cgd mvaddstr(rows - 1, 0, need_two_screens ? more : press_space);
329 1.1 cgd refresh();
330 1.1 cgd wait_for_ack();
331 1.1 cgd
332 1.1 cgd if (need_two_screens) {
333 1.1 cgd k += ((rows-1) * 2);
334 1.1 cgd need_two_screens = 0;
335 1.1 cgd goto MORE;
336 1.1 cgd }
337 1.1 cgd for (i = 0; i < rows; i++) {
338 1.1 cgd move(i, 0);
339 1.1 cgd for (j = 0; j < DCOLS; j++) {
340 1.1 cgd addch(save[i][j]);
341 1.1 cgd }
342 1.1 cgd }
343 1.1 cgd }
344 1.1 cgd break;
345 1.1 cgd default:
346 1.1 cgd if (!pr_com_id(ch)) {
347 1.1 cgd if (!pr_motion_char(ch)) {
348 1.1 cgd check_message();
349 1.11 dholland messagef(0, "unknown character");
350 1.1 cgd }
351 1.1 cgd }
352 1.1 cgd ch = CANCEL;
353 1.1 cgd break;
354 1.1 cgd }
355 1.1 cgd }
356 1.1 cgd }
357 1.1 cgd
358 1.5 lukem int
359 1.13 dholland pr_com_id(int ch)
360 1.1 cgd {
361 1.1 cgd int i;
362 1.1 cgd
363 1.1 cgd if (!get_com_id(&i, ch)) {
364 1.1 cgd return(0);
365 1.1 cgd }
366 1.1 cgd check_message();
367 1.11 dholland messagef(0, "%s", com_id_tab[i].com_desc);
368 1.1 cgd return(1);
369 1.1 cgd }
370 1.1 cgd
371 1.5 lukem int
372 1.13 dholland get_com_id(int *indexp, short ch)
373 1.1 cgd {
374 1.1 cgd short i;
375 1.1 cgd
376 1.1 cgd for (i = 0; i < COMS; i++) {
377 1.1 cgd if (com_id_tab[i].com_char == ch) {
378 1.7 tron *indexp = i;
379 1.1 cgd return(1);
380 1.1 cgd }
381 1.1 cgd }
382 1.1 cgd return(0);
383 1.1 cgd }
384 1.1 cgd
385 1.5 lukem int
386 1.13 dholland pr_motion_char(int ch)
387 1.1 cgd {
388 1.1 cgd if ( (ch == 'J') ||
389 1.1 cgd (ch == 'K') ||
390 1.1 cgd (ch == 'L') ||
391 1.1 cgd (ch == 'H') ||
392 1.1 cgd (ch == 'Y') ||
393 1.1 cgd (ch == 'U') ||
394 1.1 cgd (ch == 'N') ||
395 1.1 cgd (ch == 'B') ||
396 1.1 cgd (ch == '\012') ||
397 1.1 cgd (ch == '\013') ||
398 1.1 cgd (ch == '\010') ||
399 1.1 cgd (ch == '\014') ||
400 1.1 cgd (ch == '\025') ||
401 1.1 cgd (ch == '\031') ||
402 1.1 cgd (ch == '\016') ||
403 1.1 cgd (ch == '\002')) {
404 1.11 dholland const char *until;
405 1.10 christos int n = 0; /* XXX: GCC */
406 1.1 cgd if (ch <= '\031') {
407 1.1 cgd ch += 96;
408 1.11 dholland until = " until adjacent";
409 1.1 cgd } else {
410 1.1 cgd ch += 32;
411 1.11 dholland until = "";
412 1.1 cgd }
413 1.12 dholland (void)get_com_id(&n, ch);
414 1.1 cgd check_message();
415 1.11 dholland messagef(0, "run %s%s", com_id_tab[n].com_desc + 8, until);
416 1.1 cgd return(1);
417 1.1 cgd } else {
418 1.1 cgd return(0);
419 1.1 cgd }
420 1.1 cgd }
421 1.1 cgd
422 1.5 lukem void
423 1.13 dholland mix_colors(void)
424 1.1 cgd {
425 1.1 cgd short i, j, k;
426 1.8 mrg char t[MAX_ID_TITLE_LEN];
427 1.1 cgd
428 1.1 cgd for (i = 0; i <= 32; i++) {
429 1.1 cgd j = get_rand(0, (POTIONS - 1));
430 1.1 cgd k = get_rand(0, (POTIONS - 1));
431 1.11 dholland strlcpy(t, id_potions[j].title, sizeof(t));
432 1.11 dholland strlcpy(id_potions[j].title, id_potions[k].title,
433 1.11 dholland sizeof(id_potions[j].title));
434 1.11 dholland strlcpy(id_potions[k].title, t, sizeof(id_potions[k].title));
435 1.1 cgd }
436 1.1 cgd }
437 1.1 cgd
438 1.5 lukem void
439 1.13 dholland make_scroll_titles(void)
440 1.1 cgd {
441 1.1 cgd short i, j, n;
442 1.1 cgd short sylls, s;
443 1.11 dholland size_t maxlen = sizeof(id_scrolls[0].title);
444 1.1 cgd
445 1.1 cgd for (i = 0; i < SCROLS; i++) {
446 1.1 cgd sylls = get_rand(2, 5);
447 1.12 dholland (void)strlcpy(id_scrolls[i].title, "'", maxlen);
448 1.1 cgd
449 1.1 cgd for (j = 0; j < sylls; j++) {
450 1.1 cgd s = get_rand(1, (MAXSYLLABLES-1));
451 1.12 dholland (void)strlcat(id_scrolls[i].title, syllables[s],
452 1.11 dholland maxlen);
453 1.1 cgd }
454 1.11 dholland /* trim trailing space */
455 1.1 cgd n = strlen(id_scrolls[i].title);
456 1.11 dholland id_scrolls[i].title[n-1] = 0;
457 1.11 dholland
458 1.12 dholland (void)strlcat(id_scrolls[i].title, "' ", maxlen);
459 1.11 dholland }
460 1.11 dholland }
461 1.11 dholland
462 1.11 dholland struct sbuf {
463 1.11 dholland char *buf;
464 1.11 dholland size_t maxlen;
465 1.11 dholland };
466 1.11 dholland
467 1.13 dholland static void sbuf_init(struct sbuf *s, char *buf, size_t maxlen);
468 1.13 dholland static void sbuf_addstr(struct sbuf *s, const char *str);
469 1.13 dholland static void sbuf_addf(struct sbuf *s, const char *fmt, ...)
470 1.13 dholland __attribute__((__format__(__printf__, 2, 3)));
471 1.13 dholland static void desc_count(struct sbuf *s, int n);
472 1.13 dholland static void desc_called(struct sbuf *s, const object *);
473 1.11 dholland
474 1.11 dholland static
475 1.11 dholland void
476 1.13 dholland sbuf_init(struct sbuf *s, char *buf, size_t maxlen)
477 1.11 dholland {
478 1.11 dholland s->buf = buf;
479 1.11 dholland s->maxlen = maxlen;
480 1.11 dholland /*assert(maxlen>0);*/
481 1.11 dholland s->buf[0] = 0;
482 1.11 dholland }
483 1.11 dholland
484 1.11 dholland static
485 1.11 dholland void
486 1.13 dholland sbuf_addstr(struct sbuf *s, const char *str)
487 1.11 dholland {
488 1.11 dholland strlcat(s->buf, str, s->maxlen);
489 1.11 dholland }
490 1.11 dholland
491 1.11 dholland static
492 1.11 dholland void
493 1.11 dholland sbuf_addf(struct sbuf *s, const char *fmt, ...)
494 1.11 dholland {
495 1.11 dholland va_list ap;
496 1.11 dholland size_t initlen;
497 1.11 dholland
498 1.11 dholland initlen = strlen(s->buf);
499 1.11 dholland va_start(ap, fmt);
500 1.11 dholland vsnprintf(s->buf+initlen, s->maxlen-initlen, fmt, ap);
501 1.11 dholland va_end(ap);
502 1.11 dholland }
503 1.11 dholland
504 1.11 dholland static
505 1.11 dholland void
506 1.13 dholland desc_count(struct sbuf *s, int n)
507 1.11 dholland {
508 1.11 dholland if (n == 1) {
509 1.11 dholland sbuf_addstr(s, "an ");
510 1.11 dholland } else {
511 1.11 dholland sbuf_addf(s, "%d ", n);
512 1.1 cgd }
513 1.1 cgd }
514 1.1 cgd
515 1.11 dholland static
516 1.5 lukem void
517 1.13 dholland desc_called(struct sbuf *s, const object *obj)
518 1.11 dholland {
519 1.11 dholland struct id *id_table;
520 1.11 dholland
521 1.11 dholland id_table = get_id_table(obj);
522 1.11 dholland sbuf_addstr(s, name_of(obj));
523 1.11 dholland sbuf_addstr(s, "called ");
524 1.11 dholland sbuf_addstr(s, id_table[obj->which_kind].title);
525 1.11 dholland }
526 1.11 dholland
527 1.11 dholland void
528 1.13 dholland get_desc(const object *obj, char *desc, size_t desclen)
529 1.1 cgd {
530 1.6 hubertf const char *item_name;
531 1.1 cgd struct id *id_table;
532 1.11 dholland struct sbuf db;
533 1.11 dholland unsigned short objtype_id_status;
534 1.1 cgd
535 1.1 cgd if (obj->what_is == AMULET) {
536 1.12 dholland (void)strlcpy(desc, "the amulet of Yendor ", desclen);
537 1.1 cgd return;
538 1.1 cgd }
539 1.1 cgd
540 1.1 cgd if (obj->what_is == GOLD) {
541 1.11 dholland snprintf(desc, desclen, "%d pieces of gold", obj->quantity);
542 1.1 cgd return;
543 1.1 cgd }
544 1.1 cgd
545 1.11 dholland item_name = name_of(obj);
546 1.11 dholland id_table = get_id_table(obj);
547 1.11 dholland if (wizard || id_table == NULL) {
548 1.11 dholland objtype_id_status = IDENTIFIED;
549 1.11 dholland }
550 1.11 dholland else {
551 1.11 dholland objtype_id_status = id_table[obj->which_kind].id_status;
552 1.11 dholland }
553 1.11 dholland if (obj->what_is & (WEAPON | ARMOR | WAND | RING)) {
554 1.11 dholland if (obj->identified) {
555 1.11 dholland objtype_id_status = IDENTIFIED;
556 1.1 cgd }
557 1.1 cgd }
558 1.11 dholland
559 1.11 dholland sbuf_init(&db, desc, desclen);
560 1.11 dholland
561 1.11 dholland switch (obj->what_is) {
562 1.11 dholland case FOOD:
563 1.1 cgd if (obj->which_kind == RATION) {
564 1.1 cgd if (obj->quantity > 1) {
565 1.11 dholland sbuf_addf(&db,
566 1.11 dholland "%d rations of %s", obj->quantity,
567 1.11 dholland item_name);
568 1.1 cgd } else {
569 1.11 dholland sbuf_addf(&db, "some %s", item_name);
570 1.1 cgd }
571 1.1 cgd } else {
572 1.11 dholland sbuf_addf(&db, "an %s", item_name);
573 1.1 cgd }
574 1.11 dholland break;
575 1.11 dholland case SCROL:
576 1.11 dholland desc_count(&db, obj->quantity);
577 1.11 dholland if (objtype_id_status==UNIDENTIFIED) {
578 1.11 dholland sbuf_addstr(&db, item_name);
579 1.11 dholland sbuf_addstr(&db, "entitled: ");
580 1.11 dholland sbuf_addstr(&db, id_table[obj->which_kind].title);
581 1.11 dholland } else if (objtype_id_status==CALLED) {
582 1.11 dholland desc_called(&db, obj);
583 1.11 dholland } else {
584 1.11 dholland sbuf_addstr(&db, item_name);
585 1.11 dholland sbuf_addstr(&db, id_table[obj->which_kind].real);
586 1.1 cgd }
587 1.1 cgd break;
588 1.11 dholland case POTION:
589 1.11 dholland desc_count(&db, obj->quantity);
590 1.11 dholland if (objtype_id_status==UNIDENTIFIED) {
591 1.11 dholland sbuf_addstr(&db, id_table[obj->which_kind].title);
592 1.11 dholland sbuf_addstr(&db, item_name);
593 1.11 dholland } else if (objtype_id_status==CALLED) {
594 1.11 dholland desc_called(&db, obj);
595 1.11 dholland } else {
596 1.11 dholland sbuf_addstr(&db, item_name);
597 1.11 dholland sbuf_addstr(&db, id_table[obj->which_kind].real);
598 1.1 cgd }
599 1.1 cgd break;
600 1.11 dholland case WAND:
601 1.11 dholland desc_count(&db, obj->quantity);
602 1.11 dholland if (objtype_id_status==UNIDENTIFIED) {
603 1.11 dholland sbuf_addstr(&db, id_table[obj->which_kind].title);
604 1.11 dholland sbuf_addstr(&db, item_name);
605 1.11 dholland } else if (objtype_id_status==CALLED) {
606 1.11 dholland desc_called(&db, obj);
607 1.11 dholland } else {
608 1.11 dholland sbuf_addstr(&db, item_name);
609 1.11 dholland sbuf_addstr(&db, id_table[obj->which_kind].real);
610 1.1 cgd if (wizard || obj->identified) {
611 1.11 dholland sbuf_addf(&db, "[%d]", obj->class);
612 1.1 cgd }
613 1.11 dholland }
614 1.11 dholland break;
615 1.11 dholland case RING:
616 1.11 dholland desc_count(&db, obj->quantity);
617 1.11 dholland if (objtype_id_status==UNIDENTIFIED) {
618 1.11 dholland sbuf_addstr(&db, id_table[obj->which_kind].title);
619 1.11 dholland sbuf_addstr(&db, item_name);
620 1.11 dholland } else if (objtype_id_status==CALLED) {
621 1.11 dholland desc_called(&db, obj);
622 1.11 dholland } else {
623 1.11 dholland if ((wizard || obj->identified) &&
624 1.11 dholland (obj->which_kind == DEXTERITY ||
625 1.11 dholland obj->which_kind == ADD_STRENGTH)) {
626 1.11 dholland sbuf_addf(&db, "%+d ", obj->class);
627 1.1 cgd }
628 1.11 dholland sbuf_addstr(&db, item_name);
629 1.11 dholland sbuf_addstr(&db, id_table[obj->which_kind].real);
630 1.1 cgd }
631 1.1 cgd break;
632 1.11 dholland case ARMOR:
633 1.11 dholland /* no desc_count() */
634 1.11 dholland if (objtype_id_status==UNIDENTIFIED) {
635 1.11 dholland sbuf_addstr(&db, id_table[obj->which_kind].title);
636 1.11 dholland } else {
637 1.11 dholland sbuf_addf(&db, "%+d %s[%d] ", obj->d_enchant,
638 1.11 dholland id_table[obj->which_kind].title,
639 1.11 dholland get_armor_class(obj));
640 1.11 dholland }
641 1.11 dholland break;
642 1.11 dholland case WEAPON:
643 1.11 dholland desc_count(&db, obj->quantity);
644 1.11 dholland if (objtype_id_status==UNIDENTIFIED) {
645 1.11 dholland sbuf_addstr(&db, name_of(obj));
646 1.11 dholland } else {
647 1.11 dholland sbuf_addf(&db, "%+d,%+d %s",
648 1.11 dholland obj->hit_enchant, obj->d_enchant,
649 1.11 dholland name_of(obj));
650 1.1 cgd }
651 1.11 dholland break;
652 1.1 cgd }
653 1.11 dholland
654 1.1 cgd if (obj->in_use_flags & BEING_WIELDED) {
655 1.11 dholland sbuf_addstr(&db, "in hand");
656 1.1 cgd } else if (obj->in_use_flags & BEING_WORN) {
657 1.11 dholland sbuf_addstr(&db, "being worn");
658 1.1 cgd } else if (obj->in_use_flags & ON_LEFT_HAND) {
659 1.11 dholland sbuf_addstr(&db, "on left hand");
660 1.1 cgd } else if (obj->in_use_flags & ON_RIGHT_HAND) {
661 1.11 dholland sbuf_addstr(&db, "on right hand");
662 1.11 dholland }
663 1.11 dholland
664 1.11 dholland if (!strncmp(db.buf, "an ", 3)) {
665 1.11 dholland if (!is_vowel(db.buf[3])) {
666 1.11 dholland memmove(db.buf+2, db.buf+3, strlen(db.buf+3)+1);
667 1.11 dholland db.buf[1] = ' ';
668 1.11 dholland }
669 1.1 cgd }
670 1.1 cgd }
671 1.1 cgd
672 1.5 lukem void
673 1.13 dholland get_wand_and_ring_materials(void)
674 1.1 cgd {
675 1.1 cgd short i, j;
676 1.1 cgd boolean used[WAND_MATERIALS];
677 1.1 cgd
678 1.1 cgd for (i = 0; i < WAND_MATERIALS; i++) {
679 1.1 cgd used[i] = 0;
680 1.1 cgd }
681 1.1 cgd for (i = 0; i < WANDS; i++) {
682 1.1 cgd do {
683 1.1 cgd j = get_rand(0, WAND_MATERIALS-1);
684 1.1 cgd } while (used[j]);
685 1.1 cgd used[j] = 1;
686 1.12 dholland (void)strlcpy(id_wands[i].title, wand_materials[j],
687 1.11 dholland sizeof(id_wands[i].title));
688 1.1 cgd is_wood[i] = (j > MAX_METAL);
689 1.1 cgd }
690 1.1 cgd for (i = 0; i < GEMS; i++) {
691 1.1 cgd used[i] = 0;
692 1.1 cgd }
693 1.1 cgd for (i = 0; i < RINGS; i++) {
694 1.1 cgd do {
695 1.1 cgd j = get_rand(0, GEMS-1);
696 1.1 cgd } while (used[j]);
697 1.1 cgd used[j] = 1;
698 1.12 dholland (void)strlcpy(id_rings[i].title, gems[j],
699 1.11 dholland sizeof(id_rings[i].title));
700 1.1 cgd }
701 1.1 cgd }
702 1.1 cgd
703 1.5 lukem void
704 1.13 dholland single_inv(short ichar)
705 1.1 cgd {
706 1.11 dholland short ch, ch2;
707 1.1 cgd char desc[DCOLS];
708 1.1 cgd object *obj;
709 1.1 cgd
710 1.1 cgd ch = ichar ? ichar : pack_letter("inventory what?", ALL_OBJECTS);
711 1.1 cgd
712 1.1 cgd if (ch == CANCEL) {
713 1.1 cgd return;
714 1.1 cgd }
715 1.1 cgd if (!(obj = get_letter_object(ch))) {
716 1.11 dholland messagef(0, "no such item.");
717 1.1 cgd return;
718 1.1 cgd }
719 1.11 dholland ch2 = ((obj->what_is & ARMOR) && obj->is_protected) ? '}' : ')';
720 1.11 dholland get_desc(obj, desc, sizeof(desc));
721 1.11 dholland messagef(0, "%c%c %s", ch, ch2, desc);
722 1.1 cgd }
723 1.1 cgd
724 1.1 cgd struct id *
725 1.13 dholland get_id_table(const object *obj)
726 1.1 cgd {
727 1.1 cgd switch(obj->what_is) {
728 1.1 cgd case SCROL:
729 1.1 cgd return(id_scrolls);
730 1.1 cgd case POTION:
731 1.1 cgd return(id_potions);
732 1.1 cgd case WAND:
733 1.1 cgd return(id_wands);
734 1.1 cgd case RING:
735 1.1 cgd return(id_rings);
736 1.1 cgd case WEAPON:
737 1.1 cgd return(id_weapons);
738 1.1 cgd case ARMOR:
739 1.1 cgd return(id_armors);
740 1.1 cgd }
741 1.12 dholland return((struct id *)0);
742 1.1 cgd }
743 1.1 cgd
744 1.5 lukem void
745 1.13 dholland inv_armor_weapon(boolean is_weapon)
746 1.1 cgd {
747 1.1 cgd if (is_weapon) {
748 1.1 cgd if (rogue.weapon) {
749 1.1 cgd single_inv(rogue.weapon->ichar);
750 1.1 cgd } else {
751 1.11 dholland messagef(0, "not wielding anything");
752 1.1 cgd }
753 1.1 cgd } else {
754 1.1 cgd if (rogue.armor) {
755 1.1 cgd single_inv(rogue.armor->ichar);
756 1.1 cgd } else {
757 1.11 dholland messagef(0, "not wearing anything");
758 1.1 cgd }
759 1.1 cgd }
760 1.1 cgd }
761 1.1 cgd
762 1.5 lukem void
763 1.13 dholland id_type(void)
764 1.1 cgd {
765 1.6 hubertf const char *id;
766 1.1 cgd int ch;
767 1.1 cgd
768 1.11 dholland messagef(0, "what do you want identified?");
769 1.1 cgd
770 1.1 cgd ch = rgetchar();
771 1.1 cgd
772 1.1 cgd if ((ch >= 'A') && (ch <= 'Z')) {
773 1.1 cgd id = m_names[ch-'A'];
774 1.1 cgd } else if (ch < 32) {
775 1.1 cgd check_message();
776 1.1 cgd return;
777 1.1 cgd } else {
778 1.1 cgd switch(ch) {
779 1.1 cgd case '@':
780 1.1 cgd id = "you";
781 1.1 cgd break;
782 1.1 cgd case '%':
783 1.1 cgd id = "staircase";
784 1.1 cgd break;
785 1.1 cgd case '^':
786 1.1 cgd id = "trap";
787 1.1 cgd break;
788 1.1 cgd case '+':
789 1.1 cgd id = "door";
790 1.1 cgd break;
791 1.1 cgd case '-':
792 1.1 cgd case '|':
793 1.1 cgd id = "wall of a room";
794 1.1 cgd break;
795 1.1 cgd case '.':
796 1.1 cgd id = "floor";
797 1.1 cgd break;
798 1.1 cgd case '#':
799 1.1 cgd id = "passage";
800 1.1 cgd break;
801 1.1 cgd case ' ':
802 1.1 cgd id = "solid rock";
803 1.1 cgd break;
804 1.1 cgd case '=':
805 1.1 cgd id = "ring";
806 1.1 cgd break;
807 1.1 cgd case '?':
808 1.1 cgd id = "scroll";
809 1.1 cgd break;
810 1.1 cgd case '!':
811 1.1 cgd id = "potion";
812 1.1 cgd break;
813 1.1 cgd case '/':
814 1.1 cgd id = "wand or staff";
815 1.1 cgd break;
816 1.1 cgd case ')':
817 1.1 cgd id = "weapon";
818 1.1 cgd break;
819 1.1 cgd case ']':
820 1.1 cgd id = "armor";
821 1.1 cgd break;
822 1.1 cgd case '*':
823 1.1 cgd id = "gold";
824 1.1 cgd break;
825 1.1 cgd case ':':
826 1.1 cgd id = "food";
827 1.1 cgd break;
828 1.1 cgd case ',':
829 1.1 cgd id = "the Amulet of Yendor";
830 1.1 cgd break;
831 1.1 cgd default:
832 1.1 cgd id = "unknown character";
833 1.1 cgd break;
834 1.1 cgd }
835 1.1 cgd }
836 1.1 cgd check_message();
837 1.11 dholland messagef(0, "'%c': %s", ch, id);
838 1.1 cgd }
839