-+-+-+-+-+-+-+-+ START OF PART 22 -+-+-+-+-+-+-+-+ X main_loop_count = 0; X start_row = row1; X start_col = col1; X correct_dir(&row_dir, &col_dir, row1, col1, row2, col2); X X do X `7B X /* prevent infinite loops, just in case */ X main_loop_count++; X if (main_loop_count > 2000) X`09stop_flag = TRUE; X X if (randint(100) > DUN_TUN_CHG) X`09`7B X`09 if (randint(DUN_TUN_RND) == 1) X`09 rand_dir(&row_dir, &col_dir); X`09 else X`09 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2); X`09`7D X tmp_row = row1 + row_dir; X tmp_col = col1 + col_dir; X while (!in_bounds(tmp_row, tmp_col)) X`09`7B X`09 if (randint(DUN_TUN_RND) == 1) X`09 rand_dir(&row_dir, &col_dir); X`09 else X`09 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2); X`09 tmp_row = row1 + row_dir; X`09 tmp_col = col1 + col_dir; X`09`7D X c_ptr = &cave`5Btmp_row`5D`5Btmp_col`5D; X if (c_ptr->fval == NULL_WALL) X`09`7B X`09 row1 = tmp_row; X`09 col1 = tmp_col; X`09 if (tunindex < 1000) X`09 `7B X`09 tunstk`5Btunindex`5D.y = row1; X`09 tunstk`5Btunindex`5D.x = col1; X`09 tunindex++; X`09 `7D X`09 door_flag = FALSE; X`09`7D X else if (c_ptr->fval == TMP2_WALL) X`09/* do nothing */ X`09; X else if (c_ptr->fval == GRANITE_WALL) X`09`7B X`09 row1 = tmp_row; X`09 col1 = tmp_col; X`09 if (wallindex < 1000) X`09 `7B X`09 wallstk`5Bwallindex`5D.y = row1; X`09 wallstk`5Bwallindex`5D.x = col1; X`09 wallindex++; X`09 `7D X`09 for (i = row1-1; i <= row1+1; i++) X`09 for (j = col1-1; j <= col1+1; j++) X`09 if (in_bounds(i, j)) X`09`09`7B X`09`09 d_ptr = &cave`5Bi`5D`5Bj`5D; X`09`09 /* values 11 and 12 are impossible here, place_streamer X`09`09 is never run before build_tunnel */ X`09`09 if (d_ptr->fval == GRANITE_WALL) X`09`09 d_ptr->fval = TMP2_WALL; X`09`09`7D X`09`7D X else if (c_ptr->fval == CORR_FLOOR `7C`7C c_ptr->fval == BLOCKED_FLOOR V) X`09`7B X`09 row1 = tmp_row; X`09 col1 = tmp_col; X`09 if (!door_flag) X`09 `7B X`09 if (doorindex < 100) X`09`09`7B X`09`09 doorstk`5Bdoorindex`5D.y = row1; X`09`09 doorstk`5Bdoorindex`5D.x = col1; X`09`09 doorindex++; X`09`09`7D X`09 door_flag = TRUE; X`09 `7D X`09 if (randint(100) > DUN_TUN_CON) X`09 `7B X`09 /* make sure that tunnel has gone a reasonable distance X`09`09 before stopping it, this helps prevent isolated rooms */ X`09 tmp_row = row1 - start_row; X`09 if (tmp_row < 0) tmp_row = -tmp_row; X`09 tmp_col = col1 - start_col; X`09 if (tmp_col < 0) tmp_col = -tmp_col; X`09 if (tmp_row > 10 `7C`7C tmp_col > 10) X`09`09stop_flag = TRUE; X`09 `7D X`09`7D X else /* c_ptr->fval != NULL, TMP2, GRANITE, CORR */ X`09`7B X`09 row1 = tmp_row; X`09 col1 = tmp_col; X`09`7D X `7D X while (((row1 != row2) `7C`7C (col1 != col2)) && (!stop_flag)); X X tun_ptr = &tunstk`5B0`5D; X for (i = 0; i < tunindex; i++) X `7B X d_ptr = &cave`5Btun_ptr->y`5D`5Btun_ptr->x`5D; X d_ptr->fval = CORR_FLOOR; X tun_ptr++; X `7D X for (i = 0; i < wallindex; i++) X `7B X c_ptr = &cave`5Bwallstk`5Bi`5D.y`5D`5Bwallstk`5Bi`5D.x`5D; X if (c_ptr->fval == TMP2_WALL) X`09`7B X`09 if (randint(100) < DUN_TUN_PEN) X`09 place_door(wallstk`5Bi`5D.y, wallstk`5Bi`5D.x); X`09 else X`09 `7B X`09 /* these have to be doorways to rooms */ X`09 c_ptr->fval = CORR_FLOOR; X`09 `7D X`09`7D X `7D X`7D X X Xstatic int next_to(y, x) Xregister int y, x; X`7B X register int next; X X if (next_to_corr(y, x) > 2) X if ((cave`5By-1`5D`5Bx`5D.fval >= MIN_CAVE_WALL) X`09&& (cave`5By+1`5D`5Bx`5D.fval >= MIN_CAVE_WALL)) X next = TRUE; X else if ((cave`5By`5D`5Bx-1`5D.fval >= MIN_CAVE_WALL) X`09 && (cave`5By`5D`5Bx+1`5D.fval >= MIN_CAVE_WALL)) X next = TRUE; X else X next = FALSE; X else X next = FALSE; X return(next); X`7D X X/* Places door at y, x position if at least 2 walls found`09*/ Xstatic void try_door(y, x) Xregister int y, x; X`7B X if ((cave`5By`5D`5Bx`5D.fval == CORR_FLOOR) && (randint(100) > DUN_TUN_JCT V) X && next_to(y, x)) X place_door(y, x); X`7D X X X/* Returns random co-ordinates`09`09`09`09-RAK-`09*/ Xstatic void new_spot(y, x) Xint16 *y, *x; X`7B X register int i, j; X register cave_type *c_ptr; X X do X `7B X i = randint(cur_height - 2); X j = randint(cur_width - 2); X c_ptr = &cave`5Bi`5D`5Bj`5D; X `7D X while (c_ptr->fval >= MIN_CLOSED_SPACE `7C`7C (c_ptr->cptr != 0) X`09 `7C`7C (c_ptr->tptr != 0)); X *y = i; X *x = j; X`7D X X X/* Cave logic flow for generation of new dungeon`09`09*/ Xstatic void cave_gen() X`7B X struct spot_type X `7B X int endx; X int endy; X `7D; X int room_map`5B20`5D`5B20`5D; X register int i, j, k; X int y1, x1, y2, x2, pick1, pick2, tmp; X int row_rooms, col_rooms, alloc_level; X int16 yloc`5B400`5D, xloc`5B400`5D; X X row_rooms = 2*(cur_height/SCREEN_HEIGHT); X col_rooms = 2*(cur_width /SCREEN_WIDTH); X for (i = 0; i < row_rooms; i++) X for (j = 0; j < col_rooms; j++) X room_map`5Bi`5D`5Bj`5D = FALSE; X k = randnor(DUN_ROO_MEA, 2); X for (i = 0; i < k; i++) X room_map`5Brandint(row_rooms)-1`5D`5Brandint(col_rooms)-1`5D = TRUE; X k = 0; X for (i = 0; i < row_rooms; i++) X for (j = 0; j < col_rooms; j++) X if (room_map`5Bi`5D`5Bj`5D == TRUE) X`09`7B X`09 yloc`5Bk`5D = i * (SCREEN_HEIGHT >> 1) + QUART_HEIGHT; X`09 xloc`5Bk`5D = j * (SCREEN_WIDTH >> 1) + QUART_WIDTH; X`09 if (dun_level > randint(DUN_UNUSUAL)) X`09 `7B X`09 tmp = randint(3); X`09 if (tmp == 1)`09 build_type1(yloc`5Bk`5D, xloc`5Bk`5D); X`09 else if (tmp == 2) build_type2(yloc`5Bk`5D, xloc`5Bk`5D); X`09 else`09`09 build_type3(yloc`5Bk`5D, xloc`5Bk`5D); X`09 `7D X`09 else X`09 build_room(yloc`5Bk`5D, xloc`5Bk`5D); X`09 k++; X#ifdef MAC X`09 SystemTask (); X#endif X`09`7D X for (i = 0; i < k; i++) X `7B X pick1 = randint(k) - 1; X pick2 = randint(k) - 1; X y1 = yloc`5Bpick1`5D; X x1 = xloc`5Bpick1`5D; X yloc`5Bpick1`5D = yloc`5Bpick2`5D; X xloc`5Bpick1`5D = xloc`5Bpick2`5D; X yloc`5Bpick2`5D = y1; X xloc`5Bpick2`5D = x1; X `7D X doorindex = 0; X /* move zero entry to k, so that can call build_tunnel all k times */ X yloc`5Bk`5D = yloc`5B0`5D; X xloc`5Bk`5D = xloc`5B0`5D; X for (i = 0; i < k; i++) X `7B X y1 = yloc`5Bi`5D; X x1 = xloc`5Bi`5D; X y2 = yloc`5Bi+1`5D; X x2 = xloc`5Bi+1`5D; X build_tunnel(y2, x2, y1, x1); X `7D X#ifdef MAC X SystemTask (); X#endif X fill_cave(GRANITE_WALL); X for (i = 0; i < DUN_STR_MAG; i++) X place_streamer(MAGMA_WALL, DUN_STR_MC); X for (i = 0; i < DUN_STR_QUA; i++) X place_streamer(QUARTZ_WALL, DUN_STR_QC); X place_boundary(); X /* Place intersection doors`09*/ X for (i = 0; i < doorindex; i++) X `7B X try_door(doorstk`5Bi`5D.y, doorstk`5Bi`5D.x-1); X try_door(doorstk`5Bi`5D.y, doorstk`5Bi`5D.x+1); X try_door(doorstk`5Bi`5D.y-1, doorstk`5Bi`5D.x); X try_door(doorstk`5Bi`5D.y+1, doorstk`5Bi`5D.x); X `7D X#ifdef MAC X SystemTask (); X#endif X alloc_level = (dun_level/3); X if (alloc_level < 2) X alloc_level = 2; X else if (alloc_level > 10) X alloc_level = 10; X place_stairs(2, randint(2)+2, 3); X place_stairs(1, randint(2), 3); X /* Set up the character co-ords, used by alloc_monster, place_win_monster V */ X new_spot(&char_row, &char_col); X alloc_monster((randint(8)+MIN_MALLOC_LEVEL+alloc_level), 0, TRUE); X alloc_object(set_corr, 3, randint(alloc_level)); X alloc_object(set_room, 5, randnor(TREAS_ROOM_ALLOC, 3)); X alloc_object(set_floor, 5, randnor(TREAS_ANY_ALLOC, 3)); X alloc_object(set_floor, 4, randnor(TREAS_GOLD_ALLOC, 3)); X alloc_object(set_floor, 1, randint(alloc_level)); X if (dun_level >= WIN_MON_APPEAR) place_win_monster(); X`7D X X X/* Builds a store at a row, column coordinate`09`09`09*/ Xstatic void build_store(store_num, y, x) Xint store_num, y, x; X`7B X int yval, y_height, y_depth; X int xval, x_left, x_right; X register int i, j; X int cur_pos, tmp; X register cave_type *c_ptr; X X yval`09 = y*10 + 5; X xval`09 = x*16 + 16; X y_height = yval - randint(3); X y_depth = yval + randint(4); X x_left = xval - randint(6); X x_right = xval + randint(6); X for (i = y_height; i <= y_depth; i++) X for (j = x_left; j <= x_right; j++) X cave`5Bi`5D`5Bj`5D.fval`09 = BOUNDARY_WALL; X tmp = randint(4); X if (tmp < 3) X `7B X i = randint(y_depth-y_height) + y_height - 1; X if (tmp == 1) j = x_left; X else`09 j = x_right; X `7D X else X `7B X j = randint(x_right-x_left) + x_left - 1; X if (tmp == 3) i = y_depth; X else`09 i = y_height; X `7D X c_ptr = &cave`5Bi`5D`5Bj`5D; X c_ptr->fval = CORR_FLOOR; X cur_pos = popt(); X c_ptr->tptr = cur_pos; X invcopy(&t_list`5Bcur_pos`5D, OBJ_STORE_DOOR + store_num); X`7D X X X/* Link all free space in treasure list together`09`09*/ Xstatic void tlink() X`7B X register int i; X X for (i = 0; i < MAX_TALLOC; i++) X invcopy(&t_list`5Bi`5D, OBJ_NOTHING); X tcptr = MIN_TRIX; X`7D X X X/* Link all free space in monster list together`09`09`09*/ Xstatic void mlink() X`7B X register int i; X X for (i = 0; i < MAX_MALLOC; i++) X m_list`5Bi`5D = blank_monster; X mfptr = MIN_MONIX; X`7D X X X/* Town logic flow for generation of new town`09`09*/ Xstatic void town_gen() X`7B X register int i, j, l, m; X register cave_type *c_ptr; X int rooms`5B6`5D, k; X X set_seed(town_seed); X for (i = 0; i < 6; i++) X rooms`5Bi`5D = i; X l = 6; X for (i = 0; i < 2; i++) X for (j = 0; j < 3; j++) X `7B X`09k = randint(l) - 1; X`09build_store(rooms`5Bk`5D, i, j); X`09for (m = k; m < l-1; m++) X`09 rooms`5Bm`5D = rooms`5Bm+1`5D; X`09l--; X `7D X fill_cave(DARK_FLOOR); X /* make stairs before reset_seed, so that they don't move around */ X place_boundary(); X place_stairs(2, 1, 0); X reset_seed(); X /* Set up the character co-ords, used by alloc_monster below */ X new_spot(&char_row, &char_col); X if (0x1 & (turn / 5000)) X `7B`09`09/* Night`09*/ X for (i = 0; i < cur_height; i++) X`09`7B X`09 c_ptr = &cave`5Bi`5D`5B0`5D; X`09 for (j = 0; j < cur_width; j++) X`09 `7B X`09 if (c_ptr->fval != DARK_FLOOR) X`09`09c_ptr->pl = TRUE; X`09 c_ptr++; X`09 `7D X#ifdef MAC X`09 SystemTask (); X#endif X`09`7D X alloc_monster(MIN_MALLOC_TN, 3, TRUE); X `7D X else X `7B`09`09/* Day`09*/ X for (i = 0; i < cur_height; i++) X`09`7B X`09 c_ptr = &cave`5Bi`5D`5B0`5D; X`09 for (j = 0; j < cur_width; j++) X`09 `7B X`09 c_ptr->pl = TRUE; X`09 c_ptr++; X`09 `7D X#ifdef MAC X`09 SystemTask (); X#endif X`09`7D X alloc_monster(MIN_MALLOC_TD, 3, TRUE); X `7D X store_maint(); X`7D X X X/* Generates a random dungeon level`09`09`09-RAK-`09*/ Xvoid generate_cave() X`7B X panel_row_min`09= 0; X panel_row_max`09= 0; X panel_col_min`09= 0; X panel_col_max`09= 0; X char_row = -1; X char_col = -1; X X#ifdef MAC X macbeginwait (); X#endif X X tlink(); X mlink(); X blank_cave(); X X if (dun_level == 0) X `7B X cur_height = SCREEN_HEIGHT; X cur_width`09 = SCREEN_WIDTH; X max_panel_rows = (cur_height/SCREEN_HEIGHT)*2 - 2; X max_panel_cols = (cur_width /SCREEN_WIDTH )*2 - 2; X panel_row = max_panel_rows; X panel_col = max_panel_cols; X town_gen(); X `7D X else X `7B X cur_height = MAX_HEIGHT; X cur_width`09 = MAX_WIDTH; X max_panel_rows = (cur_height/SCREEN_HEIGHT)*2 - 2; X max_panel_cols = (cur_width /SCREEN_WIDTH )*2 - 2; X panel_row = max_panel_rows; X panel_col = max_panel_cols; X cave_gen(); X `7D X#ifdef MAC X macendwait (); X#endif X`7D $ CALL UNPACK GENERATE.C;1 621904936 $ create 'f' X/* vms/getch.c: input routines for VMS, integrated with smcurses for VMS X X Copyright (c) 1986-92 Joshua Delahunty, James E. Wilson X X This software may be copied and distributed for educational, research, an Vd X not for profit purposes provided that this copyright and statement are X included in all such copies. */ X X#include X#include X#include X#include X X#ifndef TRUE X# define TRUE 1 X# define FALSE 0 X#endif X X/* the type of keyboard read we're doing */ X#define FUNC IO$_TTYREADALL`7CIO$M_NOECHO`7CIO$M_TRMNOECHO X X`09static $DESCRIPTOR(chan, "tt:"); X`09static char ungotch; X`09static unsigned short int kb_chan = 0;`09/* channel # */ X`09static unsigned short int`09charwaiting = FALSE, X`09`09`09`09`09crmode_status = TRUE, X`09`09`09`09`09echo_status = FALSE; X X/* This code was tested and worked on a VAX 11/785 running VMS 5.2. X contributed by Ralph Waters, rwaters@jabba.ess.harris.com. */ X X/* Returns 1 is a character has been pressed, 0 otherwise. */ Xint kbhit() X`7B X /* sys$qiow ( `5Befn`5D ,chan ,func `5B,iosb`5D `5B,astadr`5D `5B,astprm`5 VD X`09`09`5B,p1`5D `5B,p2`5D `5B,p3`5D `5B,p4`5D `5B,p5`5D `5B,p6`5D )`09`09`09 V*/ X X /* The sys$qiow call with the IO$_SENSEMODE`7CIO$M_TYPEAHDCNT function X will return the following in p1: X X 31 24 23 16 15 0 X ------------`7C------------`7C------------------------ X `7C reserved `7C first `7C number of characters `7C X `7C `7C character `7C in type-ahead buffer `7C X `7C-----------`7C------------`7C-----------------------`7C X `7C reserved `7C X `7C `7C X -------------------------------------------------- X */ X X struct qio_return_type `7B X`09 unsigned short int type_ahead_count;`09/* type-ahead count */ X`09 unsigned char first_char;`09`09/* first character in buffer */ X`09 unsigned char b_reserved;`09`09/* reserved byte */ X`09 unsigned long int l_reserved; `7D`09/* reserved long word */ X qio_return; X X sys$qiow (0, kb_chan, (IO$_SENSEMODE `7C IO$M_TYPEAHDCNT), 0, 0, 0, X`09 &qio_return, 0, 0, 0, 0, 0); X if (qio_return.type_ahead_count > 0) +-+-+-+-+-+-+-+- END OF PART 22 +-+-+-+-+-+-+-+-