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