move.c revision 1.6 1 1.6 agc /* $NetBSD: move.c,v 1.6 2003/08/07 09:37:38 agc Exp $ */
2 1.3 cgd
3 1.1 cgd /*
4 1.3 cgd * Copyright (c) 1988, 1993
5 1.3 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * This code is derived from software contributed to Berkeley by
8 1.1 cgd * Timothy C. Stoehr.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.6 agc * 3. Neither the name of the University nor the names of its contributors
19 1.1 cgd * may be used to endorse or promote products derived from this software
20 1.1 cgd * without specific prior written permission.
21 1.1 cgd *
22 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 cgd * SUCH DAMAGE.
33 1.1 cgd */
34 1.1 cgd
35 1.4 lukem #include <sys/cdefs.h>
36 1.1 cgd #ifndef lint
37 1.3 cgd #if 0
38 1.3 cgd static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
39 1.3 cgd #else
40 1.6 agc __RCSID("$NetBSD: move.c,v 1.6 2003/08/07 09:37:38 agc Exp $");
41 1.3 cgd #endif
42 1.1 cgd #endif /* not lint */
43 1.1 cgd
44 1.1 cgd /*
45 1.1 cgd * move.c
46 1.1 cgd *
47 1.1 cgd * This source herein may be modified and/or distributed by anybody who
48 1.1 cgd * so desires, with the following restrictions:
49 1.1 cgd * 1.) No portion of this notice shall be removed.
50 1.1 cgd * 2.) Credit shall not be taken for the creation of this source.
51 1.1 cgd * 3.) This code is not to be traded, sold, or used for personal
52 1.1 cgd * gain or profit.
53 1.1 cgd *
54 1.1 cgd */
55 1.1 cgd
56 1.1 cgd #include "rogue.h"
57 1.1 cgd
58 1.1 cgd short m_moves = 0;
59 1.1 cgd boolean jump = 0;
60 1.5 hubertf const char *you_can_move_again = "you can move again";
61 1.1 cgd
62 1.4 lukem int
63 1.1 cgd one_move_rogue(dirch, pickup)
64 1.4 lukem short dirch, pickup;
65 1.1 cgd {
66 1.1 cgd short row, col;
67 1.1 cgd object *obj;
68 1.1 cgd char desc[DCOLS];
69 1.1 cgd short n, status, d;
70 1.1 cgd
71 1.1 cgd row = rogue.row;
72 1.1 cgd col = rogue.col;
73 1.1 cgd
74 1.1 cgd if (confused) {
75 1.1 cgd dirch = gr_dir();
76 1.1 cgd }
77 1.1 cgd (void) is_direction(dirch, &d);
78 1.1 cgd get_dir_rc(d, &row, &col, 1);
79 1.1 cgd
80 1.1 cgd if (!can_move(rogue.row, rogue.col, row, col)) {
81 1.1 cgd return(MOVE_FAILED);
82 1.1 cgd }
83 1.1 cgd if (being_held || bear_trap) {
84 1.1 cgd if (!(dungeon[row][col] & MONSTER)) {
85 1.1 cgd if (being_held) {
86 1.1 cgd message("you are being held", 1);
87 1.1 cgd } else {
88 1.1 cgd message("you are still stuck in the bear trap", 0);
89 1.1 cgd (void) reg_move();
90 1.1 cgd }
91 1.1 cgd return(MOVE_FAILED);
92 1.1 cgd }
93 1.1 cgd }
94 1.1 cgd if (r_teleport) {
95 1.1 cgd if (rand_percent(R_TELE_PERCENT)) {
96 1.1 cgd tele();
97 1.1 cgd return(STOPPED_ON_SOMETHING);
98 1.1 cgd }
99 1.1 cgd }
100 1.1 cgd if (dungeon[row][col] & MONSTER) {
101 1.1 cgd rogue_hit(object_at(&level_monsters, row, col), 0);
102 1.1 cgd (void) reg_move();
103 1.1 cgd return(MOVE_FAILED);
104 1.1 cgd }
105 1.1 cgd if (dungeon[row][col] & DOOR) {
106 1.1 cgd if (cur_room == PASSAGE) {
107 1.1 cgd cur_room = get_room_number(row, col);
108 1.1 cgd light_up_room(cur_room);
109 1.1 cgd wake_room(cur_room, 1, row, col);
110 1.1 cgd } else {
111 1.1 cgd light_passage(row, col);
112 1.1 cgd }
113 1.1 cgd } else if ((dungeon[rogue.row][rogue.col] & DOOR) &&
114 1.1 cgd (dungeon[row][col] & TUNNEL)) {
115 1.1 cgd light_passage(row, col);
116 1.1 cgd wake_room(cur_room, 0, rogue.row, rogue.col);
117 1.1 cgd darken_room(cur_room);
118 1.1 cgd cur_room = PASSAGE;
119 1.1 cgd } else if (dungeon[row][col] & TUNNEL) {
120 1.1 cgd light_passage(row, col);
121 1.1 cgd }
122 1.1 cgd mvaddch(rogue.row, rogue.col, get_dungeon_char(rogue.row, rogue.col));
123 1.1 cgd mvaddch(row, col, rogue.fchar);
124 1.1 cgd
125 1.1 cgd if (!jump) {
126 1.1 cgd refresh();
127 1.1 cgd }
128 1.1 cgd rogue.row = row;
129 1.1 cgd rogue.col = col;
130 1.1 cgd if (dungeon[row][col] & OBJECT) {
131 1.1 cgd if (levitate && pickup) {
132 1.1 cgd return(STOPPED_ON_SOMETHING);
133 1.1 cgd }
134 1.1 cgd if (pickup && !levitate) {
135 1.4 lukem if ((obj = pick_up(row, col, &status)) != NULL) {
136 1.1 cgd get_desc(obj, desc);
137 1.1 cgd if (obj->what_is == GOLD) {
138 1.1 cgd free_object(obj);
139 1.1 cgd goto NOT_IN_PACK;
140 1.1 cgd }
141 1.1 cgd } else if (!status) {
142 1.1 cgd goto MVED;
143 1.1 cgd } else {
144 1.1 cgd goto MOVE_ON;
145 1.1 cgd }
146 1.1 cgd } else {
147 1.1 cgd MOVE_ON:
148 1.1 cgd obj = object_at(&level_objects, row, col);
149 1.1 cgd (void) strcpy(desc, "moved onto ");
150 1.1 cgd get_desc(obj, desc+11);
151 1.1 cgd goto NOT_IN_PACK;
152 1.1 cgd }
153 1.1 cgd n = strlen(desc);
154 1.1 cgd desc[n] = '(';
155 1.1 cgd desc[n+1] = obj->ichar;
156 1.1 cgd desc[n+2] = ')';
157 1.1 cgd desc[n+3] = 0;
158 1.1 cgd NOT_IN_PACK:
159 1.1 cgd message(desc, 1);
160 1.1 cgd (void) reg_move();
161 1.1 cgd return(STOPPED_ON_SOMETHING);
162 1.1 cgd }
163 1.1 cgd if (dungeon[row][col] & (DOOR | STAIRS | TRAP)) {
164 1.1 cgd if ((!levitate) && (dungeon[row][col] & TRAP)) {
165 1.1 cgd trap_player(row, col);
166 1.1 cgd }
167 1.1 cgd (void) reg_move();
168 1.1 cgd return(STOPPED_ON_SOMETHING);
169 1.1 cgd }
170 1.1 cgd MVED: if (reg_move()) { /* fainted from hunger */
171 1.1 cgd return(STOPPED_ON_SOMETHING);
172 1.1 cgd }
173 1.1 cgd return((confused ? STOPPED_ON_SOMETHING : MOVED));
174 1.1 cgd }
175 1.1 cgd
176 1.4 lukem void
177 1.1 cgd multiple_move_rogue(dirch)
178 1.4 lukem short dirch;
179 1.1 cgd {
180 1.1 cgd short row, col;
181 1.1 cgd short m;
182 1.1 cgd
183 1.1 cgd switch(dirch) {
184 1.1 cgd case '\010':
185 1.1 cgd case '\012':
186 1.1 cgd case '\013':
187 1.1 cgd case '\014':
188 1.1 cgd case '\031':
189 1.1 cgd case '\025':
190 1.1 cgd case '\016':
191 1.1 cgd case '\002':
192 1.1 cgd do {
193 1.1 cgd row = rogue.row;
194 1.1 cgd col = rogue.col;
195 1.1 cgd if (((m = one_move_rogue((dirch + 96), 1)) == MOVE_FAILED) ||
196 1.1 cgd (m == STOPPED_ON_SOMETHING) ||
197 1.1 cgd interrupted) {
198 1.1 cgd break;
199 1.1 cgd }
200 1.1 cgd } while (!next_to_something(row, col));
201 1.1 cgd if ( (!interrupted) && passgo && (m == MOVE_FAILED) &&
202 1.1 cgd (dungeon[rogue.row][rogue.col] & TUNNEL)) {
203 1.1 cgd turn_passage(dirch + 96, 0);
204 1.1 cgd }
205 1.1 cgd break;
206 1.1 cgd case 'H':
207 1.1 cgd case 'J':
208 1.1 cgd case 'K':
209 1.1 cgd case 'L':
210 1.1 cgd case 'B':
211 1.1 cgd case 'Y':
212 1.1 cgd case 'U':
213 1.1 cgd case 'N':
214 1.1 cgd while ((!interrupted) && (one_move_rogue((dirch + 32), 1) == MOVED)) ;
215 1.1 cgd
216 1.1 cgd if ( (!interrupted) && passgo &&
217 1.1 cgd (dungeon[rogue.row][rogue.col] & TUNNEL)) {
218 1.1 cgd turn_passage(dirch + 32, 1);
219 1.1 cgd }
220 1.1 cgd break;
221 1.1 cgd }
222 1.1 cgd }
223 1.1 cgd
224 1.4 lukem boolean
225 1.1 cgd is_passable(row, col)
226 1.4 lukem int row, col;
227 1.1 cgd {
228 1.1 cgd if ((row < MIN_ROW) || (row > (DROWS - 2)) || (col < 0) ||
229 1.1 cgd (col > (DCOLS-1))) {
230 1.1 cgd return(0);
231 1.1 cgd }
232 1.1 cgd if (dungeon[row][col] & HIDDEN) {
233 1.1 cgd return((dungeon[row][col] & TRAP) ? 1 : 0);
234 1.1 cgd }
235 1.1 cgd return(dungeon[row][col] & (FLOOR | TUNNEL | DOOR | STAIRS | TRAP));
236 1.1 cgd }
237 1.1 cgd
238 1.4 lukem boolean
239 1.1 cgd next_to_something(drow, dcol)
240 1.4 lukem int drow, dcol;
241 1.1 cgd {
242 1.1 cgd short i, j, i_end, j_end, row, col;
243 1.1 cgd short pass_count = 0;
244 1.1 cgd unsigned short s;
245 1.1 cgd
246 1.1 cgd if (confused) {
247 1.1 cgd return(1);
248 1.1 cgd }
249 1.1 cgd if (blind) {
250 1.1 cgd return(0);
251 1.1 cgd }
252 1.1 cgd i_end = (rogue.row < (DROWS-2)) ? 1 : 0;
253 1.1 cgd j_end = (rogue.col < (DCOLS-1)) ? 1 : 0;
254 1.1 cgd
255 1.1 cgd for (i = ((rogue.row > MIN_ROW) ? -1 : 0); i <= i_end; i++) {
256 1.1 cgd for (j = ((rogue.col > 0) ? -1 : 0); j <= j_end; j++) {
257 1.1 cgd if ((i == 0) && (j == 0)) {
258 1.1 cgd continue;
259 1.1 cgd }
260 1.1 cgd if (((rogue.row+i) == drow) && ((rogue.col+j) == dcol)) {
261 1.1 cgd continue;
262 1.1 cgd }
263 1.1 cgd row = rogue.row + i;
264 1.1 cgd col = rogue.col + j;
265 1.1 cgd s = dungeon[row][col];
266 1.1 cgd if (s & HIDDEN) {
267 1.1 cgd continue;
268 1.1 cgd }
269 1.1 cgd /* If the rogue used to be right, up, left, down, or right of
270 1.1 cgd * row,col, and now isn't, then don't stop */
271 1.1 cgd if (s & (MONSTER | OBJECT | STAIRS)) {
272 1.1 cgd if (((row == drow) || (col == dcol)) &&
273 1.1 cgd (!((row == rogue.row) || (col == rogue.col)))) {
274 1.1 cgd continue;
275 1.1 cgd }
276 1.1 cgd return(1);
277 1.1 cgd }
278 1.1 cgd if (s & TRAP) {
279 1.1 cgd if (!(s & HIDDEN)) {
280 1.1 cgd if (((row == drow) || (col == dcol)) &&
281 1.1 cgd (!((row == rogue.row) || (col == rogue.col)))) {
282 1.1 cgd continue;
283 1.1 cgd }
284 1.1 cgd return(1);
285 1.1 cgd }
286 1.1 cgd }
287 1.1 cgd if ((((i - j) == 1) || ((i - j) == -1)) && (s & TUNNEL)) {
288 1.1 cgd if (++pass_count > 1) {
289 1.1 cgd return(1);
290 1.1 cgd }
291 1.1 cgd }
292 1.1 cgd if ((s & DOOR) && ((i == 0) || (j == 0))) {
293 1.1 cgd return(1);
294 1.1 cgd }
295 1.1 cgd }
296 1.1 cgd }
297 1.1 cgd return(0);
298 1.1 cgd }
299 1.1 cgd
300 1.4 lukem boolean
301 1.1 cgd can_move(row1, col1, row2, col2)
302 1.4 lukem int row1, col1, row2, col2;
303 1.1 cgd {
304 1.1 cgd if (!is_passable(row2, col2)) {
305 1.1 cgd return(0);
306 1.1 cgd }
307 1.1 cgd if ((row1 != row2) && (col1 != col2)) {
308 1.1 cgd if ((dungeon[row1][col1] & DOOR) || (dungeon[row2][col2] & DOOR)) {
309 1.1 cgd return(0);
310 1.1 cgd }
311 1.1 cgd if ((!dungeon[row1][col2]) || (!dungeon[row2][col1])) {
312 1.1 cgd return(0);
313 1.1 cgd }
314 1.1 cgd }
315 1.1 cgd return(1);
316 1.1 cgd }
317 1.1 cgd
318 1.4 lukem void
319 1.1 cgd move_onto()
320 1.1 cgd {
321 1.1 cgd short ch, d;
322 1.1 cgd boolean first_miss = 1;
323 1.1 cgd
324 1.1 cgd while (!is_direction(ch = rgetchar(), &d)) {
325 1.1 cgd sound_bell();
326 1.1 cgd if (first_miss) {
327 1.1 cgd message("direction? ", 0);
328 1.1 cgd first_miss = 0;
329 1.1 cgd }
330 1.1 cgd }
331 1.1 cgd check_message();
332 1.1 cgd if (ch != CANCEL) {
333 1.1 cgd (void) one_move_rogue(ch, 0);
334 1.1 cgd }
335 1.1 cgd }
336 1.1 cgd
337 1.1 cgd boolean
338 1.1 cgd is_direction(c, d)
339 1.4 lukem short c;
340 1.4 lukem short *d;
341 1.1 cgd {
342 1.1 cgd switch(c) {
343 1.1 cgd case 'h':
344 1.1 cgd *d = LEFT;
345 1.1 cgd break;
346 1.1 cgd case 'j':
347 1.1 cgd *d = DOWN;
348 1.1 cgd break;
349 1.1 cgd case 'k':
350 1.1 cgd *d = UPWARD;
351 1.1 cgd break;
352 1.1 cgd case 'l':
353 1.1 cgd *d = RIGHT;
354 1.1 cgd break;
355 1.1 cgd case 'b':
356 1.1 cgd *d = DOWNLEFT;
357 1.1 cgd break;
358 1.1 cgd case 'y':
359 1.1 cgd *d = UPLEFT;
360 1.1 cgd break;
361 1.1 cgd case 'u':
362 1.1 cgd *d = UPRIGHT;
363 1.1 cgd break;
364 1.1 cgd case 'n':
365 1.1 cgd *d = DOWNRIGHT;
366 1.1 cgd break;
367 1.1 cgd case CANCEL:
368 1.1 cgd break;
369 1.1 cgd default:
370 1.1 cgd return(0);
371 1.1 cgd }
372 1.1 cgd return(1);
373 1.1 cgd }
374 1.1 cgd
375 1.1 cgd boolean
376 1.1 cgd check_hunger(msg_only)
377 1.4 lukem boolean msg_only;
378 1.1 cgd {
379 1.4 lukem short i, n;
380 1.1 cgd boolean fainted = 0;
381 1.1 cgd
382 1.1 cgd if (rogue.moves_left == HUNGRY) {
383 1.1 cgd (void) strcpy(hunger_str, "hungry");
384 1.1 cgd message(hunger_str, 0);
385 1.1 cgd print_stats(STAT_HUNGER);
386 1.1 cgd }
387 1.1 cgd if (rogue.moves_left == WEAK) {
388 1.1 cgd (void) strcpy(hunger_str, "weak");
389 1.1 cgd message(hunger_str, 1);
390 1.1 cgd print_stats(STAT_HUNGER);
391 1.1 cgd }
392 1.1 cgd if (rogue.moves_left <= FAINT) {
393 1.1 cgd if (rogue.moves_left == FAINT) {
394 1.1 cgd (void) strcpy(hunger_str, "faint");
395 1.1 cgd message(hunger_str, 1);
396 1.1 cgd print_stats(STAT_HUNGER);
397 1.1 cgd }
398 1.1 cgd n = get_rand(0, (FAINT - rogue.moves_left));
399 1.1 cgd if (n > 0) {
400 1.1 cgd fainted = 1;
401 1.1 cgd if (rand_percent(40)) {
402 1.1 cgd rogue.moves_left++;
403 1.1 cgd }
404 1.1 cgd message("you faint", 1);
405 1.1 cgd for (i = 0; i < n; i++) {
406 1.1 cgd if (coin_toss()) {
407 1.1 cgd mv_mons();
408 1.1 cgd }
409 1.1 cgd }
410 1.1 cgd message(you_can_move_again, 1);
411 1.1 cgd }
412 1.1 cgd }
413 1.1 cgd if (msg_only) {
414 1.1 cgd return(fainted);
415 1.1 cgd }
416 1.1 cgd if (rogue.moves_left <= STARVE) {
417 1.1 cgd killed_by((object *) 0, STARVATION);
418 1.1 cgd }
419 1.1 cgd
420 1.1 cgd switch(e_rings) {
421 1.1 cgd /*case -2:
422 1.1 cgd Subtract 0, i.e. do nothing.
423 1.1 cgd break;*/
424 1.1 cgd case -1:
425 1.1 cgd rogue.moves_left -= (rogue.moves_left % 2);
426 1.1 cgd break;
427 1.1 cgd case 0:
428 1.1 cgd rogue.moves_left--;
429 1.1 cgd break;
430 1.1 cgd case 1:
431 1.1 cgd rogue.moves_left--;
432 1.1 cgd (void) check_hunger(1);
433 1.1 cgd rogue.moves_left -= (rogue.moves_left % 2);
434 1.1 cgd break;
435 1.1 cgd case 2:
436 1.1 cgd rogue.moves_left--;
437 1.1 cgd (void) check_hunger(1);
438 1.1 cgd rogue.moves_left--;
439 1.1 cgd break;
440 1.1 cgd }
441 1.1 cgd return(fainted);
442 1.1 cgd }
443 1.1 cgd
444 1.1 cgd boolean
445 1.1 cgd reg_move()
446 1.1 cgd {
447 1.1 cgd boolean fainted;
448 1.1 cgd
449 1.1 cgd if ((rogue.moves_left <= HUNGRY) || (cur_level >= max_level)) {
450 1.1 cgd fainted = check_hunger(0);
451 1.1 cgd } else {
452 1.1 cgd fainted = 0;
453 1.1 cgd }
454 1.1 cgd
455 1.1 cgd mv_mons();
456 1.1 cgd
457 1.1 cgd if (++m_moves >= 120) {
458 1.1 cgd m_moves = 0;
459 1.1 cgd wanderer();
460 1.1 cgd }
461 1.1 cgd if (halluc) {
462 1.1 cgd if (!(--halluc)) {
463 1.1 cgd unhallucinate();
464 1.1 cgd } else {
465 1.1 cgd hallucinate();
466 1.1 cgd }
467 1.1 cgd }
468 1.1 cgd if (blind) {
469 1.1 cgd if (!(--blind)) {
470 1.1 cgd unblind();
471 1.1 cgd }
472 1.1 cgd }
473 1.1 cgd if (confused) {
474 1.1 cgd if (!(--confused)) {
475 1.1 cgd unconfuse();
476 1.1 cgd }
477 1.1 cgd }
478 1.1 cgd if (bear_trap) {
479 1.1 cgd bear_trap--;
480 1.1 cgd }
481 1.1 cgd if (levitate) {
482 1.1 cgd if (!(--levitate)) {
483 1.1 cgd message("you float gently to the ground", 1);
484 1.1 cgd if (dungeon[rogue.row][rogue.col] & TRAP) {
485 1.1 cgd trap_player(rogue.row, rogue.col);
486 1.1 cgd }
487 1.1 cgd }
488 1.1 cgd }
489 1.1 cgd if (haste_self) {
490 1.1 cgd if (!(--haste_self)) {
491 1.1 cgd message("you feel yourself slowing down", 0);
492 1.1 cgd }
493 1.1 cgd }
494 1.1 cgd heal();
495 1.1 cgd if (auto_search > 0) {
496 1.1 cgd search(auto_search, auto_search);
497 1.1 cgd }
498 1.1 cgd return(fainted);
499 1.1 cgd }
500 1.1 cgd
501 1.4 lukem void
502 1.1 cgd rest(count)
503 1.4 lukem int count;
504 1.1 cgd {
505 1.1 cgd int i;
506 1.1 cgd
507 1.1 cgd interrupted = 0;
508 1.1 cgd
509 1.1 cgd for (i = 0; i < count; i++) {
510 1.1 cgd if (interrupted) {
511 1.1 cgd break;
512 1.1 cgd }
513 1.1 cgd (void) reg_move();
514 1.1 cgd }
515 1.1 cgd }
516 1.1 cgd
517 1.4 lukem char
518 1.1 cgd gr_dir()
519 1.1 cgd {
520 1.1 cgd short d;
521 1.1 cgd
522 1.1 cgd d = get_rand(1, 8);
523 1.1 cgd
524 1.1 cgd switch(d) {
525 1.1 cgd case 1:
526 1.1 cgd d = 'j';
527 1.1 cgd break;
528 1.1 cgd case 2:
529 1.1 cgd d = 'k';
530 1.1 cgd break;
531 1.1 cgd case 3:
532 1.1 cgd d = 'l';
533 1.1 cgd break;
534 1.1 cgd case 4:
535 1.1 cgd d = 'h';
536 1.1 cgd break;
537 1.1 cgd case 5:
538 1.1 cgd d = 'y';
539 1.1 cgd break;
540 1.1 cgd case 6:
541 1.1 cgd d = 'u';
542 1.1 cgd break;
543 1.1 cgd case 7:
544 1.1 cgd d = 'b';
545 1.1 cgd break;
546 1.1 cgd case 8:
547 1.1 cgd d = 'n';
548 1.1 cgd break;
549 1.1 cgd }
550 1.1 cgd return(d);
551 1.1 cgd }
552 1.1 cgd
553 1.4 lukem void
554 1.1 cgd heal()
555 1.1 cgd {
556 1.1 cgd static short heal_exp = -1, n, c = 0;
557 1.1 cgd static boolean alt;
558 1.1 cgd
559 1.1 cgd if (rogue.hp_current == rogue.hp_max) {
560 1.1 cgd c = 0;
561 1.1 cgd return;
562 1.1 cgd }
563 1.1 cgd if (rogue.exp != heal_exp) {
564 1.1 cgd heal_exp = rogue.exp;
565 1.1 cgd
566 1.1 cgd switch(heal_exp) {
567 1.1 cgd case 1:
568 1.1 cgd n = 20;
569 1.1 cgd break;
570 1.1 cgd case 2:
571 1.1 cgd n = 18;
572 1.1 cgd break;
573 1.1 cgd case 3:
574 1.1 cgd n = 17;
575 1.1 cgd break;
576 1.1 cgd case 4:
577 1.1 cgd n = 14;
578 1.1 cgd break;
579 1.1 cgd case 5:
580 1.1 cgd n = 13;
581 1.1 cgd break;
582 1.1 cgd case 6:
583 1.1 cgd n = 10;
584 1.1 cgd break;
585 1.1 cgd case 7:
586 1.1 cgd n = 9;
587 1.1 cgd break;
588 1.1 cgd case 8:
589 1.1 cgd n = 8;
590 1.1 cgd break;
591 1.1 cgd case 9:
592 1.1 cgd n = 7;
593 1.1 cgd break;
594 1.1 cgd case 10:
595 1.1 cgd n = 4;
596 1.1 cgd break;
597 1.1 cgd case 11:
598 1.1 cgd n = 3;
599 1.1 cgd break;
600 1.1 cgd case 12:
601 1.1 cgd default:
602 1.1 cgd n = 2;
603 1.1 cgd }
604 1.1 cgd }
605 1.1 cgd if (++c >= n) {
606 1.1 cgd c = 0;
607 1.1 cgd rogue.hp_current++;
608 1.4 lukem if ((alt = !alt) != 0) {
609 1.1 cgd rogue.hp_current++;
610 1.1 cgd }
611 1.1 cgd if ((rogue.hp_current += regeneration) > rogue.hp_max) {
612 1.1 cgd rogue.hp_current = rogue.hp_max;
613 1.1 cgd }
614 1.1 cgd print_stats(STAT_HP);
615 1.1 cgd }
616 1.1 cgd }
617 1.1 cgd
618 1.4 lukem boolean
619 1.1 cgd can_turn(nrow, ncol)
620 1.4 lukem short nrow, ncol;
621 1.1 cgd {
622 1.1 cgd if ((dungeon[nrow][ncol] & TUNNEL) && is_passable(nrow, ncol)) {
623 1.1 cgd return(1);
624 1.1 cgd }
625 1.1 cgd return(0);
626 1.1 cgd }
627 1.1 cgd
628 1.4 lukem void
629 1.1 cgd turn_passage(dir, fast)
630 1.4 lukem short dir;
631 1.4 lukem boolean fast;
632 1.1 cgd {
633 1.1 cgd short crow = rogue.row, ccol = rogue.col, turns = 0;
634 1.4 lukem short ndir = 0;
635 1.1 cgd
636 1.1 cgd if ((dir != 'h') && can_turn(crow, ccol + 1)) {
637 1.1 cgd turns++;
638 1.1 cgd ndir = 'l';
639 1.1 cgd }
640 1.1 cgd if ((dir != 'l') && can_turn(crow, ccol - 1)) {
641 1.1 cgd turns++;
642 1.1 cgd ndir = 'h';
643 1.1 cgd }
644 1.1 cgd if ((dir != 'k') && can_turn(crow + 1, ccol)) {
645 1.1 cgd turns++;
646 1.1 cgd ndir = 'j';
647 1.1 cgd }
648 1.1 cgd if ((dir != 'j') && can_turn(crow - 1, ccol)) {
649 1.1 cgd turns++;
650 1.1 cgd ndir = 'k';
651 1.1 cgd }
652 1.1 cgd if (turns == 1) {
653 1.1 cgd multiple_move_rogue(ndir - (fast ? 32 : 96));
654 1.1 cgd }
655 1.1 cgd }
656