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 $
39 * This source herein may be modified and/or distributed by anybody who
40 * so desires, with the following restrictions:
41 * 1.) No portion of this notice shall be removed.
42 * 2.) Credit shall not be taken for the creation of this source.
43 * 3.) This code is not to be traded, sold, or used for personal
52 const char you_can_move_again
[] = "you can move again";
54 static boolean
can_turn(short, short);
55 static boolean
check_hunger(boolean
);
56 static short gr_dir(void);
57 static void heal(void);
58 static boolean
next_to_something(int, int);
59 static void turn_passage(short, boolean
);
62 one_move_rogue(short dirch
, short pickup
)
75 is_direction(dirch
, &d
);
76 get_dir_rc(d
, &row
, &col
, 1);
78 if (!can_move(rogue
.row
, rogue
.col
, row
, col
)) {
81 if (being_held
|| bear_trap
) {
82 if (!(dungeon
[row
][col
] & MONSTER
)) {
84 message("you are being held", 1);
86 message("you are still stuck in the bear trap", 0);
93 if (rand_percent(R_TELE_PERCENT
)) {
95 return(STOPPED_ON_SOMETHING
);
98 if (dungeon
[row
][col
] & MONSTER
) {
99 rogue_hit(object_at(&level_monsters
, row
, col
), 0);
103 if (dungeon
[row
][col
] & DOOR
) {
104 if (cur_room
== PASSAGE
) {
105 cur_room
= get_room_number(row
, col
);
106 if (cur_room
== NO_ROOM
)
107 clean_up("one_move_rogue: door to nowhere");
108 light_up_room(cur_room
);
109 wake_room(cur_room
, 1, row
, col
);
111 light_passage(row
, col
);
113 } else if ((dungeon
[rogue
.row
][rogue
.col
] & DOOR
) &&
114 (dungeon
[row
][col
] & TUNNEL
)) {
115 light_passage(row
, col
);
116 wake_room(cur_room
, 0, rogue
.row
, rogue
.col
);
117 darken_room(cur_room
);
119 } else if (dungeon
[row
][col
] & TUNNEL
) {
120 light_passage(row
, col
);
122 mvaddch(rogue
.row
, rogue
.col
, get_dungeon_char(rogue
.row
, rogue
.col
));
123 mvaddch(row
, col
, rogue
.fchar
);
130 if (dungeon
[row
][col
] & OBJECT
) {
131 if (levitate
&& pickup
) {
132 return(STOPPED_ON_SOMETHING
);
134 if (pickup
&& !levitate
) {
135 if ((obj
= pick_up(row
, col
, &status
)) != NULL
) {
137 if (obj
->what_is
== GOLD
) {
141 } else if (!status
) {
148 obj
= object_at(&level_objects
, row
, col
);
149 strcpy(desc
, "moved onto ");
150 get_desc(obj
, desc
+11);
155 desc
[n
+1] = obj
->ichar
;
161 return(STOPPED_ON_SOMETHING
);
163 if (dungeon
[row
][col
] & (DOOR
| STAIRS
| TRAP
)) {
164 if ((!levitate
) && (dungeon
[row
][col
] & TRAP
)) {
165 trap_player(row
, col
);
168 return(STOPPED_ON_SOMETHING
);
170 MVED
: if (reg_move()) { /* fainted from hunger */
171 return(STOPPED_ON_SOMETHING
);
173 return((confused
? STOPPED_ON_SOMETHING
: MOVED
));
177 multiple_move_rogue(short dirch
)
194 if (((m
= one_move_rogue((dirch
+ 96), 1)) == MOVE_FAILED
) ||
195 (m
== STOPPED_ON_SOMETHING
) ||
199 } while (!next_to_something(row
, col
));
200 if ( (!interrupted
) && passgo
&& (m
== MOVE_FAILED
) &&
201 (dungeon
[rogue
.row
][rogue
.col
] & TUNNEL
)) {
202 turn_passage(dirch
+ 96, 0);
213 while ((!interrupted
) && (one_move_rogue((dirch
+ 32), 1) == MOVED
))
216 if ( (!interrupted
) && passgo
&&
217 (dungeon
[rogue
.row
][rogue
.col
] & TUNNEL
)) {
218 turn_passage(dirch
+ 32, 1);
225 is_passable(int row
, int col
)
227 if ((row
< MIN_ROW
) || (row
> (DROWS
- 2)) || (col
< 0) ||
231 if (dungeon
[row
][col
] & HIDDEN
) {
232 return((dungeon
[row
][col
] & TRAP
) ? 1 : 0);
234 return(dungeon
[row
][col
] & (FLOOR
| TUNNEL
| DOOR
| STAIRS
| TRAP
));
238 next_to_something(int drow
, int dcol
)
240 short i
, j
, i_end
, j_end
, row
, col
;
241 short pass_count
= 0;
250 i_end
= (rogue
.row
< (DROWS
-2)) ? 1 : 0;
251 j_end
= (rogue
.col
< (DCOLS
-1)) ? 1 : 0;
253 for (i
= ((rogue
.row
> MIN_ROW
) ? -1 : 0); i
<= i_end
; i
++) {
254 for (j
= ((rogue
.col
> 0) ? -1 : 0); j
<= j_end
; j
++) {
255 if ((i
== 0) && (j
== 0)) {
258 if (((rogue
.row
+i
) == drow
) && ((rogue
.col
+j
) == dcol
)) {
263 s
= dungeon
[row
][col
];
267 /* If the rogue used to be right, up, left, down, or right of
268 * row,col, and now isn't, then don't stop */
269 if (s
& (MONSTER
| OBJECT
| STAIRS
)) {
270 if (((row
== drow
) || (col
== dcol
)) &&
271 (!((row
== rogue
.row
) || (col
== rogue
.col
)))) {
278 if (((row
== drow
) || (col
== dcol
)) &&
279 (!((row
== rogue
.row
) || (col
== rogue
.col
)))) {
285 if ((((i
- j
) == 1) || ((i
- j
) == -1)) && (s
& TUNNEL
)) {
286 if (++pass_count
> 1) {
290 if ((s
& DOOR
) && ((i
== 0) || (j
== 0))) {
299 can_move(short row1
, short col1
, short row2
, short col2
)
301 if (!is_passable(row2
, col2
)) {
304 if ((row1
!= row2
) && (col1
!= col2
)) {
305 if ((dungeon
[row1
][col1
] & DOOR
) || (dungeon
[row2
][col2
] & DOOR
)) {
308 if ((!dungeon
[row1
][col2
]) || (!dungeon
[row2
][col1
])) {
319 boolean first_miss
= 1;
321 while (!is_direction(ch
= rgetchar(), &d
)) {
324 message("direction? ", 0);
330 one_move_rogue(ch
, 0);
335 is_direction(short c
, short *d
)
371 check_hunger(boolean msg_only
)
376 if (rogue
.moves_left
== HUNGRY
) {
377 strcpy(hunger_str
, "hungry");
378 message(hunger_str
, 0);
379 print_stats(STAT_HUNGER
);
381 if (rogue
.moves_left
== WEAK
) {
382 strcpy(hunger_str
, "weak");
383 message(hunger_str
, 1);
384 print_stats(STAT_HUNGER
);
386 if (rogue
.moves_left
<= FAINT
) {
387 if (rogue
.moves_left
== FAINT
) {
388 strcpy(hunger_str
, "faint");
389 message(hunger_str
, 1);
390 print_stats(STAT_HUNGER
);
392 n
= get_rand(0, (FAINT
- rogue
.moves_left
));
395 if (rand_percent(40)) {
398 message("you faint", 1);
399 for (i
= 0; i
< n
; i
++) {
404 message(you_can_move_again
, 1);
410 if (rogue
.moves_left
<= STARVE
) {
411 killed_by(NULL
, STARVATION
);
416 rogue
.moves_left
-= (rogue
.moves_left
% 2);
424 rogue
.moves_left
-= (rogue
.moves_left
% 2);
440 if ((rogue
.moves_left
<= HUNGRY
) || (cur_level
>= max_level
)) {
441 fainted
= check_hunger(0);
448 if (++m_moves
>= 120) {
474 message("you float gently to the ground", 1);
475 if (dungeon
[rogue
.row
][rogue
.col
] & TRAP
) {
476 trap_player(rogue
.row
, rogue
.col
);
481 if (!(--haste_self
)) {
482 message("you feel yourself slowing down", 0);
486 if (auto_search
> 0) {
487 search(auto_search
, auto_search
);
499 for (i
= 0; i
< count
; i
++) {
546 static short heal_exp
= -1, n
, c
= 0;
549 if (rogue
.hp_current
== rogue
.hp_max
) {
553 if (rogue
.exp
!= heal_exp
) {
554 heal_exp
= rogue
.exp
;
598 if ((alt
= !alt
) != 0) {
601 if ((rogue
.hp_current
+= regeneration
) > rogue
.hp_max
) {
602 rogue
.hp_current
= rogue
.hp_max
;
604 print_stats(STAT_HP
);
609 can_turn(short nrow
, short ncol
)
611 if ((dungeon
[nrow
][ncol
] & TUNNEL
) && is_passable(nrow
, ncol
)) {
618 turn_passage(short dir
, boolean fast
)
620 short crow
= rogue
.row
, ccol
= rogue
.col
, turns
= 0;
623 if ((dir
!= 'h') && can_turn(crow
, ccol
+ 1)) {
627 if ((dir
!= 'l') && can_turn(crow
, ccol
- 1)) {
631 if ((dir
!= 'k') && can_turn(crow
+ 1, ccol
)) {
635 if ((dir
!= 'j') && can_turn(crow
- 1, ccol
)) {
640 multiple_move_rogue(ndir
- (fast
? 32 : 96));