[BACK]Return to rooms.c CVS log [TXT][DIR] Up to [contributed] / early-roguelike / rogue3

Annotation of early-roguelike/rogue3/rooms.c, Revision 1.1

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

CVSweb