+/* $NetBSD: level.c,v 1.10 2008/01/14 03:50:01 dholland Exp $ */
+
/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Timothy C. Stoehr.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-/*static char sccsid[] = "from: @(#)level.c 5.3 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: level.c,v 1.2 1993/08/01 18:52:28 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)level.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: level.c,v 1.10 2008/01/14 03:50:01 dholland Exp $");
+#endif
#endif /* not lint */
/*
#include "rogue.h"
-#define swap(x,y) {t = x; x = y; y = t;}
+#define SWAP(x,y) (t = (x), (x) = (y), (y) = t)
+
+static void add_mazes(void);
+static int connect_rooms(short, short);
+static void draw_simple_passage(short, short, short, short, short);
+static void fill_it(int, boolean);
+static void fill_out_level(void);
+static int get_exp_level(long);
+static void hide_boxed_passage(short, short, short, short, short);
+static void make_maze(short, short, short, short, short, short);
+static void make_room(short, short, short, short);
+static boolean mask_room(short, short *, short *, unsigned short);
+static void mix_random_rooms(void);
+static void put_door(room *, short, short *, short *);
+static void recursive_deadend(short, const short *, short, short);
+static int same_col(int, int);
+static int same_row(int, int);
short cur_level = 0;
short max_level = 1;
short cur_room;
-char *new_level_message = 0;
+const char *new_level_message = NULL;
short party_room = NO_ROOM;
-short r_de;
-long level_points[MAX_EXP_LEVEL] = {
+static short r_de;
+
+const long level_points[MAX_EXP_LEVEL] = {
10L,
20L,
40L,
99900000L
};
-short random_rooms[MAXROOMS] = {3, 7, 5, 2, 0, 6, 1, 4, 8};
-
-extern boolean being_held, wizard, detect_monster;
-extern boolean see_invisible;
-extern short bear_trap, levitate, extra_hp, less_hp, cur_room;
+static short random_rooms[MAXROOMS] = {3, 7, 5, 2, 0, 6, 1, 4, 8};
-make_level()
+void
+make_level(void)
{
short i, j;
short must_1, must_2, must_3;
boolean big_room;
+ must_2 = must_3 = 0;
if (cur_level < LAST_DUNGEON) {
cur_level++;
}
i = random_rooms[j];
if (i < (MAXROOMS-1)) {
- (void) connect_rooms(i, i+1);
+ (void)connect_rooms(i, i+1);
}
if (i < (MAXROOMS-3)) {
- (void) connect_rooms(i, i+3);
+ (void)connect_rooms(i, i+3);
}
if (i < (MAXROOMS-2)) {
if (rooms[i+1].is_room & R_NOTHING) {
}
}
-make_room(rn, r1, r2, r3)
-short rn, r1, r2, r3;
+static void
+make_room(short rn, short r1, short r2, short r3)
{
short left_col, right_col, top_row, bottom_row;
short width, height;
short row_offset, col_offset;
short i, j, ch;
+ left_col = right_col = top_row = bottom_row = 0;
switch(rn) {
case 0:
left_col = 0;
case BIG_ROOM:
top_row = get_rand(MIN_ROW, MIN_ROW+5);
bottom_row = get_rand(DROWS-7, DROWS-2);
- left_col = get_rand(0, 10);;
+ left_col = get_rand(0, 10);
right_col = get_rand(DCOLS-11, DCOLS-1);
rn = 0;
goto B;
rooms[rn].right_col = right_col;
}
-connect_rooms(room1, room2)
-short room1, room2;
+static int
+connect_rooms(short room1, short room2)
{
short row1, col1, row2, col2, dir;
return(1);
}
-clear_level()
+void
+clear_level(void)
{
short i, j;
clear();
}
-put_door(rm, dir, row, col)
-room *rm;
-short dir;
-short *row, *col;
+static void
+put_door(room *rm, short dir, short *row, short *col)
{
short wall_width;
rm->doors[dir/2].door_col = *col;
}
-draw_simple_passage(row1, col1, row2, col2, dir)
-short row1, col1, row2, col2, dir;
+static void
+draw_simple_passage(short row1, short col1, short row2, short col2, short dir)
{
short i, middle, t;
if ((dir == LEFT) || (dir == RIGHT)) {
if (col1 > col2) {
- swap(row1, row2);
- swap(col1, col2);
+ SWAP(row1, row2);
+ SWAP(col1, col2);
}
middle = get_rand(col1+1, col2-1);
for (i = col1+1; i != middle; i++) {
}
} else {
if (row1 > row2) {
- swap(row1, row2);
- swap(col1, col2);
+ SWAP(row1, row2);
+ SWAP(col1, col2);
}
middle = get_rand(row1+1, row2-1);
for (i = row1+1; i != middle; i++) {
}
}
-same_row(room1, room2)
+static int
+same_row(int room1, int room2)
{
return((room1 / 3) == (room2 / 3));
}
-same_col(room1, room2)
+static int
+same_col(int room1, int room2)
{
return((room1 % 3) == (room2 % 3));
}
-add_mazes()
+static void
+add_mazes(void)
{
short i, j;
short start;
}
}
-fill_out_level()
+static void
+fill_out_level(void)
{
short i, rn;
}
}
-fill_it(rn, do_rec_de)
-int rn;
-boolean do_rec_de;
+static void
+fill_it(int rn, boolean do_rec_de)
{
short i, tunnel_dir, door_dir, drow, dcol;
short target_room, rooms_found = 0;
}
}
-recursive_deadend(rn, offsets, srow, scol)
-short rn;
-short *offsets;
-short srow, scol;
+static void
+recursive_deadend(short rn, const short *offsets, short srow, short scol)
{
short i, de;
short drow, dcol, tunnel_dir;
}
}
-boolean
-mask_room(rn, row, col, mask)
-short rn;
-short *row, *col;
-unsigned short mask;
+static boolean
+mask_room(short rn, short *row, short *col, unsigned short mask)
{
short i, j;
return(0);
}
-make_maze(r, c, tr, br, lc, rc)
-short r, c, tr, br, lc, rc;
+static void
+make_maze(short r, short c, short tr, short br, short lc, short rc)
{
char dirs[4];
short i, t;
t1 = get_rand(0, 3);
t2 = get_rand(0, 3);
- swap(dirs[t1], dirs[t2]);
+ SWAP(dirs[t1], dirs[t2]);
}
}
for (i = 0; i < 4; i++) {
}
}
-hide_boxed_passage(row1, col1, row2, col2, n)
-short row1, col1, row2, col2, n;
+static void
+hide_boxed_passage(short row1, short col1, short row2, short col2, short n)
{
short i, j, t;
short row, col, row_cut, col_cut;
if (cur_level > 2) {
if (row1 > row2) {
- swap(row1, row2);
+ SWAP(row1, row2);
}
if (col1 > col2) {
- swap(col1, col2);
+ SWAP(col1, col2);
}
h = row2 - row1;
w = col2 - col1;
}
}
-put_player(nr)
-short nr; /* try not to put in this room */
+/*
+ * try not to put in room NR
+ */
+void
+put_player(short nr)
{
short rn = nr, misses;
short row, col;
rn = get_room_number(rogue.row, rogue.col);
wake_room(rn, 1, rogue.row, rogue.col);
if (new_level_message) {
- message(new_level_message, 0);
- new_level_message = 0;
+ messagef(0, "%s", new_level_message);
+ new_level_message = NULL;
}
mvaddch(rogue.row, rogue.col, rogue.fchar);
}
-drop_check()
+int
+drop_check(void)
{
if (wizard) {
return(1);
}
if (dungeon[rogue.row][rogue.col] & STAIRS) {
if (levitate) {
- message("you're floating in the air!", 0);
+ messagef(0, "you're floating in the air!");
return(0);
}
return(1);
}
- message("I see no way down", 0);
+ messagef(0, "I see no way down");
return(0);
}
-check_up()
+int
+check_up(void)
{
if (!wizard) {
if (!(dungeon[rogue.row][rogue.col] & STAIRS)) {
- message("I see no way up", 0);
+ messagef(0, "I see no way up");
return(0);
}
if (!has_amulet()) {
- message("your way is magically blocked", 0);
+ messagef(0, "your way is magically blocked");
return(0);
}
}
return(0);
}
-add_exp(e, promotion)
-int e;
-boolean promotion;
+void
+add_exp(int e, boolean promotion)
{
- char mbuf[40];
short new_exp;
short i, hp;
rogue.exp_points = MAX_EXP + 1;
}
for (i = rogue.exp+1; i <= new_exp; i++) {
- sprintf(mbuf, "welcome to level %d", i);
- message(mbuf, 0);
+ messagef(0, "welcome to level %d", i);
if (promotion) {
hp = hp_raise();
rogue.hp_current += hp;
}
}
-get_exp_level(e)
-long e;
+static int
+get_exp_level(long e)
{
short i;
return(i+1);
}
-hp_raise()
+int
+hp_raise(void)
{
int hp;
return(hp);
}
-show_average_hp()
+void
+show_average_hp(void)
{
- char mbuf[80];
float real_average;
float effective_average;
} else {
real_average = (float)
((rogue.hp_max - extra_hp - INIT_HP) + less_hp) / (rogue.exp - 1);
- effective_average = (float) (rogue.hp_max - INIT_HP) / (rogue.exp - 1);
+ effective_average = (float)(rogue.hp_max - INIT_HP) / (rogue.exp - 1);
}
- sprintf(mbuf, "R-Hp: %.2f, E-Hp: %.2f (!: %d, V: %d)", real_average,
+ messagef(0, "R-Hp: %.2f, E-Hp: %.2f (!: %d, V: %d)", real_average,
effective_average, extra_hp, less_hp);
- message(mbuf, 0);
}
-mix_random_rooms()
+static void
+mix_random_rooms(void)
{
short i, t;
short x, y;
x = get_rand(0, (MAXROOMS-1));
y = get_rand(0, (MAXROOMS-1));
} while (x == y);
- swap(random_rooms[x], random_rooms[y]);
+ SWAP(random_rooms[x], random_rooms[y]);
}
}