2 * Routines to deal with the pack
4 * @(#)pack.c 3.6 (Berkeley) 6/15/81
6 * Rogue: Exploring the Dungeons of Doom
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * See the file LICENSE.TXT for full copyright and licensing information.
19 * Pick up an object and add it to the pack. If the argument is non-null
20 * use it as the linked_list pointer instead of gettting it off the ground.
22 add_pack(item
, silent
)
23 register struct linked_list
*item
;
26 register struct linked_list
*ip
, *lp
;
27 register struct object
*obj
, *op
;
28 register bool exact
, from_floor
;
33 if ((item
= find_obj(hero
.y
, hero
.x
)) == NULL
)
38 obj
= (struct object
*) ldata(item
);
40 * Link it into the pack. Search the pack for a object of similar type
41 * if there isn't one, stuff it at the beginning, if there is, look for one
42 * that is exactly the same and just increment the count if there is.
43 * it that. Food is always put at the beginning for ease of access, but
44 * is not ordered so that you can't tell good food from bad. First check
45 * to see if there is something in thr same group and if there is then
46 * increment the count.
50 for (ip
= pack
; ip
!= NULL
; ip
= next(ip
))
52 op
= (struct object
*) ldata(ip
);
53 if (op
->o_group
== obj
->o_group
)
56 * Put it in the pack and notify the user
61 detach(lvl_obj
, item
);
62 mvaddch(hero
.y
, hero
.x
,
63 (roomin(&hero
) == NULL
? PASSAGE
: FLOOR
));
72 * Check if there is room
74 if (inpack
== MAXPACK
-1)
76 msg("You can't carry anything else.");
80 * Check for and deal with scare monster scrolls
82 if (obj
->o_type
== SCROLL
&& obj
->o_which
== S_SCARE
)
83 if (obj
->o_flags
& ISFOUND
)
85 msg("The scroll turns to dust as you pick it up.");
86 detach(lvl_obj
, item
);
87 mvaddch(hero
.y
, hero
.x
, FLOOR
);
91 obj
->o_flags
|= ISFOUND
;
96 detach(lvl_obj
, item
);
97 mvaddch(hero
.y
, hero
.x
, (roomin(&hero
) == NULL
? PASSAGE
: FLOOR
));
100 * Search for an object of the same type
103 for (ip
= pack
; ip
!= NULL
; ip
= next(ip
))
105 op
= (struct object
*) ldata(ip
);
106 if (obj
->o_type
== op
->o_type
)
112 * Put it at the end of the pack since it is a new type
114 for (ip
= pack
; ip
!= NULL
; ip
= next(ip
))
116 op
= (struct object
*) ldata(ip
);
117 if (op
->o_type
!= FOOD
)
125 * Search for an object which is exactly the same
127 while (ip
!= NULL
&& op
->o_type
== obj
->o_type
)
129 if (op
->o_which
== obj
->o_which
)
135 if ((ip
= next(ip
)) == NULL
)
137 op
= (struct object
*) ldata(ip
);
143 * Didn't find an exact match, just stick it here
157 * If we found an exact match. If it is a potion, food, or a
158 * scroll, increase the count, otherwise put it with its clones.
160 if (exact
&& ISMULT(obj
->o_type
))
167 if ((item
->l_prev
= prev(ip
)) != NULL
)
168 item
->l_prev
->l_next
= item
;
178 obj
= (struct object
*) ldata(item
);
179 if (notify
&& !silent
)
182 addmsg("You now have ");
183 msg("%s (%c)", inv_name(obj
, !terse
), pack_char(obj
));
185 if (obj
->o_type
== AMULET
)
191 * list what is in the pack
193 inventory(list
, type
)
194 struct linked_list
*list
;
197 register struct object
*obj
;
203 for (ch
= 'a'; list
!= NULL
; ch
++, list
= next(list
))
205 obj
= (struct object
*) ldata(list
);
206 if (type
&& type
!= obj
->o_type
&& !(type
== CALLABLE
&&
207 (obj
->o_type
== SCROLL
|| obj
->o_type
== POTION
||
208 obj
->o_type
== RING
|| obj
->o_type
== STICK
)))
213 * For the first thing in the inventory, just save the string
214 * in case there is only one.
217 sprintf(inv_temp
, "%c) %s", ch
, inv_name(obj
, FALSE
));
220 * If there is more than one, clear the screen, print the
221 * saved message and fall through to ...
229 waddstr(hw
, inv_temp
);
233 * Print the line for this object
237 msg("%c) %s", ch
, inv_name(obj
, FALSE
));
239 wprintw(hw
, "%c) %s\n", ch
, inv_name(obj
, FALSE
));
245 msg(type
== 0 ? "Empty handed." :
246 "Nothing appropriate");
248 msg(type
== 0 ? "You are empty handed." :
249 "You don't have anything appropriate");
259 mvwaddstr(hw
, LINES
-1, 0, "--Press space to continue--");
270 * Add something to characters pack.
281 debug("Where did you pick that up???");
290 add_pack(NULL
, FALSE
);
297 * Allow player to inventory a single item
301 register struct linked_list
*item
;
302 register char ch
, mch
;
305 msg("You aren't carrying anything");
306 else if (next(pack
) == NULL
)
307 msg("a) %s", inv_name((struct object
*) ldata(pack
), FALSE
));
310 msg(terse
? "Item: " : "Which item do you wish to inventory: ");
312 if ((mch
= readchar(cw
)) == ESCAPE
)
317 for (ch
= 'a', item
= pack
; item
!= NULL
; item
= next(item
), ch
++)
320 msg("%c) %s",ch
,inv_name((struct object
*) ldata(item
), FALSE
));
324 msg("'%s' not in pack", unctrl(mch
));
325 msg("Range is 'a' to '%c'", --ch
);
331 * pick something out of a pack for a purpose
334 get_item(purpose
, type
)
338 register struct linked_list
*obj
;
339 register char ch
, och
;
342 msg("You aren't carrying anything.");
348 addmsg("Which object do you want to ");
352 msg("? (* for list): ");
356 * Give the poor player a chance to abort the command
358 if (ch
== ESCAPE
|| ch
== CTRL('G'))
367 if (inventory(pack
, type
) == 0)
374 for (obj
= pack
, och
= 'a'; obj
!= NULL
; obj
= next(obj
), och
++)
379 msg("Please specify a letter between 'a' and '%c'", och
-1);
390 register struct object
*obj
;
392 register struct linked_list
*item
;
396 for (item
= pack
; item
!= NULL
; item
= next(item
))
397 if ((struct object
*) ldata(item
) == obj
)