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)