-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc.c
431 lines (402 loc) · 8.58 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
/*
* all sorts of miscellaneous routines
*
* @(#)misc.c 3.13 (Berkeley) 6/15/81
*
* Rogue: Exploring the Dungeons of Doom
* Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
* All rights reserved.
*
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include "curses.h"
#include "rogue.h"
#include <ctype.h>
/*
* tr_name:
* print the name of a trap
*/
char *
tr_name(int ch)
{
char *s = "";
switch (ch)
{
case TRAPDOOR:
s = terse ? "A trapdoor." : "You found a trapdoor.";
when BEARTRAP:
s = terse ? "A beartrap." : "You found a beartrap.";
when SLEEPTRAP:
s = terse ? "A sleeping gas trap.":"You found a sleeping gas trap.";
when ARROWTRAP:
s = terse ? "An arrow trap." : "You found an arrow trap.";
when TELTRAP:
s = terse ? "A teleport trap." : "You found a teleport trap.";
when DARTTRAP:
s = terse ? "A dart trap." : "You found a poison dart trap.";
}
return s;
}
/*
* Look:
* A quick glance all around the player
*/
void
look(int wakeup)
{
int x, y;
int ch;
int oldx, oldy;
int inpass;
int passcount = 0;
struct room *rp;
int ey, ex;
getyx(cw, oldy, oldx);
if (oldrp != NULL && (oldrp->r_flags & ISDARK) && off(player, ISBLIND))
{
for (x = oldpos.x - 1; x <= oldpos.x + 1; x++)
for (y = oldpos.y - 1; y <= oldpos.y + 1; y++)
if ((y != hero.y || x != hero.x) && show(y, x) == FLOOR)
mvwaddch(cw, y, x, ' ');
}
inpass = ((rp = roomin(&hero)) == NULL);
ey = hero.y + 1;
ex = hero.x + 1;
for (x = hero.x - 1; x <= ex; x++)
if (x >= 0 && x < COLS) for (y = hero.y - 1; y <= ey; y++)
{
if (y <= 0 || y >= LINES - 1)
continue;
if (isupper(mvwinch(mw, y, x)))
{
struct linked_list *it;
struct thing *tp;
if (wakeup)
it = wake_monster(y, x);
else
it = find_mons(y, x);
tp = (struct thing *) ldata(it);
if ((tp->t_oldch = mvinch(y, x)) == TRAP)
tp->t_oldch =
(trap_at(y,x)->tr_flags&ISFOUND) ? TRAP : FLOOR;
if (tp->t_oldch == FLOOR && (rp != NULL) && (rp->r_flags & ISDARK)
&& off(player, ISBLIND))
tp->t_oldch = ' ';
}
/*
* Secret doors show as walls
*/
if ((ch = show(y, x)) == SECRETDOOR)
ch = secretdoor(y, x);
/*
* Don't show room walls if he is in a passage
*/
if (off(player, ISBLIND))
{
if (y == hero.y && x == hero.x
|| (inpass && (ch == '-' || ch == '|')))
continue;
}
else if (y != hero.y || x != hero.x)
continue;
wmove(cw, y, x);
waddch(cw, ch);
if (door_stop && !firstmove && running)
{
switch (runch)
{
case 'h':
if (x == ex)
continue;
when 'j':
if (y == hero.y - 1)
continue;
when 'k':
if (y == ey)
continue;
when 'l':
if (x == hero.x - 1)
continue;
when 'y':
if ((x + y) - (hero.x + hero.y) >= 1)
continue;
when 'u':
if ((y - x) - (hero.y - hero.x) >= 1)
continue;
when 'n':
if ((x + y) - (hero.x + hero.y) <= -1)
continue;
when 'b':
if ((y - x) - (hero.y - hero.x) <= -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;
mvwaddch(cw, hero.y, hero.x, PLAYER);
wmove(cw, oldy, oldx);
oldpos = hero;
oldrp = rp;
}
/*
* secret_door:
* Figure out what a secret door looks like.
*/
int
secretdoor(int y, int x)
{
int i;
struct room *rp;
coord *cpp;
static coord cp;
cp.y = y;
cp.x = x;
cpp = &cp;
for (rp = rooms, i = 0; i < MAXROOMS; rp++, i++)
if (inroom(rp, cpp))
if (y == rp->r_pos.y || y == rp->r_pos.y + rp->r_max.y - 1)
return('-');
else
return('|');
return('p');
}
/*
* find_obj:
* find the unclaimed object at y, x
*/
struct linked_list *
find_obj(int y, int x)
{
struct linked_list *obj;
struct object *op;
for (obj = lvl_obj; obj != NULL; obj = next(obj))
{
op = (struct object *) ldata(obj);
if (op->o_pos.y == y && op->o_pos.x == x)
return obj;
}
sprintf(prbuf, "Non-object %d,%d", y, x);
debug(prbuf);
return NULL;
}
/*
* eat:
* She wants to eat something, so let her try
*/
void
eat()
{
struct linked_list *item;
struct object *obj;
if ((item = get_item("eat", FOOD)) == NULL)
return;
obj = (struct object *) ldata(item);
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 (obj->o_which == 1)
msg("My, that was a yummy %s", fruit);
else
if (rnd(100) > 70)
{
msg("Yuk, this food tastes awful");
pstats.s_exp++;
check_level();
}
else
msg("Yum, that tasted good");
if ((food_left += HUNGERTIME + rnd(400) - 200) > STOMACHSIZE)
food_left = STOMACHSIZE;
hungry_state = 0;
if (obj == cur_weapon)
cur_weapon = NULL;
if (--obj->o_count < 1)
{
detach(pack, item);
discard(item);
}
}
/*
* Used to modify the playes strength
* it keeps track of the highest it has been, just in case
*/
void
chg_str(int amt)
{
if (amt == 0)
return;
if (amt > 0)
{
while (amt--)
{
if (pstats.s_str.st_str < 18)
pstats.s_str.st_str++;
else if (pstats.s_str.st_add == 0)
pstats.s_str.st_add = rnd(50) + 1;
else if (pstats.s_str.st_add <= 50)
pstats.s_str.st_add = 51 + rnd(24);
else if (pstats.s_str.st_add <= 75)
pstats.s_str.st_add = 76 + rnd(14);
else if (pstats.s_str.st_add <= 90)
pstats.s_str.st_add = 91;
else if (pstats.s_str.st_add < 100)
pstats.s_str.st_add++;
}
if (pstats.s_str.st_str > max_stats.s_str.st_str ||
(pstats.s_str.st_str == 18 &&
pstats.s_str.st_add > max_stats.s_str.st_add))
max_stats.s_str = pstats.s_str;
}
else
{
while (amt++)
{
if (pstats.s_str.st_str < 18 || pstats.s_str.st_add == 0)
pstats.s_str.st_str--;
else if (pstats.s_str.st_add < 51)
pstats.s_str.st_add = 0;
else if (pstats.s_str.st_add < 76)
pstats.s_str.st_add = 1 + rnd(50);
else if (pstats.s_str.st_add < 91)
pstats.s_str.st_add = 51 + rnd(25);
else if (pstats.s_str.st_add < 100)
pstats.s_str.st_add = 76 + rnd(14);
else
pstats.s_str.st_add = 91 + rnd(8);
}
if (pstats.s_str.st_str < 3)
pstats.s_str.st_str = 3;
}
}
/*
* add_haste:
* add a haste to the player
*/
void
add_haste(int potion)
{
if (on(player, ISHASTE))
{
msg("You faint from exhaustion.");
no_command += rnd(8);
extinguish(nohaste);
}
else
{
player.t_flags |= ISHASTE;
if (potion)
fuse(nohaste, 0, rnd(4)+4, AFTER);
}
}
/*
* aggravate:
* aggravate all the monsters on this level
*/
void
aggravate()
{
struct linked_list *mi;
for (mi = mlist; mi != NULL; mi = next(mi))
runto(&((struct thing *) ldata(mi))->t_pos, &hero);
}
/*
* for printfs: if string starts with a vowel, return "n" for an "an"
*/
char *
vowelstr(char *str)
{
switch (*str)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return "n";
default:
return "";
}
}
/*
* see if the object is one of the currently used items
*/
int
is_current(struct object *obj)
{
if (obj == NULL)
return FALSE;
if (obj == cur_armor || obj == cur_weapon || obj == cur_ring[LEFT]
|| obj == cur_ring[RIGHT])
{
msg(terse ? "In use." : "That's already in use.");
return TRUE;
}
return FALSE;
}
/*
* set up the direction co_ordinate for use in varios "prefix" commands
*/
int
get_dir()
{
char *prompt;
int gotit;
if (!terse)
msg(prompt = "Which direction? ");
else
prompt = "Direction: ";
do
{
gotit = TRUE;
switch (readchar(cw))
{
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(100) > 80)
do
{
delta.y = rnd(3) - 1;
delta.x = rnd(3) - 1;
} while (delta.y == 0 && delta.x == 0);
mpos = 0;
return TRUE;
}