-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrooms.c
184 lines (168 loc) · 4.2 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
/*
* Draw the nine rooms on the screen
*
* @(#)rooms.c 3.8 (Berkeley) 6/15/81
*/
#include "curses.h"
#include "rogue.h"
#include "rooms.h"
#include "random.h"
#include "new_level.h"
#include "monsters.h"
#pragma code-name(push, "LC")
void do_rooms(void)
{
register int i;
register struct room *rp;
register struct linked_list *item;
register struct monster *monster;
register int left_out;
coord top;
coord bsze;
coord mp;
/*
* bsze is the maximum room size
*/
bsze.x = COLS/3;
bsze.y = LINES/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++)
rooms[rnd_room()].r_flags |= ISGONE;
/*
* 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)
{
/*
* 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 = 1;
rp->r_max.x = 1;
} until(rp->r_pos.y > 0 && rp->r_pos.y < LINES-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);
} until (rp->r_pos.y != 0);
/*
* Put the gold in
*/
if (rnd(100) < 50 && (!amulet || level >= max_level))
{
rp->r_goldval = GOLDCALC;
rnd_pos(rp, &(rp->r_gold));
//A2ROGUE: I think this checks if gold just added was actually added, and quits if not?? why is this needed?
// if (roomin(&rp->r_gold) != rp)
// endwin(), abort();
}
draw_room(rp);
/*
* Put the monster in
*/
if (rnd(100) < (rp->r_goldval > 0 ? 80 : 25))
{
// item = new_item(sizeof *tp);
// tp = (struct monster *) ldata(item);
do
{
rnd_pos(rp, &mp);
} until(mvwinch(stdscr, mp.y, mp.x) == FLOOR);
monster = new_monster(randmonster(FALSE), &mp);
/*
* See if we want to give it a treasure to carry around.
*/
// if (rnd(100) < monster_types[tp->t_type-'A'].m_carry)
// attach(tp->t_pack, new_thing());
}
}
}
/*
* Draw a box around a room
*/
void draw_room(struct room *rp)
{
register 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);
}
/*
* Put the gold there
*/
if (rp->r_goldval)
mvaddch(rp->r_gold.y, rp->r_gold.x, GOLD);
}
/*
* horiz:
* draw a horizontal line
*/
void horiz(unsigned char cnt)
{
while (cnt--)
addch('-');
}
/*
* vert:
* draw a vertical line
*/
void vert(char cnt)
{
register unsigned char 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;
}
#pragma code-name(pop)