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

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

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

CVSweb