Annotation of researchv10no/games/rogue/rooms.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Draw the nine rooms on the screen
                      3:  *
                      4:  * @(#)rooms.c 3.8 (Berkeley) 6/15/81
                      5:  */
                      6: 
                      7: #include <curses.h>
                      8: #include "rogue.h"
                      9: 
                     10: do_rooms()
                     11: {
                     12:     register int i;
                     13:     register struct room *rp;
                     14:     register struct linked_list *item;
                     15:     register struct thing *tp;
                     16:     register int left_out;
                     17:     coord top;
                     18:     coord bsze;
                     19:     coord mp;
                     20: 
                     21:     /*
                     22:      * bsze is the maximum room size
                     23:      */
                     24:     bsze.x = COLS/3;
                     25:     bsze.y = LINES/3;
                     26:     /*
                     27:      * Clear things for a new level
                     28:      */
                     29:     for (rp = rooms; rp < &rooms[MAXROOMS]; rp++)
                     30:        rp->r_goldval = rp->r_nexits = rp->r_flags = 0;
                     31:     /*
                     32:      * Put the gone rooms, if any, on the level
                     33:      */
                     34:     left_out = rnd(4);
                     35:     for (i = 0; i < left_out; i++)
                     36:        rooms[rnd_room()].r_flags |= ISGONE;
                     37:     /*
                     38:      * dig and populate all the rooms on the level
                     39:      */
                     40:     for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++)
                     41:     {
                     42:        /*
                     43:         * Find upper left corner of box that this room goes in
                     44:         */
                     45:        top.x = (i%3)*bsze.x + 1;
                     46:        top.y = i/3*bsze.y;
                     47:        if (rp->r_flags & ISGONE)
                     48:        {
                     49:            /*
                     50:             * Place a gone room.  Make certain that there is a blank line
                     51:             * for passage drawing.
                     52:             */
                     53:            do
                     54:            {
                     55:                rp->r_pos.x = top.x + rnd(bsze.x-2) + 1;
                     56:                rp->r_pos.y = top.y + rnd(bsze.y-2) + 1;
                     57:                rp->r_max.x = -COLS;
                     58:                rp->r_max.x = -LINES;
                     59:            } until(rp->r_pos.y > 0 && rp->r_pos.y < LINES-1);
                     60:            continue;
                     61:        }
                     62:        if (rnd(10) < level-1)
                     63:            rp->r_flags |= ISDARK;
                     64:        /*
                     65:         * Find a place and size for a random room
                     66:         */
                     67:        do
                     68:        {
                     69:            rp->r_max.x = rnd(bsze.x - 4) + 4;
                     70:            rp->r_max.y = rnd(bsze.y - 4) + 4;
                     71:            rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x);
                     72:            rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y);
                     73:        } until (rp->r_pos.y != 0);
                     74:        /*
                     75:         * Put the gold in
                     76:         */
                     77:        if (rnd(100) < 50 && (!amulet || level >= max_level))
                     78:        {
                     79:            rp->r_goldval = GOLDCALC;
                     80:            rnd_pos(rp, &rp->r_gold);
                     81:            if (roomin(&rp->r_gold) != rp)
                     82:                endwin(), abort();
                     83:        }
                     84:        draw_room(rp);
                     85:        /*
                     86:         * Put the monster in
                     87:         */
                     88:        if (rnd(100) < (rp->r_goldval > 0 ? 80 : 25))
                     89:        {
                     90:            item = new_item(sizeof *tp);
                     91:            tp = (struct thing *) ldata(item);
                     92:            do
                     93:            {
                     94:                rnd_pos(rp, &mp);
                     95:            } until(mvwinch(stdscr, mp.y, mp.x) == FLOOR);
                     96:            new_monster(item, randmonster(FALSE), &mp);
                     97:            /*
                     98:             * See if we want to give it a treasure to carry around.
                     99:             */
                    100:            if (rnd(100) < monsters[tp->t_type-'A'].m_carry)
                    101:                attach(tp->t_pack, new_thing());
                    102:        }
                    103:     }
                    104: }
                    105: 
                    106: /*
                    107:  * Draw a box around a room
                    108:  */
                    109: 
                    110: draw_room(rp)
                    111: register struct room *rp;
                    112: {
                    113:     register int j, k;
                    114: 
                    115:     move(rp->r_pos.y, rp->r_pos.x+1);
                    116:     vert(rp->r_max.y-2);                               /* Draw left side */
                    117:     move(rp->r_pos.y+rp->r_max.y-1, rp->r_pos.x);
                    118:     horiz(rp->r_max.x);                                        /* Draw bottom */
                    119:     move(rp->r_pos.y, rp->r_pos.x);
                    120:     horiz(rp->r_max.x);                                        /* Draw top */
                    121:     vert(rp->r_max.y-2);                               /* Draw right side */
                    122:     /*
                    123:      * Put the floor down
                    124:      */
                    125:     for (j = 1; j < rp->r_max.y-1; j++)
                    126:     {
                    127:        move(rp->r_pos.y + j, rp->r_pos.x+1);
                    128:        for (k = 1; k < rp->r_max.x-1; k++)
                    129:            addch(FLOOR);
                    130:     }
                    131:     /*
                    132:      * Put the gold there
                    133:      */
                    134:     if (rp->r_goldval)
                    135:        mvaddch(rp->r_gold.y, rp->r_gold.x, GOLD);
                    136: }
                    137: 
                    138: /*
                    139:  * horiz:
                    140:  *     draw a horizontal line
                    141:  */
                    142: 
                    143: horiz(cnt)
                    144: register int cnt;
                    145: {
                    146:     while (cnt--)
                    147:        addch('-');
                    148: }
                    149: 
                    150: /*
                    151:  * vert:
                    152:  *     draw a vertical line
                    153:  */
                    154: 
                    155: vert(cnt)
                    156: register int cnt;
                    157: {
                    158:     register int x, y;
                    159: 
                    160:     getyx(stdscr, y, x);
                    161:     x--;
                    162:     while (cnt--) {
                    163:        move(++y, x);
                    164:        addch('|');
                    165:     }
                    166: }
                    167: 
                    168: /*
                    169:  * rnd_pos:
                    170:  *     pick a random spot in a room
                    171:  */
                    172: 
                    173: rnd_pos(rp, cp)
                    174: register struct room *rp;
                    175: register coord *cp;
                    176: {
                    177:     cp->x = rp->r_pos.x + rnd(rp->r_max.x-2) + 1;
                    178:     cp->y = rp->r_pos.y + rnd(rp->r_max.y-2) + 1;
                    179: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.