Mercurial > hg > early-roguelike
comparison arogue5/util.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 | c49f7927b0fa |
comparison
equal
deleted
inserted
replaced
62:0ef99244acb8 | 63:0ed67132cf10 |
---|---|
1 /* | |
2 * all sorts of miscellaneous routines | |
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 "rogue.h" | |
17 #include <ctype.h> | |
18 | |
19 /* | |
20 * aggravate: | |
21 * aggravate all the monsters on this level | |
22 */ | |
23 | |
24 aggravate() | |
25 { | |
26 register struct linked_list *mi; | |
27 | |
28 for (mi = mlist; mi != NULL; mi = next(mi)) | |
29 runto(THINGPTR(mi), &hero); | |
30 } | |
31 | |
32 /* | |
33 * cansee: | |
34 * returns true if the hero can see a certain coordinate. | |
35 */ | |
36 | |
37 cansee(y, x) | |
38 register int y, x; | |
39 { | |
40 register struct room *rer; | |
41 register int radius; | |
42 coord tp; | |
43 | |
44 if (on(player, ISBLIND)) | |
45 return FALSE; | |
46 | |
47 tp.y = y; | |
48 tp.x = x; | |
49 rer = roomin(&tp); | |
50 | |
51 /* How far can we see? */ | |
52 if (levtype == OUTSIDE) { | |
53 if (daytime) radius = 36; | |
54 else if (lit_room(rer)) radius = 9; | |
55 else radius = 3; | |
56 } | |
57 else radius = 3; | |
58 | |
59 /* | |
60 * We can only see if the hero in the same room as | |
61 * the coordinate and the room is lit or if it is close. | |
62 */ | |
63 return ((rer != NULL && | |
64 levtype != OUTSIDE && | |
65 (levtype != MAZELEV || /* Maze level needs direct line */ | |
66 maze_view(tp.y, tp.x)) && | |
67 rer == roomin(&hero) && | |
68 lit_room(rer)) || | |
69 DISTANCE(y, x, hero.y, hero.x) < radius); | |
70 } | |
71 | |
72 /* | |
73 * check_level: | |
74 * Check to see if the guy has gone up a level. | |
75 * | |
76 * Return points needed to obtain next level. | |
77 * | |
78 * These are the beginning experience levels for all players. | |
79 * All further experience levels are computed by muliplying by 2 | |
80 * up through MAXDOUBLE. | |
81 */ | |
82 #define MAXDOUBLE 14 /* Maximum number of times score is doubled */ | |
83 static struct { | |
84 long base; /* What it starts out at for doubling */ | |
85 long cap; /* The maximum before doubling stops */ | |
86 } e_levels[4] = { | |
87 /* You must change MAXDOUBLE if you change the cap figure */ | |
88 { 90L, 1474560L }, /* Fighter */ | |
89 { 130L, 2129920L }, /* Magician */ | |
90 { 110L, 1802240L }, /* cleric */ | |
91 { 75L, 1228800L } /* Thief */ | |
92 }; | |
93 | |
94 long | |
95 check_level(get_spells) | |
96 bool get_spells; | |
97 { | |
98 register int i, j, add = 0; | |
99 register unsigned long exp; | |
100 long retval; /* Return value */ | |
101 int nsides = 0; | |
102 | |
103 /* See if we are past the doubling stage */ | |
104 exp = e_levels[player.t_ctype].cap; | |
105 if (pstats.s_exp >= exp) { | |
106 i = pstats.s_exp/exp; /* First get amount above doubling area */ | |
107 retval = exp + i * exp; /* Compute next higher boundary */ | |
108 i += MAXDOUBLE; /* Add in the previous doubled levels */ | |
109 } | |
110 else { | |
111 i = 0; | |
112 exp = e_levels[player.t_ctype].base; | |
113 while (exp <= pstats.s_exp) { | |
114 i++; | |
115 exp <<= 1; | |
116 } | |
117 retval = exp; | |
118 } | |
119 if (++i > pstats.s_lvl) { | |
120 switch (player.t_ctype) { | |
121 case C_FIGHTER: nsides = 10; | |
122 when C_MAGICIAN: nsides = 4; | |
123 when C_CLERIC: nsides = 8; | |
124 when C_THIEF: nsides = 6; | |
125 } | |
126 | |
127 /* Take care of multi-level jumps */ | |
128 for (j=0; j < (i-pstats.s_lvl); j++) | |
129 add += max(1, roll(1,nsides) + const_bonus()); | |
130 max_stats.s_hpt += add; | |
131 if ((pstats.s_hpt += add) > max_stats.s_hpt) | |
132 pstats.s_hpt = max_stats.s_hpt; | |
133 sprintf(outstring,"Welcome, %s, to level %d", | |
134 cnames[player.t_ctype][min(i-1, 10)], i); | |
135 msg(outstring); | |
136 if (get_spells) { | |
137 pray_time = 0; /* A new round of prayers */ | |
138 spell_power = 0; /* A new round of spells */ | |
139 } | |
140 } | |
141 pstats.s_lvl = i; | |
142 return(retval); | |
143 } | |
144 | |
145 /* | |
146 * Used to modify the playes strength | |
147 * it keeps track of the highest it has been, just in case | |
148 */ | |
149 | |
150 chg_str(amt) | |
151 register int amt; | |
152 { | |
153 register int ring_str; /* ring strengths */ | |
154 register struct stats *ptr; /* for speed */ | |
155 | |
156 ptr = &pstats; | |
157 ring_str = ring_value(R_ADDSTR); | |
158 ptr->s_str -= ring_str; | |
159 ptr->s_str += amt; | |
160 if (ptr->s_str > 25) | |
161 ptr->s_str = 25; | |
162 if (ptr->s_str > max_stats.s_str) | |
163 max_stats.s_str = ptr->s_str; | |
164 ptr->s_str += ring_str; | |
165 if (ptr->s_str <= 0) | |
166 death(D_STRENGTH); | |
167 updpack(TRUE); | |
168 } | |
169 | |
170 /* | |
171 * this routine computes the players current AC without dex bonus's | |
172 */ | |
173 int | |
174 ac_compute() | |
175 { | |
176 register int ac; | |
177 | |
178 ac = cur_armor != NULL ? cur_armor->o_ac : pstats.s_arm; | |
179 ac -= ring_value(R_PROTECT); | |
180 if (cur_misc[WEAR_BRACERS] != NULL) | |
181 ac -= cur_misc[WEAR_BRACERS]->o_ac; | |
182 if (cur_misc[WEAR_CLOAK] != NULL) | |
183 ac -= cur_misc[WEAR_CLOAK]->o_ac; | |
184 | |
185 /* If player has the cloak, must be wearing it */ | |
186 if (cur_relic[EMORI_CLOAK]) ac -= 5; | |
187 | |
188 if (ac > 10) | |
189 ac = 10; | |
190 return(ac); | |
191 } | |
192 | |
193 /* | |
194 * this routine computes the players current strength | |
195 */ | |
196 str_compute() | |
197 { | |
198 if (cur_misc[WEAR_GAUNTLET] != NULL && | |
199 cur_misc[WEAR_GAUNTLET]->o_which == MM_G_OGRE) { | |
200 if (cur_misc[WEAR_GAUNTLET]->o_flags & ISCURSED) | |
201 return (3); | |
202 else | |
203 return (18); | |
204 } | |
205 else | |
206 return (pstats.s_str); | |
207 } | |
208 | |
209 /* | |
210 * this routine computes the players current dexterity | |
211 */ | |
212 dex_compute() | |
213 { | |
214 if (cur_misc[WEAR_GAUNTLET] != NULL && | |
215 cur_misc[WEAR_GAUNTLET]->o_which == MM_G_DEXTERITY) { | |
216 if (cur_misc[WEAR_GAUNTLET]->o_flags & ISCURSED) | |
217 return (3); | |
218 else | |
219 return (18); | |
220 } | |
221 else | |
222 return (pstats.s_dext); | |
223 } | |
224 | |
225 | |
226 /* | |
227 * diag_ok: | |
228 * Check to see if the move is legal if it is diagonal | |
229 */ | |
230 | |
231 diag_ok(sp, ep, flgptr) | |
232 register coord *sp, *ep; | |
233 struct thing *flgptr; | |
234 { | |
235 register int numpaths = 0; | |
236 | |
237 /* Horizontal and vertical moves are always ok */ | |
238 if (ep->x == sp->x || ep->y == sp->y) | |
239 return TRUE; | |
240 | |
241 /* Diagonal moves are not allowed if there is a horizontal or | |
242 * vertical path to the destination | |
243 */ | |
244 if (step_ok(ep->y, sp->x, MONSTOK, flgptr)) numpaths++; | |
245 if (step_ok(sp->y, ep->x, MONSTOK, flgptr)) numpaths++; | |
246 return(numpaths != 1); | |
247 } | |
248 | |
249 /* | |
250 * eat: | |
251 * He wants to eat something, so let him try | |
252 */ | |
253 | |
254 eat() | |
255 { | |
256 register struct linked_list *item; | |
257 | |
258 if ((item = get_item(pack, "eat", FOOD)) == NULL) | |
259 return; | |
260 if ((OBJPTR(item))->o_which == 1) | |
261 msg("My, that was a yummy %s", fruit); | |
262 else { | |
263 if (rnd(100) > 70) { | |
264 msg("Yuk, this food tastes awful"); | |
265 | |
266 /* Do a check for overflow before increasing experience */ | |
267 if (pstats.s_exp + 1L > pstats.s_exp) pstats.s_exp++; | |
268 check_level(TRUE); | |
269 } | |
270 else | |
271 msg("Yum, that tasted good"); | |
272 } | |
273 if ((food_left += HUNGERTIME + rnd(400) - 200) > STOMACHSIZE) | |
274 food_left = STOMACHSIZE; | |
275 del_pack(item); | |
276 hungry_state = F_OKAY; | |
277 updpack(TRUE); | |
278 } | |
279 | |
280 /* | |
281 * pick a random position around the give (y, x) coordinates | |
282 */ | |
283 coord * | |
284 fallpos(pos, be_clear, range) | |
285 register coord *pos; | |
286 bool be_clear; | |
287 int range; | |
288 { | |
289 register int tried, i, j; | |
290 register char ch; | |
291 static coord ret; | |
292 static short masks[] = { | |
293 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x100 }; | |
294 | |
295 /* | |
296 * Pick a spot at random centered on the position given by 'pos' and | |
297 * up to 'range' squares away from 'pos' | |
298 * | |
299 * If 'be_clear' is TRUE, the spot must be either FLOOR or PASSAGE | |
300 * inorder to be considered valid | |
301 * | |
302 * | |
303 * Generate a number from 0 to 8, representing the position to pick. | |
304 * Note that this DOES include the positon 'pos' itself | |
305 * | |
306 * If this position is not valid, mark it as 'tried', and pick another. | |
307 * Whenever a position is picked that has been tried before, | |
308 * sequentially find the next untried position. This eliminates costly | |
309 * random number generation | |
310 */ | |
311 | |
312 tried = 0; | |
313 while( tried != 0x1ff ) { | |
314 i = rnd(9); | |
315 while( tried & masks[i] ) | |
316 i = (i + 1) % 9; | |
317 | |
318 tried |= masks[i]; | |
319 | |
320 for( j = 1; j <= range; j++ ) { | |
321 ret.x = pos->x + j*grid[i].x; | |
322 ret.y = pos->y + j*grid[i].y; | |
323 | |
324 if (ret.x == hero.x && ret.y == hero.y) | |
325 continue; /* skip the hero */ | |
326 | |
327 if (ret.x < 0 || ret.x > COLS - 1 || | |
328 ret.y < 1 || ret.y > LINES - 3) | |
329 continue; /* off the screen? */ | |
330 | |
331 ch = CCHAR( winat(ret.y, ret.x) ); | |
332 | |
333 /* | |
334 * Check to make certain the spot is valid | |
335 */ | |
336 switch( ch ) { | |
337 case FLOOR: | |
338 case PASSAGE: | |
339 return( &ret ); | |
340 case GOLD: | |
341 case SCROLL: | |
342 case POTION: | |
343 case STICK: | |
344 case RING: | |
345 case WEAPON: | |
346 case ARMOR: | |
347 case MM: | |
348 case FOOD: | |
349 if(!be_clear && levtype != POSTLEV) | |
350 return( &ret ); | |
351 default: | |
352 break; | |
353 } | |
354 } | |
355 } | |
356 return( NULL ); | |
357 } | |
358 | |
359 | |
360 /* | |
361 * find_mons: | |
362 * Find the monster from his corrdinates | |
363 */ | |
364 | |
365 struct linked_list * | |
366 find_mons(y, x) | |
367 register int y; | |
368 register int x; | |
369 { | |
370 register struct linked_list *item; | |
371 register struct thing *th; | |
372 | |
373 for (item = mlist; item != NULL; item = next(item)) | |
374 { | |
375 th = THINGPTR(item); | |
376 if (th->t_pos.y == y && th->t_pos.x == x) | |
377 return item; | |
378 } | |
379 return NULL; | |
380 } | |
381 | |
382 /* | |
383 * find_obj: | |
384 * find the unclaimed object at y, x | |
385 */ | |
386 | |
387 struct linked_list * | |
388 find_obj(y, x) | |
389 register int y; | |
390 register int x; | |
391 { | |
392 register struct linked_list *obj; | |
393 register struct object *op; | |
394 | |
395 for (obj = lvl_obj; obj != NULL; obj = next(obj)) | |
396 { | |
397 op = OBJPTR(obj); | |
398 if (op->o_pos.y == y && op->o_pos.x == x) | |
399 return obj; | |
400 } | |
401 return NULL; | |
402 } | |
403 | |
404 | |
405 /* | |
406 * set up the direction co_ordinate for use in varios "prefix" commands | |
407 */ | |
408 get_dir() | |
409 { | |
410 register char *prompt; | |
411 register bool gotit; | |
412 | |
413 prompt = terse ? "Direction?" : "Which direction? "; | |
414 msg(prompt); | |
415 do | |
416 { | |
417 gotit = TRUE; | |
418 switch (readchar()) | |
419 { | |
420 case 'h': case'H': delta.y = 0; delta.x = -1; | |
421 when 'j': case'J': delta.y = 1; delta.x = 0; | |
422 when 'k': case'K': delta.y = -1; delta.x = 0; | |
423 when 'l': case'L': delta.y = 0; delta.x = 1; | |
424 when 'y': case'Y': delta.y = -1; delta.x = -1; | |
425 when 'u': case'U': delta.y = -1; delta.x = 1; | |
426 when 'b': case'B': delta.y = 1; delta.x = -1; | |
427 when 'n': case'N': delta.y = 1; delta.x = 1; | |
428 when ESCAPE: return FALSE; | |
429 otherwise: | |
430 mpos = 0; | |
431 msg(prompt); | |
432 gotit = FALSE; | |
433 } | |
434 } until (gotit); | |
435 if ((on(player, ISHUH) || on(player, ISDANCE)) && rnd(100) > 20) { | |
436 do | |
437 { | |
438 delta = grid[rnd(9)]; | |
439 } while (delta.y == 0 && delta.x == 0); | |
440 } | |
441 mpos = 0; | |
442 return TRUE; | |
443 } | |
444 | |
445 /* | |
446 * see if the object is one of the currently used items | |
447 */ | |
448 is_current(obj) | |
449 register struct object *obj; | |
450 { | |
451 if (obj == NULL) | |
452 return FALSE; | |
453 if (obj == cur_armor || obj == cur_weapon || | |
454 obj == cur_ring[LEFT_1] || obj == cur_ring[LEFT_2] || | |
455 obj == cur_ring[LEFT_3] || obj == cur_ring[LEFT_4] || | |
456 obj == cur_ring[RIGHT_1] || obj == cur_ring[RIGHT_2] || | |
457 obj == cur_ring[RIGHT_3] || obj == cur_ring[RIGHT_4] || | |
458 obj == cur_misc[WEAR_BOOTS] || obj == cur_misc[WEAR_JEWEL] || | |
459 obj == cur_misc[WEAR_BRACERS] || obj == cur_misc[WEAR_CLOAK] || | |
460 obj == cur_misc[WEAR_GAUNTLET] || obj == cur_misc[WEAR_NECKLACE]) { | |
461 | |
462 return TRUE; | |
463 } | |
464 | |
465 /* Is it a "current" relic? */ | |
466 if (obj->o_type == RELIC) { | |
467 switch (obj->o_which) { | |
468 case MUSTY_DAGGER: | |
469 case EMORI_CLOAK: | |
470 case HEIL_ANKH: | |
471 case YENDOR_AMULET: | |
472 case HRUGGEK_MSTAR: | |
473 case YEENOGHU_FLAIL: | |
474 if (cur_relic[obj->o_which]) return TRUE; | |
475 } | |
476 } | |
477 | |
478 return FALSE; | |
479 } | |
480 | |
481 | |
482 /* | |
483 * Look: | |
484 * A quick glance all around the player | |
485 */ | |
486 | |
487 look(wakeup, runend) | |
488 bool wakeup; /* Should we wake up monsters */ | |
489 bool runend; /* At end of a run -- for mazes */ | |
490 { | |
491 register int x, y, radius; | |
492 register char ch, och; | |
493 register int oldx, oldy; | |
494 register bool inpass, horiz, vert, do_light = FALSE, do_blank = FALSE; | |
495 register int passcount = 0, curfloorcount = 0, nextfloorcount = 0; | |
496 register struct room *rp; | |
497 register int ey, ex; | |
498 | |
499 inpass = ((rp = roomin(&hero)) == NULL); /* Are we in a passage? */ | |
500 | |
501 /* Are we moving vertically or horizontally? */ | |
502 if (runch == 'h' || runch == 'l') horiz = TRUE; | |
503 else horiz = FALSE; | |
504 if (runch == 'j' || runch == 'k') vert = TRUE; | |
505 else vert = FALSE; | |
506 | |
507 /* How far around himself can the player see? */ | |
508 if (levtype == OUTSIDE) { | |
509 if (daytime) radius = 6; | |
510 else if (lit_room(rp)) radius = 3; | |
511 else radius = 1; | |
512 } | |
513 else radius = 1; | |
514 | |
515 getyx(cw, oldy, oldx); /* Save current position */ | |
516 | |
517 /* Blank out the floor around our last position and check for | |
518 * moving out of a corridor in a maze. | |
519 */ | |
520 if (levtype == OUTSIDE) do_blank = !daytime; | |
521 else if (oldrp != NULL && !lit_room(oldrp) && off(player, ISBLIND)) | |
522 do_blank = TRUE; | |
523 | |
524 /* Now move around the old position and blank things out */ | |
525 ey = player.t_oldpos.y + radius; | |
526 ex = player.t_oldpos.x + radius; | |
527 for (x = player.t_oldpos.x - radius; x <= ex; x++) | |
528 if (x >= 0 && x < COLS) | |
529 for (y = player.t_oldpos.y - radius; y <= ey; y++) { | |
530 char savech; /* Saves character in monster window */ | |
531 | |
532 if (y < 1 || y > LINES - 3) continue; | |
533 | |
534 /* See what's there -- ignore monsters, just see what they're on */ | |
535 savech = CCHAR( mvwinch(mw, y, x) ); | |
536 waddch(mw, ' '); | |
537 ch = show(y, x); | |
538 mvwaddch(mw, y, x, savech); /* Restore monster */ | |
539 | |
540 if (do_blank && (y != hero.y || x != hero.x)) | |
541 switch (ch) { | |
542 case DOOR: | |
543 case SECRETDOOR: | |
544 case PASSAGE: | |
545 case STAIRS: | |
546 case TRAPDOOR: | |
547 case TELTRAP: | |
548 case BEARTRAP: | |
549 case SLEEPTRAP: | |
550 case ARROWTRAP: | |
551 case DARTTRAP: | |
552 case MAZETRAP: | |
553 case POOL: | |
554 case POST: | |
555 case '|': | |
556 case '-': | |
557 case WALL: | |
558 /* If there was a monster showing, make it disappear */ | |
559 if (isalpha(savech)) mvwaddch(cw, y, x, ch); | |
560 break; | |
561 when FLOOR: | |
562 case FOREST: | |
563 default: | |
564 mvwaddch(cw, y, x, ' '); | |
565 } | |
566 | |
567 /* Moving out of a corridor? */ | |
568 if (levtype == MAZELEV && !ce(hero, player.t_oldpos) && | |
569 !running && !isrock(ch) && /* Not running and not a wall */ | |
570 ((vert && x != player.t_oldpos.x && y==player.t_oldpos.y) || | |
571 (horiz && y != player.t_oldpos.y && x==player.t_oldpos.x))) | |
572 do_light = off(player, ISBLIND); | |
573 } | |
574 | |
575 /* Take care of unlighting a corridor */ | |
576 if (do_light && lit_room(rp)) light(&player.t_oldpos); | |
577 | |
578 /* Are we coming or going between a wall and a corridor in a maze? */ | |
579 och = show(player.t_oldpos.y, player.t_oldpos.x); | |
580 ch = show(hero.y, hero.x); | |
581 if (levtype == MAZELEV && | |
582 ((isrock(och) && !isrock(ch)) || (isrock(ch) && !isrock(och)))) { | |
583 do_light = off(player, ISBLIND); /* Light it up if not blind */ | |
584 | |
585 /* Unlight what we just saw */ | |
586 if (do_light && lit_room(&rooms[0])) light(&player.t_oldpos); | |
587 } | |
588 | |
589 /* Look around the player */ | |
590 ey = hero.y + radius; | |
591 ex = hero.x + radius; | |
592 for (x = hero.x - radius; x <= ex; x++) | |
593 if (x >= 0 && x < COLS) for (y = hero.y - radius; y <= ey; y++) { | |
594 if (y < 1 || y >= LINES - 2) | |
595 continue; | |
596 if (isalpha(mvwinch(mw, y, x))) | |
597 { | |
598 register struct linked_list *it; | |
599 register struct thing *tp; | |
600 | |
601 if (wakeup) | |
602 it = wake_monster(y, x); | |
603 else | |
604 it = find_mons(y, x); | |
605 tp = THINGPTR(it); | |
606 tp->t_oldch = CCHAR( mvinch(y, x) ); | |
607 if (isatrap(tp->t_oldch)) { | |
608 register struct trap *trp = trap_at(y, x); | |
609 | |
610 tp->t_oldch = (trp->tr_flags & ISFOUND) ? tp->t_oldch | |
611 : trp->tr_show; | |
612 } | |
613 if (tp->t_oldch == FLOOR && !lit_room(rp) && | |
614 off(player, ISBLIND)) | |
615 tp->t_oldch = ' '; | |
616 } | |
617 | |
618 /* | |
619 * Secret doors show as walls | |
620 */ | |
621 if ((ch = show(y, x)) == SECRETDOOR) | |
622 ch = secretdoor(y, x); | |
623 /* | |
624 * Don't show room walls if he is in a passage and | |
625 * check for maze turns | |
626 */ | |
627 if (off(player, ISBLIND)) | |
628 { | |
629 if (y == hero.y && x == hero.x | |
630 || (inpass && (ch == '-' || ch == '|'))) | |
631 continue; | |
632 | |
633 /* Did we come to a crossroads in a maze? */ | |
634 if (levtype == MAZELEV && | |
635 (runend || !ce(hero, player.t_oldpos)) && | |
636 !isrock(ch) && /* Not a wall */ | |
637 ((vert && x != hero.x && y == hero.y) || | |
638 (horiz && y != hero.y && x == hero.x))) | |
639 /* Just came to a turn */ | |
640 do_light = off(player, ISBLIND); | |
641 } | |
642 else if (y != hero.y || x != hero.x) | |
643 continue; | |
644 | |
645 wmove(cw, y, x); | |
646 waddch(cw, ch); | |
647 if (door_stop && !firstmove && running) | |
648 { | |
649 switch (runch) | |
650 { | |
651 case 'h': | |
652 if (x == hero.x + 1) | |
653 continue; | |
654 when 'j': | |
655 if (y == hero.y - 1) | |
656 continue; | |
657 when 'k': | |
658 if (y == hero.y + 1) | |
659 continue; | |
660 when 'l': | |
661 if (x == hero.x - 1) | |
662 continue; | |
663 when 'y': | |
664 if ((x + y) - (hero.x + hero.y) >= 1) | |
665 continue; | |
666 when 'u': | |
667 if ((y - x) - (hero.y - hero.x) >= 1) | |
668 continue; | |
669 when 'n': | |
670 if ((x + y) - (hero.x + hero.y) <= -1) | |
671 continue; | |
672 when 'b': | |
673 if ((y - x) - (hero.y - hero.x) <= -1) | |
674 continue; | |
675 } | |
676 switch (ch) | |
677 { | |
678 case DOOR: | |
679 if (x == hero.x || y == hero.y) | |
680 running = FALSE; | |
681 break; | |
682 case PASSAGE: | |
683 if (x == hero.x || y == hero.y) | |
684 passcount++; | |
685 break; | |
686 case FLOOR: | |
687 /* Stop by new passages in a maze (floor next to us) */ | |
688 if ((levtype == MAZELEV) && | |
689 !(hero.y == y && hero.x == x)) { | |
690 if (vert) { /* Moving vertically */ | |
691 /* We have a passage on our row */ | |
692 if (y == hero.y) curfloorcount++; | |
693 | |
694 /* Some passage on the next row */ | |
695 else if (y != player.t_oldpos.y) | |
696 nextfloorcount++; | |
697 } | |
698 else { /* Moving horizontally */ | |
699 /* We have a passage on our column */ | |
700 if (x == hero.x) curfloorcount++; | |
701 | |
702 /* Some passage in the next column */ | |
703 else if (x != player.t_oldpos.x) | |
704 nextfloorcount++; | |
705 } | |
706 } | |
707 case '|': | |
708 case '-': | |
709 case ' ': | |
710 break; | |
711 default: | |
712 running = FALSE; | |
713 break; | |
714 } | |
715 } | |
716 } | |
717 | |
718 /* Have we passed a side passage, with multiple choices? */ | |
719 if (curfloorcount > 0 && nextfloorcount > 0) running = FALSE; | |
720 | |
721 else if (door_stop && !firstmove && passcount > 1) | |
722 running = FALSE; | |
723 | |
724 /* Do we have to light up the area (just stepped into a new corridor)? */ | |
725 if (do_light && !running && lit_room(rp)) light(&hero); | |
726 | |
727 mvwaddch(cw, hero.y, hero.x, PLAYER); | |
728 wmove(cw, oldy, oldx); | |
729 if (!ce(player.t_oldpos, hero)) { | |
730 player.t_oldpos = hero; /* Don't change if we didn't move */ | |
731 oldrp = rp; | |
732 } | |
733 } | |
734 | |
735 /* | |
736 * raise_level: | |
737 * The guy just magically went up a level. | |
738 */ | |
739 | |
740 raise_level(get_spells) | |
741 bool get_spells; | |
742 { | |
743 unsigned long test; /* Next level -- be sure it is not an overflow */ | |
744 | |
745 test = check_level(FALSE); /* Get next boundary */ | |
746 | |
747 /* Be sure it is higher than what we have no -- else overflow */ | |
748 if (test > pstats.s_exp) pstats.s_exp = test; | |
749 check_level(get_spells); | |
750 } | |
751 | |
752 /* | |
753 * saving throw matrix for character saving throws | |
754 * this table is indexed by char type and saving throw type | |
755 */ | |
756 static int st_matrix[5][5] = { | |
757 /* Poison, Petrify, wand, Breath, Magic */ | |
758 { 14, 15, 16, 16, 17 }, | |
759 { 14, 13, 11, 15, 12 }, | |
760 { 10, 13, 14, 16, 15 }, | |
761 { 13, 12, 14, 16, 15 }, | |
762 { 14, 15, 16, 16, 17 } | |
763 }; | |
764 | |
765 /* | |
766 * save: | |
767 * See if a creature saves against something | |
768 */ | |
769 save(which, who, adj) | |
770 int which; /* which type of save */ | |
771 struct thing *who; /* who is saving */ | |
772 int adj; /* saving throw adjustment */ | |
773 { | |
774 register int need, level; | |
775 | |
776 level = who->t_stats.s_lvl; | |
777 need = st_matrix[who->t_ctype][which]; | |
778 switch (who->t_ctype) { | |
779 case C_FIGHTER: | |
780 need -= (level-1) / 2; | |
781 when C_MAGICIAN: | |
782 need -= 2 * (level-1) / 5; | |
783 when C_CLERIC: | |
784 need -= (level-1) / 3; | |
785 when C_THIEF: | |
786 need -= 2 * (level-1) / 4; | |
787 when C_MONSTER: | |
788 need -= level / 2; | |
789 } | |
790 /* | |
791 * add in pluses against poison for execeptional constitution | |
792 */ | |
793 if (which == VS_POISON && who->t_stats.s_const > 18) | |
794 need -= (who->t_stats.s_const - 17) / 2; | |
795 /* | |
796 * does the player have a ring of protection on? | |
797 */ | |
798 if (who == &player) | |
799 need -= (min(ring_value(R_PROTECT),3)); /* no more than +3 bonus */ | |
800 /* | |
801 * does the player have a cloak of protection on? | |
802 */ | |
803 if (who == &player && cur_misc[WEAR_CLOAK]) | |
804 need -= (min(cur_misc[WEAR_CLOAK]->o_ac,3)); /* no more than +3 bonus */ | |
805 need -= adj; | |
806 debug("need a %d to save", need); | |
807 return (roll(1, 20) >= need); | |
808 } | |
809 | |
810 | |
811 /* | |
812 * secret_door: | |
813 * Figure out what a secret door looks like. | |
814 */ | |
815 | |
816 secretdoor(y, x) | |
817 register int y, x; | |
818 { | |
819 register int i; | |
820 register struct room *rp; | |
821 register coord *cpp; | |
822 static coord cp; | |
823 | |
824 cp.y = y; | |
825 cp.x = x; | |
826 cpp = &cp; | |
827 for (rp = rooms, i = 0; i < MAXROOMS; rp++, i++) | |
828 if (inroom(rp, cpp)) | |
829 if (y == rp->r_pos.y || y == rp->r_pos.y + rp->r_max.y - 1) | |
830 return('-'); | |
831 else | |
832 return('|'); | |
833 | |
834 return('p'); | |
835 } | |
836 | |
837 /* | |
838 * copy string using unctrl for things | |
839 */ | |
840 strucpy(s1, s2, len) | |
841 register char *s1, *s2; | |
842 register int len; | |
843 { | |
844 register char *sp; | |
845 | |
846 while (len--) | |
847 { | |
848 strcpy(s1, (sp = unctrl(*s2))); | |
849 s1 += strlen(sp); | |
850 s2++; | |
851 } | |
852 *s1 = '\0'; | |
853 } | |
854 | |
855 /* | |
856 * tr_name: | |
857 * print the name of a trap | |
858 */ | |
859 | |
860 char * | |
861 tr_name(ch) | |
862 char ch; | |
863 { | |
864 register char *s = NULL; | |
865 | |
866 switch (ch) | |
867 { | |
868 case TRAPDOOR: | |
869 s = terse ? "A trapdoor." : "You found a trapdoor."; | |
870 when BEARTRAP: | |
871 s = terse ? "A beartrap." : "You found a beartrap."; | |
872 when SLEEPTRAP: | |
873 s = terse ? "A sleeping gas trap.":"You found a sleeping gas trap."; | |
874 when ARROWTRAP: | |
875 s = terse ? "An arrow trap." : "You found an arrow trap."; | |
876 when TELTRAP: | |
877 s = terse ? "A teleport trap." : "You found a teleport trap."; | |
878 when DARTTRAP: | |
879 s = terse ? "A dart trap." : "You found a poison dart trap."; | |
880 when POOL: | |
881 s = terse ? "A shimmering pool." : "You found a shimmering pool"; | |
882 when MAZETRAP: | |
883 s = terse ? "A maze entrance." : "You found a maze entrance"; | |
884 } | |
885 return s; | |
886 } | |
887 | |
888 /* | |
889 * for printfs: if string starts with a vowel, return "n" for an "an" | |
890 */ | |
891 char * | |
892 vowelstr(str) | |
893 register char *str; | |
894 { | |
895 switch (*str) | |
896 { | |
897 case 'a': | |
898 case 'e': | |
899 case 'i': | |
900 case 'o': | |
901 case 'u': | |
902 return "n"; | |
903 default: | |
904 return ""; | |
905 } | |
906 } | |
907 | |
908 /* | |
909 * waste_time: | |
910 * Do nothing but let other things happen | |
911 */ | |
912 | |
913 waste_time() | |
914 { | |
915 if (inwhgt) /* if from wghtchk then done */ | |
916 return; | |
917 do_daemons(BEFORE); | |
918 do_fuses(BEFORE); | |
919 do_daemons(AFTER); | |
920 do_fuses(AFTER); | |
921 } |