forked from RoguelikeRestorationProject/urogue1.03
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrooms.c
302 lines (256 loc) · 6.05 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
295
296
297
298
299
300
301
302
/*
rooms.c - Draw the nine rooms on the screen
UltraRogue
Copyright (C) 1984, 1985, 1986, 1987, 1990, 1991 Herb Chong
All rights reserved.
Based on "Advanced Rogue"
Copyright (C) 1983, 1984 Michael Morgan, Ken Dalka and AT&T
All rights reserved.
Based on "Super-Rogue"
Copyright (C) 1982, 1983 Robert D. Kindelberger
All rights reserved.
Based on "Rogue: Exploring the Dungeons of Doom"
Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
All rights reserved.
See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <stdlib.h>
#include "rogue.h"
void
do_rooms()
{
int i;
struct room *rp;
struct linked_list *item;
struct thing *tp;
int left_out;
coord top;
coord bsze;
coord mp;
/*
* bsze is the maximum room size
*/
bsze.x = ur_cols / 3;
bsze.y = (ur_lines - 2) / 3;
/*
* Clear things for a new level
*/
for (rp = rooms; rp < &rooms[MAXROOMS]; rp++)
rp->r_nexits = rp->r_flags = rp->r_fires = 0;
/*
* Put the gone rooms, if any, on the level
*/
left_out = rnd(4);
for (i = 0; i < left_out; i++)
rooms[rnd_room()].r_flags |= ISGONE;
/*
* dig and populate all the rooms on the level
*/
for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++) {
bool has_gold = FALSE;
/*
* Find upper left corner of box that this room goes in
*/
top.x = (i % 3) * bsze.x;
top.y = i / 3 * bsze.y + 1;
if (rp->r_flags & ISGONE) {
/*
* 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 = -ur_cols;
rp->r_max.x = -ur_lines;
} while (rp->r_pos.y < 1 || rp->r_pos.y > ur_lines - 3);
continue;
}
if (rnd(80) < level - 15)
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 the room */
draw_room(rp);
/*
* Put the gold in
*/
if (rnd(100) < 50 && (!has_artifact || level >= max_level)) {
struct linked_list *item;
struct object *cur;
coord tp;
has_gold = TRUE; /* This room has gold in it */
item = spec_item(GOLD, 0, 0, 0);
cur = OBJPTR(item);
/* Put it somewhere */
rnd_pos(rp, &tp);
cur->o_pos = tp;
/* Put the gold into the level list of items */
add_obj(item, tp.y, tp.x);
if (roomin(&tp) != rp) {
endwin();
abort();
}
}
/*
* Put the monster in
*/
if (rnd(100) < (has_gold ? 80 : 40)) {
short which;
int i, count;
item = new_item(sizeof *tp);
tp = THINGPTR(item);
do {
rnd_pos(rp, &mp);
} while (mvwinch(stdscr, mp.y, mp.x) != FLOOR);
which = randmonster(NOWANDER, NOGRAB);
new_monster(item, which, &mp, NOMAXSTATS);
/*
* See if we want to give it a treasure to carry
* around.
*/
if (rnd(100) < monsters[tp->t_index].m_carry)
attach(tp->t_pack, new_thing());
/*
* If it has a fire, mark it
*/
if (on(*tp, HASFIRE)) {
rp->r_flags |= HASFIRE;
rp->r_fires++;
}
/*
* If it carries gold, give it some
*/
if (on(*tp, CARRYGOLD)) {
struct object *cur;
item = spec_item(GOLD, 0, 0, 0);
cur = OBJPTR(item);
cur->o_count = GOLDCALC + GOLDCALC + GOLDCALC;
cur->o_pos = tp->t_pos;
attach(tp->t_pack, item);
}
i = rnd(7);
if (on(*tp, ISSWARM) && i < 5)
count = roll(2, 4);
else if (on(*tp, ISFLOCK) && i < 5)
count = roll(1, 4);
else
count = 0;
for (i = 1; i <= count; i++) {
coord *mpos;
if ((mpos = place_mons(mp.y, mp.x)) != NULL) {
struct linked_list *nitem;
nitem = new_item(sizeof(struct thing));
new_monster(nitem, which, mpos,
NOMAXSTATS);
/*
* If the monster is on a trap, trap
* it
*/
if (isatrap(mvinch(mpos->y, mpos->x))) {
struct thing *tmp = THINGPTR(nitem);
be_trapped(&tmp, &mp);
if (!tmp)
nitem = NULL;
}
if (nitem && on(*tp, ISFRIENDLY))
turn_on(*(THINGPTR(nitem)),
ISFRIENDLY);
else if (nitem)
turn_off(*(THINGPTR(nitem)),
ISFRIENDLY);
}
}
if (count > 0) {
int boost = rnd(3) + 1;
if (on(*tp, LOWCAST) || on(*tp, MEDCAST) ||
on(*tp, HIGHCAST))
turn_on(*tp, CANCAST);
tp->t_stats.s_hpt += 3 * boost;
tp->t_stats.s_arm -= 2 * boost;
tp->t_stats.s_lvl += 2 * boost;
tp->t_stats.s_str += 2 * boost;
tp->t_stats.s_intel += 2 * boost;
tp->t_stats.s_exp += 4 * boost *
monsters[which].m_add_exp;
}
}
}
}
/*
* Draw a box around a room
*/
void
draw_room(struct room *rp)
{
int j, k;
move(rp->r_pos.y, rp->r_pos.x + 1);
vert(rp->r_max.y - 2); /* Draw left side */
move(rp->r_pos.y + rp->r_max.y - 1, rp->r_pos.x);
horiz(rp->r_max.x); /* Draw bottom */
move(rp->r_pos.y, rp->r_pos.x);
horiz(rp->r_max.x); /* Draw top */
vert(rp->r_max.y - 2); /* Draw right side */
/*
* Put the floor down
*/
for (j = 1; j < rp->r_max.y - 1; j++) {
move(rp->r_pos.y + j, rp->r_pos.x + 1);
for (k = 1; k < rp->r_max.x - 1; k++)
addch(FLOOR);
}
}
/*
* horiz: draw a horizontal line
*/
void
horiz(int cnt)
{
while (cnt--)
addch('-');
}
/*
* vert: draw a vertical line
*/
void
vert(int cnt)
{
int x, y;
getyx(stdscr, y, x);
x--;
while (cnt--) {
move(++y, x);
addch('|');
}
}
/*
* rnd_pos: pick a random spot in a room
*/
void
rnd_pos(struct room *rp, 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;
}
/*
* Pick a room that is really there
*/
int
rnd_room()
{
int rm;
if (levtype != NORMLEV)
rm = 0;
else
do {
rm = rnd(MAXROOMS);
} while (rooms[rm].r_flags & ISGONE);
return rm;
}