Mercurial > hg > early-roguelike
comparison rogue5/move.c @ 33:f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
| author | elwin |
|---|---|
| date | Mon, 24 May 2010 20:10:59 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 32:2dcd75e6a736 | 33:f502bf60e6e4 |
|---|---|
| 1 /* | |
| 2 * hero movement commands | |
| 3 * | |
| 4 * @(#)move.c 4.49 (Berkeley) 02/05/99 | |
| 5 * | |
| 6 * Rogue: Exploring the Dungeons of Doom | |
| 7 * Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman | |
| 8 * All rights reserved. | |
| 9 * | |
| 10 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 11 */ | |
| 12 | |
| 13 #include <curses.h> | |
| 14 #include <ctype.h> | |
| 15 #include "rogue.h" | |
| 16 | |
| 17 /* | |
| 18 * used to hold the new hero position | |
| 19 */ | |
| 20 | |
| 21 | |
| 22 /* | |
| 23 * do_run: | |
| 24 * Start the hero running | |
| 25 */ | |
| 26 | |
| 27 void | |
| 28 do_run(int ch) | |
| 29 { | |
| 30 running = TRUE; | |
| 31 after = FALSE; | |
| 32 runch = ch; | |
| 33 } | |
| 34 | |
| 35 /* | |
| 36 * do_move: | |
| 37 * Check to see that a move is legal. If it is handle the | |
| 38 * consequences (fighting, picking up, etc.) | |
| 39 */ | |
| 40 | |
| 41 void | |
| 42 do_move(int dy, int dx) | |
| 43 { | |
| 44 int ch, fl; | |
| 45 coord nh; | |
| 46 | |
| 47 firstmove = FALSE; | |
| 48 if (no_move) | |
| 49 { | |
| 50 no_move--; | |
| 51 msg("you are still stuck in the bear trap"); | |
| 52 return; | |
| 53 } | |
| 54 /* | |
| 55 * Do a confused move (maybe) | |
| 56 */ | |
| 57 if (on(player, ISHUH) && rnd(5) != 0) | |
| 58 { | |
| 59 nh = rndmove(&player); | |
| 60 if (ce(nh, hero)) | |
| 61 { | |
| 62 after = FALSE; | |
| 63 running = FALSE; | |
| 64 to_death = FALSE; | |
| 65 return; | |
| 66 } | |
| 67 } | |
| 68 else | |
| 69 { | |
| 70 over: | |
| 71 nh.y = hero.y + dy; | |
| 72 nh.x = hero.x + dx; | |
| 73 } | |
| 74 | |
| 75 /* | |
| 76 * Check if he tried to move off the screen or make an illegal | |
| 77 * diagonal move, and stop him if he did. | |
| 78 */ | |
| 79 if (nh.x < 0 || nh.x >= NUMCOLS || nh.y <= 0 || nh.y >= NUMLINES - 1) | |
| 80 goto hit_bound; | |
| 81 if (!diag_ok(&hero, &nh)) | |
| 82 { | |
| 83 after = FALSE; | |
| 84 running = FALSE; | |
| 85 return; | |
| 86 } | |
| 87 if (running && ce(hero, nh)) | |
| 88 after = running = FALSE; | |
| 89 fl = flat(nh.y, nh.x); | |
| 90 ch = winat(nh.y, nh.x); | |
| 91 if (!(fl & F_REAL) && ch == FLOOR) | |
| 92 { | |
| 93 if (!on(player, ISLEVIT)) | |
| 94 { | |
| 95 chat(nh.y, nh.x) = ch = TRAP; | |
| 96 flat(nh.y, nh.x) |= F_REAL; | |
| 97 } | |
| 98 } | |
| 99 else if (on(player, ISHELD) && ch != 'F') | |
| 100 { | |
| 101 msg("you are being held"); | |
| 102 return; | |
| 103 } | |
| 104 switch (ch) | |
| 105 { | |
| 106 case ' ': | |
| 107 case '|': | |
| 108 case '-': | |
| 109 hit_bound: | |
| 110 if (passgo && running && (proom->r_flags & ISGONE) | |
| 111 && !on(player, ISBLIND)) | |
| 112 { | |
| 113 int b1, b2; | |
| 114 | |
| 115 switch (runch) | |
| 116 { | |
| 117 case 'h': | |
| 118 case 'l': | |
| 119 b1 = (hero.y != 1 && turn_ok(hero.y - 1, hero.x)); | |
| 120 b2 = (hero.y != NUMLINES - 2 && turn_ok(hero.y + 1, hero.x)); | |
| 121 if (!(b1 ^ b2)) | |
| 122 break; | |
| 123 if (b1) | |
| 124 { | |
| 125 runch = 'k'; | |
| 126 dy = -1; | |
| 127 } | |
| 128 else | |
| 129 { | |
| 130 runch = 'j'; | |
| 131 dy = 1; | |
| 132 } | |
| 133 dx = 0; | |
| 134 turnref(); | |
| 135 goto over; | |
| 136 case 'j': | |
| 137 case 'k': | |
| 138 b1 = (hero.x != 0 && turn_ok(hero.y, hero.x - 1)); | |
| 139 b2 = (hero.x != NUMCOLS - 1 && turn_ok(hero.y, hero.x + 1)); | |
| 140 if (!(b1 ^ b2)) | |
| 141 break; | |
| 142 if (b1) | |
| 143 { | |
| 144 runch = 'h'; | |
| 145 dx = -1; | |
| 146 } | |
| 147 else | |
| 148 { | |
| 149 runch = 'l'; | |
| 150 dx = 1; | |
| 151 } | |
| 152 dy = 0; | |
| 153 turnref(); | |
| 154 goto over; | |
| 155 } | |
| 156 } | |
| 157 running = FALSE; | |
| 158 after = FALSE; | |
| 159 break; | |
| 160 case DOOR: | |
| 161 running = FALSE; | |
| 162 if (flat(hero.y, hero.x) & F_PASS) | |
| 163 enter_room(&nh); | |
| 164 goto move_stuff; | |
| 165 case TRAP: | |
| 166 ch = be_trapped(&nh); | |
| 167 if (ch == T_DOOR || ch == T_TELEP) | |
| 168 return; | |
| 169 goto move_stuff; | |
| 170 case PASSAGE: | |
| 171 /* | |
| 172 * when you're in a corridor, you don't know if you're in | |
| 173 * a maze room or not, and there ain't no way to find out | |
| 174 * if you're leaving a maze room, so it is necessary to | |
| 175 * always recalculate proom. | |
| 176 */ | |
| 177 proom = roomin(&hero); | |
| 178 goto move_stuff; | |
| 179 case FLOOR: | |
| 180 if (!(fl & F_REAL)) | |
| 181 be_trapped(&hero); | |
| 182 goto move_stuff; | |
| 183 case STAIRS: | |
| 184 seenstairs = TRUE; |
