comparison rogue4/misc.c @ 12:9535a08ddc39

Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
author edwarj4
date Sat, 24 Oct 2009 16:52:52 +0000
parents
children 1b73a8641b37
comparison
equal deleted inserted replaced
11:949d558c2162 12:9535a08ddc39
1 /*
2 * All sorts of miscellaneous routines
3 *
4 * @(#)misc.c 4.30 (Berkeley) 4/6/82
5 *
6 * Rogue: Exploring the Dungeons of Doom
7 * Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman
8 * All rights reserved.
9 *
10 * See the file LICENSE.TXT for full copyright and licensing information.
11 */
12
13 #include <stdlib.h>
14 #include <curses.h>
15 #include <ctype.h>
16 #include <string.h>
17 #include "rogue.h"
18
19 /*
20 * tr_name:
21 * Print the name of a trap
22 */
23 char *
24 tr_name(type)
25 char type;
26 {
27 switch (type)
28 {
29 case T_DOOR:
30 return terse ? "a trapdoor" : "you found a trapdoor";
31 case T_BEAR:
32 return terse ? "a beartrap" : "you found a beartrap";
33 case T_SLEEP:
34 return terse ? "a sleeping gas trap":"you found a sleeping gas trap";
35 case T_ARROW:
36 return terse ? "an arrow trap" : "you found an arrow trap";
37 case T_TELEP:
38 return terse ? "a teleport trap" : "you found a teleport trap";
39 case T_DART:
40 return terse ? "a dart trap" : "you found a poison dart trap";
41 }
42 msg("wierd trap: %d", type);
43 return NULL;
44 }
45
46 /*
47 * look:
48 * A quick glance all around the player
49 */
50 look(wakeup)
51 bool wakeup;
52 {
53 register int x, y;
54 register unsigned char ch;
55 register int index;
56 register THING *tp;
57 register struct room *rp;
58 register int ey, ex;
59 register int passcount = 0;
60 register char pfl, *fp, pch;
61 register int sy, sx, sumhero = 0, diffhero = 0;
62 register int oldx, oldy;
63
64 getyx(stdscr, oldy, oldx);
65 rp = proom;
66 if (!ce(oldpos, hero))
67 {
68 if ((oldrp->r_flags & (ISGONE|ISDARK)) == ISDARK && !on(player,ISBLIND))
69 {
70 ey = oldpos.y + 1;
71 ex = oldpos.x + 1;
72 sy = oldpos.y - 1;
73 for (x = oldpos.x - 1; x <= ex; x++)
74 for (y = sy; y <= ey; y++)
75 {
76 if (y == hero.y && x == hero.x)
77 continue;
78 move(y, x);
79 if (inch() == FLOOR)
80 addch(' ');
81 }
82 }
83 oldpos = hero;
84 oldrp = rp;
85 }
86 ey = hero.y + 1;
87 ex = hero.x + 1;
88 sx = hero.x - 1;
89 sy = hero.y - 1;
90 if (door_stop && !firstmove && running)
91 {
92 sumhero = hero.y + hero.x;
93 diffhero = hero.y - hero.x;
94 }
95 index = INDEX(hero.y, hero.x);
96 pfl = _flags[index];
97 pch = _level[index];
98 for (y = sy; y <= ey; y++)
99 if (y > 0 && y < LINES - 1) for (x = sx; x <= ex; x++)
100 {
101 if (x <= 0 || x >= COLS)
102 continue;
103 if (!on(player, ISBLIND))
104 {
105 if (y == hero.y && x == hero.x)
106 continue;
107 }
108 else if (y != hero.y || x != hero.x)
109 continue;
110
111 index = INDEX(y, x);
112 /*
113 * THIS REPLICATES THE moat() MACRO. IF MOAT IS CHANGED,
114 * THIS MUST BE CHANGED ALSO
115 */
116 fp = &_flags[index];
117 ch = _level[index];
118 if (pch != DOOR && ch != DOOR)
119 if ((pfl & F_PASS) != (*fp & F_PASS))
120 continue;
121 else if ((*fp & F_PASS) && (*fp & F_PNUM) != (pfl & F_PNUM))
122 continue;
123
124 if ((tp = _monst[index]) != NULL)
125 if (on(player, SEEMONST) && on(*tp, ISINVIS))
126 {
127 if (door_stop && !firstmove)
128 running = FALSE;
129 continue;
130 }
131 else
132 {
133 if (wakeup)
134 wake_monster(y, x);
135 if (tp->t_oldch != ' ' ||
136 (!(rp->r_flags & ISDARK) && !on(player, ISBLIND)))
137 tp->t_oldch = _level[index];
138 if (see_monst(tp))
139 ch = tp->t_disguise;
140 }
141
142 move(y, x);
143 if (ch != inch())
144 addch(ch);
145
146 if (door_stop && !firstmove && running)
147 {
148 switch (runch)
149 {
150 case 'h':
151 if (x == ex)
152 continue;
153 when 'j':
154 if (y == sy)
155 continue;
156 when 'k':
157 if (y == ey)
158 continue;
159 when 'l':
160 if (x == sx)
161 continue;
162 when 'y':
163 if ((y + x) - sumhero >= 1)
164 continue;
165 when 'u':
166 if ((y - x) - diffhero >= 1)
167 continue;
168 when 'n':
169 if ((y + x) - sumhero <= -1)
170 continue;
171 when 'b':
172 if ((y - x) - diffhero <= -1)
173 continue;
174 }
175 switch (ch)
176 {
177 case DOOR:
178 if (x == hero.x || y == hero.y)
179 running = FALSE;
180 break;
181 case PASSAGE:
182 if (x == hero.x || y == hero.y)
183 passcount++;
184 break;
185 case FLOOR:
186 case '|':
187 case '-':
188 case ' ':
189 break;
190 default:
191 running = FALSE;
192 break;
193 }
194 }
195 }
196 if (door_stop && !firstmove && passcount > 1)
197 running = FALSE;
198 move(hero.y, hero.x);
199 addch(PLAYER);
200 }
201
202 /*
203 * find_obj:
204 * Find the unclaimed object at y, x
205 */
206 THING *
207 find_obj(y, x)
208 register int y, x;
209 {
210 register THING *op;
211
212 for (op = lvl_obj; op != NULL; op = next(op))
213 {
214 if (op->o_pos.y == y && op->o_pos.x == x)
215 return op;
216 }
217 #ifdef WIZARD
218 sprintf(prbuf, "Non-object %d,%d", y, x);
219 debug(prbuf);
220 #endif
221 return NULL;
222 }
223
224 /*
225 * eat:
226 * She wants to eat something, so let her try
227 */
228 eat()
229 {
230 register THING *obj;
231
232 if ((obj = get_item("eat", FOOD)) == NULL)
233 return;
234 if (obj->o_type != FOOD)
235 {
236 if (!terse)
237 msg("ugh, you would get ill if you ate that");
238 else
239 msg("that's Inedible!");
240 return;
241 }
242 inpack--;
243
244 if (food_left < 0)
245 food_left = 0;
246 if ((food_left += HUNGERTIME - 200 + rnd(400)) > STOMACHSIZE)
247 food_left = STOMACHSIZE;
248 hungry_state = 0;
249 if (obj == cur_weapon)
250 cur_weapon = NULL;
251 if (obj->o_which == 1)
252 msg("my, that was a yummy %s", fruit);
253 else
254 if (rnd(100) > 70)
255 {
256 pstats.s_exp++;
257 msg("yuk, this food tastes awful");
258 check_level();
259 }
260 else
261 msg("yum, that tasted good");
262
263 if (--obj->o_count < 1)
264 {
265 detach(pack, obj);
266 discard(obj);
267 }
268 }
269
270 /*
271 * chg_str:
272 * Used to modify the playes strength. It keeps track of the
273 * highest it has been, just in case
274 */
275 chg_str(amt)
276 register int amt;
277 {
278 str_t comp;
279
280 if (amt == 0)
281 return;
282 add_str(&pstats.s_str, amt);
283 comp = pstats.s_str;
284 if (ISRING(LEFT, R_ADDSTR))
285 add_str(&comp, -cur_ring[LEFT]->o_ac);
286 if (ISRING(RIGHT, R_ADDSTR))
287 add_str(&comp, -cur_ring[RIGHT]->o_ac);
288 if (comp > max_stats.s_str)
289 max_stats.s_str = comp;
290 }
291
292 /*
293 * add_str:
294 * Perform the actual add, checking upper and lower bound limits
295 */
296 add_str(sp, amt)
297 register str_t *sp;
298 int amt;
299 {
300 if ((*sp += amt) < 3)
301 *sp = 3;
302 else if (*sp > 31)
303 *sp = 31;
304 }
305
306 /*
307 * add_haste:
308 * Add a haste to the player
309 */
310 add_haste(potion)
311 bool potion;
312 {
313 if (on(player, ISHASTE))
314 {
315 no_command += rnd(8);
316 player.t_flags &= ~ISRUN;
317 extinguish(nohaste);
318 player.t_flags &= ~ISHASTE;
319 msg("you faint from exhaustion");
320 return FALSE;
321 }
322 else
323 {
324 player.t_flags |= ISHASTE;
325 if (potion)
326 fuse(nohaste, 0, rnd(4)+4, AFTER);
327 return TRUE;
328 }
329 }
330
331 /*
332 * aggravate:
333 * Aggravate all the monsters on this level
334 */
335 aggravate()
336 {
337 register THING *mi;
338
339 for (mi = mlist; mi != NULL; mi = next(mi))
340 runto(&mi->t_pos, &hero);
341 }
342
343 /*
344 * vowelstr:
345 * For printfs: if string starts with a vowel, return "n" for an
346 * "an".
347 */
348 char *
349 vowelstr(str)
350 register char *str;
351 {
352 switch (*str)
353 {
354 case 'a': case 'A':
355 case 'e': case 'E':
356 case 'i': case 'I':
357 case 'o': case 'O':
358 case 'u': case 'U':
359 return "n";
360 default:
361 return "";
362 }
363 }
364
365 /*
366 * is_current:
367 * See if the object is one of the currently used items
368 */
369 is_current(obj)
370 register THING *obj;
371 {
372 if (obj == NULL)
373 return FALSE;
374 if (obj == cur_armor || obj == cur_weapon || obj == cur_ring[LEFT]
375 || obj == cur_ring[RIGHT])
376 {
377 if (!terse)
378 addmsg("That's already ");
379 msg("in use");
380 return TRUE;
381 }
382 return FALSE;
383 }
384
385 /*
386 * get_dir:
387 * Set up the direction co_ordinate for use in varios "prefix"
388 * commands