1 1.13 joerg /* $NetBSD: move.c,v 1.13 2011/05/23 23:01:17 joerg Exp $ */ 2 1.3 cgd 3 1.1 cgd /* 4 1.3 cgd * Copyright (c) 1988, 1993 5 1.3 cgd * The Regents of the University of California. All rights reserved. 6 1.1 cgd * 7 1.1 cgd * This code is derived from software contributed to Berkeley by 8 1.1 cgd * Timothy C. Stoehr. 9 1.1 cgd * 10 1.1 cgd * Redistribution and use in source and binary forms, with or without 11 1.1 cgd * modification, are permitted provided that the following conditions 12 1.1 cgd * are met: 13 1.1 cgd * 1. Redistributions of source code must retain the above copyright 14 1.1 cgd * notice, this list of conditions and the following disclaimer. 15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 cgd * notice, this list of conditions and the following disclaimer in the 17 1.1 cgd * documentation and/or other materials provided with the distribution. 18 1.6 agc * 3. Neither the name of the University nor the names of its contributors 19 1.1 cgd * may be used to endorse or promote products derived from this software 20 1.1 cgd * without specific prior written permission. 21 1.1 cgd * 22 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 1.1 cgd * SUCH DAMAGE. 33 1.1 cgd */ 34 1.1 cgd 35 1.4 lukem #include <sys/cdefs.h> 36 1.1 cgd #ifndef lint 37 1.3 cgd #if 0 38 1.3 cgd static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93"; 39 1.3 cgd #else 40 1.13 joerg __RCSID("$NetBSD: move.c,v 1.13 2011/05/23 23:01:17 joerg Exp $"); 41 1.3 cgd #endif 42 1.1 cgd #endif /* not lint */ 43 1.1 cgd 44 1.1 cgd /* 45 1.1 cgd * move.c 46 1.1 cgd * 47 1.1 cgd * This source herein may be modified and/or distributed by anybody who 48 1.1 cgd * so desires, with the following restrictions: 49 1.1 cgd * 1.) No portion of this notice shall be removed. 50 1.1 cgd * 2.) Credit shall not be taken for the creation of this source. 51 1.1 cgd * 3.) This code is not to be traded, sold, or used for personal 52 1.1 cgd * gain or profit. 53 1.1 cgd * 54 1.1 cgd */ 55 1.1 cgd 56 1.1 cgd #include "rogue.h" 57 1.1 cgd 58 1.1 cgd short m_moves = 0; 59 1.1 cgd boolean jump = 0; 60 1.13 joerg const char you_can_move_again[] = "you can move again"; 61 1.1 cgd 62 1.12 dholland static boolean can_turn(short, short); 63 1.12 dholland static boolean check_hunger(boolean); 64 1.12 dholland static char gr_dir(void); 65 1.12 dholland static void heal(void); 66 1.12 dholland static boolean next_to_something(int, int); 67 1.12 dholland static void turn_passage(short, boolean); 68 1.12 dholland 69 1.4 lukem int 70 1.11 dholland one_move_rogue(short dirch, short pickup) 71 1.1 cgd { 72 1.1 cgd short row, col; 73 1.1 cgd object *obj; 74 1.1 cgd char desc[DCOLS]; 75 1.9 dholland short status, d = 0; /* XXX: GCC */ 76 1.1 cgd 77 1.1 cgd row = rogue.row; 78 1.1 cgd col = rogue.col; 79 1.1 cgd 80 1.1 cgd if (confused) { 81 1.1 cgd dirch = gr_dir(); 82 1.1 cgd } 83 1.10 dholland (void)is_direction(dirch, &d); 84 1.1 cgd get_dir_rc(d, &row, &col, 1); 85 1.1 cgd 86 1.1 cgd if (!can_move(rogue.row, rogue.col, row, col)) { 87 1.1 cgd return(MOVE_FAILED); 88 1.1 cgd } 89 1.1 cgd if (being_held || bear_trap) { 90 1.1 cgd if (!(dungeon[row][col] & MONSTER)) { 91 1.1 cgd if (being_held) { 92 1.9 dholland messagef(1, "you are being held"); 93 1.1 cgd } else { 94 1.9 dholland messagef(0, "you are still stuck in the bear trap"); 95 1.10 dholland (void)reg_move(); 96 1.1 cgd } 97 1.1 cgd return(MOVE_FAILED); 98 1.1 cgd } 99 1.1 cgd } 100 1.1 cgd if (r_teleport) { 101 1.1 cgd if (rand_percent(R_TELE_PERCENT)) { 102 1.1 cgd tele(); 103 1.1 cgd return(STOPPED_ON_SOMETHING); 104 1.1 cgd } 105 1.1 cgd } 106 1.1 cgd if (dungeon[row][col] & MONSTER) { 107 1.1 cgd rogue_hit(object_at(&level_monsters, row, col), 0); 108 1.10 dholland (void)reg_move(); 109 1.1 cgd return(MOVE_FAILED); 110 1.1 cgd } 111 1.1 cgd if (dungeon[row][col] & DOOR) { 112 1.1 cgd if (cur_room == PASSAGE) { 113 1.1 cgd cur_room = get_room_number(row, col); 114 1.7 jnemeth if (cur_room == NO_ROOM) 115 1.7 jnemeth clean_up("one_move_rogue: door to nowhere"); 116 1.1 cgd light_up_room(cur_room); 117 1.1 cgd wake_room(cur_room, 1, row, col); 118 1.1 cgd } else { 119 1.1 cgd light_passage(row, col); 120 1.1 cgd } 121 1.1 cgd } else if ((dungeon[rogue.row][rogue.col] & DOOR) && 122 1.1 cgd (dungeon[row][col] & TUNNEL)) { 123 1.1 cgd light_passage(row, col); 124 1.1 cgd wake_room(cur_room, 0, rogue.row, rogue.col); 125 1.1 cgd darken_room(cur_room); 126 1.1 cgd cur_room = PASSAGE; 127 1.1 cgd } else if (dungeon[row][col] & TUNNEL) { 128 1.1 cgd light_passage(row, col); 129 1.1 cgd } 130 1.1 cgd mvaddch(rogue.row, rogue.col, get_dungeon_char(rogue.row, rogue.col)); 131 1.1 cgd mvaddch(row, col, rogue.fchar); 132 1.1 cgd 133 1.1 cgd if (!jump) { 134 1.1 cgd refresh(); 135 1.1 cgd } 136 1.1 cgd rogue.row = row; 137 1.1 cgd rogue.col = col; 138 1.1 cgd if (dungeon[row][col] & OBJECT) { 139 1.1 cgd if (levitate && pickup) { 140 1.1 cgd return(STOPPED_ON_SOMETHING); 141 1.1 cgd } 142 1.1 cgd if (pickup && !levitate) { 143 1.4 lukem if ((obj = pick_up(row, col, &status)) != NULL) { 144 1.9 dholland get_desc(obj, desc, sizeof(desc)); 145 1.1 cgd if (obj->what_is == GOLD) { 146 1.1 cgd free_object(obj); 147 1.9 dholland messagef(1, "%s", desc); 148 1.1 cgd goto NOT_IN_PACK; 149 1.1 cgd } 150 1.1 cgd } else if (!status) { 151 1.1 cgd goto MVED; 152 1.1 cgd } else { 153 1.1 cgd goto MOVE_ON; 154 1.1 cgd } 155 1.1 cgd } else { 156 1.1 cgd MOVE_ON: 157 1.1 cgd obj = object_at(&level_objects, row, col); 158 1.9 dholland get_desc(obj, desc, sizeof(desc)); 159 1.9 dholland messagef(1, "moved onto %s", desc); 160 1.1 cgd goto NOT_IN_PACK; 161 1.1 cgd } 162 1.9 dholland messagef(1, "%s(%c)", desc, obj->ichar); 163 1.1 cgd NOT_IN_PACK: 164 1.10 dholland (void)reg_move(); 165 1.1 cgd return(STOPPED_ON_SOMETHING); 166 1.1 cgd } 167 1.1 cgd if (dungeon[row][col] & (DOOR | STAIRS | TRAP)) { 168 1.1 cgd if ((!levitate) && (dungeon[row][col] & TRAP)) { 169 1.1 cgd trap_player(row, col); 170 1.1 cgd } 171 1.10 dholland (void)reg_move(); 172 1.1 cgd return(STOPPED_ON_SOMETHING); 173 1.1 cgd } 174 1.1 cgd MVED: if (reg_move()) { /* fainted from hunger */ 175 1.1 cgd return(STOPPED_ON_SOMETHING); 176 1.1 cgd } 177 1.1 cgd return((confused ? STOPPED_ON_SOMETHING : MOVED)); 178 1.1 cgd } 179 1.1 cgd 180 1.4 lukem void 181 1.11 dholland multiple_move_rogue(short dirch) 182 1.1 cgd { 183 1.1 cgd short row, col; 184 1.1 cgd short m; 185 1.1 cgd 186 1.1 cgd switch(dirch) { 187 1.1 cgd case '\010': 188 1.1 cgd case '\012': 189 1.1 cgd case '\013': 190 1.1 cgd case '\014': 191 1.1 cgd case '\031': 192 1.1 cgd case '\025': 193 1.1 cgd case '\016': 194 1.1 cgd case '\002': 195 1.1 cgd do { 196 1.1 cgd row = rogue.row; 197 1.1 cgd col = rogue.col; 198 1.1 cgd if (((m = one_move_rogue((dirch + 96), 1)) == MOVE_FAILED) || 199 1.1 cgd (m == STOPPED_ON_SOMETHING) || 200 1.1 cgd interrupted) { 201 1.1 cgd break; 202 1.1 cgd } 203 1.1 cgd } while (!next_to_something(row, col)); 204 1.1 cgd if ( (!interrupted) && passgo && (m == MOVE_FAILED) && 205 1.1 cgd (dungeon[rogue.row][rogue.col] & TUNNEL)) { 206 1.1 cgd turn_passage(dirch + 96, 0); 207 1.1 cgd } 208 1.1 cgd break; 209 1.1 cgd case 'H': 210 1.1 cgd case 'J': 211 1.1 cgd case 'K': 212 1.1 cgd case 'L': 213 1.1 cgd case 'B': 214 1.1 cgd case 'Y': 215 1.1 cgd case 'U': 216 1.1 cgd case 'N': 217 1.10 dholland while ((!interrupted) && (one_move_rogue((dirch + 32), 1) == MOVED)) 218 1.10 dholland ; 219 1.1 cgd 220 1.1 cgd if ( (!interrupted) && passgo && 221 1.1 cgd (dungeon[rogue.row][rogue.col] & TUNNEL)) { 222 1.1 cgd turn_passage(dirch + 32, 1); 223 1.1 cgd } 224 1.1 cgd break; 225 1.1 cgd } 226 1.1 cgd } 227 1.1 cgd 228 1.4 lukem boolean 229 1.11 dholland is_passable(int row, int col) 230 1.1 cgd { 231 1.1 cgd if ((row < MIN_ROW) || (row > (DROWS - 2)) || (col < 0) || 232 1.1 cgd (col > (DCOLS-1))) { 233 1.1 cgd return(0); 234 1.1 cgd } 235 1.1 cgd if (dungeon[row][col] & HIDDEN) { 236 1.1 cgd return((dungeon[row][col] & TRAP) ? 1 : 0); 237 1.1 cgd } 238 1.1 cgd return(dungeon[row][col] & (FLOOR | TUNNEL | DOOR | STAIRS | TRAP)); 239 1.1 cgd } 240 1.1 cgd 241 1.12 dholland static boolean 242 1.11 dholland next_to_something(int drow, int dcol) 243 1.1 cgd { 244 1.1 cgd short i, j, i_end, j_end, row, col; 245 1.1 cgd short pass_count = 0; 246 1.1 cgd unsigned short s; 247 1.1 cgd 248 1.1 cgd if (confused) { 249 1.1 cgd return(1); 250 1.1 cgd } 251 1.1 cgd if (blind) { 252 1.1 cgd return(0); 253 1.1 cgd } 254 1.1 cgd i_end = (rogue.row < (DROWS-2)) ? 1 : 0; 255 1.1 cgd j_end = (rogue.col < (DCOLS-1)) ? 1 : 0; 256 1.1 cgd 257 1.1 cgd for (i = ((rogue.row > MIN_ROW) ? -1 : 0); i <= i_end; i++) { 258 1.1 cgd for (j = ((rogue.col > 0) ? -1 : 0); j <= j_end; j++) { 259 1.1 cgd if ((i == 0) && (j == 0)) { 260 1.1 cgd continue; 261 1.1 cgd } 262 1.1 cgd if (((rogue.row+i) == drow) && ((rogue.col+j) == dcol)) { 263 1.1 cgd continue; 264 1.1 cgd } 265 1.1 cgd row = rogue.row + i; 266 1.1 cgd col = rogue.col + j; 267 1.1 cgd s = dungeon[row][col]; 268 1.1 cgd if (s & HIDDEN) { 269 1.1 cgd continue; 270 1.1 cgd } 271 1.1 cgd /* If the rogue used to be right, up, left, down, or right of 272 1.1 cgd * row,col, and now isn't, then don't stop */ 273 1.1 cgd if (s & (MONSTER | OBJECT | STAIRS)) { 274 1.1 cgd if (((row == drow) || (col == dcol)) && 275 1.1 cgd (!((row == rogue.row) || (col == rogue.col)))) { 276 1.1 cgd continue; 277 1.1 cgd } 278 1.1 cgd return(1); 279 1.1 cgd } 280 1.1 cgd if (s & TRAP) { 281 1.1 cgd if (!(s & HIDDEN)) { 282 1.1 cgd if (((row == drow) || (col == dcol)) && 283 1.1 cgd (!((row == rogue.row) || (col == rogue.col)))) { 284 1.1 cgd continue; 285 1.1 cgd } 286 1.1 cgd return(1); 287 1.1 cgd } 288 1.1 cgd } 289 1.1 cgd if ((((i - j) == 1) || ((i - j) == -1)) && (s & TUNNEL)) { 290 1.1 cgd if (++pass_count > 1) { 291 1.1 cgd return(1); 292 1.1 cgd } 293 1.1 cgd } 294 1.1 cgd if ((s & DOOR) && ((i == 0) || (j == 0))) { 295 1.1 cgd return(1); 296 1.1 cgd } 297 1.1 cgd } 298 1.1 cgd } 299 1.1 cgd return(0); 300 1.1 cgd } 301 1.1 cgd 302 1.4 lukem boolean 303 1.11 dholland can_move(int row1, int col1, int row2, int col2) 304 1.1 cgd { 305 1.1 cgd if (!is_passable(row2, col2)) { 306 1.1 cgd return(0); 307 1.1 cgd } 308 1.1 cgd if ((row1 != row2) && (col1 != col2)) { 309 1.1 cgd if ((dungeon[row1][col1] & DOOR) || (dungeon[row2][col2] & DOOR)) { 310 1.1 cgd return(0); 311 1.1 cgd } 312 1.1 cgd if ((!dungeon[row1][col2]) || (!dungeon[row2][col1])) { 313 1.1 cgd return(0); 314 1.1 cgd } 315 1.1 cgd } 316 1.1 cgd return(1); 317 1.1 cgd } 318 1.1 cgd 319 1.4 lukem void 320 1.11 dholland move_onto(void) 321 1.1 cgd { 322 1.1 cgd short ch, d; 323 1.1 cgd boolean first_miss = 1; 324 1.1 cgd 325 1.1 cgd while (!is_direction(ch = rgetchar(), &d)) { 326 1.1 cgd sound_bell(); 327 1.1 cgd if (first_miss) { 328 1.9 dholland messagef(0, "direction? "); 329 1.1 cgd first_miss = 0; 330 1.1 cgd } 331 1.1 cgd } 332 1.1 cgd check_message(); 333 1.1 cgd if (ch != CANCEL) { 334 1.10 dholland (void)one_move_rogue(ch, 0); 335 1.1 cgd } 336 1.1 cgd } 337 1.1 cgd 338 1.1 cgd boolean 339 1.11 dholland is_direction(short c, short *d) 340 1.1 cgd { 341 1.1 cgd switch(c) { 342 1.1 cgd case 'h': 343 1.1 cgd *d = LEFT; 344 1.1 cgd break; 345 1.1 cgd case 'j': 346 1.1 cgd *d = DOWN; 347 1.1 cgd break; 348 1.1 cgd case 'k': 349 1.1 cgd *d = UPWARD; 350 1.1 cgd break; 351 1.1 cgd case 'l': 352 1.1 cgd *d = RIGHT; 353 1.1 cgd break; 354 1.1 cgd case 'b': 355 1.1 cgd *d = DOWNLEFT; 356 1.1 cgd break; 357 1.1 cgd case 'y': 358 1.1 cgd *d = UPLEFT; 359 1.1 cgd break; 360 1.1 cgd case 'u': 361 1.1 cgd *d = UPRIGHT; 362 1.1 cgd break; 363 1.1 cgd case 'n': 364 1.1 cgd *d = DOWNRIGHT; 365 1.1 cgd break; 366 1.1 cgd case CANCEL: 367 1.1 cgd break; 368 1.1 cgd default: 369 1.1 cgd return(0); 370 1.1 cgd } 371 1.1 cgd return(1); 372 1.1 cgd } 373 1.1 cgd 374 1.12 dholland static boolean 375 1.11 dholland check_hunger(boolean msg_only) 376 1.1 cgd { 377 1.4 lukem short i, n; 378 1.1 cgd boolean fainted = 0; 379 1.1 cgd 380 1.1 cgd if (rogue.moves_left == HUNGRY) { 381 1.10 dholland (void)strlcpy(hunger_str, "hungry", sizeof(hunger_str)); 382 1.9 dholland messagef(0, "%s", hunger_str); 383 1.1 cgd print_stats(STAT_HUNGER); 384 1.1 cgd } 385 1.1 cgd if (rogue.moves_left == WEAK) { 386 1.10 dholland (void)strlcpy(hunger_str, "weak", sizeof(hunger_str)); 387 1.9 dholland messagef(1, "%s", hunger_str); 388 1.1 cgd print_stats(STAT_HUNGER); 389 1.1 cgd } 390 1.1 cgd if (rogue.moves_left <= FAINT) { 391 1.1 cgd if (rogue.moves_left == FAINT) { 392 1.10 dholland (void)strlcpy(hunger_str, "faint", sizeof(hunger_str)); 393 1.9 dholland messagef(1, "%s", hunger_str); 394 1.1 cgd print_stats(STAT_HUNGER); 395 1.1 cgd } 396 1.1 cgd n = get_rand(0, (FAINT - rogue.moves_left)); 397 1.1 cgd if (n > 0) { 398 1.1 cgd fainted = 1; 399 1.1 cgd if (rand_percent(40)) { 400 1.1 cgd rogue.moves_left++; 401 1.1 cgd } 402 1.9 dholland messagef(1, "you faint"); 403 1.1 cgd for (i = 0; i < n; i++) { 404 1.1 cgd if (coin_toss()) { 405 1.1 cgd mv_mons(); 406 1.1 cgd } 407 1.1 cgd } 408 1.13 joerg messagef(1, "%s", you_can_move_again); 409 1.1 cgd } 410 1.1 cgd } 411 1.1 cgd if (msg_only) { 412 1.1 cgd return(fainted); 413 1.1 cgd } 414 1.1 cgd if (rogue.moves_left <= STARVE) { 415 1.11 dholland killed_by(NULL, STARVATION); 416 1.1 cgd } 417 1.1 cgd 418 1.1 cgd switch(e_rings) { 419 1.1 cgd /*case -2: 420 1.1 cgd Subtract 0, i.e. do nothing. 421 1.1 cgd break;*/ 422 1.1 cgd case -1: 423 1.1 cgd rogue.moves_left -= (rogue.moves_left % 2); 424 1.1 cgd break; 425 1.1 cgd case 0: 426 1.1 cgd rogue.moves_left--; 427 1.1 cgd break; 428 1.1 cgd case 1: 429 1.1 cgd rogue.moves_left--; 430 1.10 dholland (void)check_hunger(1); 431 1.1 cgd rogue.moves_left -= (rogue.moves_left % 2); 432 1.1 cgd break; 433 1.1 cgd case 2: 434 1.1 cgd rogue.moves_left--; 435 1.10 dholland (void)check_hunger(1); 436 1.1 cgd rogue.moves_left--; 437 1.1 cgd break; 438 1.1 cgd } 439 1.1 cgd return(fainted); 440 1.1 cgd } 441 1.1 cgd 442 1.1 cgd boolean 443 1.11 dholland reg_move(void) 444 1.1 cgd { 445 1.1 cgd boolean fainted; 446 1.1 cgd 447 1.1 cgd if ((rogue.moves_left <= HUNGRY) || (cur_level >= max_level)) { 448 1.1 cgd fainted = check_hunger(0); 449 1.1 cgd } else { 450 1.1 cgd fainted = 0; 451 1.1 cgd } 452 1.1 cgd 453 1.1 cgd mv_mons(); 454 1.1 cgd 455 1.1 cgd if (++m_moves >= 120) { 456 1.1 cgd m_moves = 0; 457 1.1 cgd wanderer(); 458 1.1 cgd } 459 1.1 cgd if (halluc) { 460 1.1 cgd if (!(--halluc)) { 461 1.1 cgd unhallucinate(); 462 1.1 cgd } else { 463 1.1 cgd hallucinate(); 464 1.1 cgd } 465 1.1 cgd } 466 1.1 cgd if (blind) { 467 1.1 cgd if (!(--blind)) { 468 1.1 cgd unblind(); 469 1.1 cgd } 470 1.1 cgd } 471 1.1 cgd if (confused) { 472 1.1 cgd if (!(--confused)) { 473 1.1 cgd unconfuse(); 474 1.1 cgd } 475 1.1 cgd } 476 1.1 cgd if (bear_trap) { 477 1.1 cgd bear_trap--; 478 1.1 cgd } 479 1.1 cgd if (levitate) { 480 1.1 cgd if (!(--levitate)) { 481 1.9 dholland messagef(1, "you float gently to the ground"); 482 1.1 cgd if (dungeon[rogue.row][rogue.col] & TRAP) { 483 1.1 cgd trap_player(rogue.row, rogue.col); 484 1.1 cgd } 485 1.1 cgd } 486 1.1 cgd } 487 1.1 cgd if (haste_self) { 488 1.1 cgd if (!(--haste_self)) { 489 1.9 dholland messagef(0, "you feel yourself slowing down"); 490 1.1 cgd } 491 1.1 cgd } 492 1.1 cgd heal(); 493 1.1 cgd if (auto_search > 0) { 494 1.1 cgd search(auto_search, auto_search); 495 1.1 cgd } 496 1.1 cgd return(fainted); 497 1.1 cgd } 498 1.1 cgd 499 1.4 lukem void 500 1.11 dholland rest(int count) 501 1.1 cgd { 502 1.1 cgd int i; 503 1.1 cgd 504 1.1 cgd interrupted = 0; 505 1.1 cgd 506 1.1 cgd for (i = 0; i < count; i++) { 507 1.1 cgd if (interrupted) { 508 1.1 cgd break; 509 1.1 cgd } 510 1.10 dholland (void)reg_move(); 511 1.1 cgd } 512 1.1 cgd } 513 1.1 cgd 514 1.12 dholland static char 515 1.11 dholland gr_dir(void) 516 1.1 cgd { 517 1.1 cgd short d; 518 1.1 cgd 519 1.1 cgd d = get_rand(1, 8); 520 1.1 cgd 521 1.1 cgd switch(d) { 522 1.1 cgd case 1: 523 1.1 cgd d = 'j'; 524 1.1 cgd break; 525 1.1 cgd case 2: 526 1.1 cgd d = 'k'; 527 1.1 cgd break; 528 1.1 cgd case 3: 529 1.1 cgd d = 'l'; 530 1.1 cgd break; 531 1.1 cgd case 4: 532 1.1 cgd d = 'h'; 533 1.1 cgd break; 534 1.1 cgd case 5: 535 1.1 cgd d = 'y'; 536 1.1 cgd break; 537 1.1 cgd case 6: 538 1.1 cgd d = 'u'; 539 1.1 cgd break; 540 1.1 cgd case 7: 541 1.1 cgd d = 'b'; 542 1.1 cgd break; 543 1.1 cgd case 8: 544 1.1 cgd d = 'n'; 545 1.1 cgd break; 546 1.1 cgd } 547 1.1 cgd return(d); 548 1.1 cgd } 549 1.1 cgd 550 1.12 dholland static void 551 1.11 dholland heal(void) 552 1.1 cgd { 553 1.1 cgd static short heal_exp = -1, n, c = 0; 554 1.1 cgd static boolean alt; 555 1.1 cgd 556 1.1 cgd if (rogue.hp_current == rogue.hp_max) { 557 1.1 cgd c = 0; 558 1.1 cgd return; 559 1.1 cgd } 560 1.1 cgd if (rogue.exp != heal_exp) { 561 1.1 cgd heal_exp = rogue.exp; 562 1.1 cgd 563 1.1 cgd switch(heal_exp) { 564 1.1 cgd case 1: 565 1.1 cgd n = 20; 566 1.1 cgd break; 567 1.1 cgd case 2: 568 1.1 cgd n = 18; 569 1.1 cgd break; 570 1.1 cgd case 3: 571 1.1 cgd n = 17; 572 1.1 cgd break; 573 1.1 cgd case 4: 574 1.1 cgd n = 14; 575 1.1 cgd break; 576 1.1 cgd case 5: 577 1.1 cgd n = 13; 578 1.1 cgd break; 579 1.1 cgd case 6: 580 1.1 cgd n = 10; 581 1.1 cgd break; 582 1.1 cgd case 7: 583 1.1 cgd n = 9; 584 1.1 cgd break; 585 1.1 cgd case 8: 586 1.1 cgd n = 8; 587 1.1 cgd break; 588 1.1 cgd case 9: 589 1.1 cgd n = 7; 590 1.1 cgd break; 591 1.1 cgd case 10: 592 1.1 cgd n = 4; 593 1.1 cgd break; 594 1.1 cgd case 11: 595 1.1 cgd n = 3; 596 1.1 cgd break; 597 1.1 cgd case 12: 598 1.1 cgd default: 599 1.1 cgd n = 2; 600 1.1 cgd } 601 1.1 cgd } 602 1.1 cgd if (++c >= n) { 603 1.1 cgd c = 0; 604 1.1 cgd rogue.hp_current++; 605 1.4 lukem if ((alt = !alt) != 0) { 606 1.1 cgd rogue.hp_current++; 607 1.1 cgd } 608 1.1 cgd if ((rogue.hp_current += regeneration) > rogue.hp_max) { 609 1.1 cgd rogue.hp_current = rogue.hp_max; 610 1.1 cgd } 611 1.1 cgd print_stats(STAT_HP); 612 1.1 cgd } 613 1.1 cgd } 614 1.1 cgd 615 1.12 dholland static boolean 616 1.11 dholland can_turn(short nrow, short ncol) 617 1.1 cgd { 618 1.1 cgd if ((dungeon[nrow][ncol] & TUNNEL) && is_passable(nrow, ncol)) { 619 1.1 cgd return(1); 620 1.1 cgd } 621 1.1 cgd return(0); 622 1.1 cgd } 623 1.1 cgd 624 1.12 dholland static void 625 1.11 dholland turn_passage(short dir, boolean fast) 626 1.1 cgd { 627 1.1 cgd short crow = rogue.row, ccol = rogue.col, turns = 0; 628 1.4 lukem short ndir = 0; 629 1.1 cgd 630 1.1 cgd if ((dir != 'h') && can_turn(crow, ccol + 1)) { 631 1.1 cgd turns++; 632 1.1 cgd ndir = 'l'; 633 1.1 cgd } 634 1.1 cgd if ((dir != 'l') && can_turn(crow, ccol - 1)) { 635 1.1 cgd turns++; 636 1.1 cgd ndir = 'h'; 637 1.1 cgd } 638 1.1 cgd if ((dir != 'k') && can_turn(crow + 1, ccol)) { 639 1.1 cgd turns++; 640 1.1 cgd ndir = 'j'; 641 1.1 cgd } 642 1.1 cgd if ((dir != 'j') && can_turn(crow - 1, ccol)) { 643 1.1 cgd turns++; 644 1.1 cgd ndir = 'k'; 645 1.1 cgd } 646 1.1 cgd if (turns == 1) { 647 1.1 cgd multiple_move_rogue(ndir - (fast ? 32 : 96)); 648 1.1 cgd } 649 1.1 cgd } 650