xref: /netbsd-src/games/rogue/object.c (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: object.c,v 1.9 2003/08/07 09:37:39 agc Exp $	*/
2 
3 /*
4  * Copyright (c) 1988, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Timothy C. Stoehr.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #include <sys/cdefs.h>
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)object.c	8.1 (Berkeley) 5/31/93";
39 #else
40 __RCSID("$NetBSD: object.c,v 1.9 2003/08/07 09:37:39 agc Exp $");
41 #endif
42 #endif /* not lint */
43 
44 /*
45  * object.c
46  *
47  * This source herein may be modified and/or distributed by anybody who
48  * so desires, with the following restrictions:
49  *    1.)  No portion of this notice shall be removed.
50  *    2.)  Credit shall not be taken for the creation of this source.
51  *    3.)  This code is not to be traded, sold, or used for personal
52  *         gain or profit.
53  *
54  */
55 
56 #include "rogue.h"
57 
58 object level_objects;
59 unsigned short dungeon[DROWS][DCOLS];
60 short foods = 0;
61 object *free_list = (object *) 0;
62 char *fruit = (char *) 0;
63 
64 fighter rogue = {
65 	INIT_AW,	/* armor */
66 	INIT_AW,	/* weapon */
67 	INIT_RINGS,	/* left ring */
68 	INIT_RINGS,	/* right ring */
69 	INIT_HP,	/* Hp current */
70 	INIT_HP,	/* Hp max */
71 	INIT_STR,	/* Str current */
72 	INIT_STR,	/* Str max */
73 	INIT_PACK,	/* pack */
74 	INIT_GOLD,	/* gold */
75 	INIT_EXPLEVEL,	/* exp level */
76 	INIT_EXP,	/* exp points */
77 	0, 0,		/* row, col */
78 	INIT_CHAR,	/* char */
79 	INIT_MOVES	/* moves */
80 };
81 
82 struct id id_potions[POTIONS] = {
83 {100, "blue \0                           ", "of increase strength ", 0},
84 {250, "red \0                            ", "of restore strength ", 0},
85 {100, "green \0                          ", "of healing ", 0},
86 {200, "grey \0                           ", "of extra healing ", 0},
87  {10, "brown \0                          ", "of poison ", 0},
88 {300, "clear \0                          ", "of raise level ", 0},
89  {10, "pink \0                           ", "of blindness ", 0},
90  {25, "white \0                          ", "of hallucination ", 0},
91 {100, "purple \0                         ", "of detect monster ", 0},
92 {100, "black \0                          ", "of detect things ", 0},
93  {10, "yellow \0                         ", "of confusion ", 0},
94  {80, "plaid \0                          ", "of levitation ", 0},
95 {150, "burgundy \0                       ", "of haste self ", 0},
96 {145, "beige \0                          ", "of see invisible ", 0}
97 };
98 
99 struct id id_scrolls[SCROLS] = {
100 {505, "                                   ", "of protect armor ", 0},
101 {200, "                                   ", "of hold monster ", 0},
102 {235, "                                   ", "of enchant weapon ", 0},
103 {235, "                                   ", "of enchant armor ", 0},
104 {175, "                                   ", "of identify ", 0},
105 {190, "                                   ", "of teleportation ", 0},
106  {25, "                                   ", "of sleep ", 0},
107 {610, "                                   ", "of scare monster ", 0},
108 {210, "                                   ", "of remove curse ", 0},
109  {80, "                                   ", "of create monster ",0},
110  {25, "                                   ", "of aggravate monster ",0},
111 {180, "                                   ", "of magic mapping ", 0},
112  {90, "                                   ", "of confuse monster ", 0}
113 };
114 
115 struct id id_weapons[WEAPONS] = {
116 	{150, "short bow ", "", 0},
117 	  {8, "darts ", "", 0},
118 	 {15, "arrows ", "", 0},
119 	 {27, "daggers ", "", 0},
120 	 {35, "shurikens ", "", 0},
121 	{360, "mace ", "", 0},
122 	{470, "long sword ", "", 0},
123 	{580, "two-handed sword ", "", 0}
124 };
125 
126 struct id id_armors[ARMORS] = {
127 	{300, "leather armor ", "", (UNIDENTIFIED)},
128 	{300, "ring mail ", "", (UNIDENTIFIED)},
129 	{400, "scale mail ", "", (UNIDENTIFIED)},
130 	{500, "chain mail ", "", (UNIDENTIFIED)},
131 	{600, "banded mail ", "", (UNIDENTIFIED)},
132 	{600, "splint mail ", "", (UNIDENTIFIED)},
133 	{700, "plate mail ", "", (UNIDENTIFIED)}
134 };
135 
136 struct id id_wands[WANDS] = {
137 	 {25, "                                 ", "of teleport away ",0},
138 	 {50, "                                 ", "of slow monster ", 0},
139 	  {8, "                                 ", "of invisibility ",0},
140 	 {55, "                                 ", "of polymorph ",0},
141 	  {2, "                                 ", "of haste monster ",0},
142 	 {20, "                                 ", "of magic missile ",0},
143 	 {20, "                                 ", "of cancellation ",0},
144 	  {0, "                                 ", "of do nothing ",0},
145 	 {35, "                                 ", "of drain life ",0},
146 	 {20, "                                 ", "of cold ",0},
147 	 {20, "                                 ", "of fire ",0}
148 };
149 
150 struct id id_rings[RINGS] = {
151 	 {250, "                                 ", "of stealth ",0},
152 	 {100, "                                 ", "of teleportation ", 0},
153 	 {255, "                                 ", "of regeneration ",0},
154 	 {295, "                                 ", "of slow digestion ",0},
155 	 {200, "                                 ", "of add strength ",0},
156 	 {250, "                                 ", "of sustain strength ",0},
157 	 {250, "                                 ", "of dexterity ",0},
158 	  {25, "                                 ", "of adornment ",0},
159 	 {300, "                                 ", "of see invisible ",0},
160 	 {290, "                                 ", "of maintain armor ",0},
161 	 {270, "                                 ", "of searching ",0},
162 };
163 
164 void
165 put_objects()
166 {
167 	short i, n;
168 	object *obj;
169 
170 	if (cur_level < max_level) {
171 		return;
172 	}
173 	n = coin_toss() ? get_rand(2, 4) : get_rand(3, 5);
174 	while (rand_percent(33)) {
175 		n++;
176 	}
177 	if (party_room != NO_ROOM) {
178 		make_party();
179 	}
180 	for (i = 0; i < n; i++) {
181 		obj = gr_object();
182 		rand_place(obj);
183 	}
184 	put_gold();
185 }
186 
187 void
188 put_gold()
189 {
190 	short i, j;
191 	short row,col;
192 	boolean is_maze, is_room;
193 
194 	for (i = 0; i < MAXROOMS; i++) {
195 		is_maze = (rooms[i].is_room & R_MAZE) ? 1 : 0;
196 		is_room = (rooms[i].is_room & R_ROOM) ? 1 : 0;
197 
198 		if (!(is_room || is_maze)) {
199 			continue;
200 		}
201 		if (is_maze || rand_percent(GOLD_PERCENT)) {
202 			for (j = 0; j < 50; j++) {
203 				row = get_rand(rooms[i].top_row+1,
204 				rooms[i].bottom_row-1);
205 				col = get_rand(rooms[i].left_col+1,
206 				rooms[i].right_col-1);
207 				if ((dungeon[row][col] == FLOOR) ||
208 					(dungeon[row][col] == TUNNEL)) {
209 					plant_gold(row, col, is_maze);
210 					break;
211 				}
212 			}
213 		}
214 	}
215 }
216 
217 void
218 plant_gold(row, col, is_maze)
219 	short row, col;
220 	boolean is_maze;
221 {
222 	object *obj;
223 
224 	obj = alloc_object();
225 	obj->row = row; obj->col = col;
226 	obj->what_is = GOLD;
227 	obj->quantity = get_rand((2 * cur_level), (16 * cur_level));
228 	if (is_maze) {
229 		obj->quantity += obj->quantity / 2;
230 	}
231 	dungeon[row][col] |= OBJECT;
232 	(void) add_to_pack(obj, &level_objects, 0);
233 }
234 
235 void
236 place_at(obj, row, col)
237 	object *obj;
238 	int row, col;
239 {
240 	obj->row = row;
241 	obj->col = col;
242 	dungeon[row][col] |= OBJECT;
243 	(void) add_to_pack(obj, &level_objects, 0);
244 }
245 
246 object *
247 object_at(pack, row, col)
248 	object *pack;
249 	short row, col;
250 {
251 	object *obj = (object *) 0;
252 
253 	if (dungeon[row][col] & (MONSTER | OBJECT)) {
254 		obj = pack->next_object;
255 
256 		while (obj && ((obj->row != row) || (obj->col != col))) {
257 			obj = obj->next_object;
258 		}
259 		if (!obj) {
260 			message("object_at(): inconsistent", 1);
261 		}
262 	}
263 	return(obj);
264 }
265 
266 object *
267 get_letter_object(ch)
268 	int ch;
269 {
270 	object *obj;
271 
272 	obj = rogue.pack.next_object;
273 
274 	while (obj && (obj->ichar != ch)) {
275 		obj = obj->next_object;
276 	}
277 	return(obj);
278 }
279 
280 void
281 free_stuff(objlist)
282 	object *objlist;
283 {
284 	object *obj;
285 
286 	while (objlist->next_object) {
287 		obj = objlist->next_object;
288 		objlist->next_object =
289 			objlist->next_object->next_object;
290 		free_object(obj);
291 	}
292 }
293 
294 const char *
295 name_of(obj)
296 	const object *obj;
297 {
298 	const char *retstring;
299 
300 	switch(obj->what_is) {
301 	case SCROL:
302 		retstring = obj->quantity > 1 ? "scrolls " : "scroll ";
303 		break;
304 	case POTION:
305 		retstring = obj->quantity > 1 ? "potions " : "potion ";
306 		break;
307 	case FOOD:
308 		if (obj->which_kind == RATION) {
309 			retstring = "food ";
310 		} else {
311 			retstring = fruit;
312 		}
313 		break;
314 	case WAND:
315 		retstring = is_wood[obj->which_kind] ? "staff " : "wand ";
316 		break;
317 	case WEAPON:
318 		switch(obj->which_kind) {
319 		case DART:
320 			retstring=obj->quantity > 1 ? "darts " : "dart ";
321 			break;
322 		case ARROW:
323 			retstring=obj->quantity > 1 ? "arrows " : "arrow ";
324 			break;
325 		case DAGGER:
326 			retstring=obj->quantity > 1 ? "daggers " : "dagger ";
327 			break;
328 		case SHURIKEN:
329 			retstring=obj->quantity > 1?"shurikens ":"shuriken ";
330 			break;
331 		default:
332 			retstring = id_weapons[obj->which_kind].title;
333 		}
334 		break;
335 	case ARMOR:
336 		retstring = "armor ";
337 		break;
338 	case RING:
339 			retstring = "ring ";
340 		break;
341 	case AMULET:
342 		retstring = "amulet ";
343 		break;
344 	default:
345 		retstring = "unknown ";
346 		break;
347 	}
348 	return(retstring);
349 }
350 
351 object *
352 gr_object()
353 {
354 	object *obj;
355 
356 	obj = alloc_object();
357 
358 	if (foods < (cur_level / 3)) {
359 		obj->what_is = FOOD;
360 		foods++;
361 	} else {
362 		obj->what_is = gr_what_is();
363 	}
364 	switch(obj->what_is) {
365 	case SCROL:
366 		gr_scroll(obj);
367 		break;
368 	case POTION:
369 		gr_potion(obj);
370 		break;
371 	case WEAPON:
372 		gr_weapon(obj, 1);
373 		break;
374 	case ARMOR:
375 		gr_armor(obj);
376 		break;
377 	case WAND:
378 		gr_wand(obj);
379 		break;
380 	case FOOD:
381 		get_food(obj, 0);
382 		break;
383 	case RING:
384 		gr_ring(obj, 1);
385 		break;
386 	}
387 	return(obj);
388 }
389 
390 unsigned short
391 gr_what_is()
392 {
393 	short percent;
394 	unsigned short what_is;
395 
396 	percent = get_rand(1, 91);
397 
398 	if (percent <= 30) {
399 		what_is = SCROL;
400 	} else if (percent <= 60) {
401 		what_is = POTION;
402 	} else if (percent <= 64) {
403 		what_is = WAND;
404 	} else if (percent <= 74) {
405 		what_is = WEAPON;
406 	} else if (percent <= 83) {
407 		what_is = ARMOR;
408 	} else if (percent <= 88) {
409 		what_is = FOOD;
410 	} else {
411 		what_is = RING;
412 	}
413 	return(what_is);
414 }
415 
416 void
417 gr_scroll(obj)
418 	object *obj;
419 {
420 	short percent;
421 
422 	percent = get_rand(0, 91);
423 
424 	obj->what_is = SCROL;
425 
426 	if (percent <= 5) {
427 		obj->which_kind = PROTECT_ARMOR;
428 	} else if (percent <= 10) {
429 		obj->which_kind = HOLD_MONSTER;
430 	} else if (percent <= 20) {
431 		obj->which_kind = CREATE_MONSTER;
432 	} else if (percent <= 35) {
433 		obj->which_kind = IDENTIFY;
434 	} else if (percent <= 43) {
435 		obj->which_kind = TELEPORT;
436 	} else if (percent <= 50) {
437 		obj->which_kind = SLEEP;
438 	} else if (percent <= 55) {
439 		obj->which_kind = SCARE_MONSTER;
440 	} else if (percent <= 64) {
441 		obj->which_kind = REMOVE_CURSE;
442 	} else if (percent <= 69) {
443 		obj->which_kind = ENCH_ARMOR;
444 	} else if (percent <= 74) {
445 		obj->which_kind = ENCH_WEAPON;
446 	} else if (percent <= 80) {
447 		obj->which_kind = AGGRAVATE_MONSTER;
448 	} else if (percent <= 86) {
449 		obj->which_kind = CON_MON;
450 	} else {
451 		obj->which_kind = MAGIC_MAPPING;
452 	}
453 }
454 
455 void
456 gr_potion(obj)
457 	object *obj;
458 {
459 	short percent;
460 
461 	percent = get_rand(1, 118);
462 
463 	obj->what_is = POTION;
464 
465 	if (percent <= 5) {
466 		obj->which_kind = RAISE_LEVEL;
467 	} else if (percent <= 15) {
468 		obj->which_kind = DETECT_OBJECTS;
469 	} else if (percent <= 25) {
470 		obj->which_kind = DETECT_MONSTER;
471 	} else if (percent <= 35) {
472 		obj->which_kind = INCREASE_STRENGTH;
473 	} else if (percent <= 45) {
474 		obj->which_kind = RESTORE_STRENGTH;
475 	} else if (percent <= 55) {
476 		obj->which_kind = HEALING;
477 	} else if (percent <= 65) {
478 		obj->which_kind = EXTRA_HEALING;
479 	} else if (percent <= 75) {
480 		obj->which_kind = BLINDNESS;
481 	} else if (percent <= 85) {
482 		obj->which_kind = HALLUCINATION;
483 	} else if (percent <= 95) {
484 		obj->which_kind = CONFUSION;
485 	} else if (percent <= 105) {
486 		obj->which_kind = POISON;
487 	} else if (percent <= 110) {
488 		obj->which_kind = LEVITATION;
489 	} else if (percent <= 114) {
490 		obj->which_kind = HASTE_SELF;
491 	} else {
492 		obj->which_kind = SEE_INVISIBLE;
493 	}
494 }
495 
496 void
497 gr_weapon(obj, assign_wk)
498 	object *obj;
499 	int assign_wk;
500 {
501 	short percent;
502 	short i;
503 	short blessing, increment;
504 
505 	obj->what_is = WEAPON;
506 	if (assign_wk) {
507 		obj->which_kind = get_rand(0, (WEAPONS - 1));
508 	}
509 	if ((obj->which_kind == ARROW) || (obj->which_kind == DAGGER) ||
510 		(obj->which_kind == SHURIKEN) | (obj->which_kind == DART)) {
511 		obj->quantity = get_rand(3, 15);
512 		obj->quiver = get_rand(0, 126);
513 	} else {
514 		obj->quantity = 1;
515 	}
516 	obj->hit_enchant = obj->d_enchant = 0;
517 
518 	percent = get_rand(1, 96);
519 	blessing = get_rand(1, 3);
520 
521 	if (percent <= 32) {
522 		if (percent <= 16) {
523 			increment = 1;
524 		} else {
525 			increment = -1;
526 			obj->is_cursed = 1;
527 		}
528 		for (i = 0; i < blessing; i++) {
529 			if (coin_toss()) {
530 				obj->hit_enchant += increment;
531 			} else {
532 				obj->d_enchant += increment;
533 			}
534 		}
535 	}
536 	switch(obj->which_kind) {
537 	case BOW:
538 	case DART:
539 		obj->damage = "1d1";
540 		break;
541 	case ARROW:
542 		obj->damage = "1d2";
543 		break;
544 	case DAGGER:
545 		obj->damage = "1d3";
546 		break;
547 	case SHURIKEN:
548 		obj->damage = "1d4";
549 		break;
550 	case MACE:
551 		obj->damage = "2d3";
552 		break;
553 	case LONG_SWORD:
554 		obj->damage = "3d4";
555 		break;
556 	case TWO_HANDED_SWORD:
557 		obj->damage = "4d5";
558 		break;
559 	}
560 }
561 
562 void
563 gr_armor(obj)
564 	object *obj;
565 {
566 	short percent;
567 	short blessing;
568 
569 	obj->what_is = ARMOR;
570 	obj->which_kind = get_rand(0, (ARMORS - 1));
571 	obj->class = obj->which_kind + 2;
572 	if ((obj->which_kind == PLATE) || (obj->which_kind == SPLINT)) {
573 		obj->class--;
574 	}
575 	obj->is_protected = 0;
576 	obj->d_enchant = 0;
577 
578 	percent = get_rand(1, 100);
579 	blessing = get_rand(1, 3);
580 
581 	if (percent <= 16) {
582 		obj->is_cursed = 1;
583 		obj->d_enchant -= blessing;
584 	} else if (percent <= 33) {
585 		obj->d_enchant += blessing;
586 	}
587 }
588 
589 void
590 gr_wand(obj)
591 	object *obj;
592 {
593 	obj->what_is = WAND;
594 	obj->which_kind = get_rand(0, (WANDS - 1));
595 	obj->class = get_rand(3, 7);
596 }
597 
598 void
599 get_food(obj, force_ration)
600 	object *obj;
601 	boolean force_ration;
602 {
603 	obj->what_is = FOOD;
604 
605 	if (force_ration || rand_percent(80)) {
606 		obj->which_kind = RATION;
607 	} else {
608 		obj->which_kind = FRUIT;
609 	}
610 }
611 
612 void
613 put_stairs()
614 {
615 	short row, col;
616 
617 	gr_row_col(&row, &col, (FLOOR | TUNNEL));
618 	dungeon[row][col] |= STAIRS;
619 }
620 
621 int
622 get_armor_class(obj)
623 	const object *obj;
624 {
625 	if (obj) {
626 		return(obj->class + obj->d_enchant);
627 	}
628 	return(0);
629 }
630 
631 object *
632 alloc_object()
633 {
634 	object *obj;
635 
636 	if (free_list) {
637 		obj = free_list;
638 		free_list = free_list->next_object;
639 	} else if (!(obj = (object *) md_malloc(sizeof(object)))) {
640 			message("cannot allocate object, saving game", 0);
641 			save_into_file(error_file);
642 	}
643 	obj->quantity = 1;
644 	obj->ichar = 'L';
645 	obj->picked_up = obj->is_cursed = 0;
646 	obj->in_use_flags = NOT_USED;
647 	obj->identified = UNIDENTIFIED;
648 	obj->damage = "1d1";
649 	return(obj);
650 }
651 
652 void
653 free_object(obj)
654 	object *obj;
655 {
656 	obj->next_object = free_list;
657 	free_list = obj;
658 }
659 
660 void
661 make_party()
662 {
663 	short n;
664 
665 	party_room = gr_room();
666 
667 	n = rand_percent(99) ? party_objects(party_room) : 11;
668 	if (rand_percent(99)) {
669 		party_monsters(party_room, n);
670 	}
671 }
672 
673 void
674 show_objects()
675 {
676 	object *obj;
677 	short mc, rc, row, col;
678 	object *monster;
679 
680 	obj = level_objects.next_object;
681 
682 	while (obj) {
683 		row = obj->row;
684 		col = obj->col;
685 
686 		rc = get_mask_char(obj->what_is);
687 
688 		if (dungeon[row][col] & MONSTER) {
689 			if ((monster =
690 			    object_at(&level_monsters, row, col)) != NULL) {
691 				monster->trail_char = rc;
692 			}
693 		}
694 		mc = mvinch(row, col);
695 		if (((mc < 'A') || (mc > 'Z')) &&
696 			((row != rogue.row) || (col != rogue.col))) {
697 			mvaddch(row, col, rc);
698 		}
699 		obj = obj->next_object;
700 	}
701 
702 	monster = level_monsters.next_object;
703 
704 	while (monster) {
705 		if (monster->m_flags & IMITATES) {
706 			mvaddch(monster->row, monster->col, (int) monster->disguise);
707 		}
708 		monster = monster->next_monster;
709 	}
710 }
711 
712 void
713 put_amulet()
714 {
715 	object *obj;
716 
717 	obj = alloc_object();
718 	obj->what_is = AMULET;
719 	rand_place(obj);
720 }
721 
722 void
723 rand_place(obj)
724 	object *obj;
725 {
726 	short row, col;
727 
728 	gr_row_col(&row, &col, (FLOOR | TUNNEL));
729 	place_at(obj, row, col);
730 }
731 
732 void
733 c_object_for_wizard()
734 {
735 	short ch, max, wk;
736 	object *obj;
737 	char buf[80];
738 
739 	max = 0;
740 	if (pack_count((object *) 0) >= MAX_PACK_COUNT) {
741 		message("pack full", 0);
742 		return;
743 	}
744 	message("type of object?", 0);
745 
746 	while (r_index("!?:)]=/,\033", (ch = rgetchar()), 0) == -1) {
747 		sound_bell();
748 	}
749 	check_message();
750 
751 	if (ch == '\033') {
752 		return;
753 	}
754 	obj = alloc_object();
755 
756 	switch(ch) {
757 	case '!':
758 		obj->what_is = POTION;
759 		max = POTIONS - 1;
760 		break;
761 	case '?':
762 		obj->what_is = SCROL;
763 		max = SCROLS - 1;
764 		break;
765 	case ',':
766 		obj->what_is = AMULET;
767 		break;
768 	case ':':
769 		get_food(obj, 0);
770 		break;
771 	case ')':
772 		gr_weapon(obj, 0);
773 		max = WEAPONS - 1;
774 		break;
775 	case ']':
776 		gr_armor(obj);
777 		max = ARMORS - 1;
778 		break;
779 	case '/':
780 		gr_wand(obj);
781 		max = WANDS - 1;
782 		break;
783 	case '=':
784 		max = RINGS - 1;
785 		obj->what_is = RING;
786 		break;
787 	}
788 	if ((ch != ',') && (ch != ':')) {
789 GIL:
790 		if (get_input_line("which kind?", "", buf, "", 0, 1)) {
791 			wk = get_number(buf);
792 			if ((wk >= 0) && (wk <= max)) {
793 				obj->which_kind = (unsigned short) wk;
794 				if (obj->what_is == RING) {
795 					gr_ring(obj, 0);
796 				}
797 			} else {
798 				sound_bell();
799 				goto GIL;
800 			}
801 		} else {
802 			free_object(obj);
803 			return;
804 		}
805 	}
806 	get_desc(obj, buf);
807 	message(buf, 0);
808 	(void) add_to_pack(obj, &rogue.pack, 1);
809 }
810