Mercurial > hg > early-roguelike
annotate rogue4/move.c @ 12:9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
author | edwarj4 |
---|---|
date | Sat, 24 Oct 2009 16:52:52 +0000 |
parents | |
children | 1b73a8641b37 |
rev | line source |
---|---|
12
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
1 /* |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
2 * Hero movement commands |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
3 * |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
4 * @(#)move.c 4.24 (Berkeley) 5/12/82 |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
5 * |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
6 * Rogue: Exploring the Dungeons of Doom |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
7 * Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
8 * All rights reserved. |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
9 * |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
10 * See the file LICENSE.TXT for full copyright and licensing information. |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
11 */ |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
12 |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
13 #include <curses.h> |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
14 #include <ctype.h> |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
15 #include "rogue.h" |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
16 |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
17 /* |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
18 * Used to hold the new hero position |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
19 */ |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
20 |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
21 coord nh; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
22 |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
23 /* |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
24 * do_run: |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
25 * Start the hero running |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
26 */ |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
27 do_run(ch) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
28 char ch; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
29 { |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
30 running = TRUE; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
31 after = FALSE; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
32 runch = ch; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
33 } |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
34 |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
35 /* |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
36 * do_move: |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
37 * Check to see that a move is legal. If it is handle the |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
38 * consequences (fighting, picking up, etc.) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
39 */ |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
40 do_move(dy, dx) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
41 int dy, dx; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
42 { |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
43 register char ch, fl; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
44 |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
45 firstmove = FALSE; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
46 if (no_move) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
47 { |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
48 no_move--; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
49 msg("you are still stuck in the bear trap"); |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
50 return; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
51 } |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
52 /* |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
53 * Do a confused move (maybe) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
54 */ |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
55 if (on(player, ISHUH) && rnd(5) != 0) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
56 { |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
57 nh = *rndmove(&player); |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
58 if (ce(nh, hero)) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
59 { |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
60 after = FALSE; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
61 running = FALSE; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
62 return; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
63 } |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
64 } |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
65 else |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
66 { |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
67 over: |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
68 nh.y = hero.y + dy; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
69 nh.x = hero.x + dx; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
70 } |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
71 |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
72 /* |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
73 * Check if he tried to move off the screen or make an illegal |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
74 * diagonal move, and stop him if he did. |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
75 */ |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
76 if (nh.x < 0 || nh.x > COLS-1 || nh.y < 1 || nh.y > LINES - 2) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
77 goto hit_bound; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
78 if (!diag_ok(&hero, &nh)) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
79 { |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
80 after = FALSE; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
81 running = FALSE; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
82 return; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
83 } |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
84 if (running && ce(hero, nh)) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
85 after = running = FALSE; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
86 fl = flat(nh.y, nh.x); |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
87 ch = winat(nh.y, nh.x); |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
88 if (!(fl & F_REAL) && ch == FLOOR) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
89 { |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
90 chat(nh.y, nh.x) = ch = TRAP; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
91 flat(nh.y, nh.x) |= F_REAL; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
92 } |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
93 else |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
94 if (on(player, ISHELD) && ch != 'F') |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
95 { |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
96 msg("you are being held"); |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
97 return; |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
98 } |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
99 switch (ch) |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
100 { |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
101 case ' ': |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
102 case '|': |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
103 case '-': |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
104 hit_bound: |
9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|