comparison arogue5/pack.c @ 63:0ed67132cf10

Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 09 Aug 2012 22:58:48 +0000
parents
children 56e748983fa8
comparison
equal deleted inserted replaced
62:0ef99244acb8 63:0ed67132cf10
1 /*
2 * Routines to deal with the pack
3 *
4 * Advanced Rogue
5 * Copyright (C) 1984, 1985 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
19 char outstring[512]; /* ridiculously long string for use with msg */
20
21 /*
22 * add_pack:
23 * Pick up an object and add it to the pack. If the argument is non-null
24 * use it as the linked_list pointer instead of gettting it off the ground.
25 */
26 bool
27 add_pack(item, silent, packret)
28 register struct linked_list *item, **packret;
29 bool silent;
30 {
31 register struct linked_list *ip, *lp = NULL, *ap;
32 register struct object *obj, *op = NULL;
33 register bool exact, from_floor;
34
35 if (packret != NULL)
36 *packret = NULL;
37
38 if (item == NULL)
39 {
40 from_floor = TRUE;
41 if ((item = find_obj(hero.y, hero.x)) == NULL)
42 return(FALSE);
43 }
44 else
45 from_floor = FALSE;
46 obj = OBJPTR(item);
47 /*
48 * If it is gold, just add its value to rogue's purse and get rid
49 * of it.
50 */
51 if (obj->o_type == GOLD) {
52 register struct linked_list *mitem;
53 register struct thing *tp;
54
55 if (!silent) {
56 if (!terse) addmsg("You found ");
57 msg("%d gold pieces.", obj->o_count);
58 }
59
60 /* First make sure no greedy monster is after this gold.
61 * If so, make the monster run after the rogue instead.
62 */
63 for (mitem = mlist; mitem != NULL; mitem = next(mitem)) {
64 tp = THINGPTR(mitem);
65 if (tp->t_dest == &obj->o_pos) tp->t_dest = &hero;
66 }
67
68 purse += obj->o_count;
69 if (from_floor) {
70 detach(lvl_obj, item);
71 if ((ap = find_obj(hero.y, hero.x)) == NULL)
72 mvaddch(hero.y,hero.x,(roomin(&hero)==NULL ? PASSAGE : FLOOR));
73 else
74 mvaddch(hero.y,hero.x,(OBJPTR(ap))->o_type);
75 }
76 o_discard(item);
77 return(TRUE);
78 }
79
80 /*
81 * see if he can carry any more weight
82 */
83 if (itemweight(obj) + pstats.s_pack > pstats.s_carry) {
84 msg("Too much for you to carry.");
85 return FALSE;
86 }
87 /*
88 * Link it into the pack. Search the pack for a object of similar type
89 * if there isn't one, stuff it at the beginning, if there is, look for one
90 * that is exactly the same and just increment the count if there is.
91 * it that. Food is always put at the beginning for ease of access, but
92 * is not ordered so that you can't tell good food from bad. First check
93 * to see if there is something in thr same group and if there is then
94 * increment the count.
95 */
96 if (obj->o_group)
97 {
98 for (ip = pack; ip != NULL; ip = next(ip))
99 {
100 op = OBJPTR(ip);
101 if (op->o_group == obj->o_group)
102 {
103 /*
104 * Put it in the pack and notify the user
105 */
106 op->o_count += obj->o_count;
107 if (from_floor)
108 {
109 detach(lvl_obj, item);
110 if ((ap = find_obj(hero.y, hero.x)) == NULL)
111 mvaddch(hero.y,hero.x,
112 (roomin(&hero)==NULL ? PASSAGE : FLOOR));
113 else
114 mvaddch(hero.y,hero.x,(OBJPTR(ap))->o_type);
115 }
116 o_discard(item);
117 item = ip;
118 goto picked_up;
119 }
120 }
121 }
122
123 /*
124 * Check for and deal with scare monster scrolls
125 */
126 if (obj->o_type == SCROLL && obj->o_which == S_SCARE)
127 if (obj->o_flags & ISCURSED)
128 {
129 msg("The scroll turns to dust as you pick it up.");
130 detach(lvl_obj, item);
131 if ((ap = find_obj(hero.y, hero.x)) == NULL)
132 mvaddch(hero.y,hero.x,(roomin(&hero)==NULL ? PASSAGE : FLOOR));
133 else
134 mvaddch(hero.y,hero.x,(OBJPTR(ap))->o_type);
135 return(TRUE);
136 }
137
138 /*
139 * Search for an object of the same type
140 */
141 exact = FALSE;
142 for (ip = pack; ip != NULL; ip = next(ip))
143 {
144 op = OBJPTR(ip);
145 if (obj->o_type == op->o_type)
146 break;
147 }
148 if (ip == NULL)
149 {
150 /*
151 * Put it at the end of the pack since it is a new type
152 */
153 for (ip = pack; ip != NULL; ip = next(ip))
154 {
155 op = OBJPTR(ip);
156 if (op->o_type != FOOD)
157 break;
158 lp = ip;
159 }
160 }
161 else
162 {
163 /*
164 * Search for an object which is exactly the same
165 */
166 while (ip != NULL && op->o_type == obj->o_type)
167 {
168 if (op->o_which == obj->o_which)
169 {
170 exact = TRUE;
171 break;
172 }
173 lp = ip;
174 if ((ip = next(ip)) == NULL)
175 break;
176 op = OBJPTR(ip);
177 }
178 }
179 /*
180 * Check if there is room
181 */
182 if (ip == NULL || !exact || !ISMULT(obj->o_type)) {
183 if (inpack == MAXPACK-1) {
184 msg(terse ? "No room." : "You can't carry anything else.");
185 return(FALSE);
186 }
187 }
188 inpack++;
189 if (from_floor)
190 {
191 detach(lvl_obj, item);
192 if ((ap = find_obj(hero.y, hero.x)) == NULL)
193 mvaddch(hero.y,hero.x,(roomin(&hero)==NULL ? PASSAGE : FLOOR));
194 else
195 mvaddch(hero.y,hero.x,(OBJPTR(ap))->o_type);
196 }
197 if (ip == NULL)
198 {
199 /*
200 * Didn't find an exact match, just stick it here
201 */
202 if (pack == NULL)
203 pack = item;
204 else
205 {
206 lp->l_next = item;
207 item->l_prev = lp;
208 item->l_next = NULL;
209 }
210 }
211 else
212 {
213 /*
214 * If we found an exact match. If it is food,
215 * increase the count, otherwise put it with its clones.
216 */
217 if (exact && ISMULT(obj->o_type))
218 {
219 op->o_count += obj->o_count;
220 inpack--; /* adjust for previous addition */
221 o_discard(item);
222 item = ip;
223 goto picked_up;
224 }
225 if ((item->l_prev = prev(ip)) != NULL)
226 item->l_prev->l_next = item;
227 else
228 pack = item;
229 item->l_next = ip;
230 ip->l_prev = item;
231 }
232 picked_up:
233 /*
234 * Notify the user
235 */
236 obj = OBJPTR(item);
237 if (!silent)
238 {
239 if (!terse)
240 addmsg("You now have ");
241 sprintf(outstring,"%s (%c)", inv_name(obj, !terse), pack_char(pack, obj));
242 msg(outstring);
243 }
244
245 /* Relics can do strange things when you pick them up */
246 if (obj->o_type == RELIC) {
247 cur_relic[obj->o_which]++; /* Note that we have it */
248 switch (obj->o_which) {
249 case HEIL_ANKH:
250 msg("The ankh welds itself into your hand.");
251
252 /* A cloak must be worn. */
253 when EMORI_CLOAK:
254 if (cur_armor != NULL || cur_misc[WEAR_CLOAK]) {
255 msg("The cloak insists you remove your current garments.");
256 if (!dropcheck(cur_armor != NULL ? cur_armor
257 : cur_misc[WEAR_CLOAK])) {
258 pstats.s_hpt = -1;
259 msg("The cloak constricts around you.");
260 msg("It draws your life force from you!!! -- More --");
261 wait_for(cw,' ');
262 death(D_RELIC);
263 }
264 }
265
266 /* The amulet must be worn. */
267 when YENDOR_AMULET:
268 if (cur_misc[WEAR_JEWEL]) {
269 msg("You have an urge to remove your current amulet.");
270 if (!dropcheck(cur_misc[WEAR_JEWEL])) {
271 pstats.s_hpt = -1;
272 msg("The Amulet of Yendor begins pulsing.");
273 msg("It fades away.... -- More --");
274 wait_for(cw,' ');
275 death(D_RELIC);
276 }
277 }
278 msg("The amulet welds itself into your chest.");
279
280 /* Weapons will insist on being wielded. */
281 when MUSTY_DAGGER:
282 case HRUGGEK_MSTAR:
283 case YEENOGHU_FLAIL:
284 if (cur_weapon != NULL) {
285 msg("The artifact insists you release your current weapon.");
286 if (!dropcheck(cur_weapon)) {
287 pstats.s_hpt = -1;
288 msg("The artifact forces your weapon into your heart.");
289 msg("It hums with satisfaction. -- More --");
290 wait_for(cw,' ');
291 death(D_RELIC);
292 }
293 }
294 cur_weapon = obj;
295 }
296 }
297
298 updpack(FALSE);
299 if (packret != NULL)
300 *packret = item;
301 return(TRUE);
302 }
303
304 /*
305 * inventory:
306 * list what is in the pack
307 */
308 inventory(list, type)
309 register struct linked_list *list;
310 register int type;
311 {
312 register struct object *obj;
313 register char ch;
314 register int n_objs;
315 register int cnt;
316 char inv_temp[LINELEN];
317
318 cnt = 0;
319 n_objs = 0;
320 for (ch = 'a'; list != NULL; ch++, list = next(list)) {
321 obj = OBJPTR(list);
322 if (!is_type(obj, type))
323 continue;
324 switch (n_objs++) {
325 /*
326 * For the first thing in the inventory, just save the string
327 * in case there is only one.
328 */
329 case 0:
330 sprintf(inv_temp, "%c) %s", ch, inv_name(obj, FALSE));
331 break;
332 /*
333 * If there is more than one, clear the screen, print the
334 * saved message and fall through to ...
335 */
336 case 1:
337 if (slow_invent)
338 msg(inv_temp);
339 else
340 {
341 wclear(hw);
342 waddstr(hw, inv_temp);
343 waddch(hw, '\n');
344 }
345 /*
346 * Print the line for this object
347 */
348 default:
349 if (ch > 'z')
350 ch = 'A';
351 if (slow_invent){
352 sprintf(outstring,"%c) %s", ch, inv_name(obj, FALSE));
353 msg(outstring);
354 }
355 else {
356 if (++cnt >= LINES - 2) { /* if bottom of screen */
357 dbotline(hw, morestr);
358 cnt = 0;
359 wclear(hw);
360 }
361 wprintw(hw, "%c) %s\n", ch, inv_name(obj, FALSE));
362 }
363 }
364 }
365 if (n_objs == 0) {
366 if (terse)
367 msg(type == 0 ? "Empty handed." :
368 "Nothing appropriate");
369 else
370 msg(type == 0 ? "You are empty handed." :
371 "You don't have anything appropriate");
372 return FALSE;
373 }
374 if (n_objs == 1) {
375 msg(inv_temp);
376 return TRUE;
377 }
378 if (!slow_invent)
379 {
380 mvwaddstr(hw, LINES-1, 0, spacemsg);
381 draw(hw);
382 wait_for(hw,' ');
383 clearok(cw, TRUE);
384 touchwin(cw);
385 }
386 return TRUE;
387 }
388
389 /*
390 * pick_up:
391 * Add something to characters pack.
392 */
393 pick_up(ch)
394 char ch;
395 {
396 switch (ch) {
397 default:
398 debug("Where did you pick that up???");
399 case GOLD:
400 case ARMOR:
401 case POTION:
402 case FOOD:
403 case WEAPON:
404 case SCROLL:
405 case MM:
406 case RING:
407 case STICK:
408 case RELIC:
409 while (add_pack(NULL, FALSE, NULL)); /* pick up everything there */
410 break;
411 }
412 }
413
414 /*
415 * picky_inven:
416 * Allow player to inventory a single item
417 */
418 void
419 picky_inven()
420 {
421 register struct linked_list *item;
422 register char ch, mch;
423
424 if (pack == NULL)
425 msg("You aren't carrying anything");
426 else if (next(pack) == NULL)
427 msg("a) %s", inv_name(OBJPTR(pack), FALSE));
428 else
429 {
430 msg(terse ? "Item: " : "Which item do you wish to inventory: ");
431 mpos = 0;
432 if ((mch = readchar()) == ESCAPE)
433 {
434 msg("");
435 return;
436 }
437
438 /* Check for a special character */
439 switch (mch) {
440 case FOOD:
441 case SCROLL:
442 case POTION:
443 case RING:
444 case STICK:
445 case RELIC:
446 case ARMOR:
447 case WEAPON:
448 case MM:
449 msg("");
450 if (get_item(pack, NULL, mch) == NULL) {
451 if (terse) msg("None in pack.");
452 else msg("You have no %c in your pack.", mch);
453 }
454 return;
455 }
456
457 for (ch = 'a', item = pack; item != NULL; item = next(item), ch++)
458 if (ch == mch)
459 {
460 sprintf(outstring, "%c) %s",ch ,inv_name(OBJPTR(item), FALSE));
461 msg(outstring);
462 return;
463 }
464 if (!terse)
465 msg("'%s' not in pack.", unctrl(mch));
466 msg("Range is 'a' to '%c'", --ch);
467 }
468 }
469
470
471 /*
472 * get_item:
473 * pick something out of a pack for a purpose
474 */
475 struct linked_list *
476 get_item(list, purpose, type)
477 reg struct linked_list *list;
478 char *purpose; /* NULL if we should be silent (no prompts) */
479 int type;
480 {
481 reg struct linked_list *item;
482 reg struct object *obj;
483 reg int cnt, ch, och;
484 struct linked_list *saveitem = NULL;
485
486 cnt = 0;
487 if (list == NULL) {
488 msg("You aren't carrying anything.");
489 return NULL;
490 }
491 /* see if we have any of the type requested */
492 for(ch = 'a',item = list ; item != NULL ; item = next(item), ch++) {
493 obj = OBJPTR(item);
494 if (is_type(obj, type)) {
495 cnt++;
496 saveitem = item;
497 }
498 }
499 if (cnt == 0) {
500 if (purpose) msg("Nothing to %s",purpose);
501 after = FALSE;
502 return NULL;
503 }
504 else if (cnt == 1) { /* only found one of 'em */
505 obj = OBJPTR(saveitem);
506 for(;;) {
507 if (purpose) { /* Should we prompt the player? */
508 msg("%s what (* for the item)? ",purpose);
509 ch = tolower(readchar());
510 }
511 else {
512 sprintf(outstring, "%c) %s", pack_char(list, obj), inv_name(obj,FALSE));
513 msg(outstring);
514 }
515
516 if (ch == '*') {
517 mpos = 0;
518 sprintf(outstring, "%c) %s", pack_char(list, obj), inv_name(obj,FALSE));
519 msg(outstring);
520 continue;
521 }
522 if (ch == ESCAPE) {
523 msg("");
524 after = FALSE;
525 return NULL;
526 }
527 for(item = list,och = 'a'; item != NULL; item = next(item),och++) {
528 if (ch == och) break;
529 if (och == 'z') och = 'A' - 1;
530 }
531 if (item == NULL) {
532 msg("Please specify a letter between 'a' and '%c'",
533 och == 'A' ? 'z' : och-1);
534 continue;
535 }
536 if (is_type (OBJPTR(item), type)) {
537 if (purpose) mpos = 0;
538 return item;
539 }
540 else
541 msg ("You can't %s that!", purpose);
542
543 }
544 }
545 for(;;) {
546 if (purpose) {
547 msg("%s what? (* for list): ",purpose);
548 ch = readchar();
549 }
550 else ch = '*';
551
552 mpos = 0;
553 if (ch == ESCAPE) { /* abort if escape hit */
554 after = FALSE;
555 msg(""); /* clear display */
556 return NULL;
557 }
558 if (ch == '*') {
559 wclear(hw);
560 cnt = 0;
561 for(item = list,ch = 'a'; item != NULL ; item = next(item), ch++) {
562 obj = OBJPTR(item);
563 if (!is_type(OBJPTR(item), type))
564 continue;
565 wprintw(hw,"%c) %s\n\r",ch,inv_name(obj,FALSE));
566 if (++cnt >= LINES - 2 && next(item) != NULL) {
567 cnt = 0;
568 dbotline(hw, spacemsg);
569 wclear(hw);
570 }
571 if (ch == 'z') ch = 'A' - 1;
572 }
573 wmove(hw, LINES - 1,0);
574 if (purpose) wprintw(hw,"%s what? ",purpose);
575 else waddstr(hw, spacemsg);
576
577 draw(hw); /* write screen */
578
579 if (purpose) {
580 do {
581 ch = tolower(wgetch(hw));
582 } until (isalpha(ch) || ch == ESCAPE);
583 }
584 else {
585 ch = pack_char(list, OBJPTR(saveitem)); /* Pick a valid item */
586 wait_for(hw,' ');
587 }
588
589 restscr(cw); /* redraw orig screen */
590 if(ch == ESCAPE) {
591 after = FALSE;
592 msg(""); /* clear top line */
593 return NULL; /* all done if abort */
594 }
595 /* ch has item to get from list */
596 }
597 for(item = list,och = 'a'; item != NULL; item = next(item),och++) {
598 if (ch == och) break;
599 if (och == 'z') och = 'A' - 1;
600 }
601 if (item == NULL) {
602 msg("Please specify a letter between 'a' and '%c'",
603 och == 'A' ? 'z' : och-1);
604 continue;
605 }
606 if (is_type(OBJPTR(item), type))
607 return (item);
608 else
609 msg ("You can't %s that!", purpose);
610 }
611 }
612
613 pack_char(list, obj)
614 register struct object *obj;
615 struct linked_list *list;
616 {
617 register struct linked_list *item;
618 register char c;
619
620 c = 'a';
621 for (item = list; item != NULL; item = next(item)) {
622 if (OBJPTR(item) == obj)
623 return c;
624 else {
625 if (c == 'z') c = 'A';
626 else c++;
627 }
628 }
629 return 'z';
630 }
631
632
633 /*
634 * cur_null:
635 * This updates cur_weapon etc for dropping things
636 */
637 cur_null(op)
638 reg struct object *op;
639 {
640 if (op == cur_weapon) cur_weapon = NULL;
641 else if (op == cur_armor) cur_armor = NULL;
642 else if (op == cur_ring[LEFT_1]) cur_ring[LEFT_1] = NULL;
643 else if (op == cur_ring[LEFT_2]) cur_ring[LEFT_2] = NULL;
644 else if (op == cur_ring[LEFT_3]) cur_ring[LEFT_3] = NULL;
645 else if (op == cur_ring[LEFT_4]) cur_ring[LEFT_4] = NULL;
646 else if (op == cur_ring[RIGHT_1]) cur_ring[RIGHT_1] = NULL;
647 else if (op == cur_ring[RIGHT_2]) cur_ring[RIGHT_2] = NULL;
648 else if (op == cur_ring[RIGHT_3]) cur_ring[RIGHT_3] = NULL;
649 else if (op == cur_ring[RIGHT_4]) cur_ring[RIGHT_4] = NULL;
650 else if (op == cur_misc[WEAR_BOOTS]) cur_misc[WEAR_BOOTS] = NULL;
651 else if (op == cur_misc[WEAR_JEWEL]) cur_misc[WEAR_JEWEL] = NULL;
652 else if (op == cur_misc[WEAR_GAUNTLET]) cur_misc[WEAR_GAUNTLET] = NULL;
653 else if (op == cur_misc[WEAR_CLOAK]) cur_misc[WEAR_CLOAK] = NULL;
654 else if (op == cur_misc[WEAR_BRACERS]) cur_misc[WEAR_BRACERS] = NULL;
655 else if (op == cur_misc[WEAR_NECKLACE]) cur_misc[WEAR_NECKLACE] = NULL;
656 }
657
658 /*
659 * idenpack:
660 * Identify all the items in the pack
661 */
662 idenpack()
663 {
664 reg struct linked_list *pc;
665
666 for (pc = pack ; pc != NULL ; pc = next(pc))
667 whatis(pc);
668 }
669
670 is_type (obj, type)
671 register struct object *obj;
672 register int type;
673 {
674 register bool current;
675
676 if (type == obj->o_type)
677 return (TRUE);
678
679 switch (type) {
680 case ALL:
681 return (TRUE);
682 when ZAPPABLE:
683 if (obj->o_type == STICK) return (TRUE);
684 if (obj->o_type == RELIC)
685 switch (obj->o_which) {
686 case MING_STAFF:
687 case ASMO_ROD:
688 case ORCUS_WAND:
689 return (TRUE);
690 }
691 when WEARABLE:
692 case REMOVABLE:
693 current = is_current(obj);
694
695 /*
696 * Don't wear thing we are already wearing or remove things
697 * we aren't wearing.
698 */
699 if (type == WEARABLE && current) return (FALSE);
700 else if (type == REMOVABLE && !current) return (FALSE);
701
702 switch (obj->o_type) {
703 case RELIC:
704 switch (obj->o_which) {
705 case HEIL_ANKH:
706 case EMORI_CLOAK:
707 return (TRUE);
708 }
709 when MM:
710 switch (obj->o_which) {
711 case MM_ELF_BOOTS:
712 case MM_DANCE:
713 case MM_BRACERS:
714 case MM_DISP:
715 case MM_PROTECT:
716 case MM_G_DEXTERITY:
717 case MM_G_OGRE:
718 case MM_JEWEL:
719 case MM_R_POWERLESS:
720 case MM_FUMBLE:
721 case MM_STRANGLE:
722 case MM_ADAPTION:
723 return (TRUE);
724 }
725 when ARMOR:
726 case RING:
727 return (TRUE);
728 }
729 when CALLABLE:
730 switch (obj->o_type) {
731 case RING:
732 case POTION:
733 case STICK:
734 case SCROLL:
735 case MM:
736 return(TRUE);
737 }
738 when WIELDABLE:
739 switch (obj->o_type) {
740 case STICK:
741 case WEAPON:
742 return(TRUE);
743 when RELIC:
744 switch (obj->o_which) {
745 case MUSTY_DAGGER:
746 case HRUGGEK_MSTAR:
747 case YEENOGHU_FLAIL:
748 case MING_STAFF:
749 case ORCUS_WAND:
750 case ASMO_ROD:
751 return(TRUE);
752 }
753 }
754 when IDENTABLE:
755 if (!(obj->o_flags & ISKNOW) && obj->o_type != FOOD)
756 return (TRUE);
757 if (obj->o_type == MM) {
758 switch (obj->o_which) {
759 case MM_JUG:
760 /* Can still identify a jug if we don't know the potion */
761 if (obj->o_ac != JUG_EMPTY && !p_know[obj->o_ac])
762 return (TRUE);
763 }
764 }
765 when USEABLE:
766 if (obj->o_type == MM) {
767 switch(obj->o_which) {
768 case MM_JUG:
769 case MM_BEAKER:
770 case MM_BOOK:
771 case MM_SKILLS:
772 case MM_OPEN:
773 case MM_HUNGER:
774 case MM_DRUMS:
775 case MM_DISAPPEAR:
776 case MM_CHOKE:
777 case MM_KEOGHTOM:
778 return (TRUE);
779 }
780 }
781 else if (obj->o_type == RELIC) {
782 switch (obj->o_which) {
783 case EMORI_CLOAK:
784 case BRIAN_MANDOLIN:
785 case HEIL_ANKH:
786 case YENDOR_AMULET:
787 case GERYON_HORN:
788 return (TRUE);
789 }
790 }
791 when PROTECTABLE:
792 switch (obj->o_type) {
793 case WEAPON:
794 if ((obj->o_flags & ISMETAL) == 0) return (FALSE);
795
796 /* Fall through */
797 case ARMOR:
798 return (TRUE);
799
800 when MM:
801 if (obj->o_which == MM_BRACERS) return (TRUE);
802 }
803 }
804 return(FALSE);
805 }
806
807 del_pack(item)
808 register struct linked_list *item;
809 {
810 register struct object *obj;
811
812 obj = OBJPTR(item);
813 if (obj->o_count > 1) {
814 obj->o_count--;
815 }
816 else {
817 cur_null(obj);
818 detach(pack, item);
819 o_discard(item);
820 inpack--;
821 }
822 }
823
824 /*
825 * carry_obj:
826 * Check to see if a monster is carrying something and, if so, give
827 * it to him.
828 */
829
830 carry_obj(mp, chance)
831 register struct thing *mp;
832 int chance;
833 {
834 reg struct linked_list *item;
835 reg struct object *obj;
836
837 /*
838 * If there is no chance, just return.
839 * Note that this means there must be a "chance" in order for
840 * the creature to carry a relic.
841 */
842 if (chance <= 0) return;
843
844 /*
845 * check for the relic/artifacts
846 * Do the relics first so they end up last in the pack. Attach()
847 * always adds things to the beginning. This way they will be the
848 * last things dropped when the creature is killed. This will ensure
849 * the relic will be on top if there is a stack of item lying on the
850 * floor and so the hero will know where it is if he's trying to
851 * avoid it
852 */
853 if (on(*mp, CARRYDAGGER)) {
854 item = spec_item(RELIC, MUSTY_DAGGER, NULL, NULL);
855 obj = OBJPTR(item);
856 obj->o_pos = mp->t_pos;
857 attach(mp->t_pack, item);
858 }
859
860 if (on(*mp, CARRYCLOAK)) {
861 item = spec_item(RELIC, EMORI_CLOAK, NULL, NULL);
862 obj = OBJPTR(item);
863 obj->o_pos = mp->t_pos;
864 attach(mp->t_pack, item);
865 }
866
867 if (on(*mp, CARRYANKH)) {
868 item = spec_item(RELIC, HEIL_ANKH, NULL, NULL);
869 obj = OBJPTR(item);
870 obj->o_pos = mp->t_pos;
871 attach(mp->t_pack, item);
872 }
873
874 if (on(*mp, CARRYSTAFF)) {
875 item = spec_item(RELIC, MING_STAFF, NULL, NULL);
876 obj = OBJPTR(item);
877 obj->o_pos = mp->t_pos;
878 attach(mp->t_pack, item);
879 }
880
881 if (on(*mp, CARRYWAND)) {
882 item = spec_item(RELIC, ORCUS_WAND, NULL, NULL);
883 obj = OBJPTR(item);
884 obj->o_pos = mp->t_pos;
885 attach(mp->t_pack, item);
886 }
887
888 if (on(*mp, CARRYROD)) {
889 item = spec_item(RELIC, ASMO_ROD, NULL, NULL);
890 obj = OBJPTR(item);
891 obj->o_pos = mp->t_pos;
892 attach(mp->t_pack, item);
893 }
894
895 if (on(*mp, CARRYAMULET)) {
896 item = spec_item(RELIC, YENDOR_AMULET, NULL, NULL);
897 obj = OBJPTR(item);
898 obj->o_pos = mp->t_pos;
899 attach(mp->t_pack, item);
900 }
901
902 if (on(*mp, CARRYMANDOLIN)) {
903 item = spec_item(RELIC, BRIAN_MANDOLIN, NULL, NULL);
904 obj = OBJPTR(item);
905 obj->o_pos = mp->t_pos;
906 attach(mp->t_pack, item);
907 }
908 if (on(*mp, CARRYMSTAR)) {
909 item = spec_item(RELIC, HRUGGEK_MSTAR, NULL, NULL);
910 obj = OBJPTR(item);
911 obj->o_pos = mp->t_pos;
912 attach(mp->t_pack, item);
913 }
914 if (on(*mp, CARRYFLAIL)) {
915 item = spec_item(RELIC, YEENOGHU_FLAIL, NULL, NULL);
916 obj = OBJPTR(item);
917 obj->o_pos = mp->t_pos;
918 attach(mp->t_pack, item);
919 }
920 if (on(*mp, CARRYHORN)) {
921 item = spec_item(RELIC, GERYON_HORN, NULL, NULL);
922 obj = OBJPTR(item);
923 obj->o_pos = mp->t_pos;
924 attach(mp->t_pack, item);
925 }
926 /*
927 * If it carries gold, give it some
928 */
929 if (on(*mp, CARRYGOLD) && rnd(100) < chance) {
930 item = spec_item(GOLD, NULL, NULL, NULL);
931 obj = OBJPTR(item);
932 obj->o_count = GOLDCALC + GOLDCALC;
933 obj->o_pos = mp->t_pos;
934 attach(mp->t_pack, item);
935 }
936
937 /*
938 * If it carries food, give it some
939 */
940 if (on(*mp, CARRYFOOD) && rnd(100) < chance) {
941 item = spec_item(FOOD, NULL, NULL, NULL);
942 obj = OBJPTR(item);
943 obj->o_weight = things[TYP_FOOD].mi_wght;
944 obj->o_pos = mp->t_pos;
945 attach(mp->t_pack, item);
946 }
947
948 /*
949 * If it carries a weapon, give it one
950 */
951 if (on(*mp, CARRYWEAPON) && rnd(100) < chance) {
952 int type, hit, dam;
953
954 /* Get the "bonuses" */
955 hit = rnd(5) - 2;
956 dam = rnd(5) - 2;
957
958 /* Only choose an appropriate type of weapon */
959 switch (rnd(11)) {
960 case 0: type = DAGGER;
961 when 1: type = BATTLEAXE;
962 when 2: type = MACE;
963 when 3: type = SWORD;
964 when 4: type = PIKE;
965 when 5: type = HALBERD;
966 when 6: type = SPETUM;
967 when 7: type = BARDICHE;
968 when 8: type = TRIDENT;
969 when 9: type = BASWORD;
970 otherwise: type = TWOSWORD;
971 }
972
973 /* Create the item */
974 item = spec_item(WEAPON, type, hit, dam);
975 obj = OBJPTR(item);
976 obj->o_pos = mp->t_pos;
977 attach(mp->t_pack, item);
978 }
979
980 /*
981 * If it carries a scroll, give it one
982 */
983 if (on(*mp, CARRYSCROLL) && rnd(100) < chance) {
984 item = new_thing(TYP_SCROLL);
985 obj = OBJPTR(item);
986 obj->o_pos = mp->t_pos;
987
988 /* Can the monster carry this scroll? */
989 if (obj->o_which == S_SCARE && mp->t_stats.s_intel < 16)
990 fall(item, FALSE); /* This would scare us! */
991 else attach(mp->t_pack, item);
992 }
993
994 /*
995 * If it carries a potion, give it one
996 */
997 if (on(*mp, CARRYPOTION) && rnd(100) < chance) {
998 item = new_thing(TYP_POTION);
999 obj = OBJPTR(item);
1000 obj->o_pos = mp->t_pos;
1001 attach(mp->t_pack, item);
1002 }
1003
1004 /*
1005 * If it carries a ring, give it one
1006 */
1007 if (on(*mp, CARRYRING) && rnd(100) < chance) {
1008 item = new_thing(TYP_RING);
1009 obj = OBJPTR(item);
1010 obj->o_pos = mp->t_pos;
1011 attach(mp->t_pack, item);
1012 }
1013
1014 /*
1015 * If it carries a wand or staff, give it one
1016 */
1017 if (on(*mp, CARRYSTICK) && rnd(100) < chance) {
1018 item = new_thing(TYP_STICK);
1019 obj = OBJPTR(item);
1020 obj->o_pos = mp->t_pos;
1021 attach(mp->t_pack, item);
1022 }
1023
1024 /*
1025 * If it carries any miscellaneous magic, give it one
1026 */
1027 if (on(*mp, CARRYMISC) && rnd(100) < chance) {
1028 item = new_thing(TYP_MM);
1029 obj = OBJPTR(item);
1030 obj->o_pos = mp->t_pos;
1031 attach(mp->t_pack, item);
1032 }
1033 }
1034
1035
1036 /*
1037 * grab():
1038 * See what is on the spot where the player is standing. If
1039 * nothing is there, do nothing. If there is one thing, pick it
1040 * up. If there are multiple things, prompt the player for what
1041 * he wants (* means everything).
1042 */
1043
1044 grab(y, x)
1045 register y, x;
1046 {
1047 register struct linked_list *next_item, *item;
1048 register struct object *obj;
1049 register int cnt;
1050 int num_there = 0, ch, och;
1051
1052 /*
1053 * Count how many objects there are and move them to the front
1054 * of the level list.
1055 */
1056 for (item = lvl_obj; item != NULL; item = next_item) {
1057 obj = OBJPTR(item);
1058 next_item = next(item);
1059 if (obj->o_pos.y == y && obj->o_pos.x == x) {
1060 num_there++;
1061 detach(lvl_obj, item); /* Remove it from the list */
1062 attach(lvl_obj, item); /* Place it at the front of the list */
1063 }
1064 }
1065
1066 /* Nothing there. */
1067 if (num_there < 1) msg("Nothing %s", terse ? "there." : "to pick up.");
1068
1069 /* One thing there */
1070 else if (num_there == 1) {
1071 add_pack(FALSE, FALSE, NULL);
1072 return(1);
1073 }
1074
1075 /* Multiple things there */
1076 else {
1077 wclear(hw);
1078 cnt = 0;
1079 for (item = lvl_obj, ch = 'a'; item != NULL && cnt < num_there;
1080 item = next(item), ch++) {
1081 obj = OBJPTR(item);
1082 wprintw(hw,"%c) %s\n\r", ch, inv_name(obj,FALSE));
1083 if (++cnt >= LINES - 2 && next(item) != NULL) {
1084 cnt = 0;
1085 dbotline(hw, spacemsg);
1086 wclear(hw);
1087 }
1088 if (ch == 'z') ch = 'A' - 1;
1089 }
1090 wmove(hw, LINES - 1,0);
1091 wprintw(hw, "Pick up what? (* for all): ");
1092 draw(hw); /* write screen */
1093
1094 for (;;) {
1095 do {
1096 ch = tolower(wgetch(hw));
1097 } until (isalpha(ch) || ch == '*' || ch == ESCAPE);
1098 restscr(cw); /* redraw orig screen */
1099 if (ch == ESCAPE) {
1100 after = FALSE;
1101 msg(""); /* clear top line */
1102 break;
1103 }
1104 if (ch == '*') {
1105 while (add_pack(NULL, TRUE, NULL)); /* pick up everything there */
1106 return(num_there);
1107 }
1108 /* ch has item to get from list */
1109
1110 cnt = 0;
1111 for (item = lvl_obj, och = 'a'; item != NULL && cnt < num_there;
1112 item = next(item), och++, cnt++) {
1113 if (ch == och)
1114 break;
1115 if (och == 'z') och = 'A' - 1;
1116 }
1117 if (item == NULL || cnt >= num_there) {
1118 wmove(hw, LINES - 1, 25);
1119 wprintw(hw, " [between 'a' and '%c']:%c ",
1120 och == 'A' ? 'z' : och-1, '\007');
1121 draw(hw); /* write screen */
1122 continue;
1123 }
1124 else {
1125 detach(lvl_obj, item);
1126 if (add_pack(item, FALSE, NULL)) {
1127 /*
1128 * There should always be at least one item left since we
1129 * handle the one item case up above. But it never hurts
1130 * to make sure we don't have a NULL pointer.
1131 */
1132 if ((item = find_obj(hero.y, hero.x)) == NULL)
1133 mvaddch(y, x, (OBJPTR(item))->o_type);
1134 return(1);
1135 }
1136 else attach(lvl_obj, item); /* Couldn't pick it up! */
1137 break;
1138 }
1139 }
1140 }
1141
1142 return(0);
1143 }