comparison arogue5/rooms.c @ 63:0ed67132cf10

Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 09 Aug 2012 22:58:48 +0000
parents
children c49f7927b0fa
comparison
equal deleted inserted replaced
62:0ef99244acb8 63:0ed67132cf10
1 /*
2 * Draw the nine rooms on the screen
3 *
4 * Advanced Rogue
5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
6 * All rights reserved.
7 *
8 * Based on "Rogue: Exploring the Dungeons of Doom"
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * All rights reserved.
11 *
12 * See the file LICENSE.TXT for full copyright and licensing information.
13 */
14
15 #include "curses.h"
16 #include "rogue.h"
17
18 do_rooms()
19 {
20 register int i;
21 register struct room *rp;
22 register struct linked_list *item;
23 register struct thing *tp;
24 register int left_out;
25 coord top;
26 coord bsze;
27 coord mp;
28
29 /*
30 * bsze is the maximum room size
31 */
32 bsze.x = COLS/3;
33 bsze.y = (LINES-2)/3;
34 /*
35 * Clear things for a new level
36 */
37 for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
38 rp->r_flags = 0;
39 rp->r_fires = NULL;
40 }
41 /*
42 * Put the gone rooms, if any, on the level
43 */
44 left_out = rnd(4);
45 for (i = 0; i < left_out; i++)
46 rooms[rnd_room()].r_flags |= ISGONE;
47 /*
48 * dig and populate all the rooms on the level
49 */
50 for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++)
51 {
52 bool has_gold=FALSE;
53
54 /*
55 * Find upper left corner of box that this room goes in
56 */
57 top.x = (i%3)*bsze.x;
58 top.y = i/3*bsze.y + 1;
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-2);
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 /* Draw the room */
88 draw_room(rp);
89
90 /*
91 * Put the gold in
92 */
93 if (rnd(100) < 50 && level >= cur_max)
94 {
95 register struct linked_list *item;
96 register struct object *cur;
97 coord tp;
98
99 has_gold = TRUE; /* This room has gold in it */
100
101 item = spec_item(GOLD, NULL, NULL, NULL);
102 cur = OBJPTR(item);
103
104 /* Put the gold into the level list of items */
105 attach(lvl_obj, item);
106
107 /* Put it somewhere */
108 rnd_pos(rp, &tp);
109 mvaddch(tp.y, tp.x, GOLD);
110 cur->o_pos = tp;
111 if (roomin(&tp) != rp) {
112 endwin();
113 printf("\n");
114 abort();
115 }
116 }
117
118 /*
119 * Put the monster in
120 */
121 if (rnd(100) < (has_gold ? 80 : 25) + vlevel/2)
122 {
123 item = new_item(sizeof *tp);
124 tp = THINGPTR(item);
125 do
126 {
127 rnd_pos(rp, &mp);
128 } until(mvwinch(stdscr, mp.y, mp.x) == FLOOR);
129 new_monster(item, randmonster(FALSE, FALSE), &mp, FALSE);
130 /*
131 * See if we want to give it a treasure to carry around.
132 */
133 carry_obj(tp, monsters[tp->t_index].m_carry);
134
135 /*
136 * If it has a fire, mark it
137 */
138 if (on(*tp, HASFIRE)) {
139 register struct linked_list *fire_item;
140
141 fire_item = creat_item();
142 ldata(fire_item) = (char *) tp;
143 attach(rp->r_fires, fire_item);
144 rp->r_flags |= HASFIRE;
145 }
146 }
147 }
148 }
149
150
151 /*
152 * Draw a box around a room
153 */
154
155 draw_room(rp)
156 register struct room *rp;
157 {
158 register int j, k;
159
160 move(rp->r_pos.y, rp->r_pos.x+1);
161 vert(rp->r_max.y-2); /* Draw left side */
162 move(rp->r_pos.y+rp->r_max.y-1, rp->r_pos.x);
163 horiz(rp->r_max.x); /* Draw bottom */
164 move(rp->r_pos.y, rp->r_pos.x);
165 horiz(rp->r_max.x); /* Draw top */
166 vert(rp->r_max.y-2); /* Draw right side */
167 /*
168 * Put the floor down
169 */
170 for (j = 1; j < rp->r_max.y-1; j++)
171 {
172 move(rp->r_pos.y + j, rp->r_pos.x+1);
173 for (k = 1; k < rp->r_max.x-1; k++)
174 addch(FLOOR);
175 }
176 }
177
178 /*
179 * horiz:
180 * draw a horizontal line
181 */
182
183 horiz(cnt)
184 register int cnt;
185 {
186 while (cnt--)
187 addch('-');
188 }
189
190 /*
191 * rnd_pos:
192 * pick a random spot in a room
193 */
194
195 rnd_pos(rp, cp)
196 register struct room *rp;
197 register coord *cp;
198 {
199 cp->x = rp->r_pos.x + rnd(rp->r_max.x-2) + 1;
200 cp->y = rp->r_pos.y + rnd(rp->r_max.y-2) + 1;
201 }
202
203
204
205 /*
206 * roomin:
207 * Find what room some coordinates are in. NULL means they aren't
208 * in any room.
209 */
210
211 struct room *
212 roomin(cp)
213 register coord *cp;
214 {
215 register struct room *rp;
216
217 for (rp = rooms; rp < &rooms[MAXROOMS]; rp++)
218 if (inroom(rp, cp))
219 return rp;
220 return NULL;
221 }
222
223 /*
224 * vert:
225 * draw a vertical line
226 */
227
228 vert(cnt)
229 register int cnt;
230 {
231 register int x, y;
232
233 getyx(stdscr, y, x);
234 x--;
235 while (cnt--) {
236 move(++y, x);
237 addch('|');
238 }
239 }