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

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

1.1       rubenllo    1: /*
                      2:  * Draw the nine rooms on the screen
                      3:  *
                      4:  * @(#)rooms.c 9.0     (rdk)    7/17/84
                      5:  *
                      6:  * Super-Rogue
                      7:  * Copyright (C) 1984 Robert D. Kindelberger
                      8:  * All rights reserved.
                      9:  *
                     10:  * Based on "Rogue: Exploring the Dungeons of Doom"
                     11:  * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
                     12:  * All rights reserved.
                     13:  *
                     14:  * See the file LICENSE.TXT for full copyright and licensing information.
                     15:  */
                     16:
                     17: #include "rogue.h"
                     18: #include "rogue.ext"
                     19:
                     20: void horiz(int cnt);
                     21: void vert(int cnt);
                     22:
                     23: /*
                     24:  * do_rooms:
                     25:  *     Place the rooms in the dungeon
                     26:  */
                     27: void
                     28: do_rooms(void)
                     29: {
                     30:        int mloops, mchance, nummons, left_out, roomtries;
                     31:        bool treas = FALSE;
                     32:        reg int i;
                     33:        reg struct room *rp;
                     34:        reg struct linked_list *item;
                     35:        reg struct thing *tp;
                     36:        struct coord top, bsze, mp;
                     37:
                     38:        /*
                     39:         * bsze is the maximum room size
                     40:         */
                     41:        bsze.x = COLS / 3;
                     42:        bsze.y = (LINES - 1) / 3;
                     43:        /*
                     44:         * Clear things for a new level
                     45:         */
                     46:        for (rp = rooms; rp < &rooms[MAXROOMS]; rp++)
                     47:                rp->r_goldval = rp->r_nexits = rp->r_flags = 0;
                     48:        /*
                     49:         * Put the gone rooms, if any, on the level
                     50:         */
                     51:        left_out = rnd(4);
                     52:        for (i = 0; i < left_out; i++)
                     53:                rooms[rnd_room()].r_flags |= ISGONE;
                     54:        /*
                     55:         * dig and populate all the rooms on the level
                     56:         */
                     57:        for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++) {
                     58:                /*
                     59:                 * Find upper left corner of box that this room goes in
                     60:                 */
                     61:                top.x = (i%3) * bsze.x + 1;
                     62:                top.y = i/3 * bsze.y;
                     63:                if (rf_on(rp,ISGONE)) {
                     64:                        /*
                     65:                         * Place a gone room.  Make certain that there is a
                     66:                         * blank line for passage drawing.
                     67:                         */
                     68:                        roomtries = 0;
                     69:                        do {
                     70:                                rp->r_pos.x = top.x + rnd(bsze.x-2) + 1;
                     71:                                rp->r_pos.y = top.y + rnd(bsze.y-2) + 1;
                     72:                                rp->r_max.x = -COLS;
                     73:                                rp->r_max.x = -LINES;
                     74:                                if (++roomtries > 250)
                     75:                                        fatal("failed to place a gone room");
                     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:                roomtries = 0;
                     85:                do {
                     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:                        if (++roomtries > 250) {
                     91:                                fatal("failed to place a good room");
                     92:                        }
                     93:                } until (rp->r_pos.y != 0);
                     94:                if (level < max_level)
                     95:                        mchance = 30;   /* 30% when going up (all monsters) */
                     96:                else
                     97:                        mchance = 3;    /* 3% when going down */
                     98:                treas = FALSE;
                     99:                if (rnd(100) < mchance && (rp->r_max.x * rp->r_max.y) >
                    100:                  ((bsze.x * bsze.y * 55) / 100)) {
                    101:                        treas = TRUE;
                    102:                        rp->r_flags |= ISTREAS;
                    103:                        rp->r_flags |= ISDARK;
                    104:                }
                    105:                /*
                    106:                 * Put the gold in
                    107:                 */
                    108:                if ((rnd(100) < 50 || treas) && (!amulet || level >= max_level)) {
                    109:                        rp->r_goldval = GOLDCALC;
                    110:                        if (treas)
                    111:                                rp->r_goldval += 200 + (15 * (rnd(level) + 2));
                    112:                        rp->r_gold.y = rp->r_pos.y + rnd(rp->r_max.y - 2) + 1;
                    113:                        rp->r_gold.x = rp->r_pos.x + rnd(rp->r_max.x - 2) + 1;
                    114:                }
                    115:                draw_room(rp);
                    116:                /*
                    117:                 * Put the monster in
                    118:                 */
                    119:                if (treas) {
                    120:                        mloops = rnd(level / 3) + 6;
                    121:                        mchance = 1;
                    122:                }
                    123:                else {
                    124:                        mloops = 1;
                    125:                        mchance = 100;
                    126:                }
                    127:                for (nummons = 0; nummons < mloops; nummons++) {
                    128:                        if (rnd(mchance) < (rp->r_goldval > 0 ? 80 : 25))
                    129:                                add_mon(rp, treas);
                    130:                }
                    131:        }
                    132: }
                    133:
                    134: /*
                    135:  * add_mon:
                    136:  *     Add a monster to a room
                    137:  */
                    138: void
                    139: add_mon(struct room *rm, bool treas)
                    140: {
                    141:        reg struct thing *tp;
                    142:        reg struct linked_list *item;
                    143:        struct coord mp;
                    144:        int chance;
                    145:
                    146:        mp = *rnd_pos(rm);
                    147:        item = new_monster(rnd_mon(FALSE,FALSE), &mp, treas);
                    148:        tp = THINGPTR(item);
                    149:        chance = rnd(100);
                    150:        if (levtype == MAZELEV)
                    151:                chance = rnd(50);
                    152:        /*
                    153:         * See if monster has a treasure
                    154:         */
                    155:        if (levtype == MAZELEV && rnd(100) < 20) {
                    156:                reg struct linked_list *fd;
                    157:
                    158:                fd = new_thing(FALSE, FOOD, 0);
                    159:                attach(tp->t_pack, fd);
                    160:        }
                    161:        else {
                    162:                if (chance < monsters[tp->t_indx].m_carry)
                    163:                        attach(tp->t_pack, new_thing(FALSE, ANYTHING));
                    164:        }
                    165: }
                    166:
                    167: /*
                    168:  * draw_room:
                    169:  *     Draw a box around a room
                    170:  */
                    171: void
                    172: draw_room(struct room *rp)
                    173: {
                    174:        reg int j, k;
                    175:
                    176:        move(rp->r_pos.y, rp->r_pos.x+1);
                    177:        vert(rp->r_max.y-2);                    /* Draw left side */
                    178:        move(rp->r_pos.y+rp->r_max.y-1, rp->r_pos.x);
                    179:        horiz(rp->r_max.x);                             /* Draw bottom */
                    180:        move(rp->r_pos.y, rp->r_pos.x);
                    181:        horiz(rp->r_max.x);                             /* Draw top */
                    182:        vert(rp->r_max.y-2);                    /* Draw right side */
                    183:        /*
                    184:         * Put the floor down
                    185:         */
                    186:        for (j = 1; j < rp->r_max.y - 1; j++) {
                    187:                move(rp->r_pos.y + j, rp->r_pos.x + 1);
                    188:                for (k = 1; k < rp->r_max.x - 1; k++) {
                    189:                        addch(FLOOR);
                    190:                }
                    191:        }
                    192:        /*
                    193:         * Put the gold there
                    194:         */
                    195:        if (rp->r_goldval > 0)
                    196:                mvaddch(rp->r_gold.y, rp->r_gold.x, GOLD);
                    197: }
                    198:
                    199: /*
                    200:  * horiz:
                    201:  *     draw a horizontal line
                    202:  */
                    203: void
                    204: horiz(int cnt)
                    205: {
                    206:        while (cnt-- > 0)
                    207:        addch('-');
                    208: }
                    209:
                    210:
                    211: /*
                    212:  * vert:
                    213:  *     draw a vertical line
                    214:  */
                    215: void
                    216: vert(int cnt)
                    217: {
                    218:        reg int x, y;
                    219:
                    220:        getyx(stdscr, y, x);
                    221:        x--;
                    222:        while (cnt-- > 0) {
                    223:                move(++y, x);
                    224:                addch('|');
                    225:        }
                    226: }
                    227:
                    228:
                    229: /*
                    230:  * rnd_pos:
                    231:  *     pick a random spot in a room
                    232:  */
                    233: struct coord *
                    234: rnd_pos(struct room *rp)
                    235: {
                    236:        reg int y, x, i;
                    237:        static struct coord spot;
                    238:
                    239:        i = 0;
                    240:        do {
                    241:                x = rp->r_pos.x + rnd(rp->r_max.x - 2) + 1;
                    242:                y = rp->r_pos.y + rnd(rp->r_max.y - 2) + 1;
                    243:                i += 1;
                    244:        } while(winat(y, x) != FLOOR && i < 1000);
                    245:        spot.x = x;
                    246:        spot.y = y;
                    247:        return &spot;
                    248: }
                    249:
                    250: /*
                    251:  * rf_on:
                    252:  *     Returns TRUE if flag is set for room stuff
                    253:  */
                    254: bool
                    255: rf_on(struct room *rm, long bit)
                    256: {
                    257:        return (rm->r_flags & bit);
                    258: }

CVSweb