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

Annotation of early-roguelike/arogue5/rooms.c, Revision 1.1.1.1

1.1       rubenllo    1: /*
                      2:  * Draw the nine rooms on the screen
                      3:  *
                      4:  * Advanced Rogue
                      5:  * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
                      6:  * All rights reserved.
                      7:  *
                      8:  * Based on "Rogue: Exploring the Dungeons of Doom"
                      9:  * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
                     10:  * All rights reserved.
                     11:  *
                     12:  * See the file LICENSE.TXT for full copyright and licensing information.
                     13:  */
                     14:
                     15: #include "curses.h"
                     16: #include "rogue.h"
                     17: #include <stdlib.h>
                     18:
                     19: void horiz(int cnt);
                     20: void vert(int cnt);
                     21:
                     22: void
                     23: do_rooms(void)
                     24: {
                     25:     register int i;
                     26:     register struct room *rp;
                     27:     register struct linked_list *item;
                     28:     register struct thing *tp;
                     29:     register int left_out;
                     30:     coord top;
                     31:     coord bsze;
                     32:     coord mp;
                     33:
                     34:     /*
                     35:      * bsze is the maximum room size
                     36:      */
                     37:     bsze.x = COLS/3;
                     38:     bsze.y = (LINES-2)/3;
                     39:     /*
                     40:      * Clear things for a new level
                     41:      */
                     42:     for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
                     43:        rp->r_flags = 0;
                     44:        rp->r_fires = NULL;
                     45:     }
                     46:     /*
                     47:      * Put the gone rooms, if any, on the level
                     48:      */
                     49:     left_out = rnd(4);
                     50:     for (i = 0; i < left_out; i++)
                     51:        rooms[rnd_room()].r_flags |= ISGONE;
                     52:     /*
                     53:      * dig and populate all the rooms on the level
                     54:      */
                     55:     for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++)
                     56:     {
                     57:        bool has_gold=FALSE;
                     58:
                     59:        /*
                     60:         * Find upper left corner of box that this room goes in
                     61:         */
                     62:        top.x = (i%3)*bsze.x;
                     63:        top.y = i/3*bsze.y + 1;
                     64:        if (rp->r_flags & ISGONE)
                     65:        {
                     66:            /*
                     67:             * Place a gone room.  Make certain that there is a blank line
                     68:             * for passage drawing.
                     69:             */
                     70:            do
                     71:            {
                     72:                rp->r_pos.x = top.x + rnd(bsze.x-2) + 1;
                     73:                rp->r_pos.y = top.y + rnd(bsze.y-2) + 1;
                     74:                rp->r_max.x = -COLS;
                     75:                rp->r_max.x = -LINES;
                     76:            } until(rp->r_pos.y > 0 && rp->r_pos.y < LINES-2);
                     77:            continue;
                     78:        }
                     79:        if (rnd(10) < level-1)
                     80:            rp->r_flags |= ISDARK;
                     81:        /*
                     82:         * Find a place and size for a random room
                     83:         */
                     84:        do
                     85:        {
                     86:            rp->r_max.x = rnd(bsze.x - 4) + 4;
                     87:            rp->r_max.y = rnd(bsze.y - 4) + 4;
                     88:            rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x);
                     89:            rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y);
                     90:        } until (rp->r_pos.y != 0);
                     91:
                     92:        /* Draw the room */
                     93:        draw_room(rp);
                     94:
                     95:        /*
                     96:         * Put the gold in
                     97:         */
                     98:        if (rnd(100) < 50 && level >= cur_max)
                     99:        {
                    100:            register struct linked_list *item;
                    101:            register struct object *cur;
                    102:            coord tp;
                    103:
                    104:            has_gold = TRUE;    /* This room has gold in it */
                    105:
                    106:            item = spec_item(GOLD, 0, 0, 0);
                    107:            cur = OBJPTR(item);
                    108:
                    109:            /* Put the gold into the level list of items */
                    110:            attach(lvl_obj, item);
                    111:
                    112:            /* Put it somewhere */
                    113:            rnd_pos(rp, &tp);
                    114:            mvaddch(tp.y, tp.x, GOLD);
                    115:            cur->o_pos = tp;
                    116:            if (roomin(&tp) != rp) {
                    117:                endwin();
                    118:                printf("\n");
                    119:                abort();
                    120:            }
                    121:        }
                    122:
                    123:        /*
                    124:         * Put the monster in
                    125:         */
                    126:        if (rnd(100) < (has_gold ? 80 : 25) + vlevel/2)
                    127:        {
                    128:            item = new_item(sizeof *tp);
                    129:            tp = THINGPTR(item);
                    130:            do
                    131:            {
                    132:                rnd_pos(rp, &mp);
                    133:            } until(mvwinch(stdscr, mp.y, mp.x) == FLOOR);
                    134:            new_monster(item, randmonster(FALSE, FALSE), &mp, FALSE);
                    135:            /*
                    136:             * See if we want to give it a treasure to carry around.
                    137:             */
                    138:            carry_obj(tp, monsters[tp->t_index].m_carry);
                    139:
                    140:            /*
                    141:             * If it has a fire, mark it
                    142:             */
                    143:            if (on(*tp, HASFIRE)) {
                    144:                register struct linked_list *fire_item;
                    145:
                    146:                fire_item = creat_item();
                    147:                ldata(fire_item) = (char *) tp;
                    148:                attach(rp->r_fires, fire_item);
                    149:                rp->r_flags |= HASFIRE;
                    150:            }
                    151:        }
                    152:     }
                    153: }
                    154:
                    155: 
                    156: /*
                    157:  * Draw a box around a room
                    158:  */
                    159:
                    160: void
                    161: draw_room(struct room *rp)
                    162: {
                    163:     register int j, k;
                    164:
                    165:     move(rp->r_pos.y, rp->r_pos.x+1);
                    166:     vert(rp->r_max.y-2);                               /* Draw left side */
                    167:     move(rp->r_pos.y+rp->r_max.y-1, rp->r_pos.x);
                    168:     horiz(rp->r_max.x);                                        /* Draw bottom */
                    169:     move(rp->r_pos.y, rp->r_pos.x);
                    170:     horiz(rp->r_max.x);                                        /* Draw top */
                    171:     vert(rp->r_max.y-2);                               /* Draw right side */
                    172:     /*
                    173:      * Put the floor down
                    174:      */
                    175:     for (j = 1; j < rp->r_max.y-1; j++)
                    176:     {
                    177:        move(rp->r_pos.y + j, rp->r_pos.x+1);
                    178:        for (k = 1; k < rp->r_max.x-1; k++)
                    179:            addch(FLOOR);
                    180:     }
                    181: }
                    182: 
                    183: /*
                    184:  * horiz:
                    185:  *     draw a horizontal line
                    186:  */
                    187:
                    188: void
                    189: horiz(int cnt)
                    190: {
                    191:     while (cnt--)
                    192:        addch('-');
                    193: }
                    194: 
                    195: /*
                    196:  * rnd_pos:
                    197:  *     pick a random spot in a room
                    198:  */
                    199:
                    200: void
                    201: rnd_pos(struct room *rp, coord *cp)
                    202: {
                    203:     cp->x = rp->r_pos.x + rnd(rp->r_max.x-2) + 1;
                    204:     cp->y = rp->r_pos.y + rnd(rp->r_max.y-2) + 1;
                    205: }
                    206:
                    207:
                    208: 
                    209: /*
                    210:  * roomin:
                    211:  *     Find what room some coordinates are in. NULL means they aren't
                    212:  *     in any room.
                    213:  */
                    214:
                    215: struct room *
                    216: roomin(coord *cp)
                    217: {
                    218:     register struct room *rp;
                    219:
                    220:     for (rp = rooms; rp < &rooms[MAXROOMS]; rp++)
                    221:        if (inroom(rp, cp))
                    222:            return rp;
                    223:     return NULL;
                    224: }
                    225: 
                    226: /*
                    227:  * vert:
                    228:  *     draw a vertical line
                    229:  */
                    230:
                    231: void
                    232: vert(int cnt)
                    233: {
                    234:     register int x, y;
                    235:
                    236:     getyx(stdscr, y, x);
                    237:     x--;
                    238:     while (cnt--) {
                    239:        move(++y, x);
                    240:        addch('|');
                    241:     }
                    242: }

CVSweb