Mercurial > hg > early-roguelike
comparison rogue4/rooms.c @ 12:9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
| author | edwarj4 |
|---|---|
| date | Sat, 24 Oct 2009 16:52:52 +0000 |
| parents | |
| children | 1b73a8641b37 |
comparison
equal
deleted
inserted
replaced
| 11:949d558c2162 | 12:9535a08ddc39 |
|---|---|
| 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 /* | |
| 20 * do_rooms: | |
| 21 * Create rooms and corridors with a connectivity graph | |
| 22 */ | |
| 23 do_rooms() | |
| 24 { | |
| 25 register int i; | |
| 26 register struct room *rp; | |
| 27 register THING *tp; | |
| 28 register int left_out; | |
| 29 coord top; | |
| 30 coord bsze; | |
| 31 coord mp; | |
| 32 | |
| 33 /* | |
| 34 * bsze is the maximum room size | |
| 35 */ | |
| 36 bsze.x = COLS/3; | |
| 37 bsze.y = LINES/3; | |
| 38 /* | |
| 39 * Clear things for a new level | |
| 40 */ | |
| 41 for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) | |
| 42 rp->r_goldval = rp->r_nexits = rp->r_flags = 0; | |
| 43 /* | |
| 44 * Put the gone rooms, if any, on the level | |
| 45 */ | |
| 46 left_out = rnd(4); | |
| 47 for (i = 0; i < left_out; i++) | |
| 48 rooms[rnd_room()].r_flags |= ISGONE; | |
| 49 /* | |
| 50 * dig and populate all the rooms on the level | |
| 51 */ | |
| 52 for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++) | |
| 53 { | |
| 54 /* | |
| 55 * Find upper left corner of box that this room goes in | |
| 56 */ | |
| 57 top.x = (i%3)*bsze.x + 1; | |
| 58 top.y = i/3*bsze.y; | |
| 59 if (rp->r_flags & ISGONE) | |
| 60 { | |
| 61 /* | |
| 62 * Place a gone room. Make certain that there is a blank line | |
| 63 * for passage drawing. | |
| 64 */ | |
| 65 do | |
| 66 { | |
| 67 rp->r_pos.x = top.x + rnd(bsze.x-2) + 1; | |
| 68 rp->r_pos.y = top.y + rnd(bsze.y-2) + 1; | |
| 69 rp->r_max.x = -COLS; | |
| 70 rp->r_max.x = -LINES; | |
| 71 } until (rp->r_pos.y > 0 && rp->r_pos.y < LINES-1); | |
| 72 continue; | |
| 73 } | |
| 74 if (rnd(10) < level - 1) | |
| 75 rp->r_flags |= ISDARK; | |
| 76 /* | |
| 77 * Find a place and size for a random room | |
| 78 */ | |
| 79 do | |
| 80 { | |
| 81 rp->r_max.x = rnd(bsze.x - 4) + 4; | |
| 82 rp->r_max.y = rnd(bsze.y - 4) + 4; | |
| 83 rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x); | |
| 84 rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y); | |
| 85 } until (rp->r_pos.y != 0); | |
| 86 /* | |
| 87 * Put the gold in | |
| 88 */ | |
| 89 if (rnd(2) == 0 && (!amulet || level >= max_level)) | |
| 90 { | |
| 91 register THING *gold; | |
| 92 | |
| 93 gold = new_item(); | |
| 94 gold->o_goldval = rp->r_goldval = GOLDCALC; | |
| 95 rnd_pos(rp, &rp->r_gold); | |
| 96 gold->o_pos = rp->r_gold; | |
| 97 gold->o_flags = ISMANY; | |
| 98 gold->o_group = GOLDGRP; | |
| 99 gold->o_type = GOLD; | |
| 100 attach(lvl_obj, gold); | |
| 101 } | |
| 102 draw_room(rp); | |
| 103 /* | |
| 104 * Put the monster in | |
| 105 */ | |
| 106 if (rnd(100) < (rp->r_goldval > 0 ? 80 : 25)) | |
| 107 { | |
| 108 tp = new_item(); | |
| 109 do | |
| 110 { | |
| 111 rnd_pos(rp, &mp); | |
| 112 } until (winat(mp.y, mp.x) == FLOOR); | |
| 113 new_monster(tp, randmonster(FALSE), &mp); | |
| 114 give_pack(tp); | |
| 115 } | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 /* | |
| 120 * draw_room: | |
| 121 * Draw a box around a room and lay down the floor | |
| 122 */ | |
| 123 draw_room(rp) | |
| 124 register struct room *rp; | |
| 125 { | |
| 126 register int y, x; | |
| 127 | |
| 128 vert(rp, rp->r_pos.x); /* Draw left side */ | |
| 129 vert(rp, rp->r_pos.x + rp->r_max.x - 1); /* Draw right side */ | |
| 130 horiz(rp, rp->r_pos.y); /* Draw top */ | |
| 131 horiz(rp, rp->r_pos.y + rp->r_max.y - 1); /* Draw bottom */ | |
| 132 /* | |
| 133 * Put the floor down | |
| 134 */ | |
| 135 for (y = rp->r_pos.y + 1; y < rp->r_pos.y + rp->r_max.y - 1; y++) | |
| 136 /*strrep(&chat(rp->r_pos.y + 1, j), FLOOR, rp->r_max.y - rp->r_pos.y - 2);*/ | |
| 137 for (x = rp->r_pos.x + 1; x < rp->r_pos.x + rp->r_max.x - 1; x++) | |
| 138 chat(y, x) = FLOOR; | |
| 139 /* | |
| 140 * Put the gold there | |
| 141 */ | |
| 142 if (rp->r_goldval) | |
| 143 chat(rp->r_gold.y, rp->r_gold.x) = GOLD; | |
| 144 } | |
| 145 | |
| 146 /* | |
| 147 * vert: | |
| 148 * Draw a vertical line | |
| 149 */ | |
| 150 vert(rp, startx) | |
| 151 register struct room *rp; | |
| 152 register int startx; | |
| 153 { | |
| 154 register int y; | |
| 155 | |
| 156 for (y = rp->r_pos.y + 1; y <= rp->r_max.y + rp->r_pos.y - 1; y++) | |
| 157 chat(y, startx) = '|'; | |
| 158 } | |
| 159 | |
| 160 /* | |
| 161 * horiz: | |
| 162 * Draw a horizontal line | |
| 163 */ | |
| 164 horiz(rp, starty) | |
| 165 register struct room *rp; | |
| 166 int starty; | |
| 167 { | |
| 168 register int x; | |
| 169 | |
| 170 for (x = rp->r_pos.x; x <= rp->r_pos.x + rp->r_max.x - 1; x++) | |
| 171 chat(starty, x) = '-'; | |
| 172 } | |
| 173 | |
| 174 /* | |
| 175 * rnd_pos: | |
| 176 * Pick a random spot in a room | |
| 177 */ | |
| 178 rnd_pos(rp, cp) | |
| 179 register struct room *rp; | |
| 180 register coord *cp; | |
| 181 { | |
| 182 cp->x = rp->r_pos.x + rnd(rp->r_max.x - 2) + 1; | |
| 183 cp->y = rp->r_pos.y + rnd(rp->r_max.y - 2) + 1; | |
| 184 } | |
| 185 | |
| 186 /* | |
| 187 * enter_room: | |
| 188 * Code that is executed whenver you appear in a room | |
| 189 */ | |
| 190 enter_room(cp) | |
| 191 register coord *cp; | |
| 192 { | |
| 193 register struct room *rp; | |
| 194 register int y, x; | |
| 195 register THING *tp; | |
| 196 | |
| 197 rp = proom = roomin(cp); | |
| 198 if (rp->r_flags & ISGONE) | |
| 199 { | |
| 200 msg("in a gone room"); | |
| 201 return; | |
| 202 } | |
| 203 door_open(rp); | |
| 204 if (!(rp->r_flags & ISDARK) && !on(player, ISBLIND)) | |
| 205 for (y = rp->r_pos.y; y < rp->r_max.y + rp->r_pos.y; y++) | |
| 206 { | |
| 207 move(y, rp->r_pos.x); | |
| 208 for (x = rp->r_pos.x; x < rp->r_max.x + rp->r_pos.x; x++) | |
| 209 { | |
| 210 tp = moat(y, x); | |
| 211 if (tp == NULL || !see_monst(tp)) | |
| 212 addch(chat(y, x)); | |
| 213 else | |
| 214 addch(tp->t_disguise); | |
| 215 } | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 /* | |
| 220 * leave_room: | |
| 221 * Code for when we exit a room | |
| 222 */ | |
| 223 leave_room(cp) | |
| 224 register coord *cp; | |
| 225 { | |
| 226 register int y, x; | |
| 227 register struct room *rp; | |
| 228 register char floor; | |
| 229 register char ch; | |
| 230 | |
| 231 rp = proom; | |
| 232 proom = &passages[flat(cp->y, cp->x) & F_PNUM]; | |
| 233 floor = ((rp->r_flags & ISDARK) && !on(player, ISBLIND)) ? ' ' : FLOOR; | |
| 234 for (y = rp->r_pos.y + 1; y < rp->r_max.y + rp->r_pos.y - 1; y++) | |
| 235 for (x = rp->r_pos.x + 1; x < rp->r_max.x + rp->r_pos.x - 1; x++) | |
| 236 switch (ch = mvinch(y, x)) | |
| 237 { | |
| 238 case ' ': | |
| 239 case TRAP: | |
| 240 case STAIRS: | |
| 241 break; | |
| 242 case FLOOR: | |
| 243 if (floor == ' ') | |
| 244 addch(' '); | |
| 245 break; | |
| 246 default: | |
| 247 /* | |
| 248 * to check for monster, we have to strip out | |
| 249 * standout bit | |
| 250 */ | |
| 251 if (isupper(toascii(ch))) | |
| 252 if (on(player, SEEMONST)) | |
| 253 { | |
| 254 standout(); | |
| 255 addch(ch); | |
| 256 standend(); | |
| 257 break; | |
| 258 } | |
| 259 else | |
| 260 { | |
| 261 THING *tp = moat(y, x); | |
| 262 | |
| 263 if (tp != NULL) | |
| 264 tp->t_oldch = floor; | |
| 265 | |
| 266 #ifdef WIZARD | |
| 267 else | |
| 268 msg("couldn't find monster in leave_room at (%d,%d)", y, x); | |
| 269 #endif | |
| 270 } | |
| 271 | |
| 272 addch(floor); | |
| 273 } | |
| 274 door_open(rp); | |
| 275 } |
