move.c revision 1.10 1 1.10 dholland /* $NetBSD: move.c,v 1.10 2008/01/14 00:23:52 dholland 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.10 dholland __RCSID("$NetBSD: move.c,v 1.10 2008/01/14 00:23:52 dholland 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.9 dholland short status, d = 0; /* XXX: GCC */
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.10 dholland (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.9 dholland messagef(1, "you are being held");
87 1.1 cgd } else {
88 1.9 dholland messagef(0, "you are still stuck in the bear trap");
89 1.10 dholland (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.10 dholland (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.7 jnemeth if (cur_room == NO_ROOM)
109 1.7 jnemeth clean_up("one_move_rogue: door to nowhere");
110 1.1 cgd light_up_room(cur_room);
111 1.1 cgd wake_room(cur_room, 1, row, col);
112 1.1 cgd } else {
113 1.1 cgd light_passage(row, col);
114 1.1 cgd }
115 1.1 cgd } else if ((dungeon[rogue.row][rogue.col] & DOOR) &&
116 1.1 cgd (dungeon[row][col] & TUNNEL)) {
117 1.1 cgd light_passage(row, col);
118 1.1 cgd wake_room(cur_room, 0, rogue.row, rogue.col);
119 1.1 cgd darken_room(cur_room);
120 1.1 cgd cur_room = PASSAGE;
121 1.1 cgd } else if (dungeon[row][col] & TUNNEL) {
122 1.1 cgd light_passage(row, col);
123 1.1 cgd }
124 1.1 cgd mvaddch(rogue.row, rogue.col, get_dungeon_char(rogue.row, rogue.col));
125 1.1 cgd mvaddch(row, col, rogue.fchar);
126 1.1 cgd
127 1.1 cgd if (!jump) {
128 1.1 cgd refresh();
129 1.1 cgd }
130 1.1 cgd rogue.row = row;
131 1.1 cgd rogue.col = col;
132 1.1 cgd if (dungeon[row][col] & OBJECT) {
133 1.1 cgd if (levitate && pickup) {
134 1.1 cgd return(STOPPED_ON_SOMETHING);
135 1.1 cgd }
136 1.1 cgd if (pickup && !levitate) {
137 1.4 lukem if ((obj = pick_up(row, col, &status)) != NULL) {
138 1.9 dholland get_desc(obj, desc, sizeof(desc));
139 1.1 cgd if (obj->what_is == GOLD) {
140 1.1 cgd free_object(obj);
141 1.9 dholland messagef(1, "%s", desc);
142 1.1 cgd goto NOT_IN_PACK;
143 1.1 cgd }
144 1.1 cgd } else if (!status) {
145 1.1 cgd goto MVED;
146 1.1 cgd } else {
147 1.1 cgd goto MOVE_ON;
148 1.1 cgd }
149 1.1 cgd } else {
150 1.1 cgd MOVE_ON:
151 1.1 cgd obj = object_at(&level_objects, row, col);
152 1.9 dholland get_desc(obj, desc, sizeof(desc));
153 1.9 dholland messagef(1, "moved onto %s", desc);
154 1.1 cgd goto NOT_IN_PACK;
155 1.1 cgd }
156 1.9 dholland messagef(1, "%s(%c)", desc, obj->ichar);
157 1.1 cgd NOT_IN_PACK:
158 1.10 dholland (void)reg_move();
159 1.1 cgd return(STOPPED_ON_SOMETHING);
160 1.1 cgd }
161 1.1 cgd if (dungeon[row][col] & (DOOR | STAIRS | TRAP)) {
162 1.1 cgd if ((!levitate) && (dungeon[row][col] & TRAP)) {
163 1.1 cgd trap_player(row, col);
164 1.1 cgd }
165 1.10 dholland (void)reg_move();
166 1.1 cgd return(STOPPED_ON_SOMETHING);
167 1.1 cgd }
168 1.1 cgd MVED: if (reg_move()) { /* fainted from hunger */
169 1.1 cgd return(STOPPED_ON_SOMETHING);
170 1.1 cgd }
171 1.1 cgd return((confused ? STOPPED_ON_SOMETHING : MOVED));
172 1.1 cgd }
173 1.1 cgd
174 1.4 lukem void
175 1.1 cgd multiple_move_rogue(dirch)
176 1.4 lukem short dirch;
177 1.1 cgd {
178 1.1 cgd short row, col;
179 1.1 cgd short m;
180 1.1 cgd
181 1.1 cgd switch(dirch) {
182 1.1 cgd case '\010':
183 1.1 cgd case '\012':
184 1.1 cgd case '\013':
185 1.1 cgd case '\014':
186 1.1 cgd case '\031':
187 1.1 cgd case '\025':
188 1.1 cgd case '\016':
189 1.1 cgd case '\002':
190 1.1 cgd do {
191 1.1 cgd row = rogue.row;
192 1.1 cgd col = rogue.col;
193 1.1 cgd if (((m = one_move_rogue((dirch + 96), 1)) == MOVE_FAILED) ||
194 1.1 cgd (m == STOPPED_ON_SOMETHING) ||
195 1.1 cgd interrupted) {
196 1.1 cgd break;
197 1.1 cgd }
198 1.1 cgd } while (!next_to_something(row, col));
199 1.1 cgd if ( (!interrupted) && passgo && (m == MOVE_FAILED) &&
200 1.1 cgd (dungeon[rogue.row][rogue.col] & TUNNEL)) {
201 1.1 cgd turn_passage(dirch + 96, 0);
202 1.1 cgd }
203 1.1 cgd break;
204 1.1 cgd case 'H':
205 1.1 cgd case 'J':
206 1.1 cgd case 'K':
207 1.1 cgd case 'L':
208 1.1 cgd case 'B':
209 1.1 cgd case 'Y':
210 1.1 cgd case 'U':
211 1.1 cgd case 'N':
212 1.10 dholland while ((!interrupted) && (one_move_rogue((dirch + 32), 1) == MOVED))
213 1.10 dholland ;
214 1.1 cgd
215 1.1 cgd if ( (!interrupted) && passgo &&
216 1.1 cgd (dungeon[rogue.row][rogue.col] & TUNNEL)) {
217 1.1 cgd turn_passage(dirch + 32, 1);
218 1.1 cgd }
219 1.1 cgd break;
220 1.1 cgd }
221 1.1 cgd }
222 1.1 cgd
223 1.4 lukem boolean
224 1.1 cgd is_passable(row, col)
225 1.4 lukem int row, col;
226 1.1 cgd {
227 1.1 cgd if ((row < MIN_ROW) || (row > (DROWS - 2)) || (col < 0) ||
228 1.1 cgd (col > (DCOLS-1))) {
229 1.1 cgd return(0);
230 1.1 cgd }
231 1.1 cgd if (dungeon[row][col] & HIDDEN) {
232 1.1 cgd return((dungeon[row][col] & TRAP) ? 1 : 0);
233 1.1 cgd }
234 1.1 cgd return(dungeon[row][col] & (FLOOR | TUNNEL | DOOR | STAIRS | TRAP));
235 1.1 cgd }
236 1.1 cgd
237 1.4 lukem boolean
238 1.1 cgd next_to_something(drow, dcol)
239 1.4 lukem int drow, dcol;
240 1.1 cgd {
241 1.1 cgd short i, j, i_end, j_end, row, col;
242 1.1 cgd short pass_count = 0;
243 1.1 cgd unsigned short s;
244 1.1 cgd
245 1.1 cgd if (confused) {
246 1.1 cgd return(1);
247 1.1 cgd }
248 1.1 cgd if (blind) {
249 1.1 cgd return(0);
250 1.1 cgd }
251 1.1 cgd i_end = (rogue.row < (DROWS-2)) ? 1 : 0;
252 1.1 cgd j_end = (rogue.col < (DCOLS-1)) ? 1 : 0;
253 1.1 cgd
254 1.1 cgd for (i = ((rogue.row > MIN_ROW) ? -1 : 0); i <= i_end; i++) {
255 1.1 cgd for (j = ((rogue.col > 0) ? -1 : 0); j <= j_end; j++) {
256 1.1 cgd if ((i == 0) && (j == 0)) {
257 1.1 cgd continue;
258 1.1 cgd }
259 1.1 cgd if (((rogue.row+i) == drow) && ((rogue.col+j) == dcol)) {
260 1.1 cgd continue;
261 1.1 cgd }
262 1.1 cgd row = rogue.row + i;
263 1.1 cgd col = rogue.col + j;
264 1.1 cgd s = dungeon[row][col];
265 1.1 cgd if (s & HIDDEN) {
266 1.1 cgd continue;
267 1.1 cgd }
268 1.1 cgd /* If the rogue used to be right, up, left, down, or right of
269 1.1 cgd * row,col, and now isn't, then don't stop */
270 1.1 cgd if (s & (MONSTER | OBJECT | STAIRS)) {
271 1.1 cgd if (((row == drow) || (col == dcol)) &&
272 1.1 cgd (!((row == rogue.row) || (col == rogue.col)))) {
273 1.1 cgd continue;
274 1.1 cgd }
275 1.1 cgd return(1);
276 1.1 cgd }
277 1.1 cgd if (s & TRAP) {
278 1.1 cgd if (!(s & HIDDEN)) {
279 1.1 cgd if (((row == drow) || (col == dcol)) &&
280 1.1 cgd (!((row == rogue.row) || (col == rogue.col)))) {
281 1.1 cgd continue;
282 1.1 cgd }
283 1.1 cgd return(1);
284 1.1 cgd }
285 1.1 cgd }
286 1.1 cgd if ((((i - j) == 1) || ((i - j) == -1)) && (s & TUNNEL)) {
287 1.1 cgd if (++pass_count > 1) {
288 1.1 cgd return(1);
289 1.1 cgd }
290 1.1 cgd }
291 1.1 cgd if ((s & DOOR) && ((i == 0) || (j == 0))) {
292 1.1 cgd return(1);
293 1.1 cgd }
294 1.1 cgd }
295 1.1 cgd }
296 1.1 cgd return(0);
297 1.1 cgd }
298 1.1 cgd
299 1.4 lukem boolean
300 1.10 dholland can_move(row1, col1, row2, col2)
301 1.4 lukem int row1, col1, row2, col2;
302 1.1 cgd {
303 1.1 cgd if (!is_passable(row2, col2)) {
304 1.1 cgd return(0);
305 1.1 cgd }
306 1.1 cgd if ((row1 != row2) && (col1 != col2)) {
307 1.1 cgd if ((dungeon[row1][col1] & DOOR) || (dungeon[row2][col2] & DOOR)) {
308 1.1 cgd return(0);
309 1.1 cgd }
310 1.1 cgd if ((!dungeon[row1][col2]) || (!dungeon[row2][col1])) {
311 1.1 cgd return(0);
312 1.1 cgd }
313 1.1 cgd }
314 1.1 cgd return(1);
315 1.1 cgd }
316 1.1 cgd
317 1.4 lukem void
318 1.1 cgd move_onto()
319 1.1 cgd {
320 1.1 cgd short ch, d;
321 1.1 cgd boolean first_miss = 1;
322 1.1 cgd
323 1.1 cgd while (!is_direction(ch = rgetchar(), &d)) {
324 1.1 cgd sound_bell();
325 1.1 cgd if (first_miss) {
326 1.9 dholland messagef(0, "direction? ");
327 1.1 cgd first_miss = 0;
328 1.1 cgd }
329 1.1 cgd }
330 1.1 cgd check_message();
331 1.1 cgd if (ch != CANCEL) {
332 1.10 dholland (void)one_move_rogue(ch, 0);
333 1.1 cgd }
334 1.1 cgd }
335 1.1 cgd
336 1.1 cgd boolean
337 1.1 cgd is_direction(c, d)
338 1.4 lukem short c;
339 1.4 lukem short *d;
340 1.1 cgd {
341 1.1 cgd switch(c) {
342 1.1 cgd case 'h':
343 1.1 cgd *d = LEFT;
344 1.1 cgd break;
345 1.1 cgd case 'j':
346 1.1 cgd *d = DOWN;
347 1.1 cgd break;
348 1.1 cgd case 'k':
349 1.1 cgd *d = UPWARD;
350 1.1 cgd break;
351 1.1 cgd case 'l':
352 1.1 cgd *d = RIGHT;
353 1.1 cgd break;
354 1.1 cgd case 'b':
355 1.1 cgd *d = DOWNLEFT;
356 1.1 cgd break;
357 1.1 cgd case 'y':
358 1.1 cgd *d = UPLEFT;
359 1.1 cgd break;
360 1.1 cgd case 'u':
361 1.1 cgd *d = UPRIGHT;
362 1.1 cgd break;
363 1.1 cgd case 'n':
364 1.1 cgd *d = DOWNRIGHT;
365 1.1 cgd break;
366 1.1 cgd case CANCEL:
367 1.1 cgd break;
368 1.1 cgd default:
369 1.1 cgd return(0);
370 1.1 cgd }
371 1.1 cgd return(1);
372 1.1 cgd }
373 1.1 cgd
374 1.1 cgd boolean
375 1.1 cgd check_hunger(msg_only)
376 1.4 lukem boolean msg_only;
377 1.1 cgd {
378 1.4 lukem short i, n;
379 1.1 cgd boolean fainted = 0;
380 1.1 cgd
381 1.1 cgd if (rogue.moves_left == HUNGRY) {
382 1.10 dholland (void)strlcpy(hunger_str, "hungry", sizeof(hunger_str));
383 1.9 dholland messagef(0, "%s", hunger_str);
384 1.1 cgd print_stats(STAT_HUNGER);
385 1.1 cgd }
386 1.1 cgd if (rogue.moves_left == WEAK) {
387 1.10 dholland (void)strlcpy(hunger_str, "weak", sizeof(hunger_str));
388 1.9 dholland messagef(1, "%s", hunger_str);
389 1.1 cgd print_stats(STAT_HUNGER);
390 1.1 cgd }
391 1.1 cgd if (rogue.moves_left <= FAINT) {
392 1.1 cgd if (rogue.moves_left == FAINT) {
393 1.10 dholland (void)strlcpy(hunger_str, "faint", sizeof(hunger_str));
394 1.9 dholland messagef(1, "%s", hunger_str);
395 1.1 cgd print_stats(STAT_HUNGER);
396 1.1 cgd }
397 1.1 cgd n = get_rand(0, (FAINT - rogue.moves_left));
398 1.1 cgd if (n > 0) {
399 1.1 cgd fainted = 1;
400 1.1 cgd if (rand_percent(40)) {
401 1.1 cgd rogue.moves_left++;
402 1.1 cgd }
403 1.9 dholland messagef(1, "you faint");
404 1.1 cgd for (i = 0; i < n; i++) {
405 1.1 cgd if (coin_toss()) {
406 1.1 cgd mv_mons();
407 1.1 cgd }
408 1.1 cgd }
409 1.9 dholland messagef(1, you_can_move_again);
410 1.1 cgd }
411 1.1 cgd }
412 1.1 cgd if (msg_only) {
413 1.1 cgd return(fainted);
414 1.1 cgd }
415 1.1 cgd if (rogue.moves_left <= STARVE) {
416 1.10 dholland killed_by((object *)0, STARVATION);
417 1.1 cgd }
418 1.1 cgd
419 1.1 cgd switch(e_rings) {
420 1.1 cgd /*case -2:
421 1.1 cgd Subtract 0, i.e. do nothing.
422 1.1 cgd break;*/
423 1.1 cgd case -1:
424 1.1 cgd rogue.moves_left -= (rogue.moves_left % 2);
425 1.1 cgd break;
426 1.1 cgd case 0:
427 1.1 cgd rogue.moves_left--;
428 1.1 cgd break;
429 1.1 cgd case 1:
430 1.1 cgd rogue.moves_left--;
431 1.10 dholland (void)check_hunger(1);
432 1.1 cgd rogue.moves_left -= (rogue.moves_left % 2);
433 1.1 cgd break;
434 1.1 cgd case 2:
435 1.1 cgd rogue.moves_left--;
436 1.10 dholland (void)check_hunger(1);
437 1.1 cgd rogue.moves_left--;
438 1.1 cgd break;
439 1.1 cgd }
440 1.1 cgd return(fainted);
441 1.1 cgd }
442 1.1 cgd
443 1.1 cgd boolean
444 1.1 cgd reg_move()
445 1.1 cgd {
446 1.1 cgd boolean fainted;
447 1.1 cgd
448 1.1 cgd if ((rogue.moves_left <= HUNGRY) || (cur_level >= max_level)) {
449 1.1 cgd fainted = check_hunger(0);
450 1.1 cgd } else {
451 1.1 cgd fainted = 0;
452 1.1 cgd }
453 1.1 cgd
454 1.1 cgd mv_mons();
455 1.1 cgd
456 1.1 cgd if (++m_moves >= 120) {
457 1.1 cgd m_moves = 0;
458 1.1 cgd wanderer();
459 1.1 cgd }
460 1.1 cgd if (halluc) {
461 1.1 cgd if (!(--halluc)) {
462 1.1 cgd unhallucinate();
463 1.1 cgd } else {
464 1.1 cgd hallucinate();
465 1.1 cgd }
466 1.1 cgd }
467 1.1 cgd if (blind) {
468 1.1 cgd if (!(--blind)) {
469 1.1 cgd unblind();
470 1.1 cgd }
471 1.1 cgd }
472 1.1 cgd if (confused) {
473 1.1 cgd if (!(--confused)) {
474 1.1 cgd unconfuse();
475 1.1 cgd }
476 1.1 cgd }
477 1.1 cgd if (bear_trap) {
478 1.1 cgd bear_trap--;
479 1.1 cgd }
480 1.1 cgd if (levitate) {
481 1.1 cgd if (!(--levitate)) {
482 1.9 dholland messagef(1, "you float gently to the ground");
483 1.1 cgd if (dungeon[rogue.row][rogue.col] & TRAP) {
484 1.1 cgd trap_player(rogue.row, rogue.col);
485 1.1 cgd }
486 1.1 cgd }
487 1.1 cgd }
488 1.1 cgd if (haste_self) {
489 1.1 cgd if (!(--haste_self)) {
490 1.9 dholland messagef(0, "you feel yourself slowing down");
491 1.1 cgd }
492 1.1 cgd }
493 1.1 cgd heal();
494 1.1 cgd if (auto_search > 0) {
495 1.1 cgd search(auto_search, auto_search);
496 1.1 cgd }
497 1.1 cgd return(fainted);
498 1.1 cgd }
499 1.1 cgd
500 1.4 lukem void
501 1.1 cgd rest(count)
502 1.4 lukem int count;
503 1.1 cgd {
504 1.1 cgd int i;
505 1.1 cgd
506 1.1 cgd interrupted = 0;
507 1.1 cgd
508 1.1 cgd for (i = 0; i < count; i++) {
509 1.1 cgd if (interrupted) {
510 1.1 cgd break;
511 1.1 cgd }
512 1.10 dholland (void)reg_move();
513 1.1 cgd }
514 1.1 cgd }
515 1.1 cgd
516 1.4 lukem char
517 1.1 cgd gr_dir()
518 1.1 cgd {
519 1.1 cgd short d;
520 1.1 cgd
521 1.1 cgd d = get_rand(1, 8);
522 1.1 cgd
523 1.1 cgd switch(d) {
524 1.1 cgd case 1:
525 1.1 cgd d = 'j';
526 1.1 cgd break;
527 1.1 cgd case 2:
528 1.1 cgd d = 'k';
529 1.1 cgd break;
530 1.1 cgd case 3:
531 1.1 cgd d = 'l';
532 1.1 cgd break;
533 1.1 cgd case 4:
534 1.1 cgd d = 'h';
535 1.1 cgd break;
536 1.1 cgd case 5:
537 1.1 cgd d = 'y';
538 1.1 cgd break;
539 1.1 cgd case 6:
540 1.1 cgd d = 'u';
541 1.1 cgd break;
542 1.1 cgd case 7:
543 1.1 cgd d = 'b';
544 1.1 cgd break;
545 1.1 cgd case 8:
546 1.1 cgd d = 'n';
547 1.1 cgd break;
548 1.1 cgd }
549 1.1 cgd return(d);
550 1.1 cgd }
551 1.1 cgd
552 1.4 lukem void
553 1.1 cgd heal()
554 1.1 cgd {
555 1.1 cgd static short heal_exp = -1, n, c = 0;
556 1.1 cgd static boolean alt;
557 1.1 cgd
558 1.1 cgd if (rogue.hp_current == rogue.hp_max) {
559 1.1 cgd c = 0;
560 1.1 cgd return;
561 1.1 cgd }
562 1.1 cgd if (rogue.exp != heal_exp) {
563 1.1 cgd heal_exp = rogue.exp;
564 1.1 cgd
565 1.1 cgd switch(heal_exp) {
566 1.1 cgd case 1:
567 1.1 cgd n = 20;
568 1.1 cgd break;
569 1.1 cgd case 2:
570 1.1 cgd n = 18;
571 1.1 cgd break;
572 1.1 cgd case 3:
573 1.1 cgd n = 17;
574 1.1 cgd break;
575 1.1 cgd case 4:
576 1.1 cgd n = 14;
577 1.1 cgd break;
578 1.1 cgd case 5:
579 1.1 cgd n = 13;
580 1.1 cgd break;
581 1.1 cgd case 6:
582 1.1 cgd n = 10;
583 1.1 cgd break;
584 1.1 cgd case 7:
585 1.1 cgd n = 9;
586 1.1 cgd break;
587 1.1 cgd case 8:
588 1.1 cgd n = 8;
589 1.1 cgd break;
590 1.1 cgd case 9:
591 1.1 cgd n = 7;
592 1.1 cgd break;
593 1.1 cgd case 10:
594 1.1 cgd n = 4;
595 1.1 cgd break;
596 1.1 cgd case 11:
597 1.1 cgd n = 3;
598 1.1 cgd break;
599 1.1 cgd case 12:
600 1.1 cgd default:
601 1.1 cgd n = 2;
602 1.1 cgd }
603 1.1 cgd }
604 1.1 cgd if (++c >= n) {
605 1.1 cgd c = 0;
606 1.1 cgd rogue.hp_current++;
607 1.4 lukem if ((alt = !alt) != 0) {
608 1.1 cgd rogue.hp_current++;
609 1.1 cgd }
610 1.1 cgd if ((rogue.hp_current += regeneration) > rogue.hp_max) {
611 1.1 cgd rogue.hp_current = rogue.hp_max;
612 1.1 cgd }
613 1.1 cgd print_stats(STAT_HP);
614 1.1 cgd }
615 1.1 cgd }
616 1.1 cgd
617 1.4 lukem boolean
618 1.1 cgd can_turn(nrow, ncol)
619 1.4 lukem short nrow, ncol;
620 1.1 cgd {
621 1.1 cgd if ((dungeon[nrow][ncol] & TUNNEL) && is_passable(nrow, ncol)) {
622 1.1 cgd return(1);
623 1.1 cgd }
624 1.1 cgd return(0);
625 1.1 cgd }
626 1.1 cgd
627 1.4 lukem void
628 1.1 cgd turn_passage(dir, fast)
629 1.4 lukem short dir;
630 1.4 lukem boolean fast;
631 1.1 cgd {
632 1.1 cgd short crow = rogue.row, ccol = rogue.col, turns = 0;
633 1.4 lukem short ndir = 0;
634 1.1 cgd
635 1.1 cgd if ((dir != 'h') && can_turn(crow, ccol + 1)) {
636 1.1 cgd turns++;
637 1.1 cgd ndir = 'l';
638 1.1 cgd }
639 1.1 cgd if ((dir != 'l') && can_turn(crow, ccol - 1)) {
640 1.1 cgd turns++;
641 1.1 cgd ndir = 'h';
642 1.1 cgd }
643 1.1 cgd if ((dir != 'k') && can_turn(crow + 1, ccol)) {
644 1.1 cgd turns++;
645 1.1 cgd ndir = 'j';
646 1.1 cgd }
647 1.1 cgd if ((dir != 'j') && can_turn(crow - 1, ccol)) {
648 1.1 cgd turns++;
649 1.1 cgd ndir = 'k';
650 1.1 cgd }
651 1.1 cgd if (turns == 1) {
652 1.1 cgd multiple_move_rogue(ndir - (fast ? 32 : 96));
653 1.1 cgd }
654 1.1 cgd }
655