2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
44 * This source herein may be modified and/or distributed by anybody who
45 * so desires, with the following restrictions:
46 * 1.) No portion of this notice shall be removed.
47 * 2.) Credit shall not be taken for the creation of this source.
48 * 3.) This code is not to be traded, sold, or used for personal
57 char *you_can_move_again = "you can move again";
59 extern short cur_room, halluc, blind, levitate;
60 extern short cur_level, max_level;
61 extern short bear_trap, haste_self, confused;
62 extern short e_rings, regeneration, auto_search;
63 extern char hunger_str[];
64 extern boolean being_held, interrupted, r_teleport, passgo;
66 one_move_rogue(dirch, pickup)
80 (void) is_direction(dirch, &d);
81 get_dir_rc(d, &row, &col, 1);
83 if (!can_move(rogue.row, rogue.col, row, col)) {
86 if (being_held || bear_trap) {
87 if (!(dungeon[row][col] & MONSTER)) {
89 message("you are being held", 1);
91 message("you are still stuck in the bear trap", 0);
98 if (rand_percent(R_TELE_PERCENT)) {
100 return(STOPPED_ON_SOMETHING);
103 if (dungeon[row][col] & MONSTER) {
104 rogue_hit(object_at(&level_monsters, row, col), 0);
108 if (dungeon[row][col] & DOOR) {
109 if (cur_room == PASSAGE) {
110 cur_room = get_room_number(row, col);
111 light_up_room(cur_room);
112 wake_room(cur_room, 1, row, col);
114 light_passage(row, col);
116 } else if ((dungeon[rogue.row][rogue.col] & DOOR) &&
117 (dungeon[row][col] & TUNNEL)) {
118 light_passage(row, col);
119 wake_room(cur_room, 0, rogue.row, rogue.col);
120 darken_room(cur_room);
122 } else if (dungeon[row][col] & TUNNEL) {
123 light_passage(row, col);
125 mvaddch(rogue.row, rogue.col, get_dungeon_char(rogue.row, rogue.col));
126 mvaddch(row, col, rogue.fchar);
133 if (dungeon[row][col] & OBJECT) {
134 if (levitate && pickup) {
135 return(STOPPED_ON_SOMETHING);
137 if (pickup && !levitate) {
138 if (obj = pick_up(row, col, &status)) {
140 if (obj->what_is == GOLD) {
144 } else if (!status) {
151 obj = object_at(&level_objects, row, col);
152 (void) strcpy(desc, "moved onto ");
153 get_desc(obj, desc+11);
158 desc[n+1] = obj->ichar;
164 return(STOPPED_ON_SOMETHING);
166 if (dungeon[row][col] & (DOOR | STAIRS | TRAP)) {
167 if ((!levitate) && (dungeon[row][col] & TRAP)) {
168 trap_player(row, col);
171 return(STOPPED_ON_SOMETHING);
173 MVED: if (reg_move()) { /* fainted from hunger */
174 return(STOPPED_ON_SOMETHING);
176 return((confused ? STOPPED_ON_SOMETHING : MOVED));
179 multiple_move_rogue(dirch)
197 if (((m = one_move_rogue((dirch + 96), 1)) == MOVE_FAILED) ||
198 (m == STOPPED_ON_SOMETHING) ||
202 } while (!next_to_something(row, col));
203 if ( (!interrupted) && passgo && (m == MOVE_FAILED) &&
204 (dungeon[rogue.row][rogue.col] & TUNNEL)) {
205 turn_passage(dirch + 96, 0);
216 while ((!interrupted) && (one_move_rogue((dirch + 32), 1) == MOVED)) ;
218 if ( (!interrupted) && passgo &&
219 (dungeon[rogue.row][rogue.col] & TUNNEL)) {
220 turn_passage(dirch + 32, 1);
226 is_passable(row, col)
229 if ((row < MIN_ROW) || (row > (DROWS - 2)) || (col < 0) ||
233 if (dungeon[row][col] & HIDDEN) {
234 return((dungeon[row][col] & TRAP) ? 1 : 0);
236 return(dungeon[row][col] & (FLOOR | TUNNEL | DOOR | STAIRS | TRAP));
239 next_to_something(drow, dcol)
242 short i, j, i_end, j_end, row, col;
243 short pass_count = 0;
252 i_end = (rogue.row < (DROWS-2)) ? 1 : 0;
253 j_end = (rogue.col < (DCOLS-1)) ? 1 : 0;
255 for (i = ((rogue.row > MIN_ROW) ? -1 : 0); i <= i_end; i++) {
256 for (j = ((rogue.col > 0) ? -1 : 0); j <= j_end; j++) {
257 if ((i == 0) && (j == 0)) {
260 if (((rogue.row+i) == drow) && ((rogue.col+j) == dcol)) {
265 s = dungeon[row][col];
269 /* If the rogue used to be right, up, left, down, or right of
270 * row,col, and now isn't, then don't stop */
271 if (s & (MONSTER | OBJECT | STAIRS)) {
272 if (((row == drow) || (col == dcol)) &&
273 (!((row == rogue.row) || (col == rogue.col)))) {
280 if (((row == drow) || (col == dcol)) &&
281 (!((row == rogue.row) || (col == rogue.col)))) {
287 if ((((i - j) == 1) || ((i - j) == -1)) && (s & TUNNEL)) {
288 if (++pass_count > 1) {
292 if ((s & DOOR) && ((i == 0) || (j == 0))) {
300 can_move(row1, col1, row2, col2)
302 if (!is_passable(row2, col2)) {
305 if ((row1 != row2) && (col1 != col2)) {
306 if ((dungeon[row1][col1] & DOOR) || (dungeon[row2][col2] & DOOR)) {
309 if ((!dungeon[row1][col2]) || (!dungeon[row2][col1])) {
319 boolean first_miss = 1;
321 while (!is_direction(ch = rgetchar(), &d)) {
324 message("direction? ", 0);
330 (void) one_move_rogue(ch, 0);
373 check_hunger(msg_only)
379 if (rogue.moves_left == HUNGRY) {
380 (void) strcpy(hunger_str, "hungry");
381 message(hunger_str, 0);
382 print_stats(STAT_HUNGER);
384 if (rogue.moves_left == WEAK) {
385 (void) strcpy(hunger_str, "weak");
386 message(hunger_str, 1);
387 print_stats(STAT_HUNGER);
389 if (rogue.moves_left <= FAINT) {
390 if (rogue.moves_left == FAINT) {
391 (void) strcpy(hunger_str, "faint");
392 message(hunger_str, 1);
393 print_stats(STAT_HUNGER);
395 n = get_rand(0, (FAINT - rogue.moves_left));
398 if (rand_percent(40)) {
401 message("you faint", 1);
402 for (i = 0; i < n; i++) {
407 message(you_can_move_again, 1);
413 if (rogue.moves_left <= STARVE) {
414 killed_by((object *) 0, STARVATION);
419 Subtract 0, i.e. do nothing.
422 rogue.moves_left -= (rogue.moves_left % 2);
429 (void) check_hunger(1);
430 rogue.moves_left -= (rogue.moves_left % 2);
434 (void) check_hunger(1);
446 if ((rogue.moves_left <= HUNGRY) || (cur_level >= max_level)) {
447 fainted = check_hunger(0);
454 if (++m_moves >= 120) {
480 message("you float gently to the ground", 1);
481 if (dungeon[rogue.row][rogue.col] & TRAP) {
482 trap_player(rogue.row, rogue.col);
487 if (!(--haste_self)) {
488 message("you feel yourself slowing down", 0);
492 if (auto_search > 0) {
493 search(auto_search, auto_search);
504 for (i = 0; i < count; i++) {
549 static short heal_exp = -1, n, c = 0;
552 if (rogue.hp_current == rogue.hp_max) {
556 if (rogue.exp != heal_exp) {
557 heal_exp = rogue.exp;
604 if ((rogue.hp_current += regeneration) > rogue.hp_max) {
605 rogue.hp_current = rogue.hp_max;
607 print_stats(STAT_HP);
615 if ((dungeon[nrow][ncol] & TUNNEL) && is_passable(nrow, ncol)) {
621 turn_passage(dir, fast)
625 short crow = rogue.row, ccol = rogue.col, turns = 0;
628 if ((dir != 'h') && can_turn(crow, ccol + 1)) {
632 if ((dir != 'l') && can_turn(crow, ccol - 1)) {
636 if ((dir != 'k') && can_turn(crow + 1, ccol)) {
640 if ((dir != 'j') && can_turn(crow - 1, ccol)) {
645 multiple_move_rogue(ndir - (fast ? 32 : 96));