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. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)move.c 8.1 (Berkeley) 5/31/93
33 * $FreeBSD: src/games/rogue/move.c,v 1.7 1999/11/30 03:49:24 billf Exp $
34 * $DragonFly: src/games/rogue/move.c,v 1.4 2006/09/02 19:31:07 pavalos Exp $
40 * This source herein may be modified and/or distributed by anybody who
41 * so desires, with the following restrictions:
42 * 1.) No portion of this notice shall be removed.
43 * 2.) Credit shall not be taken for the creation of this source.
44 * 3.) This code is not to be traded, sold, or used for personal
53 const char *you_can_move_again = "you can move again";
55 extern short cur_room, halluc, blind, levitate;
56 extern short cur_level, max_level;
57 extern short bear_trap, haste_self, confused;
58 extern short e_rings, regeneration, auto_search;
59 extern boolean being_held, interrupted, r_teleport, passgo;
61 static boolean can_turn(short, short);
62 static boolean check_hunger(boolean);
63 static short gr_dir(void);
64 static void heal(void);
65 static boolean next_to_something(int, int);
66 static void turn_passage(short, boolean);
69 one_move_rogue(short dirch, short pickup)
82 is_direction(dirch, &d);
83 get_dir_rc(d, &row, &col, 1);
85 if (!can_move(rogue.row, rogue.col, row, col)) {
88 if (being_held || bear_trap) {
89 if (!(dungeon[row][col] & MONSTER)) {
91 message("you are being held", 1);
93 message("you are still stuck in the bear trap", 0);
100 if (rand_percent(R_TELE_PERCENT)) {
102 return(STOPPED_ON_SOMETHING);
105 if (dungeon[row][col] & MONSTER) {
106 rogue_hit(object_at(&level_monsters, row, col), 0);
110 if (dungeon[row][col] & DOOR) {
111 if (cur_room == PASSAGE) {
112 cur_room = get_room_number(row, col);
113 light_up_room(cur_room);
114 wake_room(cur_room, 1, row, col);
116 light_passage(row, col);
118 } else if ((dungeon[rogue.row][rogue.col] & DOOR) &&
119 (dungeon[row][col] & TUNNEL)) {
120 light_passage(row, col);
121 wake_room(cur_room, 0, rogue.row, rogue.col);
122 darken_room(cur_room);
124 } else if (dungeon[row][col] & TUNNEL) {
125 light_passage(row, col);
127 mvaddch(rogue.row, rogue.col, get_dungeon_char(rogue.row, rogue.col));
128 mvaddch(row, col, rogue.fchar);
135 if (dungeon[row][col] & OBJECT) {
136 if (levitate && pickup) {
137 return(STOPPED_ON_SOMETHING);
139 if (pickup && !levitate) {
140 if ((obj = pick_up(row, col, &status)) != NULL) {
142 if (obj->what_is == GOLD) {
146 } else if (!status) {
153 obj = object_at(&level_objects, row, col);
154 strcpy(desc, "moved onto ");
155 get_desc(obj, desc+11);
160 desc[n+1] = obj->ichar;
166 return(STOPPED_ON_SOMETHING);
168 if (dungeon[row][col] & (DOOR | STAIRS | TRAP)) {
169 if ((!levitate) && (dungeon[row][col] & TRAP)) {
170 trap_player(row, col);
173 return(STOPPED_ON_SOMETHING);
175 MVED: if (reg_move()) { /* fainted from hunger */
176 return(STOPPED_ON_SOMETHING);
178 return((confused ? STOPPED_ON_SOMETHING : MOVED));
182 multiple_move_rogue(short dirch)
199 if (((m = one_move_rogue((dirch + 96), 1)) == MOVE_FAILED) ||
200 (m == STOPPED_ON_SOMETHING) ||
204 } while (!next_to_something(row, col));
205 if ( (!interrupted) && passgo && (m == MOVE_FAILED) &&
206 (dungeon[rogue.row][rogue.col] & TUNNEL)) {
207 turn_passage(dirch + 96, 0);
218 while ((!interrupted) && (one_move_rogue((dirch + 32), 1) == MOVED))
221 if ( (!interrupted) && passgo &&
222 (dungeon[rogue.row][rogue.col] & TUNNEL)) {
223 turn_passage(dirch + 32, 1);
230 is_passable(int row, int col)
232 if ((row < MIN_ROW) || (row > (DROWS - 2)) || (col < 0) ||
236 if (dungeon[row][col] & HIDDEN) {
237 return((dungeon[row][col] & TRAP) ? 1 : 0);
239 return(dungeon[row][col] & (FLOOR | TUNNEL | DOOR | STAIRS | TRAP));
243 next_to_something(int drow, int dcol)
245 short i, j, i_end, j_end, row, col;
246 short pass_count = 0;
255 i_end = (rogue.row < (DROWS-2)) ? 1 : 0;
256 j_end = (rogue.col < (DCOLS-1)) ? 1 : 0;
258 for (i = ((rogue.row > MIN_ROW) ? -1 : 0); i <= i_end; i++) {
259 for (j = ((rogue.col > 0) ? -1 : 0); j <= j_end; j++) {
260 if ((i == 0) && (j == 0)) {
263 if (((rogue.row+i) == drow) && ((rogue.col+j) == dcol)) {
268 s = dungeon[row][col];
272 /* If the rogue used to be right, up, left, down, or right of
273 * row,col, and now isn't, then don't stop */
274 if (s & (MONSTER | OBJECT | STAIRS)) {
275 if (((row == drow) || (col == dcol)) &&
276 (!((row == rogue.row) || (col == rogue.col)))) {
283 if (((row == drow) || (col == dcol)) &&
284 (!((row == rogue.row) || (col == rogue.col)))) {
290 if ((((i - j) == 1) || ((i - j) == -1)) && (s & TUNNEL)) {
291 if (++pass_count > 1) {
295 if ((s & DOOR) && ((i == 0) || (j == 0))) {
304 can_move(short row1, short col1, short row2, short col2)
306 if (!is_passable(row2, col2)) {
309 if ((row1 != row2) && (col1 != col2)) {
310 if ((dungeon[row1][col1] & DOOR) || (dungeon[row2][col2] & DOOR)) {
313 if ((!dungeon[row1][col2]) || (!dungeon[row2][col1])) {
324 boolean first_miss = 1;
326 while (!is_direction(ch = rgetchar(), &d)) {
329 message("direction? ", 0);
335 one_move_rogue(ch, 0);
340 is_direction(short c, short *d)
376 check_hunger(boolean msg_only)
381 if (rogue.moves_left == HUNGRY) {
382 strcpy(hunger_str, "hungry");
383 message(hunger_str, 0);
384 print_stats(STAT_HUNGER);
386 if (rogue.moves_left == WEAK) {
387 strcpy(hunger_str, "weak");
388 message(hunger_str, 1);
389 print_stats(STAT_HUNGER);
391 if (rogue.moves_left <= FAINT) {
392 if (rogue.moves_left == FAINT) {
393 strcpy(hunger_str, "faint");
394 message(hunger_str, 1);
395 print_stats(STAT_HUNGER);
397 n = get_rand(0, (FAINT - rogue.moves_left));
400 if (rand_percent(40)) {
403 message("you faint", 1);
404 for (i = 0; i < n; i++) {
409 message(you_can_move_again, 1);
415 if (rogue.moves_left <= STARVE) {
416 killed_by(NULL, STARVATION);
421 rogue.moves_left -= (rogue.moves_left % 2);
429 rogue.moves_left -= (rogue.moves_left % 2);
445 if ((rogue.moves_left <= HUNGRY) || (cur_level >= max_level)) {
446 fainted = check_hunger(0);
453 if (++m_moves >= 120) {
479 message("you float gently to the ground", 1);
480 if (dungeon[rogue.row][rogue.col] & TRAP) {
481 trap_player(rogue.row, rogue.col);
486 if (!(--haste_self)) {
487 message("you feel yourself slowing down", 0);
491 if (auto_search > 0) {
492 search(auto_search, auto_search);
504 for (i = 0; i < count; i++) {
551 static short heal_exp = -1, n, c = 0;
554 if (rogue.hp_current == rogue.hp_max) {
558 if (rogue.exp != heal_exp) {
559 heal_exp = rogue.exp;
603 if ((alt = !alt) != 0) {
606 if ((rogue.hp_current += regeneration) > rogue.hp_max) {
607 rogue.hp_current = rogue.hp_max;
609 print_stats(STAT_HP);
614 can_turn(short nrow, short ncol)
616 if ((dungeon[nrow][ncol] & TUNNEL) && is_passable(nrow, ncol)) {
623 turn_passage(short dir, boolean 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));