]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - rogue/move.c
revert previous and don't parse octal
[bsdgames-darwin.git] / rogue / move.c
index c846b7422cda37113a4e4388943f1bb5a35a7e8a..8378654f248107b833e68fcc4f8deed08c20d3e1 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: move.c,v 1.6 2003/08/07 09:37:38 agc Exp $     */
+/*     $NetBSD: move.c,v 1.13 2011/05/23 23:01:17 joerg Exp $  */
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)move.c     8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: move.c,v 1.6 2003/08/07 09:37:38 agc Exp $");
+__RCSID("$NetBSD: move.c,v 1.13 2011/05/23 23:01:17 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -57,16 +57,22 @@ __RCSID("$NetBSD: move.c,v 1.6 2003/08/07 09:37:38 agc Exp $");
 
 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;
@@ -74,7 +80,7 @@ one_move_rogue(dirch, pickup)
        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)) {
@@ -83,10 +89,10 @@ one_move_rogue(dirch, pickup)
        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);
                }
@@ -99,12 +105,14 @@ one_move_rogue(dirch, pickup)
        }
        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 (cur_room == PASSAGE) {
                        cur_room = get_room_number(row, col);
+                       if (cur_room == NO_ROOM)
+                               clean_up("one_move_rogue: door to nowhere");
                        light_up_room(cur_room);
                        wake_room(cur_room, 1, row, col);
                } else {
@@ -133,9 +141,10 @@ one_move_rogue(dirch, pickup)
                }
                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) {
@@ -146,25 +155,20 @@ one_move_rogue(dirch, pickup)
                } 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 */
@@ -174,8 +178,7 @@ MVED:       if (reg_move()) {                       /* fainted from hunger */
 }
 
 void
-multiple_move_rogue(dirch)
-       short dirch;
+multiple_move_rogue(short dirch)
 {
        short row, col;
        short m;
@@ -211,7 +214,8 @@ multiple_move_rogue(dirch)
        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)) {
@@ -222,8 +226,7 @@ multiple_move_rogue(dirch)
 }
 
 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))) {
@@ -235,9 +238,8 @@ is_passable(row, col)
        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;
@@ -298,8 +300,7 @@ next_to_something(drow, dcol)
 }
 
 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);
@@ -316,7 +317,7 @@ can_move(row1, col1, row2, col2)
 }
 
 void
-move_onto()
+move_onto(void)
 {
        short ch, d;
        boolean first_miss = 1;
@@ -324,20 +325,18 @@ move_onto()
        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':
@@ -372,27 +371,26 @@ is_direction(c, d)
        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));
@@ -401,20 +399,20 @@ check_hunger(msg_only)
                        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) {
@@ -429,12 +427,12 @@ check_hunger(msg_only)
                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;
        }
@@ -442,7 +440,7 @@ check_hunger(msg_only)
 }
 
 boolean
-reg_move()
+reg_move(void)
 {
        boolean fainted;
 
@@ -480,7 +478,7 @@ reg_move()
        }
        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);
                        }
@@ -488,7 +486,7 @@ reg_move()
        }
        if (haste_self) {
                if (!(--haste_self)) {
-                       message("you feel yourself slowing down", 0);
+                       messagef(0, "you feel yourself slowing down");
                }
        }
        heal();
@@ -499,8 +497,7 @@ reg_move()
 }
 
 void
-rest(count)
-       int count;
+rest(int count)
 {
        int i;
 
@@ -510,12 +507,12 @@ rest(count)
                if (interrupted) {
                        break;
                }
-               (void) reg_move();
+               (void)reg_move();
        }
 }
 
-char
-gr_dir()
+static char
+gr_dir(void)
 {
        short d;
 
@@ -550,8 +547,8 @@ gr_dir()
        return(d);
 }
 
-void
-heal()
+static void
+heal(void)
 {
        static short heal_exp = -1, n, c = 0;
        static boolean alt;
@@ -615,9 +612,8 @@ heal()
        }
 }
 
-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);
@@ -625,10 +621,8 @@ can_turn(nrow, ncol)
        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;