annotate srogue/pack.c @ 315:ad2570b5b21f

Advanced Rogue 5, 7: fix some trading post messages. When attempting to buy an unaffordable object, messages were often of the form "You can't afford that a scroll of hold monster !", because the object description (stored in curpurch) was the same text used in inventory displays. This has been worked around by inspecting the contents of curpurch and using different message templates.
author John "Elwin" Edwards
date Sun, 24 Oct 2021 20:26:21 -0400
parents 94a0d9dd5ce1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
1 /*
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
2 * Routines to deal with the pack
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
3 *
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
4 * @(#)pack.c 9.0 (rdk) 7/17/84
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
5 *
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
6 * Super-Rogue
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
7 * Copyright (C) 1984 Robert D. Kindelberger
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
8 * All rights reserved.
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
9 *
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
10 * Based on "Rogue: Exploring the Dungeons of Doom"
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
11 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
12 * All rights reserved.
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
13 *
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
14 * See the file LICENSE.TXT for full copyright and licensing information.
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
15 */
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
16
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
17 #include <ctype.h>
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
18 #include "rogue.h"
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
19 #include "rogue.ext"
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
20
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
21 /*
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
22 * add_pack:
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
23 * Pick up an object and add it to the pack. If the argument
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
24 * is non-null use it as the linked_list pointer instead of
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
25 * getting it off the ground.
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
26 */
217
94a0d9dd5ce1 Super-Rogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 183
diff changeset
27 bool
94a0d9dd5ce1 Super-Rogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents: 183
diff changeset
28 add_pack(struct linked_list *item, bool silent)
36
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
29 {
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
30 reg struct linked_list *ip, *lp;
183
7f5f5f1ba09c srogue: initialize some pointers.
John "Elwin" Edwards
parents: 36
diff changeset
31 reg struct object *obj, *op = NULL;
36
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
32 bool from_floor;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
33 char delchar;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
34
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
35 if (player.t_room == NULL)
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
36 delchar = PASSAGE;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
37 else
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
38 delchar = FLOOR;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
39 if (item == NULL) {
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
40 from_floor = TRUE;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
41 if ((item = find_obj(hero.y, hero.x)) == NULL) {
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
42 mpos = 0;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
43 msg("That object must have been an illusion.");
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
44 mvaddch(hero.y, hero.x, delchar);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
45 return FALSE;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
46 }
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
47 /*
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
48 * Check for scare monster scrolls
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
49 */
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
50 obj = OBJPTR(item);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
51 if (obj->o_type == SCROLL && obj->o_which == S_SCARE) {
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
52 if (o_on(obj,ISFOUND)) {
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
53 msg("The scroll turns to dust as you pick it up.");
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
54 detach(lvl_obj, item);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
55 discard(item);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
56 mvaddch(hero.y, hero.x, delchar);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
57 return FALSE;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
58 }
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
59 }
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
60 }
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
61 else
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
62 from_floor = FALSE;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
63 obj = OBJPTR(item);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
64 /*
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
65 * See if this guy can carry any more weight
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
66 */
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
67 if (itemweight(obj) + him->s_pack > him->s_carry) {
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
68 msg("You can't carry that %s.", obj->o_typname);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
69 return FALSE;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
70 }
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
71 /*
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
72 * Check if there is room
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
73 */
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
74 if (packvol + obj->o_vol > V_PACK) {
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
75 msg("That %s won't fit in your pack.", obj->o_typname);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
76 return FALSE;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
77 }
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
78 if (from_floor) {
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
79 detach(lvl_obj, item);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
80 mvaddch(hero.y, hero.x, delchar);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
81 }
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
82 item->l_prev = NULL;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
83 item->l_next = NULL;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
84 setoflg(obj, ISFOUND);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
85 /*
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
86 * start looking thru pack to find the start of items
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
87 * with the same type.
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
88 */
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
89 lp = pack;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
90 for (ip = pack; ip != NULL; ip = next(ip)) {
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
91 op = OBJPTR(ip);
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
92 /*
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
93 * If we find a matching type then quit.
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
94 */
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
95 if (op->o_type == obj->o_type)
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
96 break;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
97 if (next(ip) != NULL)
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
98 lp = next(lp); /* update "previous" entry */
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
99 }
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
100 /*
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
101 * If the pack was empty, just stick the item in it.
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
102 */
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
103 if (pack == NULL) {
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
104 pack = item;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
105 item->l_prev = NULL;
2128c7dc8a40 Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents: