2 * Hero movement commands
4 * @(#)move.c 3.26 (Berkeley) 6/15/81
6 * Rogue: Exploring the Dungeons of Doom
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * See the file LICENSE.TXT for full copyright and licensing information.
18 * Used to hold the new hero position
25 * Start the hero running
38 * Check to see that a move is legal. If it is handle the
39 * consequences (fighting, picking up, etc.)
51 msg("You are still stuck in the bear trap");
55 * Do a confused move (maybe)
57 if (rnd(100) < 80 && on(player
, ISHUH
))
58 nh
= *rndmove(&player
);
66 * Check if he tried to move off the screen or make an illegal
67 * diagonal move, and stop him if he did.
69 if (nh
.x
< 0 || nh
.x
> COLS
-1 || nh
.y
< 0 || nh
.y
> LINES
- 1
70 || !diag_ok(&hero
, &nh
))
76 if (running
&& ce(hero
, nh
))
77 after
= running
= FALSE
;
78 ch
= winat(nh
.y
, nh
.x
);
79 if (on(player
, ISHELD
) && ch
!= 'F')
81 msg("You are being held");
90 after
= running
= FALSE
;
94 if (ch
== TRAPDOOR
|| ch
== TELTRAP
)
110 if (ch
== PASSAGE
&& winat(hero
.y
, hero
.x
) == DOOR
)
115 if (winat(hero
.y
, hero
.x
) == PASSAGE
)
118 else if (ch
== STAIRS
)
120 else if (isupper(ch
))
123 fight(&nh
, ch
, cur_weapon
, FALSE
);
126 ch
= winat(hero
.y
, hero
.x
);
127 wmove(cw
, unc(hero
));
130 wmove(cw
, unc(hero
));
136 * Called to illuminate a room.
137 * If it is dark, remove anything that might move.
143 register struct room
*rp
;
145 register char ch
, rch
;
146 register struct linked_list
*item
;
148 if ((rp
= roomin(cp
)) != NULL
&& !on(player
, ISBLIND
))
150 for (j
= 0; j
< rp
->r_max
.y
; j
++)
152 for (k
= 0; k
< rp
->r_max
.x
; k
++)
154 ch
= show(rp
->r_pos
.y
+ j
, rp
->r_pos
.x
+ k
);
155 wmove(cw
, rp
->r_pos
.y
+ j
, rp
->r_pos
.x
+ k
);
157 * Figure out how to display a secret door
159 if (ch
== SECRETDOOR
)
161 if (j
== 0 || j
== rp
->r_max
.y
- 1)
167 * If the room is a dark room, we might want to remove
168 * monsters and the like from it (since they might
173 item
= wake_monster(rp
->r_pos
.y
+j
, rp
->r_pos
.x
+k
);
174 if (((struct thing
*) ldata(item
))->t_oldch
== ' ')
175 if (!(rp
->r_flags
& ISDARK
))
176 ((struct thing
*) ldata(item
))->t_oldch
=
177 mvwinch(stdscr
, rp
->r_pos
.y
+j
, rp
->r_pos
.x
+k
);
179 if (rp
->r_flags
& ISDARK
)
181 rch
= mvwinch(cw
, rp
->r_pos
.y
+j
, rp
->r_pos
.x
+k
);
192 ch
= (on(player
, ISBLIND
) ? FLOOR
: ' ');
197 mvwaddch(cw
, rp
->r_pos
.y
+j
, rp
->r_pos
.x
+k
, ch
);
205 * returns what a certain thing will display as to the un-initiated
211 register char ch
= winat(y
, x
);
212 register struct linked_list
*it
;
213 register struct thing
*tp
;
216 return (trap_at(y
, x
)->tr_flags
& ISFOUND
) ? TRAP
: FLOOR
;
217 else if (ch
== 'M' || ch
== 'I')
219 if ((it
= find_mons(y
, x
)) == NULL
)
220 fatal("Can't find monster in show");
221 tp
= (struct thing
*) ldata(it
);
225 * Hide invisible monsters
227 else if (off(player
, CANSEE
))
228 ch
= mvwinch(stdscr
, y
, x
);
235 * The guy stepped on a trap.... Make him pay.
241 register struct trap
*tp
;
244 tp
= trap_at(tc
->y
, tc
->x
);
245 count
= running
= FALSE
;
246 mvwaddch(cw
, tp
->tr_pos
.y
, tp
->tr_pos
.x
, TRAP
);
247 tp
->tr_flags
|= ISFOUND
;
248 switch (ch
= tp
->tr_type
)
253 msg("You fell into a trap!");
256 msg("You are caught in a bear trap");
258 no_command
+= SLEEPTIME
;
259 msg("A strange white mist envelops you and you fall asleep");
261 if (swing(pstats
.s_lvl
-1, pstats
.s_arm
, 1))
263 msg("Oh no! An arrow shot you");
264 if ((pstats
.s_hpt
-= roll(1, 6)) <= 0)
266 msg("The arrow killed you.");
272 register struct linked_list
*item
;
273 register struct object
*arrow
;
275 msg("An arrow shoots past you.");
276 item
= new_item(sizeof *arrow
);
277 arrow
= (struct object
*) ldata(item
);
278 arrow
->o_type
= WEAPON
;
279 arrow
->o_which
= ARROW
;
280 init_weapon(arrow
, ARROW
);
283 arrow
->o_hplus
= arrow
->o_dplus
= 0; /* "arrow bug" FIX */
289 if (swing(pstats
.s_lvl
+1, pstats
.s_arm
, 1))
291 msg("A small dart just hit you in the shoulder");
292 if ((pstats
.s_hpt
-= roll(1, 4)) <= 0)
294 msg("The dart killed you.");
297 if (!ISWEARING(R_SUSTSTR
))
301 msg("A small dart whizzes by your ear and vanishes.");
303 flush_type(); /* flush typeahead */
309 * find the trap at (y,x) on screen.
316 register struct trap
*tp
, *ep
;
319 for (tp
= traps
; tp
< ep
; tp
++)
320 if (tp
->tr_pos
.y
== y
&& tp
->tr_pos
.x
== x
)
324 sprintf(prbuf
, "Trap at %d,%d not in array", y
, x
);
332 * move in a random direction if the monster/person is confused
341 register int ex
, ey
, nopen
= 0;
342 register struct linked_list
*item
;
343 register struct object
*obj
;
344 static coord ret
; /* what we will be returning */
349 * Now go through the spaces surrounding the player and
350 * set that place in the array to true if the space can be
355 for (y
= who
->t_pos
.y
- 1; y
<= ey
; y
++)
356 if (y
>= 0 && y
< LINES
)
357 for (x
= who
->t_pos
.x
- 1; x
<= ex
; x
++)
359 if (x
< 0 || x
>= COLS
)
366 if (!diag_ok(&who
->t_pos
, &dest
))
371 for (item
= lvl_obj
; item
!= NULL
; item
= next(item
))
373 obj
= (struct object
*) ldata(item
);
374 if (y
== obj
->o_pos
.y
&& x
== obj
->o_pos
.x
)
377 if (item
!= NULL
&& obj
->o_which
== S_SCARE
)
380 if (rnd(++nopen
) == 0)