-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc.c
474 lines (447 loc) · 8.85 KB
/
misc.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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/*
* All sorts of miscellaneous routines
*
* @(#)misc.c 4.30 (Berkeley) 4/6/82
*
* Rogue: Exploring the Dungeons of Doom
* Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman
* All rights reserved.
*
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include <curses.h>
#include <ctype.h>
#include <string.h>
#include "rogue.h"
/*
* tr_name:
* Print the name of a trap
*/
char *
tr_name(type)
char type;
{
switch (type)
{
case T_DOOR:
return terse ? "a trapdoor" : "you found a trapdoor";
case T_BEAR:
return terse ? "a beartrap" : "you found a beartrap";
case T_SLEEP:
return terse ? "a sleeping gas trap":"you found a sleeping gas trap";
case T_ARROW:
return terse ? "an arrow trap" : "you found an arrow trap";
case T_TELEP:
return terse ? "a teleport trap" : "you found a teleport trap";
case T_DART:
return terse ? "a dart trap" : "you found a poison dart trap";
}
msg("wierd trap: %d", type);
return NULL;
}
/*
* look:
* A quick glance all around the player
*/
look(wakeup)
bool wakeup;
{
register int x, y;
register unsigned char ch;
register int index;
register THING *tp;
register struct room *rp;
register int ey, ex;
register int passcount = 0;
register char pfl, *fp, pch;
register int sy, sx, sumhero = 0, diffhero = 0;
register int oldx, oldy;
getyx(stdscr, oldy, oldx);
rp = proom;
if (!ce(oldpos, hero))
{
if ((oldrp->r_flags & (ISGONE|ISDARK)) == ISDARK && !on(player,ISBLIND))
{
ey = oldpos.y + 1;
ex = oldpos.x + 1;
sy = oldpos.y - 1;
for (x = oldpos.x - 1; x <= ex; x++)
for (y = sy; y <= ey; y++)
{
if (y == hero.y && x == hero.x)
continue;
move(y, x);
if (inch() == FLOOR)
addch(' ');
}
}
oldpos = hero;
oldrp = rp;
}
ey = hero.y + 1;
ex = hero.x + 1;
sx = hero.x - 1;
sy = hero.y - 1;
if (door_stop && !firstmove && running)
{
sumhero = hero.y + hero.x;
diffhero = hero.y - hero.x;
}
index = INDEX(hero.y, hero.x);
pfl = _flags[index];
pch = _level[index];
for (y = sy; y <= ey; y++)
if (y > 0 && y < LINES - 1) for (x = sx; x <= ex; x++)
{
if (x <= 0 || x >= COLS)
continue;
if (!on(player, ISBLIND))
{
if (y == hero.y && x == hero.x)
continue;
}
else if (y != hero.y || x != hero.x)
continue;
index = INDEX(y, x);
/*
* THIS REPLICATES THE moat() MACRO. IF MOAT IS CHANGED,
* THIS MUST BE CHANGED ALSO
*/
fp = &_flags[index];
ch = _level[index];
if (pch != DOOR && ch != DOOR)
if ((pfl & F_PASS) != (*fp & F_PASS))
continue;
else if ((*fp & F_PASS) && (*fp & F_PNUM) != (pfl & F_PNUM))
continue;
if ((tp = _monst[index]) != NULL)
if (on(player, SEEMONST) && on(*tp, ISINVIS))
{
if (door_stop && !firstmove)
running = FALSE;
continue;
}
else
{
if (wakeup)
wake_monster(y, x);
if (tp->t_oldch != ' ' ||
(!(rp->r_flags & ISDARK) && !on(player, ISBLIND)))
tp->t_oldch = _level[index];
if (see_monst(tp))
ch = tp->t_disguise;
}
move(y, x);
if (ch != inch())
addch(ch);
if (door_stop && !firstmove && running)
{
switch (runch)
{
case 'h':
if (x == ex)
continue;
when 'j':
if (y == sy)
continue;
when 'k':
if (y == ey)
continue;
when 'l':
if (x == sx)
continue;
when 'y':
if ((y + x) - sumhero >= 1)
continue;
when 'u':
if ((y - x) - diffhero >= 1)
continue;
when 'n':
if ((y + x) - sumhero <= -1)
continue;
when 'b':
if ((y - x) - diffhero <= -1)
continue;
}
switch (ch)
{
case DOOR:
if (x == hero.x || y == hero.y)
running = FALSE;
break;
case PASSAGE:
if (x == hero.x || y == hero.y)
passcount++;
break;
case FLOOR:
case '|':
case '-':
case ' ':
break;
default:
running = FALSE;
break;
}
}
}
if (door_stop && !firstmove && passcount > 1)
running = FALSE;
move(hero.y, hero.x);
addch(PLAYER);
}
/*
* find_obj:
* Find the unclaimed object at y, x
*/
THING *
find_obj(y, x)
register int y, x;
{
register THING *op;
for (op = lvl_obj; op != NULL; op = next(op))
{
if (op->o_pos.y == y && op->o_pos.x == x)
return op;
}
#ifdef WIZARD
sprintf(prbuf, "Non-object %d,%d", y, x);
debug(prbuf);
#endif
return NULL;
}
/*
* eat:
* She wants to eat something, so let her try
*/
eat()
{
register THING *obj;
if ((obj = get_item("eat", FOOD)) == NULL)
return;
if (obj->o_type != FOOD)
{
if (!terse)
msg("ugh, you would get ill if you ate that");
else
msg("that's Inedible!");
return;
}
inpack--;
if (food_left < 0)
food_left = 0;
if ((food_left += HUNGERTIME - 200 + rnd(400)) > STOMACHSIZE)
food_left = STOMACHSIZE;
hungry_state = 0;
if (obj == cur_weapon)
cur_weapon = NULL;
if (obj->o_which == 1)
msg("my, that was a yummy %s", fruit);
else
if (rnd(100) > 70)
{
pstats.s_exp++;
msg("yuk, this food tastes awful");
check_level();
}
else
msg("yum, that tasted good");
if (--obj->o_count < 1)
{
detach(pack, obj);
discard(obj);
}
}
/*
* chg_str:
* Used to modify the playes strength. It keeps track of the
* highest it has been, just in case
*/
chg_str(amt)
register int amt;
{
str_t comp;
if (amt == 0)
return;
add_str(&pstats.s_str, amt);
comp = pstats.s_str;
if (ISRING(LEFT, R_ADDSTR))
add_str(&comp, -cur_ring[LEFT]->o_ac);
if (ISRING(RIGHT, R_ADDSTR))
add_str(&comp, -cur_ring[RIGHT]->o_ac);
if (comp > max_stats.s_str)
max_stats.s_str = comp;
}
/*
* add_str:
* Perform the actual add, checking upper and lower bound limits
*/
add_str(sp, amt)
register str_t *sp;
int amt;
{
if ((*sp += amt) < 3)
*sp = 3;
else if (*sp > 31)
*sp = 31;
}
/*
* add_haste:
* Add a haste to the player
*/
add_haste(potion)
bool potion;
{
if (on(player, ISHASTE))
{
no_command += rnd(8);
player.t_flags &= ~ISRUN;
extinguish(nohaste);
player.t_flags &= ~ISHASTE;
msg("you faint from exhaustion");
return FALSE;
}
else
{
player.t_flags |= ISHASTE;
if (potion)
fuse(nohaste, 0, rnd(4)+4, AFTER);
return TRUE;
}
}
/*
* aggravate:
* Aggravate all the monsters on this level
*/
aggravate()
{
register THING *mi;
for (mi = mlist; mi != NULL; mi = next(mi))
runto(&mi->t_pos, &hero);
}
/*
* vowelstr:
* For printfs: if string starts with a vowel, return "n" for an
* "an".
*/
char *
vowelstr(str)
register char *str;
{
switch (*str)
{
case 'a': case 'A':
case 'e': case 'E':
case 'i': case 'I':
case 'o': case 'O':
case 'u': case 'U':
return "n";
default:
return "";
}
}
/*
* is_current:
* See if the object is one of the currently used items
*/
is_current(obj)
register THING *obj;
{
if (obj == NULL)
return FALSE;
if (obj == cur_armor || obj == cur_weapon || obj == cur_ring[LEFT]
|| obj == cur_ring[RIGHT])
{
if (!terse)
addmsg("That's already ");
msg("in use");
return TRUE;
}
return FALSE;
}
/*
* get_dir:
* Set up the direction co_ordinate for use in varios "prefix"
* commands
*/
get_dir()
{
register char *prompt;
register bool gotit;
if (!terse)
msg(prompt = "which direction? ");
else
prompt = "direction: ";
do
{
gotit = TRUE;
switch (readchar())
{
case 'h': case'H': delta.y = 0; delta.x = -1;
when 'j': case'J': delta.y = 1; delta.x = 0;
when 'k': case'K': delta.y = -1; delta.x = 0;
when 'l': case'L': delta.y = 0; delta.x = 1;
when 'y': case'Y': delta.y = -1; delta.x = -1;
when 'u': case'U': delta.y = -1; delta.x = 1;
when 'b': case'B': delta.y = 1; delta.x = -1;
when 'n': case'N': delta.y = 1; delta.x = 1;
when ESCAPE: return FALSE;
otherwise:
mpos = 0;
msg(prompt);
gotit = FALSE;
}
} until (gotit);
if (on(player, ISHUH) && rnd(5) == 0)
do
{
delta.y = rnd(3) - 1;
delta.x = rnd(3) - 1;
} while (delta.y == 0 && delta.x == 0);
mpos = 0;
return TRUE;
}
/*
* sign:
* Return the sign of the number
*/
sign(nm)
register int nm;
{
if (nm < 0)
return -1;
else
return (nm > 0);
}
/*
* spread:
* Give a spread around a given number (+/- 10%)
*/
spread(nm)
register int nm;
{
return nm - nm / 10 + rnd(nm / 5);
}
/*
* call_it:
* Call an object something after use.
*/
call_it(know, guess)
register bool know;
register char **guess;
{
if (know && *guess)
{
free(*guess);
*guess = NULL;
}
else if (!know && askme && *guess == NULL)
{
msg(terse ? "call it: " : "what do you want to call it? ");
if (get_str(prbuf, stdscr) == NORM)
{
*guess = malloc((unsigned int) strlen(prbuf) + 1);
strcpy(*guess, prbuf);
}
}
}