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