comparison srogue/rooms.c @ 36:2128c7dc8a40

Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 25 Nov 2010 12:21:41 +0000
parents
children 94a0d9dd5ce1
comparison
equal deleted inserted replaced
35:05018c63a721 36:2128c7dc8a40
1 /*
2 * Draw the nine rooms on the screen
3 *
4 * @(#)rooms.c 9.0 (rdk) 7/17/84
5 *
6 * Super-Rogue
7 * Copyright (C) 1984 Robert D. Kindelberger
8 * All rights reserved.
9 *
10 * Based on "Rogue: Exploring the Dungeons of Doom"
11 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
12 * All rights reserved.
13 *
14 * See the file LICENSE.TXT for full copyright and licensing information.
15 */
16
17 #include "rogue.h"
18 #include "rogue.ext"
19
20 /*
21 * do_rooms:
22 * Place the rooms in the dungeon
23 */
24 do_rooms()
25 {
26 int mloops, mchance, nummons, left_out, roomtries;
27 bool treas = FALSE;
28 reg int i;
29 reg struct room *rp;
30 reg struct linked_list *item;
31 reg struct thing *tp;
32 struct coord top, bsze, mp;
33
34 /*
35 * bsze is the maximum room size
36 */
37 bsze.x = COLS / 3;
38 bsze.y = (LINES - 1) / 3;
39 /*
40 * Clear things for a new level
41 */
42 for (rp = rooms; rp < &rooms[MAXROOMS]; rp++)
43 rp->r_goldval = rp->r_nexits = rp->r_flags = 0;
44 /*
45 * Put the gone rooms, if any, on the level
46 */
47 left_out = rnd(4);
48 for (i = 0; i < left_out; i++)
49 rooms[rnd_room()].r_flags |= ISGONE;
50 /*
51 * dig and populate all the rooms on the level
52 */
53 for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++) {
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 (rf_on(rp,ISGONE)) {
60 /*
61 * Place a gone room. Make certain that there is a
62 * blank line for passage drawing.
63 */
64 roomtries = 0;
65 do {
66 rp->r_pos.x = top.x + rnd(bsze.x-2) + 1;
67 rp->r_pos.y = top.y + rnd(bsze.y-2) + 1;
68 rp->r_max.x = -COLS;
69 rp->r_max.x = -LINES;
70 if (++roomtries > 250)
71 fatal("failed to place a gone room");
72 } until(rp->r_pos.y > 0 && rp->r_pos.y < LINES-2);
73 continue;
74 }
75 if (rnd(10) < level-1)
76 rp->r_flags |= ISDARK;
77 /*
78 * Find a place and size for a random room
79 */
80 roomtries = 0;
81 do {
82 rp->r_max.x = rnd(bsze.x - 4) + 4;
83 rp->r_max.y = rnd(bsze.y - 4) + 4;
84 rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x);
85 rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y);
86 if (++roomtries > 250) {
87 fatal("failed to place a good room");
88 }
89 } until (rp->r_pos.y != 0);
90 if (level < max_level)
91 mchance = 30; /* 30% when going up (all monsters) */
92 else
93 mchance = 3; /* 3% when going down */
94 treas = FALSE;
95 if (rnd(100) < mchance && (rp->r_max.x * rp->r_max.y) >
96 ((bsze.x * bsze.y * 55) / 100)) {
97 treas = TRUE;
98 rp->r_flags |= ISTREAS;
99 rp->r_flags |= ISDARK;
100 }
101 /*
102 * Put the gold in
103 */
104 if ((rnd(100) < 50 || treas) && (!amulet || level >= max_level)) {
105 rp->r_goldval = GOLDCALC;
106 if (treas)
107 rp->r_goldval += 200 + (15 * (rnd(level) + 2));
108 rp->r_gold.y = rp->r_pos.y + rnd(rp->r_max.y - 2) + 1;
109 rp->r_gold.x = rp->r_pos.x + rnd(rp->r_max.x - 2) + 1;
110 }
111 draw_room(rp);
112 /*
113 * Put the monster in
114 */
115 if (treas) {
116 mloops = rnd(level / 3) + 6;
117 mchance = 1;
118 }
119 else {
120 mloops = 1;
121 mchance = 100;
122 }
123 for (nummons = 0; nummons < mloops; nummons++) {
124 if (rnd(mchance) < (rp->r_goldval > 0 ? 80 : 25))
125 add_mon(rp, treas);
126 }
127 }
128 }
129
130 /*
131 * add_mon:
132 * Add a monster to a room
133 */
134 add_mon(rm, treas)
135 struct room *rm;
136 bool treas;
137 {
138 reg struct thing *tp;
139 reg struct linked_list *item;
140 struct coord mp;
141 int chance;
142
143 mp = *rnd_pos(rm);
144 item = new_monster(rnd_mon(FALSE,FALSE), &mp, treas);
145 tp = THINGPTR(item);
146 chance = rnd(100);
147 if (levtype == MAZELEV)
148 chance = rnd(50);
149 /*
150 * See if monster has a treasure
151 */
152 if (levtype == MAZELEV && rnd(100) < 20) {
153 reg struct linked_list *fd;
154
155 fd = new_thing(FALSE, FOOD, 0);
156 attach(tp->t_pack, fd);
157 }
158 else {
159 if (chance < monsters[tp->t_indx].m_carry)
160 attach(tp->t_pack, new_thing(FALSE, ANYTHING));
161 }
162 }
163
164 /*
165 * draw_room:
166 * Draw a box around a room
167 */
168 draw_room(rp)
169 struct room *rp;
170 {
171 reg int j, k;
172
173 move(rp->r_pos.y, rp->r_pos.x+1);
174 vert(rp->r_max.y-2); /* Draw left side */
175 move(rp->r_pos.y+rp->r_max.y-1, rp->r_pos.x);
176 horiz(rp->r_max.x); /* Draw bottom */
177 move(rp->r_pos.y, rp->r_pos.x);
178 horiz(rp->r_max.x); /* Draw top */
179 vert(rp->r_max.y-2); /* Draw right side */
180 /*
181 * Put the floor down
182 */
183 for (j = 1; j < rp->r_max.y - 1; j++) {
184 move(rp->r_pos.y + j, rp->r_pos.x + 1);
185 for (k = 1; k < rp->r_max.x - 1; k++) {
186 addch(FLOOR);
187 }
188 }
189 /*
190 * Put the gold there
191 */
192 if (rp->r_goldval > 0)
193 mvaddch(rp->r_gold.y, rp->r_gold.x, GOLD);
194 }
195
196 /*
197 * horiz:
198 * draw a horizontal line
199 */
200 horiz(cnt)
201 int cnt;
202 {
203 while (cnt-- > 0)
204 addch('-');
205 }
206
207
208 /*
209 * vert:
210 * draw a vertical line
211 */
212 vert(cnt)
213 int cnt;
214 {
215 reg int x, y;
216
217 getyx(stdscr, y, x);
218 x--;
219 while (cnt-- > 0) {
220 move(++y, x);
221 addch('|');
222 }
223 }
224
225
226 /*
227 * rnd_pos:
228 * pick a random spot in a room
229 */
230 struct coord *
231 rnd_pos(rp)
232 struct room *rp;
233 {
234 reg int y, x, i;
235 static struct coord spot;
236
237 i = 0;
238 do {
239 x = rp->r_pos.x + rnd(rp->r_max.x - 2) + 1;
240 y = rp->r_pos.y + rnd(rp->r_max.y - 2) + 1;
241 i += 1;
242 } while(winat(y, x) != FLOOR && i < 1000);
243 spot.x = x;
244 spot.y = y;
245 return &spot;
246 }
247
248 /*
249 * rf_on:
250 * Returns TRUE if flag is set for room stuff
251 */
252 rf_on(rm, bit)
253 struct room *rm;
254 long bit;
255 {
256 return (rm->r_flags & bit);
257 }