-/* $NetBSD: move.c,v 1.7 2006/03/30 04:19:38 jnemeth Exp $ */
+/* $NetBSD: move.c,v 1.13 2011/05/23 23:01:17 joerg Exp $ */
/*
* Copyright (c) 1988, 1993
#if 0
static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: move.c,v 1.7 2006/03/30 04:19:38 jnemeth Exp $");
+__RCSID("$NetBSD: move.c,v 1.13 2011/05/23 23:01:17 joerg Exp $");
#endif
#endif /* not lint */
short m_moves = 0;
boolean jump = 0;
-const char *you_can_move_again = "you can move again";
+const char you_can_move_again[] = "you can move again";
+
+static boolean can_turn(short, short);
+static boolean check_hunger(boolean);
+static char gr_dir(void);
+static void heal(void);
+static boolean next_to_something(int, int);
+static void turn_passage(short, boolean);
int
-one_move_rogue(dirch, pickup)
- short dirch, pickup;
+one_move_rogue(short dirch, short pickup)
{
short row, col;
object *obj;
char desc[DCOLS];
- short n, status, d;
+ short status, d = 0; /* XXX: GCC */
row = rogue.row;
col = rogue.col;
if (confused) {
dirch = gr_dir();
}
- (void) is_direction(dirch, &d);
+ (void)is_direction(dirch, &d);
get_dir_rc(d, &row, &col, 1);
if (!can_move(rogue.row, rogue.col, row, col)) {
if (being_held || bear_trap) {
if (!(dungeon[row][col] & MONSTER)) {
if (being_held) {
- message("you are being held", 1);
+ messagef(1, "you are being held");
} else {
- message("you are still stuck in the bear trap", 0);
- (void) reg_move();
+ messagef(0, "you are still stuck in the bear trap");
+ (void)reg_move();
}
return(MOVE_FAILED);
}
}
if (dungeon[row][col] & MONSTER) {
rogue_hit(object_at(&level_monsters, row, col), 0);
- (void) reg_move();
+ (void)reg_move();
return(MOVE_FAILED);
}
if (dungeon[row][col] & DOOR) {
}
if (pickup && !levitate) {
if ((obj = pick_up(row, col, &status)) != NULL) {
- get_desc(obj, desc);
+ get_desc(obj, desc, sizeof(desc));
if (obj->what_is == GOLD) {
free_object(obj);
+ messagef(1, "%s", desc);
goto NOT_IN_PACK;
}
} else if (!status) {
} else {
MOVE_ON:
obj = object_at(&level_objects, row, col);
- (void) strcpy(desc, "moved onto ");
- get_desc(obj, desc+11);
+ get_desc(obj, desc, sizeof(desc));
+ messagef(1, "moved onto %s", desc);
goto NOT_IN_PACK;
}
- n = strlen(desc);
- desc[n] = '(';
- desc[n+1] = obj->ichar;
- desc[n+2] = ')';
- desc[n+3] = 0;
+ messagef(1, "%s(%c)", desc, obj->ichar);
NOT_IN_PACK:
- message(desc, 1);
- (void) reg_move();
+ (void)reg_move();
return(STOPPED_ON_SOMETHING);
}
if (dungeon[row][col] & (DOOR | STAIRS | TRAP)) {
if ((!levitate) && (dungeon[row][col] & TRAP)) {
trap_player(row, col);
}
- (void) reg_move();
+ (void)reg_move();
return(STOPPED_ON_SOMETHING);
}
MVED: if (reg_move()) { /* fainted from hunger */
}
void
-multiple_move_rogue(dirch)
- short dirch;
+multiple_move_rogue(short dirch)
{
short row, col;
short m;
case 'Y':
case 'U':
case 'N':
- while ((!interrupted) && (one_move_rogue((dirch + 32), 1) == MOVED)) ;
+ while ((!interrupted) && (one_move_rogue((dirch + 32), 1) == MOVED))
+ ;
if ( (!interrupted) && passgo &&
(dungeon[rogue.row][rogue.col] & TUNNEL)) {
}
boolean
-is_passable(row, col)
- int row, col;
+is_passable(int row, int col)
{
if ((row < MIN_ROW) || (row > (DROWS - 2)) || (col < 0) ||
(col > (DCOLS-1))) {
return(dungeon[row][col] & (FLOOR | TUNNEL | DOOR | STAIRS | TRAP));
}
-boolean
-next_to_something(drow, dcol)
- int drow, dcol;
+static boolean
+next_to_something(int drow, int dcol)
{
short i, j, i_end, j_end, row, col;
short pass_count = 0;
}
boolean
-can_move(row1, col1, row2, col2)
- int row1, col1, row2, col2;
+can_move(int row1, int col1, int row2, int col2)
{
if (!is_passable(row2, col2)) {
return(0);
}
void
-move_onto()
+move_onto(void)
{
short ch, d;
boolean first_miss = 1;
while (!is_direction(ch = rgetchar(), &d)) {
sound_bell();
if (first_miss) {
- message("direction? ", 0);
+ messagef(0, "direction? ");
first_miss = 0;
}
}
check_message();
if (ch != CANCEL) {
- (void) one_move_rogue(ch, 0);
+ (void)one_move_rogue(ch, 0);
}
}
boolean
-is_direction(c, d)
- short c;
- short *d;
+is_direction(short c, short *d)
{
switch(c) {
case 'h':
return(1);
}
-boolean
-check_hunger(msg_only)
- boolean msg_only;
+static boolean
+check_hunger(boolean msg_only)
{
short i, n;
boolean fainted = 0;
if (rogue.moves_left == HUNGRY) {
- (void) strcpy(hunger_str, "hungry");
- message(hunger_str, 0);
+ (void)strlcpy(hunger_str, "hungry", sizeof(hunger_str));
+ messagef(0, "%s", hunger_str);
print_stats(STAT_HUNGER);
}
if (rogue.moves_left == WEAK) {
- (void) strcpy(hunger_str, "weak");
- message(hunger_str, 1);
+ (void)strlcpy(hunger_str, "weak", sizeof(hunger_str));
+ messagef(1, "%s", hunger_str);
print_stats(STAT_HUNGER);
}
if (rogue.moves_left <= FAINT) {
if (rogue.moves_left == FAINT) {
- (void) strcpy(hunger_str, "faint");
- message(hunger_str, 1);
+ (void)strlcpy(hunger_str, "faint", sizeof(hunger_str));
+ messagef(1, "%s", hunger_str);
print_stats(STAT_HUNGER);
}
n = get_rand(0, (FAINT - rogue.moves_left));
if (rand_percent(40)) {
rogue.moves_left++;
}
- message("you faint", 1);
+ messagef(1, "you faint");
for (i = 0; i < n; i++) {
if (coin_toss()) {
mv_mons();
}
}
- message(you_can_move_again, 1);
+ messagef(1, "%s", you_can_move_again);
}
}
if (msg_only) {
return(fainted);
}
if (rogue.moves_left <= STARVE) {
- killed_by((object *) 0, STARVATION);
+ killed_by(NULL, STARVATION);
}
switch(e_rings) {
break;
case 1:
rogue.moves_left--;
- (void) check_hunger(1);
+ (void)check_hunger(1);
rogue.moves_left -= (rogue.moves_left % 2);
break;
case 2:
rogue.moves_left--;
- (void) check_hunger(1);
+ (void)check_hunger(1);
rogue.moves_left--;
break;
}
}
boolean
-reg_move()
+reg_move(void)
{
boolean fainted;
}
if (levitate) {
if (!(--levitate)) {
- message("you float gently to the ground", 1);
+ messagef(1, "you float gently to the ground");
if (dungeon[rogue.row][rogue.col] & TRAP) {
trap_player(rogue.row, rogue.col);
}
}
if (haste_self) {
if (!(--haste_self)) {
- message("you feel yourself slowing down", 0);
+ messagef(0, "you feel yourself slowing down");
}
}
heal();
}
void
-rest(count)
- int count;
+rest(int count)
{
int i;
if (interrupted) {
break;
}
- (void) reg_move();
+ (void)reg_move();
}
}
-char
-gr_dir()
+static char
+gr_dir(void)
{
short d;
return(d);
}
-void
-heal()
+static void
+heal(void)
{
static short heal_exp = -1, n, c = 0;
static boolean alt;
}
}
-boolean
-can_turn(nrow, ncol)
- short nrow, ncol;
+static boolean
+can_turn(short nrow, short ncol)
{
if ((dungeon[nrow][ncol] & TUNNEL) && is_passable(nrow, ncol)) {
return(1);
return(0);
}
-void
-turn_passage(dir, fast)
- short dir;
- boolean fast;
+static void
+turn_passage(short dir, boolean fast)
{
short crow = rogue.row, ccol = rogue.col, turns = 0;
short ndir = 0;