Annotation of early-roguelike/rogue4/rooms.c, Revision 1.1
1.1 ! rubenllo 1: /*
! 2: * Create the layout for the new level
! 3: *
! 4: * @(#)rooms.c 4.16 (Berkeley) 1/12/82
! 5: *
! 6: * Rogue: Exploring the Dungeons of Doom
! 7: * Copyright (C) 1980, 1981, 1982 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 <ctype.h>
! 14: #include <curses.h>
! 15: #include "rogue.h"
! 16:
! 17: #define GOLDGRP 1
! 18:
! 19: void draw_room(struct room *rp);
! 20: void vert(struct room *rp, int startx);
! 21: void horiz(struct room *rp, int starty);
! 22:
! 23: /*
! 24: * do_rooms:
! 25: * Create rooms and corridors with a connectivity graph
! 26: */
! 27: void
! 28: do_rooms(void)
! 29: {
! 30: register int i;
! 31: register struct room *rp;
! 32: register THING *tp;
! 33: register int left_out;
! 34: coord top;
! 35: coord bsze;
! 36: coord mp;
! 37:
! 38: /*
! 39: * bsze is the maximum room size
! 40: */
! 41: bsze.x = COLS/3;
! 42: bsze.y = LINES/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: /*
! 60: * Find upper left corner of box that this room goes in
! 61: */
! 62: top.x = (i%3)*bsze.x + 1;
! 63: top.y = i/3*bsze.y;
! 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-1);
! 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: * Put the gold in
! 93: */
! 94: if (rnd(2) == 0 && (!amulet || level >= max_level))
! 95: {
! 96: register THING *gold;
! 97:
! 98: gold = new_item();
! 99: gold->o_goldval = rp->r_goldval = GOLDCALC;
! 100: rnd_pos(rp, &rp->r_gold);
! 101: gold->o_pos = rp->r_gold;
! 102: gold->o_flags = ISMANY;
! 103: gold->o_group = GOLDGRP;
! 104: gold->o_type = GOLD;
! 105: attach(lvl_obj, gold);
! 106: }
! 107: draw_room(rp);
! 108: /*
! 109: * Put the monster in
! 110: */
! 111: if (rnd(100) < (rp->r_goldval > 0 ? 80 : 25))
! 112: {
! 113: tp = new_item();
! 114: do
! 115: {
! 116: rnd_pos(rp, &mp);
! 117: } until (winat(mp.y, mp.x) == FLOOR);
! 118: new_monster(tp, randmonster(FALSE), &mp);
! 119: give_pack(tp);
! 120: }
! 121: }
! 122: }
! 123:
! 124: /*
! 125: * draw_room:
! 126: * Draw a box around a room and lay down the floor
! 127: */
! 128: void
! 129: draw_room(struct room *rp)
! 130: {
! 131: register int y, x;
! 132:
! 133: vert(rp, rp->r_pos.x); /* Draw left side */
! 134: vert(rp, rp->r_pos.x + rp->r_max.x - 1); /* Draw right side */
! 135: horiz(rp, rp->r_pos.y); /* Draw top */
! 136: horiz(rp, rp->r_pos.y + rp->r_max.y - 1); /* Draw bottom */
! 137: /*
! 138: * Put the floor down
! 139: */
! 140: for (y = rp->r_pos.y + 1; y < rp->r_pos.y + rp->r_max.y - 1; y++)
! 141: /*strrep(&chat(rp->r_pos.y + 1, j), FLOOR, rp->r_max.y - rp->r_pos.y - 2);*/
! 142: for (x = rp->r_pos.x + 1; x < rp->r_pos.x + rp->r_max.x - 1; x++)
! 143: chat(y, x) = FLOOR;
! 144: /*
! 145: * Put the gold there
! 146: */
! 147: if (rp->r_goldval)
! 148: chat(rp->r_gold.y, rp->r_gold.x) = GOLD;
! 149: }
! 150:
! 151: /*
! 152: * vert:
! 153: * Draw a vertical line
! 154: */
! 155: void
! 156: vert(struct room *rp, int startx)
! 157: {
! 158: register int y;
! 159:
! 160: for (y = rp->r_pos.y + 1; y <= rp->r_max.y + rp->r_pos.y - 1; y++)
! 161: chat(y, startx) = '|';
! 162: }
! 163:
! 164: /*
! 165: * horiz:
! 166: * Draw a horizontal line
! 167: */
! 168: void
! 169: horiz(struct room *rp, int starty)
! 170: {
! 171: register int x;
! 172:
! 173: for (x = rp->r_pos.x; x <= rp->r_pos.x + rp->r_max.x - 1; x++)
! 174: chat(starty, x) = '-';
! 175: }
! 176:
! 177: /*
! 178: * rnd_pos:
! 179: * Pick a random spot in a room
! 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: }
! 187:
! 188: /*
! 189: * enter_room:
! 190: * Code that is executed whenver you appear in a room
! 191: */
! 192: void
! 193: enter_room(coord *cp)
! 194: {
! 195: register struct room *rp;
! 196: register int y, x;
! 197: register THING *tp;
! 198:
! 199: rp = proom = roomin(cp);
! 200: if (rp->r_flags & ISGONE)
! 201: {
! 202: msg("in a gone room");
! 203: return;
! 204: }
! 205: door_open(rp);
! 206: if (!(rp->r_flags & ISDARK) && !on(player, ISBLIND))
! 207: for (y = rp->r_pos.y; y < rp->r_max.y + rp->r_pos.y; y++)
! 208: {
! 209: move(y, rp->r_pos.x);
! 210: for (x = rp->r_pos.x; x < rp->r_max.x + rp->r_pos.x; x++)
! 211: {
! 212: tp = moat(y, x);
! 213: if (tp == NULL || !see_monst(tp))
! 214: addch(chat(y, x));
! 215: else
! 216: addch(tp->t_disguise);
! 217: }
! 218: }
! 219: }
! 220:
! 221: /*
! 222: * leave_room:
! 223: * Code for when we exit a room
! 224: */
! 225: void
! 226: leave_room(coord *cp)
! 227: {
! 228: register int y, x;
! 229: register struct room *rp;
! 230: register char floor;
! 231: register char ch;
! 232:
! 233: rp = proom;
! 234: proom = &passages[flat(cp->y, cp->x) & F_PNUM];
! 235: floor = ((rp->r_flags & ISDARK) && !on(player, ISBLIND)) ? ' ' : FLOOR;
! 236: for (y = rp->r_pos.y + 1; y < rp->r_max.y + rp->r_pos.y - 1; y++)
! 237: for (x = rp->r_pos.x + 1; x < rp->r_max.x + rp->r_pos.x - 1; x++)
! 238: switch (ch = mvinch(y, x))
! 239: {
! 240: case ' ':
! 241: case TRAP:
! 242: case STAIRS:
! 243: break;
! 244: case FLOOR:
! 245: if (floor == ' ')
! 246: addch(' ');
! 247: break;
! 248: default:
! 249: /*
! 250: * to check for monster, we have to strip out
! 251: * standout bit
! 252: */
! 253: if (isupper(toascii(ch)))
! 254: if (on(player, SEEMONST))
! 255: {
! 256: standout();
! 257: addch(ch);
! 258: standend();
! 259: break;
! 260: }
! 261: else
! 262: {
! 263: THING *tp = moat(y, x);
! 264:
! 265: if (tp != NULL)
! 266: tp->t_oldch = floor;
! 267:
! 268: #ifdef WIZARD
! 269: else
! 270: msg("couldn't find monster in leave_room at (%d,%d)", y, x);
! 271: #endif
! 272: }
! 273:
! 274: addch(floor);
! 275: }
! 276: door_open(rp);
! 277: }
CVSweb