⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 level.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * 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. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 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 *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char sccsid[] = "@(#)level.c	8.1 (Berkeley) 5/31/93";#endif /* not lint *//* * level.c * * This source herein may be modified and/or distributed by anybody who * so desires, with the following restrictions: *    1.)  No portion of this notice shall be removed. *    2.)  Credit shall not be taken for the creation of this source. *    3.)  This code is not to be traded, sold, or used for personal *         gain or profit. * */#include "rogue.h"#define swap(x,y) {t = x; x = y; y = t;}short cur_level = 0;short max_level = 1;short cur_room;char *new_level_message = 0;short party_room = NO_ROOM;short r_de;long level_points[MAX_EXP_LEVEL] = {		  10L,		  20L,		  40L,		  80L,		 160L,		 320L,		 640L,		1300L,		2600L,		5200L,	   10000L,	   20000L,	   40000L,	   80000L,	  160000L,	  320000L,	 1000000L,	 3333333L,	 6666666L,	  MAX_EXP,	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;make_level(){	short i, j;	short must_1, must_2, must_3;	boolean big_room;	if (cur_level < LAST_DUNGEON) {		cur_level++;	}	if (cur_level > max_level) {		max_level = cur_level;	}	must_1 = get_rand(0, 5);	switch(must_1) {	case 0:		must_1 = 0;		must_2 = 1;		must_3 = 2;		break;	case 1:		must_1 = 3;		must_2 = 4;		must_3 = 5;		break;	case 2:		must_1 = 6;		must_2 = 7;		must_3 = 8;		break;	case 3:		must_1 = 0;		must_2 = 3;		must_3 = 6;		break;	case 4:		must_1 = 1;		must_2 = 4;		must_3 = 7;		break;	case 5:		must_1 = 2;		must_2 = 5;		must_3 = 8;		break;	}	if (rand_percent(8)) {		party_room = 0;	}	big_room = ((party_room != NO_ROOM) && rand_percent(1));	if (big_room) {		make_room(BIG_ROOM, 0, 0, 0);	} else {		for (i = 0; i < MAXROOMS; i++) {			make_room(i, must_1, must_2, must_3);		}	}	if (!big_room) {		add_mazes();		mix_random_rooms();		for (j = 0; j < MAXROOMS; j++) {			i = random_rooms[j];			if (i < (MAXROOMS-1)) {				(void) connect_rooms(i, i+1);			}			if (i < (MAXROOMS-3)) {				(void) connect_rooms(i, i+3);			}			if (i < (MAXROOMS-2)) {				if (rooms[i+1].is_room & R_NOTHING) {					if (connect_rooms(i, i+2)) {						rooms[i+1].is_room = R_CROSS;					}				}			}			if (i < (MAXROOMS-6)) {				if (rooms[i+3].is_room & R_NOTHING) {					if (connect_rooms(i, i+6)) {						rooms[i+3].is_room = R_CROSS;					}				}			}			if (is_all_connected()) {				break;			}		}		fill_out_level();	}	if (!has_amulet() && (cur_level >= AMULET_LEVEL)) {		put_amulet();	}}make_room(rn, r1, r2, r3)short rn, r1, r2, r3;{	short left_col, right_col, top_row, bottom_row;	short width, height;	short row_offset, col_offset;	short i, j, ch;	switch(rn) {	case 0:		left_col = 0;		right_col = COL1-1;		top_row = MIN_ROW;		bottom_row = ROW1-1;		break;	case 1:		left_col = COL1+1;		right_col = COL2-1;		top_row = MIN_ROW;		bottom_row = ROW1-1;		break;	case 2:		left_col = COL2+1;		right_col = DCOLS-1;		top_row = MIN_ROW;		bottom_row = ROW1-1;		break;	case 3:		left_col = 0;		right_col = COL1-1;		top_row = ROW1+1;		bottom_row = ROW2-1;		break;	case 4:		left_col = COL1+1;		right_col = COL2-1;		top_row = ROW1+1;		bottom_row = ROW2-1;		break;	case 5:		left_col = COL2+1;		right_col = DCOLS-1;		top_row = ROW1+1;		bottom_row = ROW2-1;		break;	case 6:		left_col = 0;		right_col = COL1-1;		top_row = ROW2+1;		bottom_row = DROWS - 2;		break;	case 7:		left_col = COL1+1;		right_col = COL2-1;		top_row = ROW2+1;		bottom_row = DROWS - 2;		break;	case 8:		left_col = COL2+1;		right_col = DCOLS-1;		top_row = ROW2+1;		bottom_row = DROWS - 2;		break;	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);;		right_col = get_rand(DCOLS-11, DCOLS-1);		rn = 0;		goto B;	}	height = get_rand(4, (bottom_row - top_row + 1));	width = get_rand(7, (right_col - left_col - 2));	row_offset = get_rand(0, ((bottom_row - top_row) - height + 1));	col_offset = get_rand(0, ((right_col - left_col) - width + 1));	top_row += row_offset;	bottom_row = top_row + height - 1;	left_col += col_offset;	right_col = left_col + width - 1;	if ((rn != r1) && (rn != r2) && (rn != r3) && rand_percent(40)) {		goto END;	}B:	rooms[rn].is_room = R_ROOM;	for (i = top_row; i <= bottom_row; i++) {		for (j = left_col; j <= right_col; j++) {			if ((i == top_row) || (i == bottom_row)) {				ch = HORWALL;			} else if (	((i != top_row) && (i != bottom_row)) &&						((j == left_col) || (j == right_col))) {				ch = VERTWALL;			} else {				ch = FLOOR;			}			dungeon[i][j] = ch;		}	}END:	rooms[rn].top_row = top_row;	rooms[rn].bottom_row = bottom_row;	rooms[rn].left_col = left_col;	rooms[rn].right_col = right_col;}connect_rooms(room1, room2)short room1, room2;{	short row1, col1, row2, col2, dir;	if ((!(rooms[room1].is_room & (R_ROOM | R_MAZE))) ||		(!(rooms[room2].is_room & (R_ROOM | R_MAZE)))) {		return(0);	}	if (same_row(room1, room2) &&		(rooms[room1].left_col > rooms[room2].right_col)) {		put_door(&rooms[room1], LEFT, &row1, &col1);		put_door(&rooms[room2], RIGHT, &row2, &col2);		dir = LEFT;	} else if (same_row(room1, room2) &&		(rooms[room2].left_col > rooms[room1].right_col)) {		put_door(&rooms[room1], RIGHT, &row1, &col1);		put_door(&rooms[room2], LEFT, &row2, &col2);		dir = RIGHT;	} else if (same_col(room1, room2) &&		(rooms[room1].top_row > rooms[room2].bottom_row)) {		put_door(&rooms[room1], UPWARD, &row1, &col1);		put_door(&rooms[room2], DOWN, &row2, &col2);		dir = UPWARD;	} else if (same_col(room1, room2) &&		(rooms[room2].top_row > rooms[room1].bottom_row)) {		put_door(&rooms[room1], DOWN, &row1, &col1);		put_door(&rooms[room2], UPWARD, &row2, &col2);		dir = DOWN;	} else {		return(0);	}	do {		draw_simple_passage(row1, col1, row2, col2, dir);	} while (rand_percent(4));	rooms[room1].doors[dir/2].oth_room = room2;	rooms[room1].doors[dir/2].oth_row = row2;	rooms[room1].doors[dir/2].oth_col = col2;	rooms[room2].doors[(((dir+4)%DIRS)/2)].oth_room = room1;	rooms[room2].doors[(((dir+4)%DIRS)/2)].oth_row = row1;	rooms[room2].doors[(((dir+4)%DIRS)/2)].oth_col = col1;	return(1);}clear_level(){	short i, j;	for (i = 0; i < MAXROOMS; i++) {		rooms[i].is_room = R_NOTHING;		for (j = 0; j < 4; j++) {			rooms[i].doors[j].oth_room = NO_ROOM;		}	}	for (i = 0; i < MAX_TRAPS; i++) {		traps[i].trap_type = NO_TRAP;	}	for (i = 0; i < DROWS; i++) {		for (j = 0; j < DCOLS; j++) {			dungeon[i][j] = NOTHING;		}	}	detect_monster = see_invisible = 0;	being_held = bear_trap = 0;	party_room = NO_ROOM;	rogue.row = rogue.col = -1;	clear();}put_door(rm, dir, row, col)room *rm;short dir;short *row, *col;{	short wall_width;	wall_width = (rm->is_room & R_MAZE) ? 0 : 1;	switch(dir) {	case UPWARD:	case DOWN:		*row = ((dir == UPWARD) ? rm->top_row : rm->bottom_row);		do {			*col = get_rand(rm->left_col+wall_width,				rm->right_col-wall_width);		} while (!(dungeon[*row][*col] & (HORWALL | TUNNEL)));		break;	case RIGHT:	case LEFT:		*col = (dir == LEFT) ? rm->left_col : rm->right_col;		do {			*row = get_rand(rm->top_row+wall_width,				rm->bottom_row-wall_width);		} while (!(dungeon[*row][*col] & (VERTWALL | TUNNEL)));		break;	}	if (rm->is_room & R_ROOM) {		dungeon[*row][*col] = DOOR;	}	if ((cur_level > 2) && rand_percent(HIDE_PERCENT)) {		dungeon[*row][*col] |= HIDDEN;	}	rm->doors[dir/2].door_row = *row;	rm->doors[dir/2].door_col = *col;}draw_simple_passage(row1, col1, row2, col2, dir)short row1, col1, row2, col2, dir;{	short i, middle, t;	if ((dir == LEFT) || (dir == RIGHT)) {		if (col1 > col2) {			swap(row1, row2);			swap(col1, col2);		}		middle = get_rand(col1+1, col2-1);		for (i = col1+1; i != middle; i++) {			dungeon[row1][i] = TUNNEL;		}		for (i = row1; i != row2; i += (row1 > row2) ? -1 : 1) {			dungeon[i][middle] = TUNNEL;		}		for (i = middle; i != col2; i++) {			dungeon[row2][i] = TUNNEL;		}	} else {		if (row1 > row2) {			swap(row1, row2);			swap(col1, col2);		}		middle = get_rand(row1+1, row2-1);		for (i = row1+1; i != middle; i++) {			dungeon[i][col1] = TUNNEL;		}		for (i = col1; i != col2; i += (col1 > col2) ? -1 : 1) {			dungeon[middle][i] = TUNNEL;		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -