comparison arogue7/pack.c @ 125:adfa37e67084

Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
author John "Elwin" Edwards
date Fri, 08 May 2015 15:24:40 -0400
parents
children b786053d2f37
comparison
equal deleted inserted replaced
124:d10fc4a065ac 125:adfa37e67084
1 /*
2 * pack.c - Routines to deal with the pack.
3 *
4 * Advanced Rogue
5 * Copyright (C) 1984, 1985, 1986 Michael Morgan, Ken Dalka and AT&T
6 * All rights reserved.
7 *
8 * Based on "Rogue: Exploring the Dungeons of Doom"
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * All rights reserved.
11 *
12 * See the file LICENSE.TXT for full copyright and licensing information.
13 */
14
15 #include "curses.h"
16 #include <ctype.h>
17 #include "rogue.h"
18 #ifdef PC7300
19 #include "menu.h"
20 #endif
21
22 /*
23 * Routines to deal with the pack
24 */
25
26 /*
27 * add_pack:
28 * Pick up an object and add it to the pack. If the argument is non-null
29 * use it as the linked_list pointer instead of gettting it off the ground.
30 */
31 bool
32 add_pack(item, silent, packret)
33 register struct linked_list *item, **packret;
34 bool silent;
35 {
36 register struct linked_list *ip, *lp, *ap;
37 register struct object *obj, *op;
38 register bool exact, from_floor;
39
40 if (packret != NULL)
41 *packret = NULL;
42
43 if (item == NULL)
44 {
45 from_floor = TRUE;
46 if ((item = find_obj(hero.y, hero.x)) == NULL)
47 return(FALSE);
48 }
49 else
50 from_floor = FALSE;
51 obj = OBJPTR(item);
52 /*
53 * If it is gold, just add its value to rogue's purse and get rid
54 * of it.
55 */
56 if (obj->o_type == GOLD) {
57 register struct linked_list *mitem;
58 register struct thing *tp;
59
60 if (!silent) {
61 if (!terse) addmsg("You found ");
62 msg("%d gold pieces.", obj->o_count);
63 }
64
65 /* First make sure no greedy monster is after this gold.
66 * If so, make the monster run after the rogue instead.
67 */
68 for (mitem = mlist; mitem != NULL; mitem = next(mitem)) {
69 tp = THINGPTR(mitem);
70 if (tp->t_dest == &obj->o_pos) tp->t_dest = &hero;
71 }
72
73 purse += obj->o_count;
74 if (from_floor) {
75 detach(lvl_obj, item);
76 if ((ap = find_obj(hero.y, hero.x)) == NULL)
77 mvaddch(hero.y,hero.x,(roomin(&hero)==NULL ? PASSAGE : FLOOR));
78 else
79 mvaddch(hero.y,hero.x,(OBJPTR(ap))->o_type);
80 }
81 o_discard(item);
82 return(TRUE);
83 }
84
85 /*
86 * see if he can carry any more weight
87 */
88 if (itemweight(obj) + pstats.s_pack > pstats.s_carry) {
89 msg("Too much for you to carry.");
90 return FALSE;
91 }
92 /*
93 * Link it into the pack. Search the pack for a object of similar type
94 * if there isn't one, stuff it at the beginning, if there is, look for one
95 * that is exactly the same and just increment the count if there is.
96 * it that. Food is always put at the beginning for ease of access, but
97 * is not ordered so that you can't tell good food from bad. First check
98 * to see if there is something in thr same group and if there is then
99 * increment the count.
100 */
101 if (obj->o_group)
102 {
103 for (ip = pack; ip != NULL; ip = next(ip))
104 {
105 op = OBJPTR(ip);
106 if (op->o_group == obj->o_group)
107 {
108 /*
109 * Put it in the pack and notify the user
110 */
111 op->o_count += obj->o_count;
112 if (from_floor)
113 {
114 detach(lvl_obj, item);
115 if ((ap = find_obj(hero.y, hero.x)) == NULL)
116 mvaddch(hero.y,hero.x,
117 (roomin(&hero)==NULL ? PASSAGE : FLOOR));
118 else
119 mvaddch(hero.y,hero.x,(OBJPTR(ap))->o_type);
120 }
121 o_discard(item);
122 item = ip;
123 goto picked_up;
124 }
125 }
126 }
127
128 /*
129 * Check for and deal with scare monster scrolls
130 */
131 if (obj->o_type == SCROLL && obj->o_which == S_SCARE)
132 if (obj->o_flags & ISCURSED)
133 {
134 msg("The scroll turns to dust as you pick it up.");
135 detach(lvl_obj, item);
136 if ((ap = find_obj(hero.y, hero.x)) == NULL)
137 mvaddch(hero.y,hero.x,(roomin(&hero)==NULL ? PASSAGE : FLOOR));
138 else
139 mvaddch(hero.y,hero.x,(OBJPTR(ap))->o_type);
140 return(TRUE);
141 }
142
143 /*
144 * Search for an object of the same type
145 */
146 exact = FALSE;
147 for (ip = pack; ip != NULL; ip = next(ip))
148 {
149 op = OBJPTR(ip);
150 if (obj->o_type == op->o_type)
151 break;
152 }
153 if (ip == NULL)
154 {
155 /*
156 * Put it at the end of the pack since it is a new type
157 */
158 for (ip = pack; ip != NULL; ip = next(ip))
159 {
160 op = OBJPTR(ip);
161 if (op->o_type != FOOD)
162 break;
163 lp = ip;
164 }
165 }
166 else
167 {
168 /*
169 * Search for an object which is exactly the same
170 */
171 while (ip != NULL && op->o_type == obj->o_type)
172 {
173 if (op->o_which == obj->o_which)
174 {
175 exact = TRUE;
176 break;
177 }
178 lp = ip;
179 if ((ip = next(ip)) == NULL)
180 break;
181 op = OBJPTR(ip);
182 }
183 }
184 /*
185 * Check if there is room
186 */
187 if (ip == NULL || !exact || !ISMULT(obj->o_type)) {
188 if (inpack == MAXPACK-1) {
189 msg(terse ? "No room." : "You can't carry anything else.");
190 return(FALSE);
191 }
192 }
193 inpack++;
194 if (from_floor)
195 {
196 detach(lvl_obj, item);
197 if ((ap = find_obj(hero.y, hero.x)) == NULL)
198 mvaddch(hero.y,hero.x,(roomin(&hero)==NULL ? PASSAGE : FLOOR));
199 else
200 mvaddch(hero.y,hero.x,(OBJPTR(ap))->o_type);
201 }
202 if (ip == NULL)
203 {
204 /*
205 * Didn't find an exact match, just stick it here
206 */
207 if (pack == NULL)
208 pack = item;
209 else
210 {
211 lp->l_next = item;
212 item->l_prev = lp;
213 item->l_next = NULL;
214 }
215 }
216 else
217 {
218 /*
219 * If we found an exact match. If it is food,
220 * increase the count, otherwise put it with its clones.
221 */
222 if (exact && ISMULT(obj->o_type))
223 {
224 op->o_count += obj->o_count;
225 inpack--; /* adjust for previous addition */
226 o_discard(item);
227 item = ip;
228 goto picked_up;
229 }
230 if ((item->l_prev = prev(ip)) != NULL)
231 item->l_prev->l_next = item;
232 else
233 pack = item;
234 item->l_next = ip;
235 ip->l_prev = item;
236 }
237 picked_up:
238 /*
239 * Notify the user
240 */
241 obj = OBJPTR(item);
242 if (!silent)
243 {
244 if (!terse)
245 addmsg("You now have ");
246 msg("%s (%c)", inv_name(obj, !terse), pack_char(pack, obj));
247 }
248
249 /* Relics can do strange things when you pick them up */
250 if (obj->o_type == RELIC) {
251 switch (obj->o_which) {
252 /* the ankh of Heil gives you prayers */
253 case HEIL_ANKH:
254 msg("The ankh welds itself into your hand.");
255 if (player.t_ctype != C_CLERIC && player.t_ctype != C_PALADIN)
256 fuse(prayer_recovery, 0, SPELLTIME, AFTER);
257
258 /* A cloak must be worn. */
259 when EMORI_CLOAK:
260 if (cur_armor != NULL || cur_misc[WEAR_CLOAK]) {
261 msg("The cloak insists you remove your current garments.");
262 if (!dropcheck(cur_armor != NULL ? cur_armor
263 : cur_misc[WEAR_CLOAK])) {
264 pstats.s_hpt = -1;
265 msg("The cloak constricts around you.");
266 msg("It draws your life force from you!!! -- More --");
267 wait_for(' ');
268 death(D_RELIC);
269 }
270 }
271 if (obj->o_charges < 0) /* should never happen, but.... */
272 obj->o_charges = 0;
273 if (obj->o_charges == 0)
274 fuse(cloak_charge, obj, CLOAK_TIME, AFTER);
275
276 /* The amulet must be worn. */
277 when STONEBONES_AMULET:
278 case YENDOR_AMULET:
279 if (cur_misc[WEAR_JEWEL] ||
280 cur_relic[STONEBONES_AMULET] ||
281 cur_relic[YENDOR_AMULET]) {
282 msg("You have an urge to remove your current amulet.");
283 }
284 if((cur_misc[WEAR_JEWEL] && !dropcheck(cur_misc[WEAR_JEWEL])) ||
285 cur_relic[STONEBONES_AMULET] ||
286 cur_relic[YENDOR_AMULET]) {
287 pstats.s_hpt = -1;
288 msg("The %s begins pulsing.", inv_name(obj, TRUE));
289 msg("It fades away.... -- More --");
290 wait_for(' ');
291 death(D_RELIC);
292 }
293 msg("The %s welds itself into your chest.",inv_name(obj,TRUE));
294
295 /* The eye must be inserted in eye socket */
296 when EYE_VECNA:
297 msg("The eye forces you to jam it into your eye socket!");
298 pstats.s_hpt -= 75;
299 if (pstats.s_hpt < 0) {
300 msg ("The pain is too much for you! -- More --");
301 wait_for(' ');
302 death(D_RELIC);
303 }
304 waste_time();
305 msg("The excrutiating pain slowly turns into a dull throb.");
306
307 when QUILL_NAGROM:
308 fuse(quill_charge,0,player.t_ctype==C_MAGICIAN ? 4 : 8,AFTER);
309
310 /* Weapons will insist on being wielded. */
311 when MUSTY_DAGGER:
312 case HRUGGEK_MSTAR:
313 case YEENOGHU_FLAIL:
314 case AXE_AKLAD:
315 /* For the daggers start a fuse to change player to a thief. */
316 /* and set a daemon to eat gold. */
317 if (obj->o_which == MUSTY_DAGGER) {
318 fuse(changeclass, C_THIEF, roll(20, 20), AFTER);
319 if (purse > 0)
320 msg("Your purse feels lighter");
321 else
322 purse = 1; /* fudge to get right msg from eat_gold() */
323 eat_gold(obj);
324 daemon(eat_gold, obj, AFTER);
325 }
326 /* For the axe start a fuse to change player to a fighter. */
327 if (obj->o_which == AXE_AKLAD)
328 fuse(changeclass, C_FIGHTER, roll(20, 20), AFTER);
329 if (cur_weapon != NULL) {
330 msg("The artifact insists you release your current weapon.");
331 if (!dropcheck(cur_weapon)) {
332 pstats.s_hpt = -1;
333 msg("The artifact forces your weapon into your heart.");
334 msg("It hums with satisfaction. -- More --");
335 wait_for(' ');
336 death(D_RELIC);
337 }
338 }
339 cur_weapon = obj;
340
341 when SURTUR_RING:
342 msg("The ring forces itself through your nose!");
343 pstats.s_hpt -= 22;
344 if (pstats.s_hpt < 0) {
345 msg ("The pain is too much for you! -- More --");
346 wait_for(' ');
347 death(D_RELIC);
348 }
349 waste_time();
350 turn_on(player, NOFIRE);
351 msg("The pain slowly subsides.");
352 otherwise:
353 break;
354 }
355 cur_relic[obj->o_which]++; /* Note that we have it */
356 }
357
358 updpack(FALSE, &player);
359 if (packret != NULL)
360 *packret = item;
361 return(TRUE);
362 }
363
364 #ifdef PC7300
365 static menu_t Display; /* The menu structure */
366 static mitem_t Dispitems[MAXPACK+1]; /* Info for each line */
367 static char Displines[MAXPACK+1][LINELEN+1]; /* The lines themselves */
368 #endif
369
370 /*
371 * inventory:
372 * list what is in the pack
373 */
374 inventory(list, type)
375 register struct linked_list *list;
376 register int type;
377 {
378 register struct object *obj;
379 register char ch;
380 register int n_objs, cnt, maxx, curx;
381 char inv_temp[2*LINELEN+1];
382
383 cnt = 0;
384 n_objs = 0;
385 for (ch = 'a'; list != NULL; ch++, list = next(list)) {
386 obj = OBJPTR(list);
387 if (!is_type(obj, type))
388 continue;
389 switch (n_objs++) {
390 /*
391 * For the first thing in the inventory, just save the string
392 * in case there is only one.
393 */
394 case 0:
395 sprintf(inv_temp, "%c) %s", ch, inv_name(obj, FALSE));
396 break;
397 /*
398 * If there is more than one, clear the screen, print the
399 * saved message and fall through to ...
400 */
401 case 1:
402 if (slow_invent)
403 msg(inv_temp);
404 else
405 {
406 wclear(hw);
407 waddstr(hw, inv_temp);
408 waddch(hw, '\n');
409
410 maxx = strlen(inv_temp); /* Length of the listing */
411
412 #ifdef PC7300
413 /* Put it into the PC menu display */
414 strcpy(Displines[0], inv_temp);
415 Dispitems[0].mi_name = Displines[0];
416 Dispitems[0].mi_flags = 0;
417 Dispitems[0].mi_val = 0;
418 #endif
419 }
420 /*
421 * Print the line for this object
422 */
423 default:
424 if (ch > 'z')
425 ch = 'A';
426 if (slow_invent)
427 msg("%c) %s", ch, inv_name(obj, FALSE));
428 else {
429 if (++cnt >= lines - 2) { /* if bottom of screen */
430 dbotline(hw, morestr);
431 cnt = 0;
432 wclear(hw);
433 }
434 sprintf(inv_temp, "%c) %s\n", ch, inv_name(obj, FALSE));
435 curx = strlen(inv_temp) - 1; /* Don't count new-line */
436 if (curx > maxx) maxx = curx;
437 waddstr(hw, inv_temp);
438 #ifdef PC7300
439 /* Put it into the PC menu display */
440 strcpy(Displines[n_objs-1], inv_temp);
441 Displines[n_objs-1][curx] = '\0'; /* Strip newline */
442 Dispitems[n_objs-1].mi_name = Displines[n_objs-1];
443 Dispitems[n_objs-1].mi_flags = 0;
444 Dispitems[n_objs-1].mi_val = 0;
445 #endif
446 }
447 }
448 }
449 if (n_objs == 0) {
450 if (terse)
451 msg(type == ALL ? "Empty handed." :
452 "Nothing appropriate");
453 else
454 msg(type == ALL ? "You are empty handed." :
455 "You don't have anything appropriate");
456 return FALSE;
457 }
458 if (n_objs == 1) {
459 msg(inv_temp);
460 return TRUE;
461 }
462 if (!slow_invent)
463 {
464 #ifdef PC7300
465 /* Place an end marker for the items */
466 Dispitems[n_objs].mi_name = 0;
467
468 /* Set up the main menu structure */
469 Display.m_label = "Inventory";
470 Display.m_title = "Pack Contents";
471 Display.m_prompt = "Press Cancl to continue.";
472 Display.m_curptr = '\0';
473 Display.m_markptr = '\0';
474 Display.m_flags = 0;
475 Display.m_selcnt = 0;
476 Display.m_items = Dispitems;
477 Display.m_curi = 0;
478
479 /*
480 * Try to display the menu. If we don't have a local terminal,
481 * the call will fail and we will just continue with the
482 * normal mode.
483 */
484 if (menu(&Display) >= 0) return TRUE;
485 #endif
486 waddstr(hw, spacemsg);
487 curx = strlen(spacemsg);
488 if (curx > maxx) maxx = curx;
489
490 /*
491 * If we have fewer than half a screenful, don't clear the screen.
492 * Leave an extra blank line at the bottom and 3 blank columns
493 * to he right.
494 */
495 if (menu_overlay && n_objs < lines / 2 + 2) {
496 over_win(cw, hw, n_objs + 2, maxx + 3, n_objs, curx, ' ');
497 return TRUE;
498 }
499
500 draw(hw);
501 wait_for(' ');
502 clearok(cw, TRUE);
503 touchwin(cw);
504 }
505 return TRUE;
506 }
507
508 /*
509 * picky_inven:
510 * Allow player to inventory a single item
511 */
512 void
513 picky_inven()
514 {
515 register struct linked_list *item;
516 register char ch, mch;
517
518 if (pack == NULL)
519 msg("You aren't carrying anything");
520 else if (next(pack) == NULL)
521 msg("a) %s", inv_name(OBJPTR(pack), FALSE));
522 else
523 {
524 msg(terse ? "Item: " : "Which item do you wish to inventory: ");
525 mpos = 0;
526 if ((mch = readchar()) == ESCAPE)
527 {
528 msg("");
529 return;
530 }
531
532 /* Check for a special character */
533 switch (mch) {
534 case FOOD:
535 case SCROLL:
536 case POTION:
537 case RING:
538 case STICK:
539 case RELIC:
540 case ARMOR:
541 case WEAPON:
542 case MM:
543 msg("");
544 if (get_item(pack, NULL, mch, FALSE, FALSE) == NULL) {
545 if (terse) msg("None in pack.");
546 else msg("You have no %c in your pack.", mch);
547 }
548 return;
549 }
550
551 for (ch = 'a', item = pack; item != NULL; item = next(item), ch++)
552 if (ch == mch)
553 {
554 msg("%c) %s",ch,inv_name(OBJPTR(item), FALSE));
555 return;
556 }
557 if (!terse)
558 msg("'%s' not in pack.", unctrl(mch));
559 msg("Range is 'a' to '%c'", --ch);
560 }
561 }
562
563
564 /*
565 * get_item:
566 * pick something out of a pack for a purpose
567 */
568 struct linked_list *
569 get_item(list, purpose, type, askfirst, showcost)
570 reg struct linked_list *list;
571 char *purpose; /* NULL if we should be silent (no prompts) */
572 int type;
573 bool askfirst, showcost;
574 {
575 reg struct linked_list *item;
576 reg struct object *obj;
577 reg int cnt, pagecnt, ch, och, maxx, curx, confused;
578 struct linked_list *saveitem;
579 char description[2*LINELEN+1];
580 char cost[LINELEN/2];
581 #ifdef PC7300
582 int menucount = 0;
583 int usemenu = 1;
584 #endif
585
586 /*
587 * If this is the player's pack and the player is confused, we
588 * might just take anything.
589 */
590 if (list == player.t_pack && on(player, ISHUH) && rnd(100) < 75)
591 confused = 1;
592 else confused = 0;
593
594 cnt = 0;
595 if (list == NULL) {
596 msg("You aren't carrying anything.");
597 return NULL;
598 }
599 /* see if we have any of the type requested */
600 for(ch = 'a',item = list ; item != NULL ; item = next(item), ch++) {
601 obj = OBJPTR(item);
602 if (is_type(obj, type)) {
603 cnt++;
604 saveitem = item;
605 }
606 }
607 if (cnt == 0) {
608 if (purpose) msg("Nothing to %s", purpose);
609 after = FALSE;
610 return NULL;
611 }
612 else if (cnt == 1) { /* only found one of 'em */
613 obj = OBJPTR(saveitem);
614 while(TRUE) {
615 if (purpose) { /* Should we prompt the player? */
616 msg("%s what (* for the item)?",purpose);
617 ch = tolower(readchar());
618 }
619 else {
620 ch = pack_char(list, obj);
621 msg("%c) %s", ch, inv_name(obj,FALSE));
622 }
623
624 if (ch == '*') {
625 mpos = 0;
626 msg("%c) %s",pack_char(list, obj),inv_name(obj,FALSE));
627 continue;
628 }
629 if (ch == ESCAPE) {
630 msg("");
631 after = FALSE;
632 return NULL;
633 }
634 for(item = list,och = 'a'; item != NULL; item = next(item),och++) {
635 if (ch == och) break;
636 if (och == 'z') och = 'A' - 1;
637 }
638 if (item == NULL) {
639 msg("Please specify a letter between 'a' and '%c'",
640 och == 'A' ? 'z' : och-1);
641 continue;
642 }
643 if (is_type (OBJPTR(item), type)) {
644 if (purpose) mpos = 0;
645 return item;
646 }
647 else
648 msg ("You can't %s that!", purpose);
649
650 }
651 }
652 while (TRUE) {
653 if (!askfirst && purpose) {
654 msg("%s what? (* for list): ",purpose);
655 ch = readchar();
656 }
657 else ch = '*';
658
659 mpos = 0;
660 if (ch == ESCAPE) { /* abort if escape hit */
661 after = FALSE;
662 msg(""); /* clear display */
663 return NULL;
664 }
665
666 if (ch == '*') {
667 wclear(hw);
668 pagecnt = 0;
669 maxx = 0;
670 for(item = list,ch = 'a'; item != NULL ; item = next(item), ch++) {
671 obj = OBJPTR(item);
672 if (!is_type(OBJPTR(item), type))
673 continue;
674 cost[0] = '\0';
675 if (showcost) {
676 sprintf(description, "[%d] ", get_worth(obj));
677 sprintf(cost, "%8.8s", description);
678 }
679 sprintf(description,"%c) %s%s\n\r",ch,cost,inv_name(obj,FALSE));
680 waddstr(hw, description);
681 curx = strlen(description) - 2; /* Don't count \n or \r */
682 if (maxx < curx) maxx = curx;
683 #ifdef PC7300
684 if (usemenu) {
685 /* Put it into the PC menu display */
686 strcpy(Displines[menucount], description);
687 Displines[menucount][curx] = '\0'; /* Strip newline */
688 Dispitems[menucount].mi_name = Displines[menucount];
689 Dispitems[menucount].mi_flags = 0;
690 Dispitems[menucount++].mi_val = (int) item;
691 }
692 #endif
693 if (++pagecnt >= lines - 2 && next(item) != NULL) {
694 pagecnt = 0;
695 dbotline(hw, spacemsg);
696 wclear(hw);
697 }
698 if (ch == 'z') ch = 'A' - 1;
699 }
700
701 /* Put in the prompt */
702 if (purpose) sprintf(description, "%s what? ", purpose);
703 else strcpy(description, spacemsg);
704 waddstr(hw, description);
705 curx = strlen(description);
706 if (maxx < curx) maxx = curx;
707
708 #ifdef PC7300
709 if (usemenu) {
710 /* Place an end marker for the items */
711 Dispitems[menucount].mi_name = 0;
712
713 /* Set up the main menu structure */
714 Display.m_label = "Sub-Inventory";
715 if (purpose) {
716 Display.m_title = description;
717 Display.m_prompt =
718 "Select an item or press Cancl for no selection.";
719 Display.m_selcnt = 1;
720 }
721 else {
722 Display.m_title = 0;
723 Display.m_prompt = "Press Cancl to continue.";
724 Display.m_selcnt = 0;
725 }
726 Display.m_curptr = '\0';
727 Display.m_markptr = '\0';
728 Display.m_flags = 0;
729 Display.m_items = Dispitems;
730 Display.m_curi = 0;
731
732 /*
733 * Try to display the menu. If we don't have a local terminal,
734 * the call will fail and we will just continue with the
735 * normal mode.
736 */
737 if (menu(&Display) >= 0) {
738 msg("");
739 if (Display.m_selcnt == 0) {
740 /* Menu was cancelled */
741 if (purpose) {
742 after = FALSE;
743 return NULL; /* all done if abort */
744 }
745 else return saveitem;
746 }
747 else return (struct linked_list *) Display.m_curi->mi_val;
748 }
749 else {
750 usemenu = 0; /* Can't use the menu facilities */
751 }
752 }
753 #endif
754 /* Write the screen */
755 if ((menu_overlay && cnt < lines / 2 + 2) || cnt == 1) {
756 over_win(cw, hw, cnt + 2, maxx + 3, cnt, curx, NULL);
757 cnt = -1; /* Indicate we used over_win */
758 }
759 else draw(hw);
760
761 if (purpose) {
762 do {
763 ch = tolower(readchar());
764 } until (isalpha(ch) || ch == ESCAPE);
765 }
766 else {
767 ch = pack_char(list, OBJPTR(saveitem)); /* Pick a valid item */
768 wait_for(' ');
769 }
770
771 /* Redraw original screen */
772 if (cnt < 0) {
773 clearok(cw, FALSE); /* Setup to redraw current screen */
774 touchwin(cw); /* clearing first */
775 }
776 else restscr(cw);
777
778 if(ch == ESCAPE) {
779 after = FALSE;
780 msg(""); /* clear top line */
781 return NULL; /* all done if abort */
782 }
783 /* ch has item to get from list */
784 }
785
786 for (item = list,och = 'a'; item != NULL; item = next(item),och++) {
787 if (confused) {
788 /*
789 * Confused is incremented each time so that if the rnd(cnt)
790 * clause keeps failing, confused will equal cnt for the
791 * last item of the correct type and rnd(cnt) < cnt will
792 * have to be true.
793 */
794 if (is_type(OBJPTR(item), type) && rnd(cnt) < confused++)
795 break;
796 }
797 else if (ch == och) break;
798 if (och == 'z') och = 'A' - 1;
799 }
800
801 if (item == NULL) {
802 msg("Please specify a letter between 'a' and '%c'",
803 och == 'A' ? 'z' : och-1);
804 continue;
805 }
806
807 if (is_type(OBJPTR(item), type))
808 return (item);
809 else
810 msg ("You can't %s that!", purpose);
811 }
812 }
813
814 pack_char(list, obj)
815 register struct object *obj;
816 struct linked_list *list;
817 {
818 register struct linked_list *item;
819 register char c;
820
821 c = 'a';
822 for (item = list; item != NULL; item = next(item)) {
823 if (OBJPTR(item) == obj)
824 return c;
825 else {
826 if (c == 'z') c = 'A';
827 else c++;
828 }
829 }
830 return 'z';
831 }
832
833
834 /*
835 * cur_null:
836 * This updates cur_weapon etc for dropping things
837 */
838 cur_null(op)
839 reg struct object *op;
840 {
841 if (op == cur_weapon) cur_weapon = NULL;
842 else if (op == cur_armor) cur_armor = NULL;
843 else if (op == cur_ring[LEFT_1]) cur_ring[LEFT_1] = NULL;
844 else if (op == cur_ring[LEFT_2]) cur_ring[LEFT_2] = NULL;
845 else if (op == cur_ring[LEFT_3]) cur_ring[LEFT_3] = NULL;
846 else if (op == cur_ring[LEFT_4]) cur_ring[LEFT_4] = NULL;
847 else if (op == cur_ring[RIGHT_1]) cur_ring[RIGHT_1] = NULL;
848 else if (op == cur_ring[RIGHT_2]) cur_ring[RIGHT_2] = NULL;
849 else if (op == cur_ring[RIGHT_3]) cur_ring[RIGHT_3] = NULL;
850 else if (op == cur_ring[RIGHT_4]) cur_ring[RIGHT_4] = NULL;
851 else if (op == cur_misc[WEAR_BOOTS]) cur_misc[WEAR_BOOTS] = NULL;
852 else if (op == cur_misc[WEAR_JEWEL]) cur_misc[WEAR_JEWEL] = NULL;
853 else if (op == cur_misc[WEAR_GAUNTLET]) cur_misc[WEAR_GAUNTLET] = NULL;
854 else if (op == cur_misc[WEAR_CLOAK]) cur_misc[WEAR_CLOAK] = NULL;
855 else if (op == cur_misc[WEAR_BRACERS]) cur_misc[WEAR_BRACERS] = NULL;
856 else if (op == cur_misc[WEAR_NECKLACE]) cur_misc[WEAR_NECKLACE] = NULL;
857 }
858
859 /*
860 * idenpack:
861 * Identify all the items in the pack
862 */
863 idenpack()
864 {
865 reg struct linked_list *pc;
866
867 for (pc = pack ; pc != NULL ; pc = next(pc))
868 whatis(pc);
869 }
870
871 is_type (obj, type)
872 register struct object *obj;
873 register int type;
874 {
875 register bool current;
876
877 if (type == obj->o_type)
878 return (TRUE);
879
880 switch (type) {
881 case ALL:
882 return (TRUE);
883 when READABLE:
884 if (obj->o_type == SCROLL ||
885 (obj->o_type == MM && obj->o_which == MM_SKILLS))
886 return (TRUE);
887 when QUAFFABLE:
888 if (obj->o_type == POTION ||
889 (obj->o_type == MM && obj->o_which == MM_JUG))
890 return (TRUE);
891 when ZAPPABLE:
892 if (obj->o_type == STICK) return (TRUE);
893 if (obj->o_type == RELIC)
894 switch (obj->o_which) {
895 case MING_STAFF:
896 case ASMO_ROD:
897 case ORCUS_WAND:
898 case EMORI_CLOAK:
899 return (TRUE);
900 }
901 when WEARABLE:
902 case REMOVABLE:
903 current = is_current(obj);
904
905 /*
906 * Don't wear thing we are already wearing or remove things
907 * we aren't wearing.
908 */
909 if (type == WEARABLE && current) return (FALSE);
910 else if (type == REMOVABLE && !current) return (FALSE);
911
912 switch (obj->o_type) {
913 case RELIC:
914 switch (obj->o_which) {
915 case HEIL_ANKH:
916 case EMORI_CLOAK:
917 return (TRUE);
918 }
919 when MM:
920 switch (obj->o_which) {
921 case MM_ELF_BOOTS:
922 case MM_DANCE:
923 case MM_BRACERS:
924 case MM_DISP:
925 case MM_PROTECT:
926 case MM_G_DEXTERITY:
927 case MM_G_OGRE:
928 case MM_JEWEL:
929 case MM_R_POWERLESS:
930 case MM_FUMBLE:
931 case MM_STRANGLE:
932 case MM_ADAPTION:
933 return (TRUE);
934 }
935 when ARMOR:
936 case RING:
937 return (TRUE);
938 }
939 when CALLABLE:
940 switch (obj->o_type) {
941 case RING: if (!r_know[obj->o_which]) return(TRUE);
942 when POTION: if (!p_know[obj->o_which]) return(TRUE);
943 when STICK: if (!ws_know[obj->o_which]) return(TRUE);
944 when SCROLL: if (!s_know[obj->o_which]) return(TRUE);
945 when MM: if (!m_know[obj->o_which]) return(TRUE);
946 }
947 when WIELDABLE:
948 switch (obj->o_type) {
949 case STICK:
950 case WEAPON:
951 return(TRUE);
952 when RELIC:
953 switch (obj->o_which) {
954 case MUSTY_DAGGER:
955 case HRUGGEK_MSTAR:
956 case YEENOGHU_FLAIL:
957 case AXE_AKLAD:
958 case MING_STAFF:
959 case ORCUS_WAND:
960 case ASMO_ROD:
961 return(TRUE);
962 }
963 }
964 when IDENTABLE:
965 if (!(obj->o_flags & ISKNOW) && obj->o_type != FOOD)
966 return (TRUE);
967 if (obj->o_type == MM) {
968 switch (obj->o_which) {
969 case MM_JUG:
970 /* Can still identify a jug if we don't know the potion */
971 if (obj->o_ac != JUG_EMPTY && !p_know[obj->o_ac])
972 return (TRUE);
973 }
974 }
975 when USEABLE:
976 if (obj->o_type == MM) {
977 switch(obj->o_which) {
978 case MM_BEAKER:
979 case MM_BOOK:
980 case MM_OPEN:
981 case MM_HUNGER:
982 case MM_DRUMS:
983 case MM_DISAPPEAR:
984 case MM_CHOKE:
985 case MM_KEOGHTOM:
986 return (TRUE);
987 }
988 }
989 else if (obj->o_type == RELIC) {
990 switch (obj->o_which) {
991 case EMORI_CLOAK:
992 case BRIAN_MANDOLIN:
993 case HEIL_ANKH:
994 case YENDOR_AMULET:
995 case STONEBONES_AMULET:
996 case GERYON_HORN:
997 case EYE_VECNA:
998 case QUILL_NAGROM:
999 case SURTUR_RING:
1000 return (TRUE);
1001 }
1002 }
1003 else if (obj->o_type == POTION) {
1004 /*
1005 * only assassins can use poison
1006 */
1007 if (player.t_ctype == C_ASSASIN && obj->o_which == P_POISON)
1008 return(TRUE);
1009 }
1010 when PROTECTABLE:
1011 switch (obj->o_type) {
1012 case WEAPON:
1013 if ((obj->o_flags & ISMETAL) == 0) return (FALSE);
1014
1015 /* Fall through */
1016 case ARMOR:
1017 return (TRUE);
1018
1019 when MM:
1020 if (obj->o_which == MM_BRACERS) return (TRUE);
1021 }
1022 }
1023 return(FALSE);
1024 }
1025
1026 del_pack(item)
1027 register struct linked_list *item;
1028 {
1029 register struct object *obj;
1030
1031 obj = OBJPTR(item);
1032 if (obj->o_count > 1) {
1033 obj->o_count--;
1034 }
1035 else {
1036 cur_null(obj);
1037 detach(pack, item);
1038 o_discard(item);
1039 inpack--;
1040 }
1041 }
1042
1043 /*
1044 * carry_obj:
1045 * Check to see if a monster is carrying something and, if so, give
1046 * it to him.
1047 */
1048
1049 carry_obj(mp, chance)
1050 register struct thing *mp;
1051 int chance;
1052 {
1053 reg struct linked_list *item;
1054 reg struct object *obj;
1055
1056 /*
1057 * If there is no chance, just return.
1058 * Note that this means there must be a "chance" in order for
1059 * the creature to carry a relic.
1060 */
1061 if (chance <= 0) return;
1062
1063 /*
1064 * check for the relic/artifacts
1065 * Do the relics first so they end up last in the pack. Attach()
1066 * always adds things to the beginning. This way they will be the
1067 * last things dropped when the creature is killed. This will ensure
1068 * the relic will be on top if there is a stack of item lying on the
1069 * floor and so the hero will know where it is if he's trying to
1070 * avoid it. Note that only UNIQUEs carry relics.
1071 */
1072 if (on(*mp, ISUNIQUE)) {
1073 if (on(*mp, CARRYMDAGGER)) {
1074 item = spec_item(RELIC, MUSTY_DAGGER, NULL, NULL);
1075 obj = OBJPTR(item);
1076 obj->o_pos = mp->t_pos;
1077 attach(mp->t_pack, item);
1078 }
1079
1080 if (on(*mp, CARRYCLOAK)) {
1081 item = spec_item(RELIC, EMORI_CLOAK, NULL, NULL);
1082 obj = OBJPTR(item);
1083 obj->o_pos = mp->t_pos;
1084 attach(mp->t_pack, item);
1085 }
1086
1087 if (on(*mp, CARRYANKH)) {
1088 item = spec_item(RELIC, HEIL_ANKH, NULL, NULL);
1089 obj = OBJPTR(item);
1090 obj->o_pos = mp->t_pos;
1091 attach(mp->t_pack, item);
1092 }
1093
1094 if (on(*mp, CARRYSTAFF)) {
1095 item = spec_item(RELIC, MING_STAFF, NULL, NULL);
1096 obj = OBJPTR(item);
1097 obj->o_pos = mp->t_pos;
1098 attach(mp->t_pack, item);
1099 }
1100
1101 if (on(*mp, CARRYWAND)) {
1102 item = spec_item(RELIC, ORCUS_WAND, NULL, NULL);
1103 obj = OBJPTR(item);
1104 obj->o_pos = mp->t_pos;
1105 attach(mp->t_pack, item);
1106 }
1107
1108 if (on(*mp, CARRYROD)) {
1109 item = spec_item(RELIC, ASMO_ROD, NULL, NULL);
1110 obj = OBJPTR(item);
1111 obj->o_pos = mp->t_pos;
1112 attach(mp->t_pack, item);
1113 }
1114
1115 if (on(*mp, CARRYYAMULET)) {
1116 item = spec_item(RELIC, YENDOR_AMULET, NULL, NULL);
1117 obj = OBJPTR(item);
1118 obj->o_pos = mp->t_pos;
1119 attach(mp->t_pack, item);
1120 }
1121
1122 if (on(*mp, CARRYBAMULET)) {
1123 item = spec_item(RELIC, STONEBONES_AMULET, NULL, NULL);
1124 obj = OBJPTR(item);
1125 obj->o_pos = mp->t_pos;
1126 attach(mp->t_pack, item);
1127 }
1128
1129 if (on(*mp, CARRYMANDOLIN)) {
1130 item = spec_item(RELIC, BRIAN_MANDOLIN, NULL, NULL);
1131 obj = OBJPTR(item);
1132 obj->o_pos = mp->t_pos;
1133 attach(mp->t_pack, item);
1134 }
1135 if (on(*mp, CARRYEYE)) {
1136 item = spec_item(RELIC, EYE_VECNA, NULL, NULL);
1137 obj = OBJPTR(item);
1138 obj->o_pos = mp->t_pos;
1139 attach(mp->t_pack, item);
1140 }
1141 if (on(*mp, CARRYAXE)) {
1142 item = spec_item(RELIC, AXE_AKLAD, NULL, NULL);
1143 obj = OBJPTR(item);
1144 obj->o_pos = mp->t_pos;
1145 attach(mp->t_pack, item);
1146 }
1147 if (on(*mp, CARRYQUILL)) {
1148 register int i, howmany;
1149
1150 item = spec_item(RELIC, QUILL_NAGROM, NULL, NULL);
1151 obj = OBJPTR(item);
1152 obj->o_pos = mp->t_pos;
1153 obj->o_charges = rnd(QUILLCHARGES);
1154 attach(mp->t_pack, item);
1155 howmany = roll(4,3);
1156 for (i=0; i<howmany; i++) {
1157 /*
1158 * the quill writes scrolls so give him a bunch
1159 */
1160 item = new_thing(TYP_SCROLL, FALSE);
1161 obj = OBJPTR(item);
1162 obj->o_pos = mp->t_pos;
1163 attach(mp->t_pack, item);
1164 }
1165 }
1166 if (on(*mp, CARRYMSTAR)) {
1167 item = spec_item(RELIC, HRUGGEK_MSTAR, NULL, NULL);
1168 obj = OBJPTR(item);
1169 obj->o_pos = mp->t_pos;
1170 attach(mp->t_pack, item);
1171 }
1172 if (on(*mp, CARRYFLAIL)) {
1173 item = spec_item(RELIC, YEENOGHU_FLAIL, NULL, NULL);
1174 obj = OBJPTR(item);
1175 obj->o_pos = mp->t_pos;
1176 attach(mp->t_pack, item);
1177 }
1178 if (on(*mp, CARRYHORN)) {
1179 item = spec_item(RELIC, GERYON_HORN, NULL, NULL);
1180 obj = OBJPTR(item);
1181 obj->o_pos = mp->t_pos;
1182 attach(mp->t_pack, item);
1183 }
1184 if (on(*mp, CARRYSURTURRING)) {
1185 item = spec_item(RELIC, SURTUR_RING, NULL, NULL);
1186 obj = OBJPTR(item);
1187 obj->o_pos = mp->t_pos;
1188 attach(mp->t_pack, item);
1189 }
1190 }
1191 /*
1192 * If it carries gold, give it some
1193 */
1194 if (on(*mp, CARRYGOLD) && rnd(100) < chance) {
1195 item = spec_item(GOLD, NULL, NULL, NULL);
1196 obj = OBJPTR(item);
1197 obj->o_count = GOLDCALC + GOLDCALC;
1198 obj->o_pos = mp->t_pos;
1199 attach(mp->t_pack, item);
1200 }
1201
1202 /*
1203 * If it carries food, give it some
1204 */
1205 if (on(*mp, CARRYFOOD) && rnd(100) < chance) {
1206 item = spec_item(FOOD, NULL, NULL, NULL);
1207 obj = OBJPTR(item);
1208 obj->o_weight = things[TYP_FOOD].mi_wght;
1209 obj->o_pos = mp->t_pos;
1210 attach(mp->t_pack, item);
1211 }
1212
1213 /*
1214 * If it carries a weapon, give it one
1215 */
1216 if (on(*mp, CARRYWEAPON) && rnd(100) < chance) {
1217 int type, hit, dam;
1218
1219 /* Get the "bonuses" */
1220 hit = rnd(5 + (vlevel / 5)) - 2;
1221 dam = rnd(5 + (vlevel / 5)) - 2;
1222
1223 /* Only choose an appropriate type of weapon */
1224 switch (rnd(12)) {
1225 case 0: type = DAGGER;
1226 when 1: type = BATTLEAXE;
1227 when 2: type = MACE;
1228 when 3: type = SWORD;
1229 when 4: type = PIKE;
1230 when 5: type = HALBERD;
1231 when 6: type = SPETUM;
1232 when 7: type = BARDICHE;
1233 when 8: type = TRIDENT;
1234 when 9: type = BASWORD;
1235 when 10:type = DART;
1236 otherwise: type = TWOSWORD;
1237 }
1238
1239 /* Create the item */
1240 item = spec_item(WEAPON, type, hit, dam);
1241 obj = OBJPTR(item);
1242 obj->o_pos = mp->t_pos;
1243 attach(mp->t_pack, item);
1244 }
1245
1246 /*
1247 * If it carries a dagger, give it one
1248 */
1249 if (on(*mp, CARRYDAGGER) && rnd(100) < chance) {
1250 int hit, dam;
1251
1252 /* Get the "bonuses" */
1253 hit = rnd(3 + (vlevel / 5)) - 1;
1254 dam = rnd(3 + (vlevel / 5)) - 1;
1255
1256 /* Create the item */
1257 item = spec_item(WEAPON, DAGGER, hit, dam);
1258 obj = OBJPTR(item);
1259 obj->o_pos = mp->t_pos;
1260 attach(mp->t_pack, item);
1261 }
1262
1263 /*
1264 * If it carries a scroll, give it one
1265 */
1266 if (on(*mp, CARRYSCROLL) && rnd(100) < chance) {
1267 item = new_thing(TYP_SCROLL, TRUE);
1268 obj = OBJPTR(item);
1269 obj->o_pos = mp->t_pos;
1270
1271 /* Can the monster carry this scroll? */
1272 if (obj->o_which == S_SCARE && mp->t_stats.s_intel < 16)
1273 fall(item, FALSE); /* This would scare us! */
1274 else attach(mp->t_pack, item);
1275 }
1276
1277 /*
1278 * If it carries a potion, give it one
1279 */
1280 if (on(*mp, CARRYPOTION) && rnd(100) < chance) {
1281 item = new_thing(TYP_POTION, TRUE);
1282 obj = OBJPTR(item);
1283 obj->o_pos = mp->t_pos;
1284 attach(mp->t_pack, item);
1285 }
1286
1287 /*
1288 * If it carries a ring, give it one
1289 */
1290 if (on(*mp, CARRYRING) && rnd(100) < chance) {
1291 item = new_thing(TYP_RING, TRUE);
1292 obj = OBJPTR(item);
1293 obj->o_pos = mp->t_pos;
1294 attach(mp->t_pack, item);
1295 }
1296
1297 /*
1298 * If it carries a wand or staff, give it one
1299 */
1300 if (on(*mp, CARRYSTICK) && rnd(100) < chance) {
1301 item = new_thing(TYP_STICK, TRUE);
1302 obj = OBJPTR(item);
1303 obj->o_pos = mp->t_pos;
1304 attach(mp->t_pack, item);
1305 }
1306
1307 /*
1308 * If it carries any miscellaneous magic, give it one
1309 */
1310 if (on(*mp, CARRYMISC) && rnd(100) < chance) {
1311 item = new_thing(TYP_MM, TRUE);
1312 obj = OBJPTR(item);
1313 obj->o_pos = mp->t_pos;
1314 attach(mp->t_pack, item);
1315 }
1316
1317 /* Update the monster's encumberance */
1318 updpack(TRUE, mp);
1319 }
1320
1321
1322 /*
1323 * grab():
1324 * See what is on the spot where the player is standing. If
1325 * nothing is there, do nothing. If there is one thing, pick it
1326 * up. If there are multiple things, prompt the player for what
1327 * he wants (* means everything).
1328 */
1329
1330 grab(y, x)
1331 register y, x;
1332 {
1333 register struct linked_list *next_item, *item;
1334 register struct object *obj;
1335 register int cnt, pagecnt;
1336 int num_there = 0, ch, och;
1337
1338 /*
1339 * Count how many objects there are and move them to the front
1340 * of the level list.
1341 */
1342 for (item = lvl_obj; item != NULL; item = next_item) {
1343 obj = OBJPTR(item);
1344 next_item = next(item);
1345 if (obj->o_pos.y == y && obj->o_pos.x == x) {
1346 num_there++;
1347 detach(lvl_obj, item); /* Remove it from the list */
1348 attach(lvl_obj, item); /* Place it at the front of the list */
1349 }
1350 }
1351
1352 /* Nothing there. */
1353 if (num_there < 1) msg("Nothing %s", terse ? "there." : "to pick up.");
1354
1355 /* Something or things there */
1356 else {
1357 char linebuf[2*LINELEN+1];
1358 int curlen, maxlen = 0;
1359
1360 wclear(hw);
1361 cnt = 0;
1362 pagecnt = 0;
1363 for (item = lvl_obj, ch = 'a'; item != NULL && cnt < num_there;
1364 item = next(item), ch++, cnt++) {
1365 obj = OBJPTR(item);
1366 /* Construct how the line will look */
1367 sprintf(linebuf, "%c) %s\n\r", ch, inv_name(obj,FALSE));
1368
1369 /* See how long it is */
1370 curlen = strlen(linebuf) - 2; /* Don't count \n or \r */
1371 if (maxlen < curlen) maxlen = curlen;
1372
1373 /* Draw it in the window */
1374 waddstr(hw, linebuf);
1375
1376 if (++pagecnt >= lines - 2 && next(item) != NULL) {
1377 pagecnt = 0;
1378 maxlen = 0;
1379 dbotline(hw, spacemsg);
1380 wclear(hw);
1381 }
1382 if (ch == 'z') ch = 'A' - 1;
1383 }
1384
1385 strcpy(linebuf, "Pick up what? (* for all): ");
1386
1387 /* See how long it is */
1388 curlen = strlen(linebuf); /* Don't count \n or \r */
1389 if (maxlen < curlen) maxlen = curlen;
1390
1391 /* Draw it in the window */
1392 waddstr(hw, linebuf);
1393
1394 /*
1395 * If we have fewer than half a screenful, don't clear the screen.
1396 * Leave an extra blank line at the bottom and 3 blank columns
1397 * to he right.
1398 */
1399 if (menu_overlay && num_there < lines / 2 + 2) {
1400 over_win(cw, hw, num_there + 2, maxlen + 3, num_there, curlen, NULL);
1401 pagecnt = -1; /* Indicate we used over_win */
1402 }
1403 else draw(hw); /* write screen */
1404
1405 for (;;) {
1406 do {
1407 ch = tolower(readchar());
1408 } until (isalpha(ch) || ch == '*' || ch == ESCAPE);
1409
1410 /* Redraw original screen */
1411 if (pagecnt < 0) {
1412 clearok(cw, FALSE); /* Setup to redraw current screen */
1413 touchwin(cw); /* clearing first */
1414 }
1415 else restscr(cw);
1416
1417 if (ch == ESCAPE) {
1418 after = FALSE;
1419 msg(""); /* clear top line */
1420 break;
1421 }
1422 if (ch == '*') {
1423 player.t_action = A_PICKUP;
1424 return(1); /* set action to PICKUP and delay for first one */
1425 }
1426 /* ch has item to get from list */
1427
1428 cnt = 0;
1429 for (item = lvl_obj, och = 'a'; item != NULL && cnt < num_there;
1430 item = next(item), och++, cnt++) {
1431 if (ch == och)
1432 break;
1433 if (och == 'z') och = 'A' - 1;
1434 }
1435 if (item == NULL || cnt >= num_there) {
1436 wmove(hw, pagecnt < 0 ? num_there : pagecnt, 25);
1437 wprintw(hw, " [between 'a' and '%c']: ",
1438 och == 'A' ? 'z' : och-1);
1439 if (maxlen < 49) maxlen = 49;
1440
1441 /*
1442 * If we have fewer than half a screenful, don't clear the
1443 * screen. Leave an extra blank line at the bottom and
1444 * 3 blank columns to he right.
1445 */
1446 if (menu_overlay && num_there < lines / 2 + 2) {
1447 over_win(cw, hw, num_there + 2, maxlen + 3,
1448 num_there, 49, NULL);
1449 cnt = -1; /* Indicate we used over_win */
1450 }
1451 else draw(hw); /* write screen */
1452 continue;
1453 }
1454 else {
1455 detach(lvl_obj, item);
1456 if (add_pack(item, FALSE, NULL)) {
1457 /*
1458 * We make sure here that the dungeon floor gets
1459 * updated with what's left on the vacated spot.
1460 */
1461 if ((item = find_obj(y, x)) == NULL) {
1462 coord roomcoord; /* Needed to pass to roomin() */
1463
1464 roomcoord.y = y;
1465 roomcoord.x = x;
1466 mvaddch(y, x,
1467 (roomin(&roomcoord) == NULL ? PASSAGE : FLOOR));
1468 }
1469 else mvaddch(y, x, (OBJPTR(item))->o_type);
1470 return(1);
1471 }
1472 else attach(lvl_obj, item); /* Couldn't pick it up! */
1473 break;
1474 }
1475 }
1476 }
1477
1478 return(0);
1479 }
1480
1481 /*
1482 * make_sell_pack:
1483 *
1484 * Create a pack for sellers (a la quartermaster)
1485 */
1486
1487 make_sell_pack(tp)
1488 struct thing *tp;
1489 {
1490 reg struct linked_list *item;
1491 reg struct object *obj;
1492 reg int sell_type, nitems, i;
1493
1494 /* Select the items */
1495 nitems = rnd(6) + 5;
1496
1497 switch (rnd(9)) {
1498 /* Armor */
1499 case 0:
1500 case 1:
1501 turn_on(*tp, CARRYARMOR);
1502 sell_type = TYP_ARMOR;
1503 break;
1504
1505 /* Weapon */
1506 case 2:
1507 case 3:
1508 turn_on(*tp, CARRYWEAPON);
1509 sell_type = TYP_WEAPON;
1510 break;
1511
1512 /* Staff or wand */
1513 case 4:
1514 turn_on(*tp, CARRYSTICK);
1515 sell_type = TYP_STICK;
1516 break;
1517
1518 /* Ring */
1519 case 5:
1520 turn_on(*tp, CARRYRING);
1521 sell_type = TYP_RING;
1522 break;
1523
1524 /* scroll */
1525 case 6:
1526 turn_on(*tp, CARRYSCROLL);
1527 sell_type = TYP_SCROLL;
1528 break;
1529
1530 /* potions */
1531 case 7:
1532 turn_on(*tp, CARRYPOTION);
1533 sell_type = TYP_POTION;
1534 break;
1535
1536 /* Miscellaneous magic */
1537 case 8:
1538 turn_on(*tp, CARRYMISC);
1539 sell_type = TYP_MM;
1540 break;
1541 }
1542 for (i=0; i<nitems; i++) {
1543 item = new_thing(sell_type, FALSE);
1544 obj = OBJPTR(item);
1545 obj->o_pos = tp->t_pos;
1546 attach(tp->t_pack, item);
1547 }
1548 }