-
Notifications
You must be signed in to change notification settings - Fork 0
/
ROOMS.C
294 lines (275 loc) · 6.87 KB
/
ROOMS.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
* Create the layout for the new level
*
* rooms.c 1.4 (A.I. Design) 12/16/84
*/
#include "rogue.h"
#include "curses.h"
#define GOLDGRP 1
/*
* do_rooms:
* Create rooms and corridors with a connectivity graph
*/
do_rooms()
{
register int i, rm;
struct room *rp;
register THING *tp;
int left_out;
coord top;
coord bsze;
coord mp;
int old_lev;
int endline;
endline = maxrow + 1;
old_lev = level;
/*
* bsze is the maximum room size
*/
bsze.x = COLS/3;
bsze.y = endline/3;
/*
* Clear things for a new level
*/
for (rp = rooms; rp < &rooms[MAXROOMS]; rp++)
rp->r_goldval = rp->r_nexits = rp->r_flags = 0;
/*
* Put the gone rooms, if any, on the level
*/
left_out = rnd(4);
for (i = 0; i < left_out; i++) {
do
rp = &rooms[(rm = rnd_room())];
while (rp->r_flags & ISMAZE);
rp->r_flags |= ISGONE;
#ifdef TEST
if (rm > 2 && ((level > 10 && rnd(20) < level - 9) || istest()))
#else TEST
if (rm > 2 && level > 10 && rnd(20) < level - 9)
#endif TEST
rp->r_flags |= ISMAZE;
}
/*
* dig and populate all the rooms on the level
*/
for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++) {
/*
* Find upper left corner of box that this room goes in
*/
top.x = (i%3)*bsze.x + 1;
top.y = i/3*bsze.y;
if (rp->r_flags & ISGONE) {
/*
* If the gone room is a maze room, draw the maze and set the
* size equal to the maximum possible.
*/
if (rp->r_flags&ISMAZE) {
rp->r_pos.x = top.x;
rp->r_pos.y = top.y;
draw_maze(rp);
} else {
/*
* Place a gone room. Make certain that there is a blank line
* for passage drawing.
*/
do {
rp->r_pos.x = top.x + rnd(bsze.x-2) + 1;
rp->r_pos.y = top.y + rnd(bsze.y-2) + 1;
rp->r_max.x = -COLS;
rp->r_max.x = -endline;
} while (!(rp->r_pos.y > 0 && rp->r_pos.y < endline-1));
}
continue;
}
if (rnd(10) < (level - 1))
rp->r_flags |= ISDARK;
/*
* Find a place and size for a random room
*/
do {
rp->r_max.x = rnd(bsze.x - 4) + 4;
rp->r_max.y = rnd(bsze.y - 4) + 4;
rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x);
rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y);
} while (rp->r_pos.y == 0);
draw_room(rp);
/*
* Put the gold in
*/
if ((rnd(2) == 0) && (!saw_amulet || (level >= max_level))) {
THING *gold;
if ((gold = new_item()) != NULL) {
gold->o_goldval = rp->r_goldval = GOLDCALC;
while (1) {
byte gch;
rnd_pos(rp, &rp->r_gold);
gch = chat(rp->r_gold.y, rp->r_gold.x);
if (isfloor(gch))
break;
}
bcopy(gold->o_pos,rp->r_gold);
gold->o_flags = ISMANY;
gold->o_group = GOLDGRP;
gold->o_type = GOLD;
attach(lvl_obj, gold);
chat(rp->r_gold.y, rp->r_gold.x) = GOLD;
}
}
/*
* Put the monster in
*/
if (rnd(100) < (rp->r_goldval > 0 ? 80 : 25)) {
if ((tp = new_item()) != NULL) {
byte mch;
do {
rnd_pos(rp, &mp);
mch = winat(mp.y, mp.x);
} while (!isfloor(mch));
new_monster(tp, randmonster(FALSE), &mp);
give_pack(tp);
}
}
}
}
/*
* draw_room:
* Draw a box around a room and lay down the floor
*/
draw_room(rp)
struct room *rp;
{
register int y, x;
/*
* Here we draw normal rooms, one side at a time
*/
vert(rp, rp->r_pos.x); /* Draw left side */
vert(rp, rp->r_pos.x + rp->r_max.x - 1); /* Draw right side */
horiz(rp, rp->r_pos.y); /* Draw top */
horiz(rp, rp->r_pos.y + rp->r_max.y - 1); /* Draw bottom */
chat(rp->r_pos.y,rp->r_pos.x) = ULWALL;
chat(rp->r_pos.y,rp->r_pos.x+rp->r_max.x - 1) = URWALL;
chat(rp->r_pos.y+rp->r_max.y-1,rp->r_pos.x) = LLWALL;
chat(rp->r_pos.y+rp->r_max.y-1,rp->r_pos.x+rp->r_max.x - 1) = LRWALL;
/*
* Put the floor down
*/
for (y = rp->r_pos.y + 1; y < rp->r_pos.y + rp->r_max.y - 1; y++)
for (x = rp->r_pos.x + 1; x < rp->r_pos.x + rp->r_max.x - 1; x++)
chat(y, x) = FLOOR;
}
/*
* vert:
* Draw a vertical line
*/
vert(rp, startx)
register struct room *rp;
register int startx;
{
register register int y;
for (y = rp->r_pos.y + 1; y <= rp->r_max.y + rp->r_pos.y - 1; y++)
chat(y, startx) = VWALL;
}
/*
* horiz:
* Draw a horizontal line
*/
horiz(rp, starty)
struct room *rp;
int starty;
{
register int x;
for (x = rp->r_pos.x; x <= rp->r_pos.x + rp->r_max.x - 1; x++)
chat(starty, x) = HWALL;
}
/*
* rnd_pos:
* Pick a random spot in a room
*/
rnd_pos(rp, cp)
register struct room *rp;
register coord *cp;
{
cp->x = rp->r_pos.x + rnd(rp->r_max.x - 2) + 1;
cp->y = rp->r_pos.y + rnd(rp->r_max.y - 2) + 1;
}
/*
* enter_room:
* Code that is executed whenver you appear in a room
*/
enter_room(cp)
register coord *cp;
{
register struct room *rp;
register int y, x;
register THING *tp;
rp = proom = roomin(cp);
if (bailout || (rp->r_flags & ISGONE && (rp->r_flags & ISMAZE) == 0)) {
#ifdef DEBUG
msg("in a gone room");
#endif DEBUG
return;
}
door_open(rp);
if (!(rp->r_flags&ISDARK) && !on(player,ISBLIND) && !(rp->r_flags&ISMAZE))
for (y = rp->r_pos.y; y < rp->r_max.y + rp->r_pos.y; y++) {
move(y, rp->r_pos.x);
for (x = rp->r_pos.x; x < rp->r_max.x + rp->r_pos.x; x++) {
/*
* Displaying monsters is all handled in the
* chase code now
*/
tp = moat(y, x);
if (tp == NULL || !see_monst(tp))
addch(chat(y, x));
else {
tp->t_oldch = chat(y,x);
addch(tp->t_disguise);
}
}
}
}
/*
* leave_room:
* Code for when we exit a room
*/
leave_room(cp)
register coord *cp;
{
register int y, x;
register struct room *rp;
register byte floor;
register byte ch;
rp = proom;
proom = &passages[flat(cp->y, cp->x) & F_PNUM];
floor = ((rp->r_flags & ISDARK) && !on(player, ISBLIND)) ? ' ' : FLOOR;
if (rp->r_flags & ISMAZE)
floor = PASSAGE;
for (y = rp->r_pos.y + 1; y < rp->r_max.y + rp->r_pos.y - 1; y++)
for (x = rp->r_pos.x + 1; x < rp->r_max.x + rp->r_pos.x - 1; x++)
switch (ch = mvinch(y, x)) {
case ' ':
case PASSAGE:
case TRAP:
case STAIRS:
break;
case FLOOR:
if (floor == ' ')
addch(' ');
break;
default:
/*
* to check for monster, we have to strip out
* standout bit
*/
if (isupper(toascii(ch)))
if (on(player, SEEMONST)) {
standout();
addch(ch);
standend();
break;
} else
moat(y, x)->t_oldch = '@';
addch(floor);
}
door_open(rp);
}