-
Notifications
You must be signed in to change notification settings - Fork 0
/
PACK.C
407 lines (389 loc) · 8.85 KB
/
PACK.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#include "rogue.h"
#include "curses.h"
/*
* Routines to deal with the pack
*
* pack.c 1.4 (A.I. Design) 12/14/84
*/
THING *
pack_obj(ch, chp)
byte ch, *chp;
{
register THING *obj;
register byte och;
for (obj = pack, och = 'a'; obj != NULL; obj = next(obj), och++)
if (ch == och)
return obj;
*chp = och;
return NULL;
}
/*
* add_pack:
* Pick up an object and add it to the pack. If the argument is
* non-null use it as the linked_list pointer instead of gettting
* it off the ground.
*/
add_pack(obj, silent)
register THING *obj;
bool silent;
{
register THING *op, *lp;
register bool exact, from_floor;
register byte floor;
if (obj == NULL)
{
from_floor = TRUE;
if ((obj = find_obj(hero.y, hero.x)) == NULL)
return;
}
else
from_floor = FALSE;
/*
* Link it into the pack. Search the pack for a object of similar type
* if there isn't one, stuff it at the beginning, if there is, look for one
* that is exactly the same and just increment the count if there is.
* Food is always put at the beginning for ease of access, but it
* is not ordered so that you can't tell good food from bad. First check
* to see if there is something in the same group and if there is then
* increment the count.
*/
floor = (proom->r_flags & ISGONE) ? PASSAGE : FLOOR;
if (obj->o_group)
{
for (op = pack; op != NULL; op = next(op))
{
if (op->o_group == obj->o_group)
{
/*
* Put it in the pack and notify the user
*/
op->o_count += obj->o_count;
if (from_floor)
{
detach(lvl_obj, obj);
mvaddch(hero.y, hero.x, floor);
chat(hero.y, hero.x) = floor;
}
discard(obj);
obj = op;
goto picked_up;
}
}
}
/*
* Check if there is room
*/
if (inpack >= MAXPACK-1)
{
msg("you can't carry anything else");
return;
}
/*
* Check for and deal with scare monster scrolls
*/
if (obj->o_type == SCROLL && obj->o_which == S_SCARE)
if (obj->o_flags & ISFOUND)
{
detach(lvl_obj, obj);
mvaddch(hero.y, hero.x, floor);
chat(hero.y, hero.x) = floor;
msg("the scroll turns to dust%s.", noterse(" as you pick it up"));
return;
}
else
obj->o_flags |= ISFOUND;
inpack++;
if (from_floor)
{
detach(lvl_obj, obj);
mvaddch(hero.y, hero.x, floor);
chat(hero.y, hero.x) = floor;
}
/*
* Search for an object of the same type
*/
exact = FALSE;
for (op = pack; op != NULL; op = next(op))
if (obj->o_type == op->o_type)
break;
if (op == NULL)
{
/*
* Put it at the end of the pack since it is a new type
*/
for (op = pack; op != NULL; op = next(op))
{
if (op->o_type != FOOD)
break;
lp = op;
}
}
else
{
/*
* Search for an object which is exactly the same
*/
while (op->o_type == obj->o_type)
{
if (op->o_which == obj->o_which)
{
exact = TRUE;
break;
}
lp = op;
if ((op = next(op)) == NULL)
break;
}
}
if (op == NULL)
{
/*
* Didn't find an exact match, just stick it here
*/
if (pack == NULL)
pack = obj;
else
{
lp->l_next = obj;
obj->l_prev = lp;
obj->l_next = NULL;
}
}
else
{
/*
* If we found an exact match. If it is a potion, food, or a
* scroll, increase the count, otherwise put it with its clones.
*/
if (exact && ISMULT(obj->o_type))
{
op->o_count++;
discard(obj);
obj = op;
goto picked_up;
}
if ((obj->l_prev = prev(op)) != NULL)
obj->l_prev->l_next = obj;
else
pack = obj;
obj->l_next = op;
op->l_prev = obj;
}
picked_up:
/*
* If this was the object of something's desire, that monster will
* get mad and run at the hero
*/
for (op = mlist; op != NULL; op = next(op))
/*
* compiler bug: jll : 2-7-83
* It is stupid because it thinks the obj... is not an lvalue
* this may be true since there is no structure assignments,
* but still it should let you have the address??!!
*
if (&obj->_o._o_pos == op->t_dest)
*
* the following should do the same
*/
if ((op->t_dest->x == obj->o_pos.x) && (op->t_dest->y == obj->o_pos.y))
op->t_dest = &hero;
if (obj->o_type == AMULET)
{
amulet = TRUE;
saw_amulet = TRUE;
}
/*
* Notify the user
*/
if (!silent)
msg("%s%s (%c)",noterse("you now have "),
inv_name(obj, TRUE), pack_char(obj));
}
/*
* inventory:
* List what is in the pack
*/
inventory(list, type, lstr)
THING *list;
int type;
char *lstr;
{
register byte ch;
register int n_objs;
char inv_temp[MAXSTR];
n_objs = 0;
for (ch = 'a'; list != NULL; ch++, list = next(list))
{
/*
* Don't print this one if:
* the type doesn't match the type we were passed AND
* it isn't a callable type AND
* it isn't a zappable weapon
*/
if (type && type != list->o_type && !(type == CALLABLE &&
(list->o_type == SCROLL || list->o_type == POTION ||
list->o_type == RING || list->o_type == STICK)) &&
!(type == WEAPON && list->o_type == POTION) &&
!(type == STICK && list->o_enemy && list->o_charges))
continue;
n_objs++;
sprintf(inv_temp, "%c) %%s", ch);
add_line(lstr, inv_temp, inv_name(list, FALSE));
}
if (n_objs == 0)
{
msg(type == 0 ? "you are empty handed" :
"you don't have anything appropriate");
return FALSE;
}
return(end_line(lstr));
}
/*
* pick_up:
* Add something to characters pack.
*/
pick_up(ch)
byte ch;
{
register THING *obj;
switch (ch)
{
case GOLD:
if ((obj = find_obj(hero.y, hero.x)) == NULL)
return;
money(obj->o_goldval);
detach(lvl_obj, obj);
discard(obj);
proom->r_goldval = 0;
break;
default:
case ARMOR:
case POTION:
case FOOD:
case WEAPON:
case SCROLL:
case AMULET:
case RING:
case STICK:
add_pack(NULL, FALSE);
break;
}
}
/*
* get_item:
* Pick something out of a pack for a purpose
*/
THING *
get_item(purpose, type)
char *purpose;
int type;
{
register THING *obj;
register byte ch;
byte och;
static byte lch;
static THING *wasthing = NULL;
byte gi_state; /* get item sub state */
int once_only = FALSE;
if (((!strncmp(s_menu,"sel",3) && strcmp(purpose,"eat")
&& strcmp(purpose,"drop"))) || !strcmp(s_menu,"on"))
once_only = TRUE;
gi_state = again;
if (pack == NULL)
msg("you aren't carrying anything");
else {
ch = lch;
for (;;) {
/*
* if we are doing something AGAIN, and the pack hasn't
* changed then don't ask just give him the same thing
* he got on the last command.
*/
if (gi_state && wasthing == pack_obj(ch, &och))
goto skip;
if (once_only) {
ch = '*';
goto skip;
}
if (!terse && !expert)
addmsg("which object do you want to ");
msg("%s? (* for list): ",purpose);
/*
* ignore any alt characters that may be typed
*/
ch = readchar();
skip:
mpos = 0;
gi_state = FALSE;
once_only = FALSE;
if (ch == '*') {
if ((ch = inventory(pack, type, purpose)) == 0) {
after = FALSE;
return NULL;
}
if (ch == ' ')
continue;
lch = ch;
}
/*
* Give the poor player a chance to abort the command
*/
if (ch == ESCAPE) {
after = FALSE;
msg("");
return NULL;
}
if ((obj = pack_obj(ch, &och)) == NULL) {
ifterse1("range is 'a' to '%c'","please specify a letter between 'a' and '%c'", och-1);
continue;
} else {
/*
* If you find an object reset flag because
* you really don't know if the object he is getting
* is going to change the pack. If he detaches the
* thing from the pack later this flag will get set.
*/
if (strcmp(purpose, "identify")) {
lch = ch;
wasthing = obj;
}
return obj;
}
}
}
return NULL;
}
/*
* pack_char:
* Return which character would address a pack object
*/
pack_char(obj)
register THING *obj;
{
register THING *item;
register byte c;
c = 'a';
for (item = pack; item != NULL; item = next(item))
if (item == obj)
return c;
else
c++;
return '?';
}
/*
* money:
* Add or subtract gold from the pack
*/
money(value)
register int value;
{
register byte floor;
floor = (proom->r_flags & ISGONE) ? PASSAGE : FLOOR;
purse += value;
mvaddch(hero.y, hero.x, floor);
chat(hero.y, hero.x) = floor;
if (value > 0)
{
msg("you found %d gold pieces", value);
}
}